Package weka.gui.arffviewer

Examples of weka.gui.arffviewer.ArffViewerMainPanel


      jMenuItemToolsArffViewer.setMnemonic('A');
      jMenuItemToolsArffViewer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsArffViewer.getText();
    if (!containsWindow(title)) {
      ArffViewerMainPanel panel = new ArffViewerMainPanel(null);
      panel.setConfirmExit(false);
      Container frame = createFrame(
    m_Self, title, panel, new BorderLayout(),
    BorderLayout.CENTER, 800, 600, panel.getMenu(), true, true);
      panel.setParent(frame);
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });

      // Tools/SqlViewer
      jMenuItemToolsSqlViewer = new JMenuItem();
      jMenuTools.add(jMenuItemToolsSqlViewer);
      jMenuItemToolsSqlViewer.setText(Messages.getInstance().getString("Main_InitGUI_JMenuItemToolsSqlViewer_SetText_Text")); //"SqlViewer"
      jMenuItemToolsSqlViewer.setMnemonic('S');
      jMenuItemToolsSqlViewer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsSqlViewer.getText();
    if (!containsWindow(title)) {
      final SqlViewer sql = new SqlViewer(null);
      final Container frame = createFrame(
    m_Self, title, sql, new BorderLayout(),
    BorderLayout.CENTER, -1, -1, null, false, true);

      // custom listener
      if (frame instanceof ChildFrameMDI) {
        ((ChildFrameMDI) frame).addInternalFrameListener(new InternalFrameAdapter() {
    public void internalFrameClosing(InternalFrameEvent e) {
      sql.saveSize();
      ((ChildFrameMDI) frame).dispose();
    }
        });
      }
      else if (frame instanceof ChildFrameSDI) {
        ((ChildFrameSDI) frame).addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
      sql.saveSize();
      ((ChildFrameSDI) frame).dispose();
    }
        });
      }
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });
     
      // Tools/Bayes net editor
      // Tools/Bayes net editor
      final JMenuItem jMenuItemBayesNet = new JMenuItem();
      jMenuTools.add(jMenuItemBayesNet);
      jMenuItemBayesNet.setText(Messages.getInstance().getString("Main_InitGUI_JMenuItemBayesNet_SetText_Text"));
      jMenuItemBayesNet.setMnemonic('N');

      jMenuItemBayesNet.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          String title = jMenuItemBayesNet.getText();
         
          if (!containsWindow(title)) {
            final GUI bayesNetGUI = new GUI();
            final Container frame = createFrame(
                m_Self, title, bayesNetGUI, new BorderLayout(),
                BorderLayout.CENTER, 800, 600, bayesNetGUI.getMenuBar(), false, true);
          }
          else {
            showWindow(getWindow(title));
          }         
        }      
      });

      // Tools/EnsembleLibrary
      /* currently disabled due to bugs... FracPete
      jMenuItemToolsEnsembleLibrary = new JMenuItem();
      jMenuTools.add(jMenuItemToolsEnsembleLibrary);
      jMenuItemToolsEnsembleLibrary.setText("EnsembleLibrary");
      jMenuItemToolsEnsembleLibrary.setMnemonic('E');
      jMenuItemToolsEnsembleLibrary.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsEnsembleLibrary.getText();
    if (!containsWindow(title)) {
      EnsembleLibrary value = new EnsembleLibrary();
      EnsembleLibraryEditor libraryEditor = new EnsembleLibraryEditor();
      libraryEditor.setValue(value);
      createFrame(
    m_Self, title, libraryEditor.getCustomEditor(), new BorderLayout(),
    BorderLayout.CENTER, 800, 600, null, true, true);
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });
      */

      // Visualization
      jMenuVisualization = new JMenu();
      jMenuBar.add(jMenuVisualization);
      jMenuVisualization.setText(Messages.getInstance().getString("Main_InitGUI_JMenuVisualization_SetText_Text"));
      jMenuVisualization.setMnemonic('V');

      // Visualization/Plot
      jMenuItemVisualizationPlot = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationPlot);
      jMenuItemVisualizationPlot.setText(Messages.getInstance().getString("Main_InitGUI_JMenuItemVisualizationPlot_SetText_Text"));
      jMenuItemVisualizationPlot.setMnemonic('P');
      jMenuItemVisualizationPlot.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserPlot.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build plot
    VisualizePanel panel = new VisualizePanel();
    String filenames = "";
    File[] files = m_FileChooserPlot.getSelectedFiles();
    for (int j = 0; j < files.length; j++) {
      String filename = files[j].getAbsolutePath();
      if (j > 0)
        filenames += ", ";
      filenames += filename;
      System.err.println(Messages.getInstance().getString("Main_InitGUI_Error_Text") + filename);
      try {
        Reader r = new java.io.BufferedReader(new FileReader(filename));
        Instances i = new Instances(r);
        i.setClassIndex(i.numAttributes()-1);
        PlotData2D pd1 = new PlotData2D(i);

        if (j == 0) {
    pd1.setPlotName(Messages.getInstance().getString("Main_InitGUI_Pd1_SetPlotName_Text_First"));
    panel.setMasterPlot(pd1);
        } else {
    pd1.setPlotName(Messages.getInstance().getString("Main_InitGUI_Pd1_SetPlotName_Text_Second") + (j+1));
    pd1.m_useCustomColour = true;
    pd1.m_customColour = (j % 2 == 0) ? Color.red : Color.blue;
    panel.addPlot(pd1);
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
      m_Self, Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_First") + files[j] + Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Second") + e.getMessage());
        return;
      }
    }

    // create frame
    createFrame(
        m_Self, jMenuItemVisualizationPlot.getText() + " - " + filenames,
        panel, new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/ROC
      // based on this Wiki article:
      // http://weka.sourceforge.net/wiki/index.php/Visualizing_ROC_curve
      jMenuItemVisualizationROC = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationROC);
      jMenuItemVisualizationROC.setText(Messages.getInstance().getString("Main_InitGUI_JMenuItemVisualizationROC_SetText_Text"));
      jMenuItemVisualizationROC.setMnemonic('R');
      jMenuItemVisualizationROC.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserROC.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // create plot
    String filename  = m_FileChooserROC.getSelectedFile().getAbsolutePath();
    Instances result = null;
    try {
      result = new Instances(new BufferedReader(new FileReader(filename)));
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Third") + filename + Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Fourth") + e.getMessage());
      return;
    }
    result.setClassIndex(result.numAttributes() - 1);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString(Messages.getInstance().getString("Main_InitGUI_Vmc_SetROCString_Text") +
        Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
    vmc.setName(result.relationName());
    PlotData2D tempd = new PlotData2D(result);
    tempd.setPlotName(result.relationName());
    tempd.addInstanceNumberAttribute();
    try {
      vmc.addPlot(tempd);
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Fifth") + e.getMessage());
      return;
    }

    createFrame(
        m_Self, jMenuItemVisualizationROC.getText() + " - " + filename,
        vmc, new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/TreeVisualizer
      jMenuItemVisualizationTreeVisualizer = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationTreeVisualizer);
      jMenuItemVisualizationTreeVisualizer.setText(Messages.getInstance().getString("Main_InitGUI_JMenuItemVisualizationTreeVisualizer_SetText_Text"));
      jMenuItemVisualizationTreeVisualizer.setMnemonic('T');
      jMenuItemVisualizationTreeVisualizer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserTreeVisualizer.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build tree
    String filename = m_FileChooserTreeVisualizer.getSelectedFile().getAbsolutePath();
    TreeBuild builder = new TreeBuild();
    Node top = null;
    NodePlace arrange = new PlaceNode2();
    try {
      top = builder.create(new FileReader(filename));
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Sixth") + filename + Messages.getInstance().getString("Main_InitGUI_Exception_JOptionPaneShowMessageDialog_Text_Seventh") + e.getMessage());
      return;
    }

    // create frame
    createFrame(
        m_Self, jMenuItemVisualizationTreeVisualizer.getText() + " - " + filename,
        new TreeVisualizer(null, top, arrange), new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/GraphVisualizer
      jMenuItemVisualizationGraphVisualizer = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationGraphVisualizer);
      jMenuItemVisualizationGraphVisualizer.setText(Messages.getInstance().getString("Main_InitGUI_JMenuItemVisualizationGraphVisualizer_SetText_Text"));
      jMenuItemVisualizationGraphVisualizer.setMnemonic('G');
      jMenuItemVisualizationGraphVisualizer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserGraphVisualizer.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build graph
    String filename = m_FileChooserGraphVisualizer.getSelectedFile().getAbsolutePath();
    GraphVisualizer panel = new GraphVisualizer();
    try{
      if (    filename.toLowerCase().endsWith(".xml")
    || filename.toLowerCase().endsWith(".bif") ) {
        panel.readBIF(new FileInputStream(filename));
      }
      else {
        panel.readDOT(new FileReader(filename));
      }
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
View Full Code Here


      jMenuItemToolsArffViewer.setMnemonic('A');
      jMenuItemToolsArffViewer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsArffViewer.getText();
    if (!containsWindow(title)) {
      ArffViewerMainPanel panel = new ArffViewerMainPanel(null);
      panel.setConfirmExit(false);
      Container frame = createFrame(
    m_Self, title, panel, new BorderLayout(),
    BorderLayout.CENTER, 800, 600, panel.getMenu(), true, true);
      panel.setParent(frame);
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });

      // Tools/SqlViewer
      jMenuItemToolsSqlViewer = new JMenuItem();
      jMenuTools.add(jMenuItemToolsSqlViewer);
      jMenuItemToolsSqlViewer.setText("SqlViewer");
      jMenuItemToolsSqlViewer.setMnemonic('S');
      jMenuItemToolsSqlViewer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsSqlViewer.getText();
    if (!containsWindow(title)) {
      final SqlViewer sql = new SqlViewer(null);
      final Container frame = createFrame(
    m_Self, title, sql, new BorderLayout(),
    BorderLayout.CENTER, -1, -1, null, false, true);

      // custom listener
      if (frame instanceof ChildFrameMDI) {
        ((ChildFrameMDI) frame).addInternalFrameListener(new InternalFrameAdapter() {
    public void internalFrameClosing(InternalFrameEvent e) {
      sql.saveSize();
      ((ChildFrameMDI) frame).dispose();
    }
        });
      }
      else if (frame instanceof ChildFrameSDI) {
        ((ChildFrameSDI) frame).addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
      sql.saveSize();
      ((ChildFrameSDI) frame).dispose();
    }
        });
      }
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });

      // Tools/EnsembleLibrary
      /* currently disabled due to bugs... FracPete
      jMenuItemToolsEnsembleLibrary = new JMenuItem();
      jMenuTools.add(jMenuItemToolsEnsembleLibrary);
      jMenuItemToolsEnsembleLibrary.setText("EnsembleLibrary");
      jMenuItemToolsEnsembleLibrary.setMnemonic('E');
      jMenuItemToolsEnsembleLibrary.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsEnsembleLibrary.getText();
    if (!containsWindow(title)) {
      EnsembleLibrary value = new EnsembleLibrary();
      EnsembleLibraryEditor libraryEditor = new EnsembleLibraryEditor();
      libraryEditor.setValue(value);
      createFrame(
    m_Self, title, libraryEditor.getCustomEditor(), new BorderLayout(),
    BorderLayout.CENTER, 800, 600, null, true, true);
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });
      */

      // Visualization
      jMenuVisualization = new JMenu();
      jMenuBar.add(jMenuVisualization);
      jMenuVisualization.setText("Visualization");
      jMenuVisualization.setMnemonic('V');

      // Visualization/Plot
      jMenuItemVisualizationPlot = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationPlot);
      jMenuItemVisualizationPlot.setText("Plot");
      jMenuItemVisualizationPlot.setMnemonic('P');
      jMenuItemVisualizationPlot.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserPlot.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build plot
    VisualizePanel panel = new VisualizePanel();
    String filenames = "";
    File[] files = m_FileChooserPlot.getSelectedFiles();
    for (int j = 0; j < files.length; j++) {
      String filename = files[j].getAbsolutePath();
      if (j > 0)
        filenames += ", ";
      filenames += filename;
      System.err.println("Loading instances from " + filename);
      try {
        Reader r = new java.io.BufferedReader(new FileReader(filename));
        Instances i = new Instances(r);
        i.setClassIndex(i.numAttributes()-1);
        PlotData2D pd1 = new PlotData2D(i);

        if (j == 0) {
    pd1.setPlotName("Master plot");
    panel.setMasterPlot(pd1);
        } else {
    pd1.setPlotName("Plot "+(j+1));
    pd1.m_useCustomColour = true;
    pd1.m_customColour = (j % 2 == 0) ? Color.red : Color.blue;
    panel.addPlot(pd1);
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
      m_Self, "Error loading file '" + files[j] + "':\n" + e.getMessage());
        return;
      }
    }

    // create frame
    createFrame(
        m_Self, jMenuItemVisualizationPlot.getText() + " - " + filenames,
        panel, new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/ROC
      // based on this Wiki article:
      // http://weka.sourceforge.net/wiki/index.php/Visualizing_ROC_curve
      jMenuItemVisualizationROC = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationROC);
      jMenuItemVisualizationROC.setText("ROC");
      jMenuItemVisualizationROC.setMnemonic('R');
      jMenuItemVisualizationROC.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserROC.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // create plot
    String filename  = m_FileChooserROC.getSelectedFile().getAbsolutePath();
    Instances result = null;
    try {
      result = new Instances(new BufferedReader(new FileReader(filename)));
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, "Error loading file '" + filename + "':\n" + e.getMessage());
      return;
    }
    result.setClassIndex(result.numAttributes() - 1);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString("(Area under ROC = " +
        Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
    vmc.setName(result.relationName());
    PlotData2D tempd = new PlotData2D(result);
    tempd.setPlotName(result.relationName());
    tempd.addInstanceNumberAttribute();
    try {
      vmc.addPlot(tempd);
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, "Error adding plot:\n" + e.getMessage());
      return;
    }

    createFrame(
        m_Self, jMenuItemVisualizationROC.getText() + " - " + filename,
        vmc, new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/TreeVisualizer
      jMenuItemVisualizationTreeVisualizer = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationTreeVisualizer);
      jMenuItemVisualizationTreeVisualizer.setText("TreeVisualizer");
      jMenuItemVisualizationTreeVisualizer.setMnemonic('T');
      jMenuItemVisualizationTreeVisualizer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserTreeVisualizer.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build tree
    String filename = m_FileChooserTreeVisualizer.getSelectedFile().getAbsolutePath();
    TreeBuild builder = new TreeBuild();
    Node top = null;
    NodePlace arrange = new PlaceNode2();
    try {
      top = builder.create(new FileReader(filename));
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, "Error loading file '" + filename + "':\n" + e.getMessage());
      return;
    }

    // create frame
    createFrame(
        m_Self, jMenuItemVisualizationTreeVisualizer.getText() + " - " + filename,
        new TreeVisualizer(null, top, arrange), new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/GraphVisualizer
      jMenuItemVisualizationGraphVisualizer = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationGraphVisualizer);
      jMenuItemVisualizationGraphVisualizer.setText("GraphVisualizer");
      jMenuItemVisualizationGraphVisualizer.setMnemonic('G');
      jMenuItemVisualizationGraphVisualizer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserGraphVisualizer.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build graph
    String filename = m_FileChooserGraphVisualizer.getSelectedFile().getAbsolutePath();
    GraphVisualizer panel = new GraphVisualizer();
    try{
      if (    filename.toLowerCase().endsWith(".xml")
    || filename.toLowerCase().endsWith(".bif") ) {
        panel.readBIF(new FileInputStream(filename));
      }
      else {
        panel.readDOT(new FileReader(filename));
      }
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
View Full Code Here

      jMenuItemToolsArffViewer.setMnemonic('A');
      jMenuItemToolsArffViewer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsArffViewer.getText();
    if (!containsWindow(title)) {
      ArffViewerMainPanel panel = new ArffViewerMainPanel(null);
      panel.setConfirmExit(false);
      Container frame = createFrame(
    m_Self, title, panel, new BorderLayout(),
    BorderLayout.CENTER, 800, 600, panel.getMenu(), true, true);
      panel.setParent(frame);
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });

      // Tools/SqlViewer
      jMenuItemToolsSqlViewer = new JMenuItem();
      jMenuTools.add(jMenuItemToolsSqlViewer);
      jMenuItemToolsSqlViewer.setText("SqlViewer");
      jMenuItemToolsSqlViewer.setMnemonic('S');
      jMenuItemToolsSqlViewer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsSqlViewer.getText();
    if (!containsWindow(title)) {
      final SqlViewer sql = new SqlViewer(null);
      final Container frame = createFrame(
    m_Self, title, sql, new BorderLayout(),
    BorderLayout.CENTER, -1, -1, null, false, true);

      // custom listener
      if (frame instanceof ChildFrameMDI) {
        ((ChildFrameMDI) frame).addInternalFrameListener(new InternalFrameAdapter() {
    public void internalFrameClosing(InternalFrameEvent e) {
      sql.saveSize();
      ((ChildFrameMDI) frame).dispose();
    }
        });
      }
      else if (frame instanceof ChildFrameSDI) {
        ((ChildFrameSDI) frame).addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
      sql.saveSize();
      ((ChildFrameSDI) frame).dispose();
    }
        });
      }
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });
     
      // Tools/Bayes net editor
      // Tools/Bayes net editor
      final JMenuItem jMenuItemBayesNet = new JMenuItem();
      jMenuTools.add(jMenuItemBayesNet);
      jMenuItemBayesNet.setText("Bayes net editor");
      jMenuItemBayesNet.setMnemonic('N');

      jMenuItemBayesNet.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          String title = jMenuItemBayesNet.getText();
         
          if (!containsWindow(title)) {
            final GUI bayesNetGUI = new GUI();
            final Container frame = createFrame(
                m_Self, title, bayesNetGUI, new BorderLayout(),
                BorderLayout.CENTER, 800, 600, bayesNetGUI.getMenuBar(), false, true);
          }
          else {
            showWindow(getWindow(title));
          }         
        }      
      });

      // Tools/Groovy console
      if (Groovy.isPresent()) {
  jMenuItemToolsGroovyConsole = new JMenuItem();
  jMenuTools.add(jMenuItemToolsGroovyConsole);
  jMenuItemToolsGroovyConsole.setText("Groovy console");
  jMenuItemToolsGroovyConsole.setMnemonic('G');
  jMenuItemToolsGroovyConsole.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
      String title = jMenuItemToolsGroovyConsole.getText();
      if (!containsWindow(title)) {
        final GroovyPanel panel = new GroovyPanel();
        final Container frame = createFrame(
      m_Self, title, panel, new BorderLayout(),
      BorderLayout.CENTER, 800, 600, panel.getMenuBar(), false, true);

        // custom listener
        if (frame instanceof ChildFrameMDI) {
    ((ChildFrameMDI) frame).addInternalFrameListener(new InternalFrameAdapter() {
      public void internalFrameClosing(InternalFrameEvent e) {
        ((ChildFrameMDI) frame).dispose();
      }
    });
        }
        else if (frame instanceof ChildFrameSDI) {
    ((ChildFrameSDI) frame).addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        ((ChildFrameSDI) frame).dispose();
      }
    });
        }
      }
      else {
        showWindow(getWindow(title));
      }
    }
  });
      }

      // Tools/Jython console
      if (Jython.isPresent()) {
  jMenuItemToolsJythonConsole = new JMenuItem();
  jMenuTools.add(jMenuItemToolsJythonConsole);
  jMenuItemToolsJythonConsole.setText("Jython console");
  jMenuItemToolsJythonConsole.setMnemonic('J');
  jMenuItemToolsJythonConsole.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
      String title = jMenuItemToolsJythonConsole.getText();
      if (!containsWindow(title)) {
        final JythonPanel panel = new JythonPanel();
        final Container frame = createFrame(
      m_Self, title, panel, new BorderLayout(),
      BorderLayout.CENTER, 800, 600, panel.getMenuBar(), false, true);

        // custom listener
        if (frame instanceof ChildFrameMDI) {
    ((ChildFrameMDI) frame).addInternalFrameListener(new InternalFrameAdapter() {
      public void internalFrameClosing(InternalFrameEvent e) {
        ((ChildFrameMDI) frame).dispose();
      }
    });
        }
        else if (frame instanceof ChildFrameSDI) {
    ((ChildFrameSDI) frame).addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        ((ChildFrameSDI) frame).dispose();
      }
    });
        }
      }
      else {
        showWindow(getWindow(title));
      }
    }
      });
      }

      // Tools/EnsembleLibrary
      /* currently disabled due to bugs... FracPete
      jMenuItemToolsEnsembleLibrary = new JMenuItem();
      jMenuTools.add(jMenuItemToolsEnsembleLibrary);
      jMenuItemToolsEnsembleLibrary.setText("EnsembleLibrary");
      jMenuItemToolsEnsembleLibrary.setMnemonic('E');
      jMenuItemToolsEnsembleLibrary.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    String title = jMenuItemToolsEnsembleLibrary.getText();
    if (!containsWindow(title)) {
      EnsembleLibrary value = new EnsembleLibrary();
      EnsembleLibraryEditor libraryEditor = new EnsembleLibraryEditor();
      libraryEditor.setValue(value);
      createFrame(
    m_Self, title, libraryEditor.getCustomEditor(), new BorderLayout(),
    BorderLayout.CENTER, 800, 600, null, true, true);
    }
    else {
      showWindow(getWindow(title));
    }
  }
      });
      */

      // Visualization
      jMenuVisualization = new JMenu();
      jMenuBar.add(jMenuVisualization);
      jMenuVisualization.setText("Visualization");
      jMenuVisualization.setMnemonic('V');

      // Visualization/Plot
      jMenuItemVisualizationPlot = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationPlot);
      jMenuItemVisualizationPlot.setText("Plot");
      jMenuItemVisualizationPlot.setMnemonic('P');
      jMenuItemVisualizationPlot.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserPlot.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build plot
    VisualizePanel panel = new VisualizePanel();
    String filenames = "";
    File[] files = m_FileChooserPlot.getSelectedFiles();
    for (int j = 0; j < files.length; j++) {
      String filename = files[j].getAbsolutePath();
      if (j > 0)
        filenames += ", ";
      filenames += filename;
      System.err.println("Loading instances from " + filename);
      try {
        Reader r = new java.io.BufferedReader(new FileReader(filename));
        Instances i = new Instances(r);
        i.setClassIndex(i.numAttributes()-1);
        PlotData2D pd1 = new PlotData2D(i);

        if (j == 0) {
    pd1.setPlotName("Master plot");
    panel.setMasterPlot(pd1);
        } else {
    pd1.setPlotName("Plot "+(j+1));
    pd1.m_useCustomColour = true;
    pd1.m_customColour = (j % 2 == 0) ? Color.red : Color.blue;
    panel.addPlot(pd1);
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
      m_Self, "Error loading file '" + files[j] + "':\n" + e.getMessage());
        return;
      }
    }

    // create frame
    createFrame(
        m_Self, jMenuItemVisualizationPlot.getText() + " - " + filenames,
        panel, new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/ROC
      // based on this Wiki article:
      // http://weka.sourceforge.net/wiki/index.php/Visualizing_ROC_curve
      jMenuItemVisualizationROC = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationROC);
      jMenuItemVisualizationROC.setText("ROC");
      jMenuItemVisualizationROC.setMnemonic('R');
      jMenuItemVisualizationROC.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserROC.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // create plot
    String filename  = m_FileChooserROC.getSelectedFile().getAbsolutePath();
    Instances result = null;
    try {
      result = new Instances(new BufferedReader(new FileReader(filename)));
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, "Error loading file '" + filename + "':\n" + e.getMessage());
      return;
    }
    result.setClassIndex(result.numAttributes() - 1);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString("(Area under ROC = " +
        Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
    vmc.setName(result.relationName());
    PlotData2D tempd = new PlotData2D(result);
    tempd.setPlotName(result.relationName());
    tempd.addInstanceNumberAttribute();
    try {
      vmc.addPlot(tempd);
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, "Error adding plot:\n" + e.getMessage());
      return;
    }

    createFrame(
        m_Self, jMenuItemVisualizationROC.getText() + " - " + filename,
        vmc, new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/TreeVisualizer
      jMenuItemVisualizationTreeVisualizer = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationTreeVisualizer);
      jMenuItemVisualizationTreeVisualizer.setText("TreeVisualizer");
      jMenuItemVisualizationTreeVisualizer.setMnemonic('T');
      jMenuItemVisualizationTreeVisualizer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserTreeVisualizer.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build tree
    String filename = m_FileChooserTreeVisualizer.getSelectedFile().getAbsolutePath();
    TreeBuild builder = new TreeBuild();
    Node top = null;
    NodePlace arrange = new PlaceNode2();
    try {
      top = builder.create(new FileReader(filename));
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
    m_Self, "Error loading file '" + filename + "':\n" + e.getMessage());
      return;
    }

    // create frame
    createFrame(
        m_Self, jMenuItemVisualizationTreeVisualizer.getText() + " - " + filename,
        new TreeVisualizer(null, top, arrange), new BorderLayout(),
        BorderLayout.CENTER, 800, 600, null, true, true);
  }
      });

      // Visualization/GraphVisualizer
      jMenuItemVisualizationGraphVisualizer = new JMenuItem();
      jMenuVisualization.add(jMenuItemVisualizationGraphVisualizer);
      jMenuItemVisualizationGraphVisualizer.setText("GraphVisualizer");
      jMenuItemVisualizationGraphVisualizer.setMnemonic('G');
      jMenuItemVisualizationGraphVisualizer.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    // choose file
    int retVal = m_FileChooserGraphVisualizer.showOpenDialog(m_Self);
    if (retVal != JFileChooser.APPROVE_OPTION)
      return;

    // build graph
    String filename = m_FileChooserGraphVisualizer.getSelectedFile().getAbsolutePath();
    GraphVisualizer panel = new GraphVisualizer();
    try{
      if (    filename.toLowerCase().endsWith(".xml")
    || filename.toLowerCase().endsWith(".bif") ) {
        panel.readBIF(new FileInputStream(filename));
      }
      else {
        panel.readDOT(new FileReader(filename));
      }
    }
    catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
View Full Code Here

TOP

Related Classes of weka.gui.arffviewer.ArffViewerMainPanel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.