arffviewermainpanel.java

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

JAVA
1,059
字号
  public String getFrameTitle() {    if (getCurrentFilename().equals(""))      return frameTitle;    else      return frameTitle + " - " + getCurrentFilename();  }    /**   * sets the title of the parent frame, if one was provided   */  public void updateFrameTitle() {    if (getParentFrame() != null)      getParentFrame().setTitle(getFrameTitle());    if (getParentInternalFrame() != null)      getParentInternalFrame().setTitle(getFrameTitle());  }    /**   * sets the enabled/disabled state of the menu    */  protected void updateMenu() {    boolean       fileOpen;    boolean       isChanged;    boolean       canUndo;        fileOpen  = (getCurrentPanel() != null);    isChanged = fileOpen && (getCurrentPanel().isChanged());    canUndo   = fileOpen && (getCurrentPanel().canUndo());        // File    menuFileOpen.setEnabled(true);    menuFileSave.setEnabled(isChanged);    menuFileSaveAs.setEnabled(fileOpen);    menuFileClose.setEnabled(fileOpen);    menuFileCloseAll.setEnabled(fileOpen);    menuFileProperties.setEnabled(fileOpen);    menuFileExit.setEnabled(true);    // Edit    menuEditUndo.setEnabled(canUndo);    menuEditCopy.setEnabled(fileOpen);    menuEditSearch.setEnabled(fileOpen);    menuEditClearSearch.setEnabled(fileOpen);    menuEditAttributeAsClass.setEnabled(fileOpen);    menuEditRenameAttribute.setEnabled(fileOpen);    menuEditDeleteAttribute.setEnabled(fileOpen);    menuEditDeleteAttributes.setEnabled(fileOpen);    menuEditDeleteInstance.setEnabled(fileOpen);    menuEditDeleteInstances.setEnabled(fileOpen);    menuEditSortInstances.setEnabled(fileOpen);    // View    menuViewAttributes.setEnabled(fileOpen);    menuViewValues.setEnabled(fileOpen);    menuViewOptimalColWidths.setEnabled(fileOpen);  }    /**   * sets the title of the tab that contains the given component   *    * @param component		the component to set the title for   */  protected void setTabTitle(JComponent component) {    int            index;        if (!(component instanceof ArffPanel))      return;        index = tabbedPane.indexOfComponent(component);    if (index == -1)      return;        tabbedPane.setTitleAt(index, ((ArffPanel) component).getTitle());    updateFrameTitle();  }    /**   * returns the number of panels currently open   *    * @return		the number of open panels   */  public int getPanelCount() {    return tabbedPane.getTabCount();  }    /**   * returns the specified panel, <code>null</code> if index is out of bounds     *    * @param index	the index of the panel   * @return		the panel   */  public ArffPanel getPanel(int index) {    if ((index >= 0) && (index < getPanelCount()))      return (ArffPanel) tabbedPane.getComponentAt(index);    else      return null;  }    /**   * returns the currently selected tab index   *    * @return		the index of the currently selected tab   */  public int getCurrentIndex() {    return tabbedPane.getSelectedIndex();  }    /**   * returns the currently selected panel   *    * @return		the currently selected panel   */  public ArffPanel getCurrentPanel() {    return getPanel(getCurrentIndex());  }    /**   * checks whether a panel is currently selected   *    * @return		true if a panel is currently selected   */  public boolean isPanelSelected() {    return (getCurrentPanel() != null);  }    /**   * returns the filename of the specified panel    *    * @param index	the index of the panel   * @return		the filename for the panel   */  public String getFilename(int index) {    String            result;    ArffPanel         panel;        result = "";    panel  = getPanel(index);        if (panel != null)      result = panel.getFilename();        return result;  }    /**   * returns the filename of the current tab   *    * @return		the current filename   */  public String getCurrentFilename() {    return getFilename(getCurrentIndex());  }    /**   * sets the filename of the specified panel   *    * @param index	the index of the panel   * @param filename	the new filename   */  public void setFilename(int index, String filename) {    ArffPanel         panel;        panel = getPanel(index);        if (panel != null) {      panel.setFilename(filename);      setTabTitle(panel);    }  }    /**   * sets the filename of the current tab   *    * @param filename	the new filename   */  public void setCurrentFilename(String filename) {    setFilename(getCurrentIndex(), filename);  }    /**   * 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   *    * @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);

⌨️ 快捷键说明

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