📄 setuppanel.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.
*/
/*
* SetupPanel.java
* Copyright (C) 1999 Len Trigg, Mark Hall
*
*/
package weka.gui.experiment;
import weka.core.Tag;
import weka.core.SelectedTag;
import weka.core.Utils;
import weka.core.xml.KOML;
import weka.experiment.xml.XMLExperiment;
import weka.gui.ExtensionFileFilter;
import weka.gui.SelectedTagEditor;
import weka.gui.GenericObjectEditor;
import weka.gui.GenericArrayEditor;
import weka.gui.PropertyPanel;
import weka.gui.FileEditor;
import weka.experiment.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeSupport;
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;
/**
* This panel controls the configuration of an experiment.
* <p>
* If <a href="http://koala.ilog.fr/XML/serialization/" target="_blank">KOML</a>
* is in the classpath the experiments can also be saved to XML instead of a
* binary format.
*
* @author Len Trigg (trigg@cs.waikato.ac.nz)
* @author Mark Hall (mhall@cs.waikato.ac.nz)
* @author FracPete (fracpete at waikato dot ac dot nz)
* @version $Revision: 1.1 $
*/
public class SetupPanel extends JPanel {
/** The experiment being configured */
protected Experiment m_Exp;
/** 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 (*" + Experiment.FILE_EXTENSION + ")");
/** A filter to ensure only experiment (in KOML format) files get shown in the chooser */
protected FileFilter m_KOMLFilter =
new ExtensionFileFilter(KOML.FILE_EXTENSION,
"Experiment configuration files (*" + KOML.FILE_EXTENSION + ")");
/** A filter to ensure only experiment (in XML format) files get shown in the chooser */
protected FileFilter m_XMLFilter =
new ExtensionFileFilter(".xml",
"Experiment configuration files (*.xml)");
/** The file chooser for selecting experiments */
protected JFileChooser m_FileChooser = new JFileChooser(new File(System.getProperty("user.dir")));
/** The ResultProducer editor */
protected GenericObjectEditor m_RPEditor = new GenericObjectEditor();
/** The panel to contain the ResultProducer editor */
protected PropertyPanel m_RPEditorPanel = new PropertyPanel(m_RPEditor);
/** The ResultListener editor */
protected GenericObjectEditor m_RLEditor = new GenericObjectEditor();
/** The panel to contain the ResultListener editor */
protected PropertyPanel m_RLEditorPanel = new PropertyPanel(m_RLEditor);
/** The panel that configures iteration on custom resultproducer property */
protected GeneratorPropertyIteratorPanel m_GeneratorPropertyPanel
= new GeneratorPropertyIteratorPanel();
/** The panel for configuring run numbers */
protected RunNumberPanel m_RunNumberPanel = new RunNumberPanel();
/** The panel for enabling a distributed experiment */
protected DistributeExperimentPanel m_DistributeExperimentPanel =
new DistributeExperimentPanel();
/** The panel for configuring selected datasets */
protected DatasetListPanel m_DatasetListPanel = new DatasetListPanel();
/** A button for bringing up the notes */
protected JButton m_NotesButton = new JButton("Notes");
/** Frame for the notes */
protected JFrame m_NotesFrame = new JFrame("Notes");
/** Area for user notes Default of 10 rows */
protected JTextArea m_NotesText = new JTextArea(null, 10, 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);
/** Click to advacne data set before custom generator */
protected JRadioButton m_advanceDataSetFirst =
new JRadioButton("Data sets first");
/** Click to advance custom generator before data set */
protected JRadioButton m_advanceIteratorFirst =
new JRadioButton("Custom generator first");
/** Handle radio buttons */
ActionListener m_RadioListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateRadioLinks();
}
};
// Registers the appropriate property editors
static {
GenericObjectEditor.registerEditors();
}
/**
* Creates the setup panel with the supplied initial experiment.
*
* @param exp a value of type 'Experiment'
*/
public SetupPanel(Experiment exp) {
this();
setExperiment(exp);
}
/**
* Creates the setup panel with no initial experiment.
*/
public SetupPanel() {
m_DistributeExperimentPanel.
addCheckBoxActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (m_DistributeExperimentPanel.distributedExperimentSelected()) {
if (!(m_Exp instanceof RemoteExperiment)) {
try {
RemoteExperiment re = new RemoteExperiment(m_Exp);
setExperiment(re);
} catch (Exception ex) {
ex.printStackTrace();
}
}
} else {
if (m_Exp instanceof RemoteExperiment) {
setExperiment(((RemoteExperiment)m_Exp).getBaseExperiment());
}
}
}
});
m_NewBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setExperiment(new Experiment());
}
});
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.addChoosableFileFilter(m_ExpFilter);
if (KOML.isPresent())
m_FileChooser.addChoosableFileFilter(m_KOMLFilter);
m_FileChooser.addChoosableFileFilter(m_XMLFilter);
m_FileChooser.setFileFilter(m_ExpFilter);
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
m_GeneratorPropertyPanel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateRadioLinks();
}
});
m_RPEditor.setClassType(ResultProducer.class);
m_RPEditor.setEnabled(false);
m_RPEditor.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
m_Exp.setResultProducer((ResultProducer) m_RPEditor.getValue());
m_Exp.setUsePropertyIterator(false);
m_Exp.setPropertyArray(null);
m_Exp.setPropertyPath(null);
m_GeneratorPropertyPanel.setExperiment(m_Exp);
repaint();
}
});
m_RLEditor.setClassType(ResultListener.class);
m_RLEditor.setEnabled(false);
m_RLEditor.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
m_Exp.setResultListener((ResultListener) m_RLEditor.getValue());
m_Support.firePropertyChange("", null, null);
repaint();
}
});
m_NotesFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
m_NotesButton.setEnabled(true);
}
});
m_NotesFrame.getContentPane().add(new JScrollPane(m_NotesText));
m_NotesFrame.setSize(600, 400);
m_NotesButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
m_NotesButton.setEnabled(false);
m_NotesFrame.setVisible(true);
}
});
m_NotesButton.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());
}
});
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(new GridLayout(1, 3, 5, 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 src = new JPanel();
src.setLayout(new BorderLayout());
src.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Result generator"),
BorderFactory.createEmptyBorder(0, 5, 5, 5)
));
src.add(m_RPEditorPanel, BorderLayout.NORTH);
JPanel dest = new JPanel();
dest.setLayout(new BorderLayout());
dest.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Destination"),
BorderFactory.createEmptyBorder(0, 5, 5, 5)
));
dest.add(m_RLEditorPanel, BorderLayout.NORTH);
m_advanceDataSetFirst.setEnabled(false);
m_advanceIteratorFirst.setEnabled(false);
m_advanceDataSetFirst.
setToolTipText("Advance data set before custom generator");
m_advanceIteratorFirst.
setToolTipText("Advance custom generator before data set");
m_advanceDataSetFirst.setSelected(true);
ButtonGroup bg = new ButtonGroup();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -