001    /*
002     * Copyright (C) 2008-2010 by Holger Arndt
003     *
004     * This file is part of the Universal Java Matrix Package (UJMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * UJMP 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     * UJMP 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 UJMP; 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.ujmp.gui.panels;
025    
026    import java.awt.FlowLayout;
027    import java.awt.event.ActionEvent;
028    
029    import javax.swing.AbstractAction;
030    import javax.swing.JButton;
031    import javax.swing.JPanel;
032    
033    import org.ujmp.core.calculation.Calculation.Ret;
034    import org.ujmp.core.util.Matlab;
035    import org.ujmp.gui.MatrixGUIObject;
036    
037    public class MatlabPanel extends JPanel {
038            private static final long serialVersionUID = -2014717060178963100L;
039    
040            private MatrixGUIObject matrix = null;
041    
042            public MatlabPanel(MatrixGUIObject m) {
043                    this.matrix = m;
044                    setLayout(new FlowLayout());
045    
046                    add(new JButton(new MatrixPlotAction()));
047                    add(new JButton(new XYPlotAction()));
048                    add(new JButton(new ScatterPlotAction()));
049                    add(new JButton(new HistogramAction()));
050                    add(new JButton(new SurfAction()));
051                    add(new JButton(new ImagescAction()));
052                    add(new JButton(new BarAction()));
053                    add(new JButton(new BarhAction()));
054                    add(new JButton(new StemAction()));
055                    add(new JButton(new PieAction()));
056                    add(new JButton(new Pie3Action()));
057                    add(new JButton(new PairsAction()));
058            }
059    
060            class ScatterPlotAction extends AbstractAction {
061                    private static final long serialVersionUID = 4837137928213709856L;
062    
063                    public ScatterPlotAction() {
064                            super("Scatter Plot");
065                    }
066    
067                    public void actionPerformed(ActionEvent e) {
068                            try {
069                                    Matlab.getInstance().plot(
070                                                    matrix.getMatrix().selectColumns(Ret.NEW, 0),
071                                                    matrix.getMatrix().selectColumns(Ret.NEW, 1), "x");
072                            } catch (Exception e1) {
073                                    e1.printStackTrace();
074                            }
075                    }
076            }
077    
078            class MatrixPlotAction extends AbstractAction {
079                    private static final long serialVersionUID = -4928348084073744818L;
080    
081                    public MatrixPlotAction() {
082                            super("Matrix Plot");
083                    }
084    
085                    public void actionPerformed(ActionEvent e) {
086                            try {
087                                    Matlab.getInstance().plot(matrix.getMatrix());
088                            } catch (Exception e1) {
089                                    e1.printStackTrace();
090                            }
091                    }
092            }
093    
094            class XYPlotAction extends AbstractAction {
095                    private static final long serialVersionUID = -4928348084073744818L;
096    
097                    public XYPlotAction() {
098                            super("XY Plot");
099                    }
100    
101                    public void actionPerformed(ActionEvent e) {
102                            try {
103                                    Matlab.getInstance().plot(
104                                                    matrix.getMatrix().selectColumns(Ret.NEW, 0),
105                                                    matrix.getMatrix().selectColumns(Ret.NEW, 1));
106                            } catch (Exception e1) {
107                                    e1.printStackTrace();
108                            }
109                    }
110            }
111    
112            class HistogramAction extends AbstractAction {
113                    private static final long serialVersionUID = -320738954210581946L;
114    
115                    public HistogramAction() {
116                            super("Histogram");
117                    }
118    
119                    public void actionPerformed(ActionEvent e) {
120                            try {
121                                    Matlab.getInstance().hist(matrix.getMatrix());
122                            } catch (Exception e1) {
123                                    e1.printStackTrace();
124                            }
125                    }
126            }
127    
128            class SurfAction extends AbstractAction {
129                    private static final long serialVersionUID = 1936056248662686441L;
130    
131                    public SurfAction() {
132                            super("Surf");
133                    }
134    
135                    public void actionPerformed(ActionEvent e) {
136                            try {
137                                    Matlab.getInstance().surf(matrix.getMatrix());
138                            } catch (Exception e1) {
139                                    e1.printStackTrace();
140                            }
141                    }
142            }
143    
144            class ImagescAction extends AbstractAction {
145                    private static final long serialVersionUID = -69661897898443618L;
146    
147                    public ImagescAction() {
148                            super("ImageSC");
149                    }
150    
151                    public void actionPerformed(ActionEvent e) {
152                            try {
153                                    Matlab.getInstance().imagesc(matrix.getMatrix());
154                            } catch (Exception e1) {
155                                    e1.printStackTrace();
156                            }
157                    }
158            }
159    
160            class BarAction extends AbstractAction {
161                    private static final long serialVersionUID = 2326046110179603901L;
162    
163                    public BarAction() {
164                            super("Bar");
165                    }
166    
167                    public void actionPerformed(ActionEvent e) {
168                            try {
169                                    Matlab.getInstance().bar(matrix.getMatrix());
170                            } catch (Exception e1) {
171                                    e1.printStackTrace();
172                            }
173                    }
174            }
175    
176            class BarhAction extends AbstractAction {
177                    private static final long serialVersionUID = 1773781454473042057L;
178    
179                    public BarhAction() {
180                            super("BarH");
181                    }
182    
183                    public void actionPerformed(ActionEvent e) {
184                            try {
185                                    Matlab.getInstance().barh(matrix.getMatrix());
186                            } catch (Exception e1) {
187                                    e1.printStackTrace();
188                            }
189                    }
190            }
191    
192            class StemAction extends AbstractAction {
193                    private static final long serialVersionUID = 8489278103292046885L;
194    
195                    public StemAction() {
196                            super("Stem");
197                    }
198    
199                    public void actionPerformed(ActionEvent e) {
200                            try {
201                                    Matlab.getInstance().stem(matrix.getMatrix());
202                            } catch (Exception e1) {
203                                    e1.printStackTrace();
204                            }
205                    }
206            }
207    
208            class PairsAction extends AbstractAction {
209                    private static final long serialVersionUID = 5809558873714857141L;
210    
211                    public PairsAction() {
212                            super("Pairs");
213                    }
214    
215                    public void actionPerformed(ActionEvent e) {
216                            try {
217                                    Matlab.getInstance().plotmatrix(matrix.getMatrix());
218                            } catch (Exception e1) {
219                                    e1.printStackTrace();
220                            }
221                    }
222            }
223    
224            class PieAction extends AbstractAction {
225                    private static final long serialVersionUID = -7468454385004258030L;
226    
227                    public PieAction() {
228                            super("Pie Chart");
229                    }
230    
231                    public void actionPerformed(ActionEvent e) {
232                            try {
233                                    Matlab.getInstance().pie(matrix.getMatrix());
234                            } catch (Exception e1) {
235                                    e1.printStackTrace();
236                            }
237                    }
238            }
239    
240            class Pie3Action extends AbstractAction {
241                    private static final long serialVersionUID = -6838327620135999067L;
242    
243                    public Pie3Action() {
244                            super("3D Pie Chart");
245                    }
246    
247                    public void actionPerformed(ActionEvent e) {
248                            try {
249                                    Matlab.getInstance().pie3(matrix.getMatrix());
250                            } catch (Exception e1) {
251                                    e1.printStackTrace();
252                            }
253                    }
254            }
255    
256    }