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.variable;
025
026 import java.awt.BorderLayout;
027 import java.awt.Dimension;
028 import java.lang.reflect.Constructor;
029
030 import javax.swing.JPanel;
031 import javax.swing.JSplitPane;
032 import javax.swing.JTabbedPane;
033 import javax.swing.tree.TreeModel;
034
035 import org.jdmp.gui.matrix.MatrixListPanel;
036 import org.ujmp.core.Matrix;
037 import org.ujmp.core.exceptions.MatrixException;
038 import org.ujmp.core.util.GnuPlot;
039 import org.ujmp.core.util.Matlab;
040 import org.ujmp.core.util.Octave;
041 import org.ujmp.core.util.R;
042 import org.ujmp.gui.MatrixGUIObject;
043 import org.ujmp.gui.panels.AbstractPanel;
044 import org.ujmp.gui.panels.BufferedPanel;
045 import org.ujmp.gui.panels.GnuPlotPanel;
046 import org.ujmp.gui.panels.GraphPanel;
047 import org.ujmp.gui.panels.MatlabPanel;
048 import org.ujmp.gui.panels.MatrixEditorPanel;
049 import org.ujmp.gui.panels.MatrixPaintPanel;
050 import org.ujmp.gui.panels.MatrixTreePanel;
051 import org.ujmp.gui.panels.OctavePanel;
052 import org.ujmp.gui.panels.RPanel;
053 import org.ujmp.gui.plot.MatrixPlot;
054
055 public class VariablePanel extends AbstractPanel {
056 private static final long serialVersionUID = -4809155917354071285L;
057
058 public VariablePanel(VariableGUIObject v) throws MatrixException {
059 super(v);
060
061 MatrixGUIObject m = (MatrixGUIObject) v.getVariable().getAsMatrix().getGUIObject();
062
063 JSplitPane splitPane1 = new JSplitPane();
064 JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
065 JSplitPane splitPane3 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
066
067 JTabbedPane tabbedPane = new JTabbedPane();
068 tabbedPane.setMinimumSize(new Dimension(10, 10));
069
070 tabbedPane.add("2D Visualization", new MatrixPaintPanel(m, false));
071
072 if (false) {
073 try {
074 // tabbedPane.add("3D Visualization", new Matrix3DPanel(m,
075 // false));
076 } catch (Throwable t) {
077 }
078 }
079
080 if (m.getMatrix() instanceof TreeModel) {
081 tabbedPane.add("Tree View", new MatrixTreePanel(m));
082 }
083
084 try {
085 Class.forName("org.ujmp.jung.MatrixGraphPanel");
086 tabbedPane.add("Graph", new GraphPanel(m.getMatrix()));
087 } catch (Throwable e) {
088 }
089
090 try {
091 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotLinePanel");
092 Constructor<?> con = c.getConstructor(Matrix.class);
093 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
094 tabbedPane.add("Line Plot", panel);
095 } catch (Throwable e) {
096 }
097
098 try {
099 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotXYPanel");
100 Constructor<?> con = c.getConstructor(Matrix.class);
101 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
102 tabbedPane.add("XY Plot", panel);
103 } catch (Throwable e) {
104 }
105
106 try {
107 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotScatterPanel");
108 Constructor<?> con = c.getConstructor(Matrix.class);
109 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
110 tabbedPane.add("Scatter Plot", panel);
111 } catch (Throwable e) {
112 }
113
114 try {
115 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotBarPanel");
116 Constructor<?> con = c.getConstructor(Matrix.class);
117 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
118 tabbedPane.add("Bar Plot", panel);
119 } catch (Throwable e) {
120 }
121
122 try {
123 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotHistogramPanel");
124 Constructor<?> con = c.getConstructor(Matrix.class);
125 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
126 tabbedPane.add("Histogram", panel);
127 } catch (Throwable e) {
128 }
129
130 try {
131 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotStaircasePanel");
132 Constructor<?> con = c.getConstructor(Matrix.class);
133 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
134 tabbedPane.add("Staircase Plot", panel);
135 } catch (Throwable e) {
136 }
137
138 try {
139 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotGridPanel");
140 Constructor<?> con = c.getConstructor(Matrix.class);
141 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
142 tabbedPane.add("Grid Plot", panel);
143 } catch (Throwable e) {
144 }
145
146 try {
147 if (m.getColumnCount() >= 3) {
148 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotBar3DPanel");
149 Constructor<?> con = c.getConstructor(Matrix.class);
150 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
151 tabbedPane.add("Bar Plot 3D", panel);
152 }
153 } catch (Throwable e) {
154 }
155
156 try {
157 if (m.getColumnCount() >= 3) {
158 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotScatter3DPanel");
159 Constructor<?> con = c.getConstructor(Matrix.class);
160 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
161 tabbedPane.add("Scatter Plot 3D", panel);
162 }
163 } catch (Throwable e) {
164 }
165
166 try {
167 if (m.getColumnCount() >= 3) {
168 Class<?> c = Class.forName("org.ujmp.jmathplot.JMathPlotLine3DPanel");
169 Constructor<?> con = c.getConstructor(Matrix.class);
170 JPanel panel = (JPanel) con.newInstance(m.getMatrix());
171 tabbedPane.add("Line Plot 3D", panel);
172 }
173 } catch (Throwable e) {
174 }
175
176 if (GnuPlot.isAvailable()) {
177 GnuPlotPanel gnuPlotPanel = new GnuPlotPanel(m);
178 tabbedPane.add("GnuPlot", gnuPlotPanel);
179 }
180
181 if (Matlab.isAvailable()) {
182 MatlabPanel matlabPanel = new MatlabPanel(m);
183 tabbedPane.add("Matlab", matlabPanel);
184 }
185
186 if (Octave.isAvailable()) {
187 OctavePanel octavePanel = new OctavePanel(m);
188 tabbedPane.add("Octave", octavePanel);
189 }
190
191 if (R.isAvailable()) {
192 RPanel rPanel = new RPanel(m);
193 tabbedPane.add("R", rPanel);
194 }
195
196 splitPane2.setTopComponent(new BufferedPanel(new MatrixPlot(m, true)));
197 splitPane2.setBottomComponent(tabbedPane);
198
199 splitPane1.setLeftComponent(splitPane2);
200 splitPane1.setRightComponent(splitPane3);
201
202 splitPane3.setTopComponent(new MatrixListPanel(v.getVariable()));
203 splitPane3.setBottomComponent(new MatrixEditorPanel(m));
204
205 add(splitPane1, BorderLayout.CENTER);
206
207 splitPane1.setDividerLocation(600);
208 splitPane2.setDividerLocation(200);
209 splitPane3.setDividerLocation(200);
210
211 }
212 }