[4] | 1 | /* |
---|
| 2 | * This program is free software; you can redistribute it and/or modify |
---|
| 3 | * it under the terms of the GNU General Public License as published by |
---|
| 4 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 5 | * (at your option) any later version. |
---|
| 6 | * |
---|
| 7 | * This program is distributed in the hope that it will be useful, |
---|
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 10 | * GNU General Public License for more details. |
---|
| 11 | * |
---|
| 12 | * You should have received a copy of the GNU General Public License |
---|
| 13 | * along with this program; if not, write to the Free Software |
---|
| 14 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | /* |
---|
| 18 | * ScatterPlotMatrix.java |
---|
| 19 | * Copyright (C) 2003 University of Waikato, Hamilton, New Zealand |
---|
| 20 | * |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | package weka.gui.beans; |
---|
| 24 | |
---|
| 25 | import weka.core.Instances; |
---|
| 26 | import weka.gui.visualize.MatrixPanel; |
---|
| 27 | |
---|
| 28 | import java.awt.BorderLayout; |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | * Bean that encapsulates weka.gui.visualize.MatrixPanel for displaying a |
---|
| 32 | * scatter plot matrix. |
---|
| 33 | * |
---|
| 34 | * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a> |
---|
| 35 | * @version $Revision: 1.9 $ |
---|
| 36 | */ |
---|
| 37 | public class ScatterPlotMatrix |
---|
| 38 | extends DataVisualizer { |
---|
| 39 | |
---|
| 40 | /** for serialization */ |
---|
| 41 | private static final long serialVersionUID = -657856527563507491L; |
---|
| 42 | |
---|
| 43 | protected MatrixPanel m_matrixPanel; |
---|
| 44 | |
---|
| 45 | public ScatterPlotMatrix() { |
---|
| 46 | java.awt.GraphicsEnvironment ge = |
---|
| 47 | java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(); |
---|
| 48 | if (!ge.isHeadless()) { |
---|
| 49 | appearanceFinal(); |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * Global info for this bean |
---|
| 55 | * |
---|
| 56 | * @return a <code>String</code> value |
---|
| 57 | */ |
---|
| 58 | public String globalInfo() { |
---|
| 59 | return "Visualize incoming data/training/test sets in a scatter " |
---|
| 60 | +"plot matrix."; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | protected void appearanceDesign() { |
---|
| 64 | m_matrixPanel = null; |
---|
| 65 | removeAll(); |
---|
| 66 | m_visual = |
---|
| 67 | new BeanVisual("ScatterPlotMatrix", |
---|
| 68 | BeanVisual.ICON_PATH+"ScatterPlotMatrix.gif", |
---|
| 69 | BeanVisual.ICON_PATH+"ScatterPlotMatrix_animated.gif"); |
---|
| 70 | setLayout(new BorderLayout()); |
---|
| 71 | add(m_visual, BorderLayout.CENTER); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | protected void appearanceFinal() { |
---|
| 75 | removeAll(); |
---|
| 76 | setLayout(new BorderLayout()); |
---|
| 77 | setUpFinal(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | protected void setUpFinal() { |
---|
| 81 | if (m_matrixPanel == null) { |
---|
| 82 | m_matrixPanel = new MatrixPanel(); |
---|
| 83 | } |
---|
| 84 | add(m_matrixPanel, BorderLayout.CENTER); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | /** |
---|
| 88 | * Set instances for this bean. This method is a convenience method |
---|
| 89 | * for clients who use this component programatically |
---|
| 90 | * |
---|
| 91 | * @param inst an <code>Instances</code> value |
---|
| 92 | * @exception Exception if an error occurs |
---|
| 93 | */ |
---|
| 94 | public void setInstances(Instances inst) throws Exception { |
---|
| 95 | if (m_design) { |
---|
| 96 | throw new Exception("This method is not to be used during design " |
---|
| 97 | +"time. It is meant to be used if this " |
---|
| 98 | +"bean is being used programatically as as " |
---|
| 99 | +"stand alone component."); |
---|
| 100 | } |
---|
| 101 | m_visualizeDataSet = inst; |
---|
| 102 | m_matrixPanel.setInstances(m_visualizeDataSet); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * Perform a named user request |
---|
| 107 | * |
---|
| 108 | * @param request a string containing the name of the request to perform |
---|
| 109 | * @exception IllegalArgumentException if request is not supported |
---|
| 110 | */ |
---|
| 111 | public void performRequest(String request) { |
---|
| 112 | if (request.compareTo("Show plot") == 0) { |
---|
| 113 | try { |
---|
| 114 | // popup matrix panel |
---|
| 115 | if (!m_framePoppedUp) { |
---|
| 116 | m_framePoppedUp = true; |
---|
| 117 | final MatrixPanel vis = new MatrixPanel(); |
---|
| 118 | vis.setInstances(m_visualizeDataSet); |
---|
| 119 | |
---|
| 120 | final javax.swing.JFrame jf = |
---|
| 121 | new javax.swing.JFrame("Visualize"); |
---|
| 122 | jf.setSize(800,600); |
---|
| 123 | jf.getContentPane().setLayout(new BorderLayout()); |
---|
| 124 | jf.getContentPane().add(vis, BorderLayout.CENTER); |
---|
| 125 | jf.addWindowListener(new java.awt.event.WindowAdapter() { |
---|
| 126 | public void windowClosing(java.awt.event.WindowEvent e) { |
---|
| 127 | jf.dispose(); |
---|
| 128 | m_framePoppedUp = false; |
---|
| 129 | } |
---|
| 130 | }); |
---|
| 131 | jf.setVisible(true); |
---|
| 132 | m_popupFrame = jf; |
---|
| 133 | } else { |
---|
| 134 | m_popupFrame.toFront(); |
---|
| 135 | } |
---|
| 136 | } catch (Exception ex) { |
---|
| 137 | ex.printStackTrace(); |
---|
| 138 | m_framePoppedUp = false; |
---|
| 139 | } |
---|
| 140 | } else { |
---|
| 141 | throw new IllegalArgumentException(request |
---|
| 142 | + " not supported (ScatterPlotMatrix)"); |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | public static void main(String [] args) { |
---|
| 147 | try { |
---|
| 148 | if (args.length != 1) { |
---|
| 149 | System.err.println("Usage: ScatterPlotMatrix <dataset>"); |
---|
| 150 | System.exit(1); |
---|
| 151 | } |
---|
| 152 | java.io.Reader r = new java.io.BufferedReader( |
---|
| 153 | new java.io.FileReader(args[0])); |
---|
| 154 | Instances inst = new Instances(r); |
---|
| 155 | final javax.swing.JFrame jf = new javax.swing.JFrame(); |
---|
| 156 | jf.getContentPane().setLayout(new java.awt.BorderLayout()); |
---|
| 157 | final ScatterPlotMatrix as = new ScatterPlotMatrix(); |
---|
| 158 | as.setInstances(inst); |
---|
| 159 | |
---|
| 160 | jf.getContentPane().add(as, java.awt.BorderLayout.CENTER); |
---|
| 161 | jf.addWindowListener(new java.awt.event.WindowAdapter() { |
---|
| 162 | public void windowClosing(java.awt.event.WindowEvent e) { |
---|
| 163 | jf.dispose(); |
---|
| 164 | System.exit(0); |
---|
| 165 | } |
---|
| 166 | }); |
---|
| 167 | jf.setSize(800,600); |
---|
| 168 | jf.setVisible(true); |
---|
| 169 | } catch (Exception ex) { |
---|
| 170 | ex.printStackTrace(); |
---|
| 171 | System.err.println(ex.getMessage()); |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | } |
---|