📄 algorithmlistpanel.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. *//* * AlgorithmListPanel.java * Copyright (C) 2002 Richard Kirkby * */package weka.gui.experiment;import weka.core.OptionHandler;import weka.core.Utils;import weka.classifiers.Classifier;import weka.gui.ExtensionFileFilter;import weka.gui.GenericObjectEditor;import weka.gui.JListHelper;import weka.gui.PropertyDialog;import weka.classifiers.xml.XMLClassifier;import weka.core.Instances;import weka.core.SerializedObject;import weka.experiment.Experiment;import java.util.Vector;import java.awt.Component;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.ActionListener;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Insets;import javax.swing.JPanel;import javax.swing.JLabel;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.SwingConstants;import javax.swing.JTextField;import javax.swing.BorderFactory;import javax.swing.DefaultListModel;import javax.swing.JScrollPane;import javax.swing.JList;import javax.swing.JButton;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.DefaultListCellRenderer;import javax.swing.filechooser.FileFilter;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.beans.PropertyEditor;import java.io.File;/** * This panel controls setting a list of algorithms for an experiment to * iterate over. * * @author Richard Kirkby (rkirkby@cs.waikato.ac.nz) * @version $Revision: 1.15 $ */public class AlgorithmListPanel extends JPanel implements ActionListener { /* Class required to show the Classifiers nicely in the list */ public class ObjectCellRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); String rep = value.getClass().getName(); int dotPos = rep.lastIndexOf('.'); if (dotPos != -1) { rep = rep.substring(dotPos + 1); } if (value instanceof OptionHandler) { rep += " " + Utils.joinOptions(((OptionHandler)value) .getOptions()); } setText(rep); return c; } } /** The experiment to set the algorithm list of */ protected Experiment m_Exp; /** The component displaying the algorithm list */ protected JList m_List; /** Click to add an algorithm */ protected JButton m_AddBut = new JButton("Add new..."); /** Click to edit the selected algorithm */ protected JButton m_EditBut = new JButton("Edit selected..."); /** Click to remove the selected dataset from the list */ protected JButton m_DeleteBut = new JButton("Delete selected"); /** Click to edit the load the options for athe selected algorithm */ protected JButton m_LoadOptionsBut = new JButton("Load options..."); /** Click to edit the save the options from selected algorithm */ protected JButton m_SaveOptionsBut = new JButton("Save options..."); /** Click to move the selected algorithm(s) one up */ protected JButton m_UpBut = new JButton("Up"); /** Click to move the selected algorithm(s) one down */ protected JButton m_DownBut = new JButton("Down"); /** The file chooser for selecting experiments */ protected JFileChooser m_FileChooser = new JFileChooser(new File(System.getProperty("user.dir"))); /** 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)"); /** Whether an algorithm is added or only edited */ protected boolean m_Editing = false; /** Lets the user configure the classifier */ protected GenericObjectEditor m_ClassifierEditor = new GenericObjectEditor(true); /** The currently displayed property dialog, if any */ protected PropertyDialog m_PD; /** The list model used */ protected DefaultListModel m_AlgorithmListModel = new DefaultListModel(); /* Register the property editors we need */ static { GenericObjectEditor.registerEditors(); } /** * Creates the algorithm list panel with the given experiment. * * @param exp a value of type 'Experiment' */ public AlgorithmListPanel(Experiment exp) { this(); setExperiment(exp); } /** * Create the algorithm list panel initially disabled. */ public AlgorithmListPanel() { m_List = new JList(); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { // unfortunately, locationToIndex only returns the nearest entry // and not the exact one, i.e. if there's one item in the list and // one doublelclicks somewhere in the list, this index will be // returned int index = m_List.locationToIndex(e.getPoint()); if (index > -1) actionPerformed(new ActionEvent(m_EditBut, 0, "")); } } }; m_List.addMouseListener(mouseListener); m_ClassifierEditor.setClassType(Classifier.class); m_ClassifierEditor.setValue(new weka.classifiers.rules.ZeroR()); m_ClassifierEditor.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { repaint(); } }); ((GenericObjectEditor.GOEPanel) m_ClassifierEditor.getCustomEditor()).addOkListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Classifier newCopy = (Classifier) copyObject(m_ClassifierEditor.getValue()); addNewAlgorithm(newCopy); } }); m_DeleteBut.setEnabled(false); m_DeleteBut.addActionListener(this); m_AddBut.setEnabled(false); m_AddBut.addActionListener(this); m_EditBut.setEnabled(false); m_EditBut.addActionListener(this); m_LoadOptionsBut.setEnabled(false); m_LoadOptionsBut.addActionListener(this); m_SaveOptionsBut.setEnabled(false); m_SaveOptionsBut.addActionListener(this); m_UpBut.setEnabled(false); m_UpBut.addActionListener(this); m_DownBut.setEnabled(false); m_DownBut.addActionListener(this); m_List.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { setButtons(e); } }); m_FileChooser.addChoosableFileFilter(m_XMLFilter); m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); setLayout(new BorderLayout()); setBorder(BorderFactory.createTitledBorder("Algorithms")); JPanel topLab = new JPanel(); GridBagLayout gb = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); topLab.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5)); topLab.setLayout(gb); constraints.gridx=0;constraints.gridy=0;constraints.weightx=5; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridwidth=1;constraints.gridheight=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -