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

📄 associationspanel.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. *//* *    AssociationsPanel.java *    Copyright (C) 1999 Eibe Frank * */package weka.gui.explorer;import weka.associations.Associator;import weka.core.Attribute;import weka.core.Capabilities;import weka.core.Instances;import weka.core.OptionHandler;import weka.core.Utils;import weka.gui.GenericObjectEditor;import weka.gui.Logger;import weka.gui.PropertyPanel;import weka.gui.ResultHistoryPanel;import weka.gui.SaveBuffer;import weka.gui.SysErrLog;import weka.gui.TaskLogger;import weka.gui.explorer.Explorer.CapabilitiesFilterChangeEvent;import weka.gui.explorer.Explorer.CapabilitiesFilterChangeListener;import java.awt.BorderLayout;import java.awt.Font;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.InputEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.text.SimpleDateFormat;import java.util.Date;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JViewport;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;/**  * This panel allows the user to select, configure, and run a scheme * that learns associations. * * @author Eibe Frank (eibe@cs.waikato.ac.nz) * @version $Revision: 1.23 $ */public class AssociationsPanel   extends JPanel  implements CapabilitiesFilterChangeListener {    /** for serialization */  static final long serialVersionUID = -6867871711865476971L;  /** Lets the user configure the associator */  protected GenericObjectEditor m_AssociatorEditor =    new GenericObjectEditor();  /** The panel showing the current associator selection */  protected PropertyPanel m_CEPanel = new PropertyPanel(m_AssociatorEditor);    /** The output area for associations */  protected JTextArea m_OutText = new JTextArea(20, 40);  /** The destination for log/status messages */  protected Logger m_Log = new SysErrLog();  /** The buffer saving object for saving output */  protected SaveBuffer m_SaveOut = new SaveBuffer(m_Log, this);  /** A panel controlling results viewing */  protected ResultHistoryPanel m_History = new ResultHistoryPanel(m_OutText);  /** Click to start running the associator */  protected JButton m_StartBut = new JButton("Start");  /** Click to stop a running associator */  protected JButton m_StopBut = new JButton("Stop");    /** The main set of instances we're playing with */  protected Instances m_Instances;  /** The user-supplied test set (if any) */  protected Instances m_TestInstances;    /** A thread that associator runs in */  protected Thread m_RunThread;  /* Register the property editors we need */  static {     GenericObjectEditor.registerEditors();  }    /**   * Creates the associator panel   */  public AssociationsPanel() {    // Connect / configure the components    m_OutText.setEditable(false);    m_OutText.setFont(new Font("Monospaced", Font.PLAIN, 12));    m_OutText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    m_OutText.addMouseListener(new MouseAdapter() {      public void mouseClicked(MouseEvent e) {	if ((e.getModifiers() & InputEvent.BUTTON1_MASK)	    != InputEvent.BUTTON1_MASK) {	  m_OutText.selectAll();	}      }    });    m_History.setBorder(BorderFactory.createTitledBorder("Result list (right-click for options)"));    m_History.setHandleRightClicks(false);    // see if we can popup a menu for the selected result    m_History.getList().addMouseListener(new MouseAdapter() {	public void mouseClicked(MouseEvent e) {	  if (((e.getModifiers() & InputEvent.BUTTON1_MASK)	       != InputEvent.BUTTON1_MASK) || e.isAltDown()) {	    int index = m_History.getList().locationToIndex(e.getPoint());	    if (index != -1) {	      String name = m_History.getNameAtIndex(index);	      historyRightClickPopup(name, e.getX(), e.getY());	    } else {	      historyRightClickPopup(null, e.getX(), e.getY());	    }	  }	}      });    m_AssociatorEditor.setClassType(Associator.class);    m_AssociatorEditor.setValue(ExplorerDefaults.getAssociator());    m_AssociatorEditor.addPropertyChangeListener(new PropertyChangeListener() {      public void propertyChange(PropertyChangeEvent e) {	repaint();      }    });    m_StartBut.setToolTipText("Starts the associator");    m_StopBut.setToolTipText("Stops the associator");    m_StartBut.setEnabled(false);    m_StopBut.setEnabled(false);    m_StartBut.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	startAssociator();      }    });    m_StopBut.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	stopAssociator();      }    });    // Layout the GUI    JPanel p1 = new JPanel();    p1.setBorder(BorderFactory.createCompoundBorder(		 BorderFactory.createTitledBorder("Associator"),		 BorderFactory.createEmptyBorder(0, 5, 5, 5)		 ));    p1.setLayout(new BorderLayout());    p1.add(m_CEPanel, BorderLayout.NORTH);    JPanel buttons = new JPanel();    buttons.setLayout(new GridLayout(1,2));    JPanel ssButs = new JPanel();    ssButs.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    ssButs.setLayout(new GridLayout(1, 2, 5, 5));    ssButs.add(m_StartBut);    ssButs.add(m_StopBut);    buttons.add(ssButs);    JPanel p3 = new JPanel();    p3.setBorder(BorderFactory.createTitledBorder("Associator output"));    p3.setLayout(new BorderLayout());    final JScrollPane js = new JScrollPane(m_OutText);    p3.add(js, BorderLayout.CENTER);    js.getViewport().addChangeListener(new ChangeListener() {      private int lastHeight;      public void stateChanged(ChangeEvent e) {	JViewport vp = (JViewport)e.getSource();	int h = vp.getViewSize().height; 	if (h != lastHeight) { // i.e. an addition not just a user scrolling	  lastHeight = h;	  int x = h - vp.getExtentSize().height;	  vp.setViewPosition(new Point(0, x));	}      }    });        GridBagLayout gbL = new GridBagLayout();    GridBagConstraints gbC = new GridBagConstraints();    JPanel mondo = new JPanel();    gbL = new GridBagLayout();    mondo.setLayout(gbL);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.NORTH;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 1;     gbC.gridx = 0;    gbL.setConstraints(buttons, gbC);    mondo.add(buttons);    gbC = new GridBagConstraints();    gbC.fill = GridBagConstraints.BOTH;    gbC.gridy = 2;     gbC.gridx = 0; gbC.weightx = 0;    gbL.setConstraints(m_History, gbC);    mondo.add(m_History);    gbC = new GridBagConstraints();    gbC.fill = GridBagConstraints.BOTH;    gbC.gridy = 0;     gbC.gridx = 1;    gbC.gridheight = 3;    gbC.weightx = 100; gbC.weighty = 100;    gbL.setConstraints(p3, gbC);    mondo.add(p3);    setLayout(new BorderLayout());    add(p1, BorderLayout.NORTH);    add(mondo, BorderLayout.CENTER);  }    /**   * Sets the Logger to receive informational messages   *   * @param newLog the Logger that will now get info messages   */  public void setLog(Logger newLog) {    m_Log = newLog;  }    /**   * Tells the panel to use a new set of instances.   *   * @param inst a set of Instances   */  public void setInstances(Instances inst) {        m_Instances = inst;

⌨️ 快捷键说明

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