⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arffviewermainpanel.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @return 		true if project wasn't changed or saved   */  protected boolean saveChanges() {    return saveChanges(true);  }    /**   * if the file is changed it pops up a dialog whether to change the   * settings. if the project wasn't changed or saved it returns TRUE   *    * @param showCancel	whether we have YES/NO/CANCEL or only YES/NO   * @return 		true if project wasn't changed or saved   */  protected boolean saveChanges(boolean showCancel) {    int            button;    boolean        result;        if (!isPanelSelected())      return true;        result = !getCurrentPanel().isChanged();        if (getCurrentPanel().isChanged()) {      try {        if (showCancel)          button = ComponentHelper.showMessageBox(              this,              "Changed",              "The file is not saved - Do you want to save it?",              JOptionPane.YES_NO_CANCEL_OPTION,              JOptionPane.QUESTION_MESSAGE );        else          button = ComponentHelper.showMessageBox(              this,              "Changed",              "The file is not saved - Do you want to save it?",              JOptionPane.YES_NO_OPTION,              JOptionPane.QUESTION_MESSAGE );      }      catch (Exception e) {        button = JOptionPane.CANCEL_OPTION;       }            switch (button) {        case JOptionPane.YES_OPTION:          saveFile();          result = !getCurrentPanel().isChanged();          break;        case JOptionPane.NO_OPTION:          result = true;          break;        case JOptionPane.CANCEL_OPTION:           result = false;          break;      }    }        return result;  }  /**   * loads the specified file   *    * @param filename	the file to load   */  public void loadFile(String filename) {    ArffPanel         panel;    panel    = new ArffPanel(filename);    panel.addChangeListener(this);    tabbedPane.addTab(panel.getTitle(), panel);    tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);  }    /**   * loads the specified file into the table   */  public void loadFile() {    int               retVal;    int               i;    String            filename;        retVal = fileChooser.showOpenDialog(this);    if (retVal != ConverterFileChooser.APPROVE_OPTION)      return;        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));        for (i = 0; i< fileChooser.getSelectedFiles().length; i++) {      filename = fileChooser.getSelectedFiles()[i].getAbsolutePath();      loadFile(filename);    }        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  }    /**   * saves the current data into a file   */  public void saveFile() {    ArffPanel           panel;    String              filename;    AbstractSaver       saver;        // no panel? -> exit    panel = getCurrentPanel();    if (panel == null)      return;        filename = panel.getFilename();    if (filename.equals(ArffPanel.TAB_INSTANCES)) {      saveFileAs();    }    else {      saver = fileChooser.getSaver();      try {	saver.setInstances(panel.getInstances());	saver.writeBatch();	panel.setChanged(false);	setCurrentFilename(filename);      }      catch (Exception e) {	e.printStackTrace();      }    }  }    /**   * saves the current data into a new file   */  public void saveFileAs() {    int                  retVal;    ArffPanel            panel;        // no panel? -> exit    panel = getCurrentPanel();    if (panel == null) {      System.out.println("nothing selected!");      return;    }        if (!getCurrentFilename().equals("")) {      try {        fileChooser.setSelectedFile(new File(getCurrentFilename()));      }      catch (Exception e) {        // ignore      }    }        // set filter for savers    try {      fileChooser.setCapabilitiesFilter(Capabilities.forInstances(panel.getInstances()));    }    catch (Exception e) {      fileChooser.setCapabilitiesFilter(null);    }    retVal = fileChooser.showSaveDialog(this);    if (retVal != ConverterFileChooser.APPROVE_OPTION)      return;        panel.setChanged(false);    setCurrentFilename(fileChooser.getSelectedFile().getAbsolutePath());    saveFile();  }    /**   * closes the current tab   */  public void closeFile() {    closeFile(true);  }    /**   * closes the current tab   * @param showCancel           whether to show an additional CANCEL button   *                             in the "Want to save changes"-dialog   * @see                        #saveChanges(boolean)   */  public void closeFile(boolean showCancel) {    if (getCurrentIndex() == -1)      return;        if (!saveChanges(showCancel))      return;        tabbedPane.removeTabAt(getCurrentIndex());    updateFrameTitle();    System.gc();  }    /**   * closes all open files   */  public void closeAllFiles() {    while (tabbedPane.getTabCount() > 0) {      if (!saveChanges(true))        return;            tabbedPane.removeTabAt(getCurrentIndex());      updateFrameTitle();      System.gc();    }  }    /**   * displays some properties of the instances   */  public void showProperties() {    ArffPanel             panel;    ListSelectorDialog    dialog;    Vector                props;    Instances             inst;        panel = getCurrentPanel();    if (panel == null)      return;        inst  = panel.getInstances();    if (inst == null)      return;    if (inst.classIndex() < 0)      inst.setClassIndex(inst.numAttributes() - 1);        // get some data    props = new Vector();    props.add("Filename: " + panel.getFilename());    props.add("Relation name: " + inst.relationName());    props.add("# of instances: " + inst.numInstances());    props.add("# of attributes: " + inst.numAttributes());    props.add("Class attribute: " + inst.classAttribute().name());    props.add("# of class labels: " + inst.numClasses());        dialog = new ListSelectorDialog(getParentFrame(), new JList(props));    dialog.showDialog();  }    /**   * closes the window, i.e., if the parent is not null and implements   * the WindowListener interface it calls the windowClosing method   */  public void close() {    if (getParentInternalFrame() != null)      getParentInternalFrame().doDefaultCloseAction();    else if (getParentFrame() != null)      ((Window) getParentFrame()).dispatchEvent(	  new WindowEvent(	      (Window) getParentFrame(), WindowEvent.WINDOW_CLOSING));  }    /**   * undoes the last action    */  public void undo() {    if (!isPanelSelected())      return;        getCurrentPanel().undo();  }    /**   * copies the content of the selection to the clipboard   */  public void copyContent() {    if (!isPanelSelected())      return;        getCurrentPanel().copyContent();  }    /**   * searches for a string in the cells   */  public void search() {    if (!isPanelSelected())      return;    getCurrentPanel().search();  }    /**   * clears the search, i.e. resets the found cells   */  public void clearSearch() {    if (!isPanelSelected())      return;    getCurrentPanel().clearSearch();  }    /**   * renames the current selected Attribute   */  public void renameAttribute() {    if (!isPanelSelected())      return;        getCurrentPanel().renameAttribute();  }    /**   * sets the current selected Attribute as class attribute, i.e. it moves it   * to the end of the attributes   */  public void attributeAsClass() {    if (!isPanelSelected())      return;        getCurrentPanel().attributeAsClass();  }    /**   * deletes the current selected Attribute or several chosen ones   *    * @param multiple	whether to delete myultiple attributes   */  public void deleteAttribute(boolean multiple) {    if (!isPanelSelected())      return;        if (multiple)      getCurrentPanel().deleteAttributes();    else      getCurrentPanel().deleteAttribute();  }    /**   * deletes the current selected Instance or several chosen ones   *    * @param multiple		whether to delete multiple instances   */  public void deleteInstance(boolean multiple) {    if (!isPanelSelected())      return;        if (multiple)      getCurrentPanel().deleteInstances();    else      getCurrentPanel().deleteInstance();  }    /**   * sorts the current selected attribute   */  public void sortInstances() {    if (!isPanelSelected())      return;        getCurrentPanel().sortInstances();  }    /**   * displays all the attributes, returns the selected item or NULL if canceled   *    * @return		the name of the selected attribute   */  public String showAttributes() {    ArffSortedTableModel     model;    ListSelectorDialog  dialog;    int                 i;    JList               list;    String              name;    int                 result;        if (!isPanelSelected())      return null;        list   = new JList(getCurrentPanel().getAttributes());    dialog = new ListSelectorDialog(getParentFrame(), list);    result = dialog.showDialog();        if (result == ListSelectorDialog.APPROVE_OPTION) {      model = (ArffSortedTableModel) getCurrentPanel().getTable().getModel();      name  = list.getSelectedValue().toString();      i     = model.getAttributeColumn(name);      JTableHelper.scrollToVisible(getCurrentPanel().getTable(), 0, i);      getCurrentPanel().getTable().setSelectedColumn(i);      return name;    }    else {      return null;    }  }    /**   * displays all the distinct values for an attribute   */  public void showValues() {    String                attribute;    ArffSortedTableModel       model;    ArffTable             table;    HashSet               values;    Vector                items;    Iterator              iter;    ListSelectorDialog    dialog;    int                   i;    int                   col;        // choose attribute to retrieve values for    attribute = showAttributes();    if (attribute == null)      return;        table  = (ArffTable) getCurrentPanel().getTable();    model  = (ArffSortedTableModel) table.getModel();        // get column index    col    = -1;    for (i = 0; i < table.getColumnCount(); i++) {      if (table.getPlainColumnName(i).equals(attribute)) {        col = i;        break;      }    }    // not found?    if (col == -1)      return;        // get values    values = new HashSet();    items  = new Vector();    for (i = 0; i < model.getRowCount(); i++)      values.add(model.getValueAt(i, col).toString());    if (values.isEmpty())      return;    iter = values.iterator();    while (iter.hasNext())      items.add(iter.next());    Collections.sort(items);        dialog = new ListSelectorDialog(getParentFrame(), new JList(items));    dialog.showDialog();  }    /**   * sets the optimal column width for all columns   */  public void setOptimalColWidths() {    if (!isPanelSelected())      return;        getCurrentPanel().setOptimalColWidths();  }    /**   * invoked when an action occurs   *    * @param e		the action event   */  public void actionPerformed(ActionEvent e) {    Object          o;        o = e.getSource();        if (o == menuFileOpen)      loadFile();    else if (o == menuFileSave)      saveFile();    else if (o == menuFileSaveAs)      saveFileAs();    else if (o == menuFileClose)      closeFile();    else if (o == menuFileCloseAll)      closeAllFiles();    else if (o == menuFileProperties)      showProperties();    else if (o == menuFileExit)      close();    else if (o == menuEditUndo)      undo();    else if (o == menuEditCopy)      copyContent();    else if (o == menuEditSearch)      search();    else if (o == menuEditClearSearch)      clearSearch();    else if (o == menuEditDeleteAttribute)      deleteAttribute(false);    else if (o == menuEditDeleteAttributes)      deleteAttribute(true);    else if (o == menuEditRenameAttribute)      renameAttribute();    else if (o == menuEditAttributeAsClass)      attributeAsClass();    else if (o == menuEditDeleteInstance)      deleteInstance(false);    else if (o == menuEditDeleteInstances)      deleteInstance(true);    else if (o == menuEditSortInstances)      sortInstances();    else if (o == menuViewAttributes)      showAttributes();    else if (o == menuViewValues)      showValues();    else if (o == menuViewOptimalColWidths)      setOptimalColWidths();        updateMenu();  }    /**   * Invoked when the target of the listener has changed its state.   *    * @param e		the change event   */  public void stateChanged(ChangeEvent e) {    updateFrameTitle();    updateMenu();        // did the content of panel change? -> change title of tab    if (e.getSource() instanceof JComponent)      setTabTitle((JComponent) e.getSource());  }    /**   * returns only the classname   *    * @return		the classname   */  public String toString() {    return this.getClass().getName();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -