📄 simplesetuppanel.java
字号:
}); m_NotesText.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { m_Exp.setNotes(m_NotesText.getText()); } }); // Set up the GUI layout JPanel buttons = new JPanel(); GridBagLayout gb = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); buttons.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5)); buttons.setLayout(gb); constraints.gridx=0;constraints.gridy=0;constraints.weightx=5; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridwidth=1;constraints.gridheight=1; constraints.insets = new Insets(0,2,0,2); buttons.add(m_OpenBut,constraints); constraints.gridx=1;constraints.gridy=0;constraints.weightx=5; constraints.gridwidth=1;constraints.gridheight=1; buttons.add(m_SaveBut,constraints); constraints.gridx=2;constraints.gridy=0;constraints.weightx=5; constraints.gridwidth=1;constraints.gridheight=1; buttons.add(m_NewBut,constraints); JPanel destName = new JPanel(); destName.setLayout(new BorderLayout(5, 5)); destName.add(m_ResultsDestinationPathLabel, BorderLayout.WEST); destName.add(m_ResultsDestinationPathTField, BorderLayout.CENTER); m_ResultsDestinationCBox.addItem(DEST_ARFF_TEXT); m_ResultsDestinationCBox.addItem(DEST_CSV_TEXT); m_ResultsDestinationCBox.addItem(DEST_DATABASE_TEXT); m_ResultsDestinationCBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { destinationTypeChanged(); } }); JPanel destInner = new JPanel(); destInner.setLayout(new BorderLayout(5, 5)); destInner.add(m_ResultsDestinationCBox, BorderLayout.WEST); destInner.add(destName, BorderLayout.CENTER); destInner.add(m_BrowseDestinationButton, BorderLayout.EAST); JPanel dest = new JPanel(); dest.setLayout(new BorderLayout()); dest.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Results Destination"), BorderFactory.createEmptyBorder(0, 5, 5, 5) )); dest.add(destInner, BorderLayout.NORTH); JPanel expParam = new JPanel(); expParam.setLayout(new BorderLayout(5, 5)); expParam.add(m_ExperimentParameterLabel, BorderLayout.WEST); expParam.add(m_ExperimentParameterTField, BorderLayout.CENTER); ButtonGroup typeBG = new ButtonGroup(); typeBG.add(m_ExpClassificationRBut); typeBG.add(m_ExpRegressionRBut); m_ExpClassificationRBut.setSelected(true); JPanel typeRButtons = new JPanel(); typeRButtons.setLayout(new GridLayout(1,0)); typeRButtons.add(m_ExpClassificationRBut); typeRButtons.add(m_ExpRegressionRBut); m_ExperimentTypeCBox.addItem(TYPE_CROSSVALIDATION_TEXT); m_ExperimentTypeCBox.addItem(TYPE_RANDOMSPLIT_TEXT); m_ExperimentTypeCBox.addItem(TYPE_FIXEDSPLIT_TEXT); m_ExperimentTypeCBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { expTypeChanged(); } }); JPanel typeInner = new JPanel(); typeInner.setLayout(new GridLayout(0,1)); typeInner.add(m_ExperimentTypeCBox); typeInner.add(expParam); typeInner.add(typeRButtons); JPanel type = new JPanel(); type.setLayout(new BorderLayout()); type.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Experiment Type"), BorderFactory.createEmptyBorder(0, 5, 5, 5) )); type.add(typeInner, BorderLayout.NORTH); ButtonGroup iterBG = new ButtonGroup(); iterBG.add(m_OrderDatasetsFirstRBut); iterBG.add(m_OrderAlgorithmsFirstRBut); m_OrderDatasetsFirstRBut.setSelected(true); JPanel numIter = new JPanel(); numIter.setLayout(new BorderLayout(5, 5)); numIter.add(new JLabel("Number of repetitions:"), BorderLayout.WEST); numIter.add(m_NumberOfRepetitionsTField, BorderLayout.CENTER); JPanel controlInner = new JPanel(); controlInner.setLayout(new GridLayout(0,1)); controlInner.add(numIter); controlInner.add(m_OrderDatasetsFirstRBut); controlInner.add(m_OrderAlgorithmsFirstRBut); JPanel control = new JPanel(); control.setLayout(new BorderLayout()); control.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Iteration Control"), BorderFactory.createEmptyBorder(0, 5, 5, 5) )); control.add(controlInner, BorderLayout.NORTH); JPanel type_control = new JPanel(); type_control.setLayout(new GridLayout(1,0)); type_control.add(type); type_control.add(control); JPanel notes = new JPanel(); notes.setLayout(new BorderLayout()); notes.add(m_NotesButton, BorderLayout.CENTER); JPanel top1 = new JPanel(); top1.setLayout(new BorderLayout()); top1.add(dest, BorderLayout.NORTH); top1.add(type_control, BorderLayout.CENTER); JPanel top = new JPanel(); top.setLayout(new BorderLayout()); top.add(buttons, BorderLayout.NORTH); top.add(top1, BorderLayout.CENTER); JPanel datasets = new JPanel(); datasets.setLayout(new BorderLayout()); datasets.add(m_DatasetListPanel, BorderLayout.CENTER); JPanel algorithms = new JPanel(); algorithms.setLayout(new BorderLayout()); algorithms.add(m_AlgorithmListPanel, BorderLayout.CENTER); JPanel schemes = new JPanel(); schemes.setLayout(new GridLayout(1,0)); schemes.add(datasets); schemes.add(algorithms); setLayout(new BorderLayout()); add(top, BorderLayout.NORTH); add(schemes, BorderLayout.CENTER); add(notes, BorderLayout.SOUTH); } /** * Sets the selected item of an combobox, since using setSelectedItem(...) * doesn't work, if one checks object references! * * @param cb the combobox to set the item for * @param item the item to set active */ protected void setSelectedItem(JComboBox cb, String item) { int i; for (i = 0; i < cb.getItemCount(); i++) { if (cb.getItemAt(i).toString().equals(item)) { cb.setSelectedIndex(i); break; } } } /** * Deletes the notes frame. */ protected void removeNotesFrame() { m_NotesFrame.setVisible(false); } /** * Gets te users consent for converting the experiment to a simpler form. * * @return true if the user has given consent, false otherwise */ private boolean userWantsToConvert() { if (m_userHasBeenAskedAboutConversion) return true; m_userHasBeenAskedAboutConversion = true; return (JOptionPane.showConfirmDialog(this, "This experiment has settings that are too advanced\n" + "to be represented in the simple setup mode.\n" + "Do you want the experiment to be converted,\n" + "losing some of the advanced settings?\n", "Confirm conversion", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION); } /** * Sets the panel used to switch between simple and advanced modes. * * @param modePanel the panel */ public void setModePanel(SetupModePanel modePanel) { m_modePanel = modePanel; } /** * Sets the experiment to configure. * * @param exp a value of type 'Experiment' * @return true if experiment could be configured, false otherwise */ public boolean setExperiment(Experiment exp) { m_userHasBeenAskedAboutConversion = false; m_Exp = null; // hold off until we are sure we want conversion m_SaveBut.setEnabled(true); if (exp.getResultListener() instanceof DatabaseResultListener) { m_ResultsDestinationCBox.setSelectedItem(DEST_DATABASE_TEXT); m_ResultsDestinationPathLabel.setText("URL:"); m_destinationDatabaseURL = ((DatabaseResultListener)exp.getResultListener()).getDatabaseURL(); m_ResultsDestinationPathTField.setText(m_destinationDatabaseURL); m_BrowseDestinationButton.setEnabled(true); } else if (exp.getResultListener() instanceof InstancesResultListener) { m_ResultsDestinationCBox.setSelectedItem(DEST_ARFF_TEXT); m_ResultsDestinationPathLabel.setText("Filename:"); m_destinationFilename = ((InstancesResultListener)exp.getResultListener()).outputFileName(); m_ResultsDestinationPathTField.setText(m_destinationFilename); m_BrowseDestinationButton.setEnabled(true); } else if (exp.getResultListener() instanceof CSVResultListener) { m_ResultsDestinationCBox.setSelectedItem(DEST_CSV_TEXT); m_ResultsDestinationPathLabel.setText("Filename:"); m_destinationFilename = ((CSVResultListener)exp.getResultListener()).outputFileName(); m_ResultsDestinationPathTField.setText(m_destinationFilename); m_BrowseDestinationButton.setEnabled(true); } else { // unrecognised result listener System.out.println("SimpleSetup incompatibility: unrecognised result destination"); if (userWantsToConvert()) { m_ResultsDestinationCBox.setSelectedItem(DEST_ARFF_TEXT); m_ResultsDestinationPathLabel.setText("Filename:"); m_destinationFilename = ""; m_ResultsDestinationPathTField.setText(m_destinationFilename); m_BrowseDestinationButton.setEnabled(true); } else { return false; } } m_ResultsDestinationCBox.setEnabled(true); m_ResultsDestinationPathLabel.setEnabled(true); m_ResultsDestinationPathTField.setEnabled(true); if (exp.getResultProducer() instanceof CrossValidationResultProducer) { CrossValidationResultProducer cvrp = (CrossValidationResultProducer) exp.getResultProducer(); m_numFolds = cvrp.getNumFolds(); m_ExperimentParameterTField.setText("" + m_numFolds); if (cvrp.getSplitEvaluator() instanceof ClassifierSplitEvaluator) { m_ExpClassificationRBut.setSelected(true); m_ExpRegressionRBut.setSelected(false); } else if (cvrp.getSplitEvaluator() instanceof RegressionSplitEvaluator) { m_ExpClassificationRBut.setSelected(false); m_ExpRegressionRBut.setSelected(true); } else { // unknown split evaluator System.out.println("SimpleSetup incompatibility: unrecognised split evaluator"); if (userWantsToConvert()) { m_ExpClassificationRBut.setSelected(true); m_ExpRegressionRBut.setSelected(false); } else { return false; } } m_ExperimentTypeCBox.setSelectedItem(TYPE_CROSSVALIDATION_TEXT); } else if (exp.getResultProducer() instanceof RandomSplitResultProducer) { RandomSplitResultProducer rsrp = (RandomSplitResultProducer) exp.getResultProducer(); if (rsrp.getRandomizeData()) { m_ExperimentTypeCBox.setSelectedItem(TYPE_RANDOMSPLIT_TEXT); } else { m_ExperimentTypeCBox.setSelectedItem(TYPE_FIXEDSPLIT_TEXT); } if (rsrp.getSplitEvaluator() instanceof ClassifierSplitEvaluator) { m_ExpClassificationRBut.setSelected(true); m_ExpRegressionRBut.setSelected(false); } else if (rsrp.getSplitEvaluator() instanceof RegressionSplitEvaluator) { m_ExpClassificationRBut.setSelected(false); m_ExpRegressionRBut.setSelected(true); } else { // unknown split evaluator System.out.println("SimpleSetup incompatibility: unrecognised split evaluator"); if (userWantsToConvert()) { m_ExpClassificationRBut.setSelected(true); m_ExpRegressionRBut.setSelected(false); } else { return false; } } m_trainPercent = rsrp.getTrainPercent(); m_ExperimentParameterTField.setText("" + m_trainPercent); } else { // unknown experiment type System.out.println("SimpleSetup incompatibility: unrecognised resultProducer"); if (userWantsToConvert()) { m_ExperimentTypeCBox.setSelectedItem(TYPE_CROSSVALIDATION_TEXT); m_ExpClassificationRBut.setSelected(true); m_ExpRegressionRBut.setSelected(false); } else { return false; } } m_ExperimentTypeCBox.setEnabled(true); m_ExperimentParameterLabel.setEnabled(true); m_ExperimentParameterTField.setEnabled(true); m_ExpClassificationRBut.setEnabled(true); m_ExpRegressionRBut.setEnabled(true); if (exp.getRunLower() == 1) { m_numRepetitions = exp.getRunUpper(); m_NumberOfRepetitionsTField.setText("" + m_numRepetitions); } else { // unsupported iterations System.out.println("SimpleSetup incompatibility: runLower is not 1"); if (userWantsToConvert()) { exp.setRunLower(1); if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_FIXEDSPLIT_TEXT) { exp.setRunUpper(1); m_NumberOfRepetitionsTField.setEnabled(false); m_NumberOfRepetitionsTField.setText("1"); } else { exp.setRunUpper(10); m_numRepetitions = 10; m_NumberOfRepetitionsTField.setText("" + m_numRepetitions); } } else { return false; } } m_NumberOfRepetitionsTField.setEnabled(true); m_OrderDatasetsFirstRBut.setSelected(exp.getAdvanceDataSetFirst()); m_OrderAlgorithmsFirstRBut.setSelected(!exp.getAdvanceDataSetFirst()); m_OrderDatasetsFirstRBut.setEnabled(true); m_OrderAlgorithmsFirstRBut.setEnabled(true); m_NotesText.setText(exp.getNotes()); m_NotesButton.setEnabled(true); if (!exp.getUsePropertyIterator() || !(exp.getPropertyArray() instanceof Classifier[])) { // unknown property iteration System.out.println("SimpleSetup incompatibility: unrecognised property iteration"); if (userWantsToConvert()) { exp.setPropertyArray(new Classifier[0]); exp.setUsePropertyIterator(true); } else { return false; } } m_DatasetListPanel.setExperiment(exp); m_AlgorithmListPanel.setExperiment(exp); m_Exp = exp; expTypeChanged(); // recreate experiment m_Support.firePropertyChange("", null, null); return true; } /** * Gets the currently configured experiment. * * @return the currently configured experiment. */ public Experiment getExperiment() { return m_Exp; } /** * Prompts the user to select an experiment file and loads it. */ private void openExperiment() { int returnVal = m_FileChooser.showOpenDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } File expFile = m_FileChooser.getSelectedFile(); // add extension if necessary if (m_FileChooser.getFileFilter() == m_ExpFilter) { if (!expFile.getName().toLowerCase().endsWith(Experiment.FILE_EXTENSION)) expFile = new File(expFile.getParent(), expFile.getName() + Experiment.FILE_EXTENSION); } else if (m_FileChooser.getFileFilter() == m_KOMLFilter) { if (!expFile.getName().toLowerCase().endsWith(KOML.FILE_EXTENSION)) expFile = new File(expFile.getParent(), expFile.getName() + KOML.FILE_EXTENSION); } else if (m_FileChooser.getFileFilter() == m_XMLFilter) { if (!expFile.getName().toLowerCase().endsWith(".xml")) expFile = new File(expFile.getParent(), expFile.getName() + ".xml"); } try { Experiment exp; // KOML? if ( (KOML.isPresent()) && (expFile.getAbsolutePath().toLowerCase().endsWith(KOML.FILE_EXTENSION)) ) { exp = (Experiment) KOML.read(expFile.getAbsolutePath()); } else // XML?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -