001    /*
002     * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003     *
004     * This file is part of the Java Data Mining Package (JDMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * JDMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * JDMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with JDMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.jdmp.gui.util;
025    
026    import javax.swing.JFrame;
027    
028    import org.jdmp.core.CoreObject;
029    import org.jdmp.gui.algorithm.AlgorithmFrame;
030    import org.jdmp.gui.algorithm.AlgorithmGUIObject;
031    import org.jdmp.gui.dataset.DataSetFrame;
032    import org.jdmp.gui.dataset.DataSetGUIObject;
033    import org.jdmp.gui.module.ModuleFrame;
034    import org.jdmp.gui.module.ModuleGUIObject;
035    import org.jdmp.gui.sample.SampleFrame;
036    import org.jdmp.gui.sample.SampleGUIObject;
037    import org.jdmp.gui.variable.VariableFrame;
038    import org.jdmp.gui.variable.VariableGUIObject;
039    import org.ujmp.core.exceptions.MatrixException;
040    import org.ujmp.core.interfaces.GUIObject;
041    import org.ujmp.gui.MatrixGUIObject;
042    import org.ujmp.gui.frame.AbstractFrame;
043    import org.ujmp.gui.frame.MatrixFrame;
044    import org.ujmp.gui.util.FrameManager;
045    
046    public abstract class JDMPFrameManager {
047    
048            public static JFrame showFrame(GUIObject o) {
049                    if (o instanceof MatrixGUIObject) {
050                            return showFrame((MatrixGUIObject) o);
051                    } else if (o instanceof AlgorithmGUIObject) {
052                            return showFrame((AlgorithmGUIObject) o);
053                    } else if (o instanceof VariableGUIObject) {
054                            return showFrame((VariableGUIObject) o);
055                    } else if (o instanceof DataSetGUIObject) {
056                            return showFrame((DataSetGUIObject) o);
057                    } else if (o instanceof SampleGUIObject) {
058                            return showFrame((SampleGUIObject) o);
059                    } else if (o instanceof ModuleGUIObject) {
060                            return showFrame((ModuleGUIObject) o);
061                    } else {
062                            throw new MatrixException("cannot show frame for object: " + o);
063                    }
064            }
065    
066            public static JFrame showFrame(Object o) {
067                    if (o instanceof GUIObject) {
068                            return showFrame((GUIObject) o);
069                    } else if (o instanceof CoreObject) {
070                            return showFrame(((CoreObject) o).getGUIObject());
071                    } else {
072                            throw new MatrixException("wrong object type: " + o);
073                    }
074            }
075    
076            public static JFrame showFrame(MatrixGUIObject m) {
077                    try {
078                            AbstractFrame frame = FrameManager.getFrames().get(m);
079                            if (frame == null) {
080                                    frame = new MatrixFrame(m);
081                                    FrameManager.getFrames().put(m, frame);
082                            }
083                            frame.setVisible(true);
084                            return frame;
085                    } catch (Exception e) {
086                            e.printStackTrace();
087                            return null;
088                    }
089            }
090    
091            public static JFrame showFrame(AlgorithmGUIObject a) {
092                    try {
093                            AbstractFrame frame = FrameManager.getFrames().get(a);
094                            if (frame == null) {
095                                    frame = new AlgorithmFrame(a);
096                                    FrameManager.getFrames().put(a, frame);
097                            }
098                            frame.setVisible(true);
099                            return frame;
100                    } catch (Exception e) {
101                            e.printStackTrace();
102                            return null;
103                    }
104            }
105    
106            public static JFrame showFrame(VariableGUIObject v) {
107                    try {
108                            AbstractFrame frame = FrameManager.getFrames().get(v);
109                            if (frame == null) {
110                                    frame = new VariableFrame(v);
111                                    FrameManager.getFrames().put(v, frame);
112                            }
113                            frame.setVisible(true);
114                            return frame;
115                    } catch (Exception e) {
116                            e.printStackTrace();
117                            return null;
118                    }
119            }
120    
121            public static JFrame showFrame(ModuleGUIObject m) {
122                    try {
123                            AbstractFrame frame = FrameManager.getFrames().get(m);
124                            if (frame == null) {
125                                    frame = new ModuleFrame(m);
126                                    FrameManager.getFrames().put(m, frame);
127                            }
128                            frame.setVisible(true);
129                            return frame;
130                    } catch (Exception e) {
131                            e.printStackTrace();
132                            return null;
133                    }
134            }
135    
136            public static JFrame showFrame(DataSetGUIObject d) {
137                    try {
138                            AbstractFrame frame = FrameManager.getFrames().get(d);
139                            if (frame == null) {
140                                    frame = new DataSetFrame(d);
141                                    FrameManager.getFrames().put(d, frame);
142                            }
143                            frame.setVisible(true);
144                            return frame;
145                    } catch (Exception e) {
146                            e.printStackTrace();
147                            return null;
148                    }
149            }
150    
151            public static JFrame showFrame(SampleGUIObject s) {
152                    try {
153                            AbstractFrame frame = FrameManager.getFrames().get(s);
154                            if (frame == null) {
155                                    frame = new SampleFrame(s);
156                                    FrameManager.getFrames().put(s, frame);
157                            }
158                            frame.setVisible(true);
159                            return frame;
160                    } catch (Exception e) {
161                            e.printStackTrace();
162                            return null;
163                    }
164            }
165    
166    }