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

📄 mainframe.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	ToggleExpertModeAction toggleAction = (ToggleExpertModeAction)TOGGLE_EXPERT_MODE_ACTION;
	toggleAction.updateIcon();
    }

    public OperatorPropertyTable getPropertyTable() {
	return treePanel.getPropertyTable();
    }

    public MessageViewer getMessageViewer() {
	return messageViewer;
    }

    public OperatorTree getOperatorTree() {
	return treePanel.getOperatorTree();
    }
    
    public ResultDisplay getResultDisplay() {
	return resultDisplay;
    }

    public void experimentEnded(IOContainer results) {
	if (results != null) {
	    statusBar.experimentEnded();
	    resultDisplay.setData(results, "Experiment results:");
	    editorTabs.setSelectedComponent(resultDisplay);
	    resultDisplay.showSomething();
	}
    	experimentThread = null;
	enableActions();
    }

    public void breakpointReached(Operator operator, IOContainer ioContainer) {
	List additionalButtons= new LinkedList();
	additionalButtons.add(new JButton(RESUME_ACTION));
	additionalButtons.add(new JButton(STOP_ACTION));
	resultDisplay.setData(ioContainer, 
			      "Results in application "+operator.getApplyCount()+" of "+operator.getName()+":");
	ExperimentThread.beep("breakpoint");
    }

    /** Sets a new experiment and registers the MainFrame listener. */
    public void setExperiment(Experiment experiment) {
	Yale.setExperiment(experiment);
	Yale.getExperiment().addBreakpointListener(MainFrame.this);
	setOperator(Yale.getExperiment().getRootOperator());
	Yale.getExperiment().getRootOperator().addExperimentListener(monitorPanel);
	Yale.getExperiment().getRootOperator().addExperimentListener(statusBar);
	resultDisplay.clear();
	enableActions();
	setTitle();
    }

    /** Sets the root operator for all editors. */
    public void setOperator(Operator root) {
	treePanel.experimentChanged(root);
	editor.experimentChanged(root);
	experimentPanel.experimentChanged(root);
    }

    /** Must be called when the experiment changed (such that is different
     *  from the experiment last saved to disk. */
    public void experimentChanged() {
	boolean oldValue = this.changed;
	this.changed = true;
	if (!oldValue) {
	    setTitle();
	}	
	if ((Yale.getExperiment().getExperimentFile() != null) && !tutorialMode)
	    this.SAVE_ACTION.setEnabled(true);
    }

    /** Sets the window title (Yale + filename + an asterisk if experiment was modified. */
    private void setTitle() {
	File file = null;
	if (Yale.getExperiment() != null)
	    file = Yale.getExperiment().getExperimentFile();
	if (file != null) {
	    setTitle(TITLE + " ("+file.getName()+
		     (changed?"*":"")+")");	     
	} else {
	    setTitle(TITLE);
	}	
    }

    private String getBaseName() {
	if (Yale.getExperiment() != null) {
	    File file = Yale.getExperiment().getExperimentFile();
	    String base = file.getName();
	    int dot = base.lastIndexOf(".");
	    if (dot == -1)  return base;
	    else return base.substring(0, dot);
	} else {
	    return "unnamed";
	}
    }


    ////////////////////// File menu actions ////////////////////

    private boolean close() {
	if (changed) {
	    File file = Yale.getExperiment().getExperimentFile();
	    if (file == null) {
		file = new File("unnamed.xml");
	    }	
	    int choice = JOptionPane.showConfirmDialog(this,
						       "Save changes to '"+file+"'?", 
						       "Save changes", 
						       JOptionPane.YES_NO_CANCEL_OPTION);
	    switch (choice) {
	    case JOptionPane.YES_OPTION:
		save();
	    case JOptionPane.NO_OPTION:
		if (experimentThread != null) experimentThread.stopExperiment();
		return true;
	    default:
	    case JOptionPane.CANCEL_OPTION:
		return false;
	    }
	} else {
	    return true;
	}
    }


    protected void open() {
	if (close()) {
	    File file = SwingTools.chooseFile(MainFrame.this, null, true);
	    if (file == null) {
		return;
	    }	    
	    open(file);
	}
    }

    protected void open(File file) {
	open(file, true);
    }

    protected void open(File file, boolean showInfo) {
	try {
	    try {
		YaleGUI.readExperimentFile(file);		
		setExperiment(Yale.getExperiment());
	    } catch (XMLException ex) {
		//ex.printStackTrace();
		SwingTools.showErrorMessage("While loading '"+file+"'", ex);
		Experiment experiment = new Experiment();
		experiment.setExperimentFile(file);
		YaleGUI.setExperiment(experiment);
		setExperiment(experiment);
		editorTabs.setSelectedComponent(editor);	    
		editor.setText(Tools.readOutput(new BufferedReader(new FileReader(file))));
	    }
	} catch (Exception ex) { // io exceptions
	    ex.printStackTrace();
	    SwingTools.showErrorMessage("While loading '"+file+"'", ex);
	    return;
	}

	SAVE_ACTION.setEnabled(false);
	changed = false;
	YaleGUI.useExperimentFile();
	updateRecentFileList();
	setTitle();
	if (showInfo && Tools.booleanValue(System.getProperty("yale.gui.experimentinfo.show"), true)) {
	    String text = Yale.getExperiment().getRootOperator().getUserDescription();
	    if ((text != null) && (text.length() != 0)) {
		ExperimentInfoScreen infoScreen = new ExperimentInfoScreen(this, file.getName(), text);
		infoScreen.show();
	    }
	}
    }

    private void save() {
	try {
	    File file = Yale.getExperiment().getExperimentFile();
	    if (file == null) {
		file = SwingTools.chooseFile(this, new File("."), false);
		if (file == null) return;
		else Yale.getExperiment().setExperimentFile(file);
	    } 
	    Yale.getExperiment().save();	    
	    SAVE_ACTION.setEnabled(false);
	    changed = false;
	    setTitle();
	    YaleGUI.useExperimentFile();
	    updateRecentFileList(); 
  	} catch (IOException ex) {
  	    SwingTools.showErrorMessage("Cannot save experiment file!", ex);
  	}
    }

    private void exit() {
	if (changed) {
	    File file = Yale.getExperiment().getExperimentFile();
	    if (file == null) {
		file = new File("unnamed.xml");
	    }	    
	    switch (JOptionPane.showConfirmDialog(this,
						  "Save changes to '"+file+"'?", 
						  "Save changes", 
						  JOptionPane.YES_NO_CANCEL_OPTION)) {
	    case JOptionPane.YES_OPTION:
		save();
		if (changed) return;
		break;		
	    case JOptionPane.NO_OPTION:
		break;		
	    case JOptionPane.CANCEL_OPTION:
	    default:
		return;
	    }
	} else if (JOptionPane.showConfirmDialog(this, "Really exit?", "Exit Yale", JOptionPane.YES_NO_OPTION)
		   != JOptionPane.YES_OPTION) {
	    return;
	}
	dispose();
	System.exit(0);
    }

    /** Updates the list of recently used files. */
    public void updateRecentFileList() {
	recentFilesMenu.removeAll();
	List recentFiles = YaleGUI.getRecentFiles();
	Iterator i = recentFiles.iterator();
	int j = 1;
	while (i.hasNext()) {
	    final File recentFile = (File)i.next();
	    JMenuItem menuItem = new JMenuItem(j+" "+recentFile.getPath());
	    menuItem.setMnemonic('0'+j);
	    menuItem.addActionListener(new ActionListener() {
		    public void actionPerformed(ActionEvent e) {
			open(recentFile);
		    }		    
		});
	    recentFilesMenu.add(menuItem);
	    j++;
	}
    }

    public void windowOpened(WindowEvent e) { }
    public void windowClosing(WindowEvent e) { exit(); }
    public void windowClosed(WindowEvent e) { }
    public void windowIconified(WindowEvent e) { }
    public void windowDeiconified(WindowEvent e) { }
    public void windowActivated(WindowEvent e) { }
    public void windowDeactivated(WindowEvent e) { }

    /** Handles events of the editorTabs, i.e. updates all editors such that
     *  they reflect the changed experiment. */
    public void stateChanged(ChangeEvent e) {
	ExperimentEditor newEditor = (ExperimentEditor)editorTabs.getSelectedComponent();
	if (newEditor.equals(currentExperimentEditor)) {
	    return;
	}
	
	try {
	    currentExperimentEditor.validateExperiment();
	    newEditor.experimentChanged(Yale.getExperiment().getRootOperator());
	    currentExperimentEditor = newEditor;
	} catch (Exception ex) {
	    switch (JOptionPane.showConfirmDialog(this, ex.toString()+"\nCancel to ignore changes, Ok to go on editing.", 
						  "Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE)) {
	    case JOptionPane.OK_OPTION:
		editorTabs.setSelectedComponent((Component)currentExperimentEditor);		 
		break;
	    default:
	    case JOptionPane.CANCEL_OPTION:
		currentExperimentEditor.experimentChanged(Yale.getExperiment().getRootOperator());
		currentExperimentEditor = newEditor;
		break;		
	    }
	}
	enableActions();
    }

    /** Enables and disables all actions according to the current state (experiment running,
     *  operator selected... */
    public void enableActions() {
	boolean[] currentStates = new boolean[ConditionalAction.NUMBER_OF_CONDITIONS];
	Operator op = treePanel.getOperatorTree().getSelectedOperator();
	if (op != null) {
	    currentStates[ConditionalAction.OPERATOR_SELECTED] = true;
	    if (op instanceof OperatorChain) currentStates[ConditionalAction.OPERATOR_CHAIN_SELECTED] = true;
	    if (op.getParent() == null) currentStates[ConditionalAction.ROOT_SELECTED] = true;
	}
	currentStates[ConditionalAction.EXPERIMENT_RUNNING] = (experimentThread != null) && (experimentThread.isAlive());
	currentStates[ConditionalAction.CLIPBOARD_FILLED] = treePanel.getOperatorTree().getClipBoard() != null;
	
	ConditionalAction.updateAll(currentStates);	
    }

}

⌨️ 快捷键说明

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