⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addmodelspanel.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *    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. *//* *    AddModelsPanel.java *    Copyright (C) 2006 Robert Jung * */package weka.gui.ensembleLibraryEditor;import weka.classifiers.Classifier;import weka.classifiers.EnsembleLibraryModel;import weka.classifiers.trees.J48;import weka.gui.GenericObjectEditor;import weka.gui.ensembleLibraryEditor.tree.GenericObjectNode;import weka.gui.ensembleLibraryEditor.tree.ModelTreeNodeEditor;import weka.gui.ensembleLibraryEditor.tree.ModelTreeNodeRenderer;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Iterator;import java.util.Vector;import javax.swing.AbstractAction;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTree;import javax.swing.KeyStroke;import javax.swing.ListSelectionModel;import javax.swing.ToolTipManager;import javax.swing.tree.DefaultTreeModel;/** * The purpose of this class is to create a user interface that will * provide an intuitive method of building "playlists" of weka  * classifiers to be trained.  The main gui consists of two parts: the * top and bottom. The top will use a JTree to show all of the options * available for a particular classifier. The intent of showing these  * options in a tree is to allow users to collapse/expand tree nodes  * to quickly access all of the available options at different levels. * The bottom half of the gui will show the current "playlist" of  * chosen models that the user can opt to add to the current library.   * <p/> * The overall concept is that users will use the tree to specify  * combinations of options to the currently selected classifier type. * then they will use the "generate models" button to generate a set * models from the selected options. This can be done many times with * different sets of options for different model types to generate a * list in the bottom half of the gui.  Once the user is satisfied * with their list of models they are provided a button to "add all  * models" to the model library displayed by the ListModelsPanel. * <p/> * Note that there are currently 9 different classes that implement * tree nodes and tree node editors created to support this class * in modelling/rendering weka classifier parameters. see  * appropriate classes for details.  They currently reside in the  * weka.gui.libraryEditor.tree package. * <p/> * To instantiate the treeModel: * <ul> *   <li>ModelNodeEditor</li> *   <li>ModelNodeRenderer</li> * </ul> *  * To render/model weka objects: * <ul> *   <li>PropertyNode</li> *   <li>GenericObjectNode</li> *   <li>GenericObjectNodeEditor</li> *   <li>CheckBoxNode</li> *   <li>CheckBoxNodeEditor</li> *   <li>NumberNode</li> *   <li>NumberNodeEditor</li> *   <li>DefaultNode</li> * </ul> *  * These classes are responsible for  * representing the different kinds of tree nodes that will be  * contained in the JTree object, as well as the renderers and editors * that will be responsible for displaying their properties in the * user interface.   * <p/> * Code for this class was inspired and partly borrowed from the  * following excellent tutorial on creating custom JTree renderers  * and editors authored by John Zukowski: <br/> * <a href="http://www.java2s.com/ExampleCode/Swing-JFC/CheckBoxNodeTreeSample.htm" target="_blank">http://www.java2s.com/ExampleCode/Swing-JFC/CheckBoxNodeTreeSample.htm</a> *  * @author  Robert Jung (mrbobjung@gmail.com) * @version $Revision: 1.1 $ */public class AddModelsPanel   extends JPanel  implements ActionListener {    /** for serialization */  private static final long serialVersionUID = 4874639416371962573L;  /**   * This is a reference to the main gui object that is responsible    * for displaying the model library.  This panel will add models   * to the main panel through methods in this object.   */  private ListModelsPanel m_ListModelsPanel;    /**   * The JTree that will display the classifier options available in   * the currently select3ed model type   */  private JTree m_Tree;    /**   * The tree model that will be used to add and remove nodes from    * the currently selected model type   */  private DefaultTreeModel m_TreeModel;    /**   * This button will allow users to generate a group of models from   * the currently selected classifer options in the m_Tree object.   */  private JButton m_GenerateButton;    /**   * This will display messages associated with model generation.   * Currently the number of models generated and the number of   * them that had errors.   */  private JLabel m_GenerateLabel;    /**   * This button will allow users to remove all of the models    * currently selected in the m_ModeList object   */  private JButton m_RemoveSelectedButton;    /**   * This button will remove all of the models that had errors    * during model generation.   */  private JButton m_RemoveInvalidButton;    /**   * This button will add all of the models that had are    * currently selected in the model list.   */  private JButton m_AddSelectedButton;    /**   * This button will allow users to add all models currently in    * the model list to the model library in the ListModelsPanel.    * Note that this operation will exclude any models that had    * errors   */  private JButton m_AddAllButton;    /**   * This object will store all of the model sets generated from the   * m_Tree.  The ModelList class is a custom class in weka.gui that   * knows how to display library model objects in a JList   */  private ModelList m_ModelList;    /** the scroll pane holding our classifer parameters */  JScrollPane m_TreeView;    /**   * This constructor simply stores the reference to the    * ListModelsPanel and builf the user interface.   *    * @param listModelsPanel	the reference to the panel   */  public AddModelsPanel(ListModelsPanel listModelsPanel) {    m_ListModelsPanel = listModelsPanel;        createAddModelsPanel();  }    /**   * This method is responsible for building the use interface.   */  private void createAddModelsPanel() {    GridBagConstraints gbc = new GridBagConstraints();    setLayout(new GridBagLayout());        m_TreeView = new JScrollPane();    m_TreeView.setPreferredSize(new Dimension(150, 50));        buildClassifierTree(new J48());        ToolTipManager.sharedInstance().registerComponent(m_Tree);        gbc.weightx = 1;    gbc.weighty = 1.5;    gbc.fill = GridBagConstraints.BOTH;    gbc.gridx = 0;    gbc.gridy = 0;    gbc.gridwidth = 3;    gbc.anchor = GridBagConstraints.WEST;    add(m_TreeView, gbc);        m_GenerateButton = new JButton("Generate Models");    m_GenerateButton.setToolTipText(	"Generate a set of models from options specified in options tree");    m_GenerateButton.addActionListener(this);    gbc.weightx = 0;    gbc.weighty = 0;    gbc.fill = GridBagConstraints.NONE;    gbc.gridx = 0;    gbc.gridy = 1;    gbc.anchor = GridBagConstraints.WEST;    gbc.gridwidth = 1;    add(m_GenerateButton, gbc);        m_GenerateLabel = new JLabel("");    gbc.weightx = 1;    gbc.fill = GridBagConstraints.HORIZONTAL;    gbc.gridx = 1;    gbc.gridy = 1;    gbc.anchor = GridBagConstraints.WEST;    gbc.gridwidth = 2;    add(m_GenerateLabel, gbc);        m_RemoveInvalidButton = new JButton("Remove Invalid");    m_RemoveInvalidButton.setToolTipText(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -