Explorer.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 7k
Category:

Windows Develop

Development Platform:

Java

  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.  *    Explorer.java
  18.  *    Copyright (C) 1999 Len Trigg
  19.  *
  20.  */
  21. package weka.gui.explorer;
  22. import weka.core.Utils;
  23. import weka.gui.LogPanel;
  24. import weka.gui.WekaTaskMonitor;
  25. import weka.gui.visualize.VisualizePanel;
  26. import weka.gui.visualize.PlotData2D;
  27. import java.io.File;
  28. import java.io.FileInputStream;
  29. import java.awt.GridLayout;
  30. import java.awt.BorderLayout;
  31. import java.awt.event.WindowAdapter;
  32. import java.awt.event.WindowEvent;
  33. import java.awt.event.ActionListener;
  34. import java.awt.event.ActionEvent;
  35. import java.beans.PropertyChangeEvent;
  36. import java.beans.PropertyChangeListener;
  37. import java.util.Date;
  38. import java.text.SimpleDateFormat;
  39. import javax.swing.JButton;
  40. import javax.swing.JFrame;
  41. import javax.swing.JTabbedPane;
  42. import javax.swing.JPanel;
  43. import javax.swing.JFileChooser;
  44. import javax.swing.filechooser.FileFilter;
  45. import javax.swing.JOptionPane;
  46. import javax.swing.JLabel;
  47. import javax.swing.SwingConstants;
  48. import java.awt.*;
  49. import java.awt.image.*;
  50. /** 
  51.  * The main class for the Weka explorer. Lets the user create,
  52.  * open, save, configure, datasets, and perform ML analysis.
  53.  *
  54.  * @author Len Trigg (trigg@cs.waikato.ac.nz)
  55.  * @version $Revision: 1.19 $
  56.  */
  57. public class Explorer extends JPanel {
  58.   /** The panel for preprocessing instances */
  59.   protected PreprocessPanel m_PreprocessPanel = new PreprocessPanel();
  60.   /** The panel for running classifiers */
  61.   protected ClassifierPanel m_ClassifierPanel = new ClassifierPanel();
  62.   /** Label for a panel that still need to be implemented */
  63.   protected ClustererPanel m_ClustererPanel = new ClustererPanel();
  64.   /** Label for a panel that still need to be implemented */
  65.   protected AssociationsPanel m_AssociationPanel = new AssociationsPanel();
  66.   /** Label for a panel that still need to be implemented */
  67.   protected AttributeSelectionPanel m_AttributeSelectionPanel =
  68.     new AttributeSelectionPanel();
  69.   /** Label for a panel that still need to be implemented */
  70.   protected VisualizePanel m_VisualizePanel =
  71.     new VisualizePanel();
  72.   
  73.   /** The tabbed pane that controls which sub-pane we are working with */
  74.   protected JTabbedPane m_TabbedPane = new JTabbedPane();
  75.   
  76.   /** The panel for log and status messages */
  77.   protected LogPanel m_LogPanel = new LogPanel(new WekaTaskMonitor());
  78.   /**
  79.    * Creates the experiment environment gui with no initial experiment
  80.    */
  81.   public Explorer() {
  82.     
  83.     /* try {
  84.       m_logPanel = new LogPanel(new WekaTaskMonitor());
  85.     } catch (Exception ex) {
  86.       System.exit(1);
  87.       } */
  88.     String date = (new SimpleDateFormat("EEEE, d MMMM yyyy"))
  89.       .format(new Date());
  90.     m_LogPanel.logMessage("Weka Knowledge Explorer was written by Len Trigg, Mark Hall and Eibe Frank");
  91.     m_LogPanel.logMessage("(c) 1999 The University of Waikato, Hamilton,"
  92.   + " New Zealand");
  93.     m_LogPanel.logMessage("web: http://www.cs.waikato.ac.nz/~ml/");
  94.     m_LogPanel.logMessage("email: wekasupport@cs.waikato.ac.nz");
  95.     m_LogPanel.logMessage("Started on " + date);
  96.     m_LogPanel.statusMessage("Welcome to the Weka Knowledge Explorer");
  97.     m_PreprocessPanel.setLog(m_LogPanel);
  98.     m_ClassifierPanel.setLog(m_LogPanel);
  99.     m_ClassifierPanel.setPreprocess(m_PreprocessPanel);
  100.     m_AssociationPanel.setLog(m_LogPanel);
  101.     m_ClustererPanel.setLog(m_LogPanel);
  102.     m_ClustererPanel.setPreprocess(m_PreprocessPanel);
  103.     m_AttributeSelectionPanel.setLog(m_LogPanel);
  104.     m_VisualizePanel.setLog(m_LogPanel);
  105.     m_TabbedPane.addTab("Preprocess", null, m_PreprocessPanel,
  106. "Open/Edit/Save instances");
  107.     m_TabbedPane.addTab("Classify", null, m_ClassifierPanel,
  108. "Classify instances");
  109.     m_TabbedPane.addTab("Cluster", null, m_ClustererPanel,
  110.       "Identify instance clusters");
  111.     m_TabbedPane.addTab("Associate", null, m_AssociationPanel,
  112.       "Discover association rules");
  113.     m_TabbedPane.addTab("Select attributes", null, m_AttributeSelectionPanel,
  114.       "Determine relevance of attributes");
  115.     m_TabbedPane.addTab("Visualize", null, m_VisualizePanel,
  116.       "Explore the data");
  117.     m_TabbedPane.setSelectedIndex(0);
  118.     m_TabbedPane.setEnabledAt(1, false);
  119.     m_TabbedPane.setEnabledAt(2, false);
  120.     m_TabbedPane.setEnabledAt(3, false);
  121.     m_TabbedPane.setEnabledAt(4, false);
  122.     m_TabbedPane.setEnabledAt(5, false);
  123.     m_PreprocessPanel.addPropertyChangeListener(new PropertyChangeListener() {
  124.       public void propertyChange(PropertyChangeEvent e) {
  125. m_ClassifierPanel.setInstances(m_PreprocessPanel
  126.                .getWorkingInstances());
  127. m_ClassifierPanel.filterUserTestInstances();
  128. m_AssociationPanel.setInstances(m_PreprocessPanel
  129.        .getWorkingInstances());
  130. m_ClustererPanel.setInstances(m_PreprocessPanel
  131.       .getWorkingInstances());
  132. m_ClustererPanel.filterUserTestInstances();
  133. m_AttributeSelectionPanel.setInstances(m_PreprocessPanel
  134.        .getWorkingInstances());
  135. try {
  136.   PlotData2D tempd = new PlotData2D(m_PreprocessPanel.
  137.     getWorkingInstances());
  138.   tempd.setPlotName(m_PreprocessPanel.
  139.     getWorkingInstances().relationName());
  140.   tempd.addInstanceNumberAttribute();
  141.   m_VisualizePanel.setMasterPlot(tempd);
  142. } catch (Exception ex) {
  143.   ex.printStackTrace();
  144.   m_LogPanel.logMessage(ex.toString());
  145. }
  146. m_TabbedPane.setEnabledAt(1, true);
  147. m_TabbedPane.setEnabledAt(2, true);
  148. m_TabbedPane.setEnabledAt(3, true);
  149. m_TabbedPane.setEnabledAt(4, true);
  150. m_TabbedPane.setEnabledAt(5, true);
  151.       }
  152.     });
  153.     setLayout(new BorderLayout());
  154.     add(m_TabbedPane, BorderLayout.CENTER);
  155.    
  156.     add(m_LogPanel, BorderLayout.SOUTH);
  157.     //add(p1, BorderLayout.SOUTH);
  158.   }
  159.   /**
  160.    * Tests out the explorer environment.
  161.    *
  162.    * @param args ignored.
  163.    */
  164.   public static void main(String [] args) {
  165.     try {
  166.       Explorer explorer = new Explorer();
  167.       final JFrame jf = new JFrame("Weka Knowledge Explorer");
  168.       jf.getContentPane().setLayout(new BorderLayout());
  169.       jf.getContentPane().add(explorer, BorderLayout.CENTER);
  170.       jf.addWindowListener(new WindowAdapter() {
  171. public void windowClosing(WindowEvent e) {
  172.   jf.dispose();
  173.   System.exit(0);
  174. }
  175.       });
  176.       jf.pack();
  177.       jf.setSize(800, 600);
  178.       jf.setVisible(true);
  179.       Image icon = Toolkit.getDefaultToolkit().
  180. getImage(ClassLoader.getSystemResource("weka/gui/weka_icon.gif"));
  181.       jf.setIconImage(icon);
  182.       if (args.length == 1) {
  183. System.err.println("Loading instances from " + args[0]);
  184. explorer.m_PreprocessPanel.setBaseInstancesFromFile(new File(args[0]));
  185.       }
  186.     } catch (Exception ex) {
  187.       ex.printStackTrace();
  188.       System.err.println(ex.getMessage());
  189.     }
  190.   }
  191. }