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.Octave; 035 import org.ujmp.gui.MatrixGUIObject; 036 037 public class OctavePanel extends JPanel { 038 private static final long serialVersionUID = -894693635404746973L; 039 040 private MatrixGUIObject matrix = null; 041 042 public OctavePanel(MatrixGUIObject m) { 043 this.matrix = m; 044 045 setLayout(new FlowLayout()); 046 047 add(new JButton(new MatrixPlotAction())); 048 add(new JButton(new XYPlotAction())); 049 add(new JButton(new ScatterPlotAction())); 050 add(new JButton(new HistogramPlotAction())); 051 } 052 053 class MatrixPlotAction extends AbstractAction { 054 private static final long serialVersionUID = -4928348084073744818L; 055 056 public MatrixPlotAction() { 057 super("Matrix Plot"); 058 } 059 060 public void actionPerformed(ActionEvent e) { 061 try { 062 Octave.getInstance().plot(matrix.getMatrix()); 063 } catch (Exception e1) { 064 e1.printStackTrace(); 065 } 066 } 067 } 068 069 class XYPlotAction extends AbstractAction { 070 private static final long serialVersionUID = 4954900597400686518L; 071 072 public XYPlotAction() { 073 super("XY Plot"); 074 } 075 076 public void actionPerformed(ActionEvent e) { 077 try { 078 Octave.getInstance().plot( 079 matrix.getMatrix().selectColumns(Ret.NEW, 0), 080 matrix.getMatrix().selectColumns(Ret.NEW, 1)); 081 } catch (Exception e1) { 082 e1.printStackTrace(); 083 } 084 } 085 } 086 087 class ScatterPlotAction extends AbstractAction { 088 private static final long serialVersionUID = 4837137928213709856L; 089 090 public ScatterPlotAction() { 091 super("Scatter Plot"); 092 } 093 094 public void actionPerformed(ActionEvent e) { 095 try { 096 Octave.getInstance().plot( 097 matrix.getMatrix().selectColumns(Ret.NEW, 0), 098 matrix.getMatrix().selectColumns(Ret.NEW, 1), "x"); 099 } catch (Exception e1) { 100 e1.printStackTrace(); 101 } 102 } 103 } 104 105 class HistogramPlotAction extends AbstractAction { 106 private static final long serialVersionUID = -1396238157254507002L; 107 108 public HistogramPlotAction() { 109 super("Histogram"); 110 } 111 112 public void actionPerformed(ActionEvent e) { 113 try { 114 Octave.getInstance().hist(matrix.getMatrix()); 115 } catch (Exception e1) { 116 e1.printStackTrace(); 117 } 118 } 119 } 120 }