📄 resultspanel.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. *//* * ResultsPanel.java * Copyright (C) 1999 Len Trigg * */package weka.gui.experiment;import weka.gui.ExtensionFileFilter;import weka.gui.ListSelectorDialog;import weka.gui.ResultHistoryPanel;import weka.gui.SaveBuffer;import weka.gui.DatabaseConnectionDialog;import weka.experiment.Experiment;import weka.experiment.CSVResultListener;import weka.experiment.DatabaseResultListener;import weka.experiment.PairedCorrectedTTester;import weka.experiment.ResultMatrix;import weka.experiment.ResultMatrixPlainText;import weka.experiment.Tester;import weka.experiment.InstanceQuery;import weka.core.Attribute;import weka.core.Instances;import weka.core.Range;import weka.core.ClassDiscovery;import weka.core.Instance;import weka.core.converters.CSVLoader;import java.io.Reader;import java.io.FileReader;import java.io.BufferedReader;import java.io.File;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.Font;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.StringTokenizer;import java.util.Vector;import javax.swing.JPanel;import javax.swing.JLabel;import javax.swing.JFrame;import javax.swing.JButton;import javax.swing.JTextArea;import javax.swing.BorderFactory;import javax.swing.JScrollPane;import javax.swing.SwingConstants;import javax.swing.JFileChooser;import javax.swing.JComboBox;import javax.swing.JTextField;import javax.swing.DefaultComboBoxModel;import javax.swing.DefaultListModel;import javax.swing.JList;import javax.swing.JSplitPane;import javax.swing.ListSelectionModel;import javax.swing.JOptionPane;import javax.swing.JCheckBox;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Insets;import java.util.Date;import java.text.SimpleDateFormat;import java.awt.Dimension;import javax.swing.SwingUtilities;/** * This panel controls simple analysis of experimental results. * * @author Len Trigg (trigg@cs.waikato.ac.nz) * @version $Revision: 1.40 $ */public class ResultsPanel extends JPanel { /** Message shown when no experimental results have been loaded */ protected static final String NO_SOURCE = "No source"; /** Click to load results from a file */ protected JButton m_FromFileBut = new JButton("File..."); /** Click to load results from a database */ protected JButton m_FromDBaseBut = new JButton("Database..."); /** Click to get results from the destination given in the experiment */ protected JButton m_FromExpBut = new JButton("Experiment"); /** Displays a message about the current result set */ protected JLabel m_FromLab = new JLabel(NO_SOURCE); /** * This is needed to get around a bug in Swing <= 1.1 -- Once everyone * is using Swing 1.1.1 or higher just remove this variable and use the * no-arg constructor to DefaultComboBoxModel */ private static String [] FOR_JFC_1_1_DCBM_BUG = {""}; /** The model embedded in m_DatasetCombo */ protected DefaultComboBoxModel m_DatasetModel = new DefaultComboBoxModel(FOR_JFC_1_1_DCBM_BUG); /** The model embedded in m_CompareCombo */ protected DefaultComboBoxModel m_CompareModel = new DefaultComboBoxModel(FOR_JFC_1_1_DCBM_BUG); /** The model embedded in m_SortCombo */ protected DefaultComboBoxModel m_SortModel = new DefaultComboBoxModel(FOR_JFC_1_1_DCBM_BUG); /** The model embedded in m_TestsList */ protected DefaultListModel m_TestsModel = new DefaultListModel(); /** The model embedded in m_DisplayedList */ protected DefaultListModel m_DisplayedModel = new DefaultListModel(); /** Displays the currently selected Tester-Class */ protected JLabel m_TesterClassesLabel = new JLabel("Testing with", SwingConstants.RIGHT); /** Contains all the available classes implementing the Tester-Interface * (the display names) * @see Tester */ protected static DefaultComboBoxModel m_TesterClassesModel = new DefaultComboBoxModel(FOR_JFC_1_1_DCBM_BUG); /** Contains all the available classes implementing the Tester-Interface * (the actual Classes) * @see Tester */ protected static Vector m_Testers = null; /** determine all classes implementing the Tester interface (in the same * package!) * @see Tester * @see ClassDiscovery */ static { Vector classes = ClassDiscovery.find( Tester.class.getName(), Tester.class.getPackage().getName()); // set names and classes m_Testers = new Vector(); m_TesterClassesModel = new DefaultComboBoxModel(); for (int i = 0; i < classes.size(); i++) { try { Class cls = Class.forName(classes.get(i).toString()); Tester tester = (Tester) cls.newInstance(); m_Testers.add(cls); m_TesterClassesModel.addElement(tester.getDisplayName()); } catch (Exception e) { e.printStackTrace(); } } } /** Lists all the available classes implementing the Tester-Interface * @see Tester */ protected JComboBox m_TesterClasses = new JComboBox(m_TesterClassesModel); /** Displays the currently selected column names for the scheme & options */ protected JLabel m_DatasetKeyLabel = new JLabel("Row", SwingConstants.RIGHT); /** Click to edit the columns used to determine the scheme */ protected JButton m_DatasetKeyBut = new JButton("Select"); /** Stores the list of attributes for selecting the scheme columns */ protected DefaultListModel m_DatasetKeyModel = new DefaultListModel(); /** Displays the list of selected columns determining the scheme */ protected JList m_DatasetKeyList = new JList(m_DatasetKeyModel); /** Displays the currently selected column names for the scheme & options */ protected JLabel m_ResultKeyLabel = new JLabel("Column", SwingConstants.RIGHT); /** Click to edit the columns used to determine the scheme */ protected JButton m_ResultKeyBut = new JButton("Select"); /** Stores the list of attributes for selecting the scheme columns */ protected DefaultListModel m_ResultKeyModel = new DefaultListModel(); /** Displays the list of selected columns determining the scheme */ protected JList m_ResultKeyList = new JList(m_ResultKeyModel); /** Lets the user select which scheme to base comparisons against */ protected JButton m_TestsButton = new JButton("Select"); /** Lets the user select which schemes are compared to base */ protected JButton m_DisplayedButton = new JButton("Select"); /** Holds the list of schemes to base the test against */ protected JList m_TestsList = new JList(m_TestsModel); /** Holds the list of schemes to display */ protected JList m_DisplayedList = new JList(m_DisplayedModel); /** Lets the user select which performance measure to analyze */ protected JComboBox m_CompareCombo = new JComboBox(m_CompareModel); /** Lets the user select which column to use for sorting */ protected JComboBox m_SortCombo = new JComboBox(m_SortModel); /** Lets the user edit the test significance */ protected JTextField m_SigTex = new JTextField( "" + ExperimenterDefaults.getSignificance()); /** Lets the user select whether standard deviations are to be output or not */ protected JCheckBox m_ShowStdDevs = new JCheckBox(""); /** lets the user choose the format for the output */ protected JButton m_OutputFormatButton = new JButton("Select"); /** Click to start the test */ protected JButton m_PerformBut = new JButton("Perform test"); /** Click to save test output to a file */ protected JButton m_SaveOutBut = new JButton("Save output"); /** The buffer saving object for saving output */ SaveBuffer m_SaveOut = new SaveBuffer(null, this); /** Displays the output of tests */ protected JTextArea m_OutText = new JTextArea(); /** A panel controlling results viewing */ protected ResultHistoryPanel m_History = new ResultHistoryPanel(m_OutText); /** The file chooser for selecting result files */ protected JFileChooser m_FileChooser = new JFileChooser(new File(System.getProperty("user.dir"))); /** File filters for various file types */ protected ExtensionFileFilter m_csvFileFilter = new ExtensionFileFilter(CSVLoader.FILE_EXTENSION, "CSV data files"); protected ExtensionFileFilter m_arffFileFilter = new ExtensionFileFilter(Instances.FILE_EXTENSION, "Arff data files"); /** The PairedTTester object */ protected Tester m_TTester = new PairedCorrectedTTester(); /** The instances we're extracting results from */ protected Instances m_Instances; /** Does any database querying for us */ protected InstanceQuery m_InstanceQuery; /** A thread to load results instances from a file or database */ protected Thread m_LoadThread; /** An experiment (used for identifying a result source) -- optional */ protected Experiment m_Exp; private Dimension COMBO_SIZE = new Dimension(150, m_ResultKeyBut .getPreferredSize().height); /** the initial result matrix */ protected ResultMatrix m_ResultMatrix = new ResultMatrixPlainText(); /** * Creates the results panel with no initial experiment. */ public ResultsPanel() { // defaults m_TTester.setSignificanceLevel(ExperimenterDefaults.getSignificance()); m_TTester.setShowStdDevs(ExperimenterDefaults.getShowStdDevs()); try { m_ResultMatrix = (ResultMatrix) Class.forName( ExperimenterDefaults.getOutputFormat()).newInstance(); } catch (Exception e) { m_ResultMatrix = new ResultMatrixPlainText(); } m_ResultMatrix.setShowStdDev(ExperimenterDefaults.getShowStdDevs()); m_ResultMatrix.setMeanPrec(ExperimenterDefaults.getMeanPrecision()); m_ResultMatrix.setStdDevPrec(ExperimenterDefaults.getStdDevPrecision()); m_ResultMatrix.setRemoveFilterName(ExperimenterDefaults.getRemoveFilterClassnames()); m_ResultMatrix.setShowAverage(ExperimenterDefaults.getShowAverage()); // Create/Configure/Connect components m_FileChooser. addChoosableFileFilter(m_csvFileFilter); m_FileChooser. addChoosableFileFilter(m_arffFileFilter); m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); m_FromExpBut.setEnabled(false); m_FromExpBut.setMnemonic('E'); m_FromExpBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_LoadThread == null) { m_LoadThread = new Thread() { public void run() { setInstancesFromExp(m_Exp); m_LoadThread = null; } }; m_LoadThread.start(); } } }); m_FromDBaseBut.setMnemonic('D'); m_FromDBaseBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_LoadThread == null) { m_LoadThread = new Thread() { public void run() { setInstancesFromDBaseQuery(); m_LoadThread = null; } }; m_LoadThread.start(); } } }); m_FromFileBut.setMnemonic('F'); m_FromFileBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int returnVal = m_FileChooser.showOpenDialog(ResultsPanel.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File selected = m_FileChooser.getSelectedFile(); if (m_LoadThread == null) { m_LoadThread = new Thread() { public void run() { setInstancesFromFile(selected); m_LoadThread = null; } }; m_LoadThread.start(); } } } }); setComboSizes(); m_TesterClasses.setEnabled(false); m_DatasetKeyBut.setEnabled(false); m_DatasetKeyBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setDatasetKeyFromDialog(); } }); m_DatasetKeyList.setSelectionMode(ListSelectionModel .MULTIPLE_INTERVAL_SELECTION); m_ResultKeyBut.setEnabled(false); m_ResultKeyBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setResultKeyFromDialog(); } }); m_ResultKeyList.setSelectionMode(ListSelectionModel .MULTIPLE_INTERVAL_SELECTION); m_CompareCombo.setEnabled(false); m_SortCombo.setEnabled(false); m_SigTex.setEnabled(false); m_TestsButton.setEnabled(false); m_TestsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setTestBaseFromDialog(); } }); m_DisplayedButton.setEnabled(false); m_DisplayedButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setDisplayedFromDialog(); } }); m_ShowStdDevs.setEnabled(false); m_ShowStdDevs.setSelected(ExperimenterDefaults.getShowStdDevs()); m_OutputFormatButton.setEnabled(false); m_OutputFormatButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setOutputFormatFromDialog(); } }); m_PerformBut.setEnabled(false); m_PerformBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { performTest(); m_SaveOutBut.setEnabled(true); } }); m_PerformBut.setToolTipText(m_TTester.getToolTipText()); m_SaveOutBut.setEnabled(false); m_SaveOutBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { saveBuffer(); } }); m_OutText.setFont(new Font("Monospaced", Font.PLAIN, 12)); m_OutText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); m_OutText.setEditable(false); m_History.setBorder(BorderFactory.createTitledBorder("Result list")); // Set up the GUI layout JPanel p1 = new JPanel(); p1.setBorder(BorderFactory.createTitledBorder("Source")); JPanel p2 = new JPanel(); GridBagLayout gb = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5)); // p2.setLayout(new GridLayout(1, 3)); p2.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); p2.add(m_FromFileBut,constraints); constraints.gridx=1;constraints.gridy=0;constraints.weightx=5; constraints.gridwidth=1;constraints.gridheight=1; p2.add(m_FromDBaseBut,constraints); constraints.gridx=2;constraints.gridy=0;constraints.weightx=5; constraints.gridwidth=1;constraints.gridheight=1; p2.add(m_FromExpBut,constraints); p1.setLayout(new BorderLayout()); p1.add(m_FromLab, BorderLayout.CENTER); p1.add(p2, BorderLayout.EAST); JPanel p3 = new JPanel();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -