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.util.R; 034 import org.ujmp.gui.MatrixGUIObject; 035 036 public class RPanel extends JPanel { 037 private static final long serialVersionUID = -3779245352485347462L; 038 039 private MatrixGUIObject matrix = null; 040 041 public RPanel(MatrixGUIObject m) { 042 this.matrix = m; 043 044 setLayout(new FlowLayout()); 045 046 add(new JButton(new ScatterPlotAction())); 047 add(new JButton(new ImageAction())); 048 add(new JButton(new HistAction())); 049 add(new JButton(new PairsPlotAction())); 050 add(new JButton(new BoxPlotAction())); 051 add(new JButton(new QQNormAction())); 052 add(new JButton(new CloseLastFigureAction())); 053 054 } 055 056 class ScatterPlotAction extends AbstractAction { 057 private static final long serialVersionUID = -5429144529799026446L; 058 059 public ScatterPlotAction() { 060 super("Scatter Plot"); 061 } 062 063 public void actionPerformed(ActionEvent e) { 064 try { 065 R.getInstance().plot(matrix.getMatrix(), "col=\"blue\",pch=16"); 066 } catch (Exception e1) { 067 e1.printStackTrace(); 068 } 069 } 070 } 071 072 class BoxPlotAction extends AbstractAction { 073 private static final long serialVersionUID = -3887385311081144648L; 074 075 public BoxPlotAction() { 076 super("Box Plot"); 077 } 078 079 public void actionPerformed(ActionEvent e) { 080 try { 081 R.getInstance().boxplot(matrix.getMatrix(), "col=\"blue\""); 082 } catch (Exception e1) { 083 e1.printStackTrace(); 084 } 085 } 086 } 087 088 class PairsPlotAction extends AbstractAction { 089 private static final long serialVersionUID = -4346940332819549757L; 090 091 public PairsPlotAction() { 092 super("Pairs Plot"); 093 } 094 095 public void actionPerformed(ActionEvent e) { 096 try { 097 R.getInstance() 098 .pairs(matrix.getMatrix(), "col=\"blue\",pch=16"); 099 } catch (Exception e1) { 100 e1.printStackTrace(); 101 } 102 } 103 } 104 105 class QQNormAction extends AbstractAction { 106 private static final long serialVersionUID = -7646548720554325669L; 107 108 public QQNormAction() { 109 super("QQNorm"); 110 } 111 112 public void actionPerformed(ActionEvent e) { 113 try { 114 R.getInstance().qqnorm(matrix.getMatrix(), 115 "col=\"blue\",pch=16"); 116 } catch (Exception e1) { 117 e1.printStackTrace(); 118 } 119 } 120 } 121 122 class ImageAction extends AbstractAction { 123 private static final long serialVersionUID = 7429007259920214890L; 124 125 public ImageAction() { 126 super("Image"); 127 } 128 129 public void actionPerformed(ActionEvent e) { 130 try { 131 R.getInstance().image(matrix.getMatrix()); 132 } catch (Exception e1) { 133 e1.printStackTrace(); 134 } 135 } 136 } 137 138 class HistAction extends AbstractAction { 139 private static final long serialVersionUID = 8662123505287412855L; 140 141 public HistAction() { 142 super("Histogram"); 143 } 144 145 public void actionPerformed(ActionEvent e) { 146 try { 147 R.getInstance().hist(matrix.getMatrix(), "col=\"blue\""); 148 } catch (Exception e1) { 149 e1.printStackTrace(); 150 } 151 } 152 } 153 154 class CloseLastFigureAction extends AbstractAction { 155 private static final long serialVersionUID = 200834911041935616L; 156 157 public CloseLastFigureAction() { 158 super("Close last Figure"); 159 } 160 161 public void actionPerformed(ActionEvent e) { 162 try { 163 R.getInstance().closeLastFigure(); 164 } catch (Exception e1) { 165 e1.printStackTrace(); 166 } 167 } 168 } 169 170 }