📄 simplesetuppanel.java
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* * SimpleSetupPanel.java * Copyright (C) 2002 Richard Kirkby * */package weka.gui.experiment;import javax.swing.JPanel;import weka.experiment.Experiment;import weka.gui.ExtensionFileFilter;import weka.classifiers.Classifier;import weka.experiment.AveragingResultProducer;import weka.experiment.CrossValidationResultProducer;import weka.experiment.SplitEvaluator;import weka.experiment.ClassifierSplitEvaluator;import weka.experiment.RegressionSplitEvaluator;import weka.experiment.DatabaseResultListener;import weka.experiment.InstancesResultListener;import weka.experiment.CSVResultListener;import weka.experiment.PropertyNode;import weka.experiment.ResultProducer;import weka.experiment.RandomSplitResultProducer;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeSupport;import java.beans.PropertyDescriptor;import java.beans.IntrospectionException;import java.io.File;import java.io.FileOutputStream;import java.io.ObjectOutputStream;import java.io.BufferedOutputStream;import java.io.FileInputStream;import java.io.ObjectInputStream;import java.io.BufferedInputStream;import java.awt.Component;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Dimension;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.awt.event.FocusAdapter;import java.awt.event.FocusEvent;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.Insets;import javax.swing.JPanel;import javax.swing.JLabel;import javax.swing.JFrame;import javax.swing.SwingConstants;import javax.swing.JTextField;import javax.swing.Box;import javax.swing.BorderFactory;import javax.swing.BoxLayout;import javax.swing.JTextArea;import javax.swing.JScrollPane;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import javax.swing.filechooser.FileFilter;import javax.swing.JRadioButton;import javax.swing.ButtonGroup;import javax.swing.JComboBox;import javax.swing.event.DocumentListener;import javax.swing.event.DocumentEvent;/** * This panel controls the configuration of an experiment. * * @author Richard kirkby (rkirkby@cs.waikato.ac.nz) * @version $Revision: 1.1.1.1 $ */public class SimpleSetupPanel extends JPanel { /** The experiment being configured */ protected Experiment m_Exp; /** The panel which switched between simple and advanced setup modes */ protected SetupModePanel m_modePanel = null; /** The database destination URL to store results into */ protected String m_destinationDatabaseURL; /** The filename to store results into */ protected String m_destinationFilename = "-"; /** The number of folds for a cross-validation experiment */ protected int m_numFolds = 10; /** The training percentage for a train/test split experiment */ protected double m_trainPercent = 66; /** The number of times to repeat the sub-experiment */ protected int m_numRepetitions = 10; /** Whether or not the user has consented for the experiment to be simplified */ protected boolean m_userHasBeenAskedAboutConversion; /** Filter for choosing CSV files */ protected ExtensionFileFilter m_csvFileFilter = new ExtensionFileFilter(".csv", "Comma separated value files"); /** FIlter for choosing ARFF files */ protected ExtensionFileFilter m_arffFileFilter = new ExtensionFileFilter(".arff", "ARFF files"); /** Click to load an experiment */ protected JButton m_OpenBut = new JButton("Open..."); /** Click to save an experiment */ protected JButton m_SaveBut = new JButton("Save..."); /** Click to create a new experiment with default settings */ protected JButton m_NewBut = new JButton("New"); /** A filter to ensure only experiment files get shown in the chooser */ protected FileFilter m_ExpFilter = new ExtensionFileFilter(Experiment.FILE_EXTENSION, "Experiment configuration files"); /** The file chooser for selecting experiments */ protected JFileChooser m_FileChooser = new JFileChooser(new File(System.getProperty("user.dir"))); /** The file chooser for selecting result destinations */ protected JFileChooser m_DestFileChooser = new JFileChooser(new File(System.getProperty("user.dir"))); /** Combo box for choosing experiment destination type */ protected JComboBox m_ResultsDestinationCBox = new JComboBox(); /** Label for destination field */ protected JLabel m_ResultsDestinationPathLabel = new JLabel("Filename:"); /** Input field for result destination path */ protected JTextField m_ResultsDestinationPathTField = new JTextField(); /** Button for browsing destination files */ protected JButton m_BrowseDestinationButton = new JButton("Browse..."); /** Combo box for choosing experiment type */ protected JComboBox m_ExperimentTypeCBox = new JComboBox(); /** Label for parameter field */ protected JLabel m_ExperimentParameterLabel = new JLabel("Number of folds:"); /** Input field for experiment parameter */ protected JTextField m_ExperimentParameterTField = new JTextField(); /** Radio button for choosing classification experiment */ protected JRadioButton m_ExpClassificationRBut = new JRadioButton("Classification"); /** Radio button for choosing regression experiment */ protected JRadioButton m_ExpRegressionRBut = new JRadioButton("Regression"); /** Input field for number of repetitions */ protected JTextField m_NumberOfRepetitionsTField = new JTextField(); /** Radio button for choosing datasets first in order of execution */ protected JRadioButton m_OrderDatasetsFirstRBut = new JRadioButton("Data sets first"); /** Radio button for choosing algorithms first in order of execution */ protected JRadioButton m_OrderAlgorithmsFirstRBut = new JRadioButton("Algorithms first"); /** The strings used to identify the combo box choices */ protected static String DEST_DATABASE_TEXT = ("JDBC database"); protected static String DEST_ARFF_TEXT = ("ARFF file"); protected static String DEST_CSV_TEXT = ("CSV file"); protected static String TYPE_CROSSVALIDATION_TEXT = ("Cross-validation"); protected static String TYPE_RANDOMSPLIT_TEXT = ("Train/Test Percentage Split (data randomized)"); protected static String TYPE_FIXEDSPLIT_TEXT = ("Train/Test Percentage Split (order preserved)"); /** The panel for configuring selected datasets */ protected DatasetListPanel m_DatasetListPanel = new DatasetListPanel(); /** The panel for configuring selected algorithms */ protected AlgorithmListPanel m_AlgorithmListPanel = new AlgorithmListPanel(); /** Area for user notes Default of 5 rows */ protected JTextArea m_NotesText = new JTextArea(null, 5, 0); /** * Manages sending notifications to people when we change the experiment, * at this stage, only the resultlistener so the resultpanel can update. */ protected PropertyChangeSupport m_Support = new PropertyChangeSupport(this); /** * Creates the setup panel with the supplied initial experiment. * * @param exp a value of type 'Experiment' */ public SimpleSetupPanel(Experiment exp) { this(); setExperiment(exp); } /** * Creates the setup panel with no initial experiment. */ public SimpleSetupPanel() { // everything disabled on startup m_ResultsDestinationCBox.setEnabled(false); m_ResultsDestinationPathLabel.setEnabled(false); m_ResultsDestinationPathTField.setEnabled(false); m_BrowseDestinationButton.setEnabled(false); m_ExperimentTypeCBox.setEnabled(false); m_ExperimentParameterLabel.setEnabled(false); m_ExperimentParameterTField.setEnabled(false); m_ExpClassificationRBut.setEnabled(false); m_ExpRegressionRBut.setEnabled(false); m_NumberOfRepetitionsTField.setEnabled(false); m_OrderDatasetsFirstRBut.setEnabled(false); m_OrderAlgorithmsFirstRBut.setEnabled(false); // get sensible default database address try { m_destinationDatabaseURL = (new DatabaseResultListener()).getDatabaseURL(); } catch (Exception e) {} // create action listeners m_NewBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Experiment newExp = new Experiment(); AveragingResultProducer arp = new AveragingResultProducer(); CrossValidationResultProducer cvrp = new CrossValidationResultProducer(); arp.setExpectedResultsPerAverage(10); cvrp.setNumFolds(10); cvrp.setSplitEvaluator(new ClassifierSplitEvaluator()); arp.setResultProducer(cvrp); newExp.setResultProducer(arp); newExp.setPropertyArray(new Classifier[0]); newExp.setUsePropertyIterator(true); setExperiment(newExp); } }); m_SaveBut.setEnabled(false); m_SaveBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { saveExperiment(); } }); m_OpenBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openExperiment(); } }); m_FileChooser.setFileFilter(m_ExpFilter); m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); m_DestFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); m_ResultsDestinationCBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { destinationTypeChanged(); } }); m_BrowseDestinationButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chooseDestinationFile(); } }); m_ExperimentTypeCBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { expTypeChanged(); } }); m_ExpClassificationRBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { expTypeChanged(); } }); m_ExpRegressionRBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { expTypeChanged(); } }); m_OrderDatasetsFirstRBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_Exp != null) { m_Exp.setAdvanceDataSetFirst(true); m_Support.firePropertyChange("", null, null); } } }); m_OrderAlgorithmsFirstRBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_Exp != null) { m_Exp.setAdvanceDataSetFirst(false); m_Support.firePropertyChange("", null, null); } } }); m_ResultsDestinationPathTField.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) {destinationAddressChanged();} public void removeUpdate(DocumentEvent e) {destinationAddressChanged();} public void changedUpdate(DocumentEvent e) {destinationAddressChanged();} }); m_ExperimentParameterTField.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) {expParamChanged();} public void removeUpdate(DocumentEvent e) {expParamChanged();} public void changedUpdate(DocumentEvent e) {expParamChanged();} }); m_NumberOfRepetitionsTField.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) {numRepetitionsChanged();} public void removeUpdate(DocumentEvent e) {numRepetitionsChanged();} public void changedUpdate(DocumentEvent e) {numRepetitionsChanged();} }); m_NotesText.setEnabled(false); m_NotesText.setEditable(true); m_NotesText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); m_NotesText.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { m_Exp.setNotes(m_NotesText.getText());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -