arffviewermainpanel.java

来自「Weka」· Java 代码 · 共 1,059 行 · 第 1/3 页

JAVA
1,059
字号
  }    /**   * 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 + =
减小字号Ctrl + -
显示快捷键?