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

📄 binerizationoperatorproperty.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 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.
 */

/*
 * Created on 2005/1/24
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

package eti.bi.alphaminer.patch.standard.operation.property;

/**
 * @author kclai
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;


import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningStoredData;

import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.operation.property.OperatorProperty;
import eti.bi.exception.SysException;

import eti.bi.common.Locale.Resource;


public class BinerizationOperatorProperty extends OperatorProperty {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8007577666920777142L;

	private static String DEFAULT = Resource.srcStr("SelectItem");
    
	private MiningDataSpecification m_MetaData;
	@SuppressWarnings("unused")
	private MiningStoredData m_msd;
	
	// JComponents
	private JLabel m_AttributeLabel = new JLabel(Resource.srcStr("m_AttributeLabel"));
	
	private JComboBox m_AttributeJCB = new JComboBox();
	
	private JPopupMenu m_Menu = new JPopupMenu();
	 
	@SuppressWarnings("unused")
	private JMenu m_Submenu = new JMenu();

	private JMenuItem	m_MenuItemSelect;
	private JMenuItem m_MenuItemClear;
	
	private JButton m_ButtonReset = new JButton();

	private JButton m_ButtonApply = new JButton();

	private JButton m_ButtonClose = new JButton();
	
	private final Dimension m_defaultButtonSize = new Dimension(65, 25);
	
	private String[] m_MetaDataTableHeader = {
	        Resource.srcStr("Category"),
	        Resource.srcStr("Use")};
	
	private Hashtable m_TableModel;
	
	private JTable m_Table = new JTable(){
		 /**
		 * 
		 */
		private static final long serialVersionUID = 700481120421938580L;

		public boolean isCellEditable(int rowIndex, int vColIndex) {
            if (vColIndex == 1) 
            	return true;
			else
				return false;
        }
	};
	// variables
	
	public BinerizationOperatorProperty(String a_CaseID, String a_NodeID, String a_Name,  INodeInfo a_NodeInfo, ICaseHandler a_CaseHandler) throws MiningException, SysException{
		super(a_CaseID, a_NodeID, a_Name,  a_NodeInfo, a_CaseHandler);	
		createBinerizationOperatorProperty();
		this.setTitle(Resource.srcStr("BinerizationTitle")+"["+a_NodeID+"]") ; // Added title menu by Joyce 2005/02/17

	}
	
	private void createBinerizationOperatorProperty() throws MiningException{		
		/*
		 * create attribute panel
		 */
		JPanel attributePanel = new JPanel();
		attributePanel.setLayout(new BoxLayout(attributePanel, 
									BoxLayout.LINE_AXIS));
		
		/* Convert the following attriubtes to the corresponding items */
		@SuppressWarnings("unused") String[] items = {  "Please select...", "Attributes1",
				"Attributes2", "Attributes3", "Attributes4",
				"Attributes5" };

		m_AttributeJCB.setPreferredSize(new Dimension(10, 20));
		m_AttributeJCB.addActionListener(this);
		attributePanel.add(m_AttributeLabel);
		attributePanel.add(Box.createRigidArea(new Dimension(20, 0)));
		attributePanel.add(m_AttributeJCB);

		
		/*
		 * create table panel
		 */
		// set table default
		m_Table.setPreferredScrollableViewportSize(new Dimension(200, 140));
		m_Table.setCellSelectionEnabled(false);
		m_Table.getTableHeader().setReorderingAllowed(false);
		JScrollPane tableScrollPane = new JScrollPane(m_Table, 
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 
				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );

		
		
		// create Popup menu
		m_MenuItemClear = new JMenuItem(Resource.srcStr("m_MenuItemClear"));
		// m_MenuItem.addActionListener(this);
		 //<<added  by Joyce 08/03/2005
		m_MenuItemClear.addActionListener(new ActionListener() {
			  public void actionPerformed(ActionEvent event) {
			  	if ( m_Table.getRowCount() > 0){
			  		for (int i = 0; i < m_Table.getRowCount() ; i ++){
			  			m_Table.getModel().setValueAt(new Boolean(false), i, 1);
			  		}} }
			});
		
        m_Menu.add(m_MenuItemClear);
        m_MenuItemSelect = new JMenuItem(Resource.srcStr("m_MenuItemSelect"));
        //<<added  by Joyce 08/03/2005
		m_MenuItemSelect.addActionListener(new ActionListener() {
			  public void actionPerformed(ActionEvent event) {
			  	if ( m_Table.getRowCount() > 0){
			  		for (int i = 0; i < m_Table.getRowCount() ; i ++){
			  			m_Table.getModel().setValueAt(new Boolean(true), i, 1);
			  		}			  	
			  	}
			  }
			});
		//>>>
		//m_MenuItem.addActionListener(this);
        m_Menu.add(m_MenuItemSelect);
        m_Menu.setFont( m_AttributeJCB.getFont() ); 
        m_Menu.setPopupSize(new Dimension(95, 50));
        MouseListener popupListener = new PopupListener(m_Menu);
        m_Table.addMouseListener(popupListener);

        
		/*
		 * create button panel
		 */
		JPanel buttonPanel = new JPanel();
		
		m_ButtonApply.setText(Resource.srcStr("m_ButtonApply"));
		m_ButtonApply.setPreferredSize(m_defaultButtonSize);

		m_ButtonReset.setSelected(false);
		m_ButtonReset.setText(Resource.srcStr("m_ButtonReset"));
		m_ButtonReset.setPreferredSize(m_defaultButtonSize);

		m_ButtonClose.setSelected(false);
		m_ButtonClose.setText(Resource.srcStr("m_ButtonClose"));
		m_ButtonClose.setPreferredSize(m_defaultButtonSize);

		buttonPanel.add(m_ButtonApply);
		buttonPanel.add(m_ButtonReset);
		buttonPanel.add(m_ButtonClose);
		
//		JPanel upperPanel = new JPanel(new BorderLayout(0, 5));
//		JPanel lowerPanel = new JPanel(new BorderLayout(0, 5));
//		upperPanel.add(attributePanel, BorderLayout.CENTER);
//		lowerPanel.add(tableScrollPane, BorderLayout.NORTH);
//		lowerPanel.add(buttonPanel, BorderLayout.SOUTH);
//
//		this.getContentPane().add(upperPanel, BorderLayout.NORTH);
//		this.getContentPane().add(lowerPanel, BorderLayout.SOUTH);
		
		
		BorderLayout contentLayout = new BorderLayout(0, 10);
		this.getContentPane().setLayout(contentLayout);
		attributePanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
		this.getContentPane().add(attributePanel, BorderLayout.NORTH);
		this.getContentPane().add(tableScrollPane, BorderLayout.CENTER);
		this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
		
		this.setContentPane(this.getContentPane());
//		this.setVisible(true);remarked by Joyce
		this.setSize(300, 260);
		//Added by Joyce 2005/01/24
		m_ButtonReset.addActionListener(this);
		m_ButtonApply.addActionListener(this);
		m_ButtonClose.addActionListener(this);
		
		initContent();
		getContent();
	}
	
	
	/**
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
	 */
    public void actionPerformed(ActionEvent e) {
    	/* Remarked by Joyce error?
    	JMenuItem source = (JMenuItem)(e.getSource());
    	if ( source.getText() == "Clear ALL" ) {
        	// set all category uses to be false
    	} else if ( source.getText() == "Select ALL" ) {
    		// set all category uses to be true
    	} */
    	
    	if (e.getSource() == m_ButtonApply) {
    		if (setContent())
			{
				m_ParameterChanged = true;
				setPropertiesModified();
			}
		} else if (e.getSource() == m_ButtonReset) {
			getContent();
		} else if (e.getSource() == m_ButtonClose) {
			close();
		} else if (e.getSource() == m_AttributeJCB){
		    String attrName =(String)m_AttributeJCB.getSelectedItem();
		   
			if(attrName!=null && attrName.trim().length()>0 && !attrName.equalsIgnoreCase(DEFAULT)){
			    m_Table.setModel((BinerizationTableModel)m_TableModel.get(attrName));
			}
		    else {
		        m_Table.setModel(new BinerizationTableModel());
		    }
		}
    }
    
	

	class PopupListener extends MouseAdapter {
		JPopupMenu menu;

        PopupListener(JPopupMenu popup) {
        	menu = popup;
        }

        public void mousePressed(MouseEvent me) {
            showMenu(me);
        }

        public void mouseReleased(MouseEvent me) {
        	showMenu(me);
        }

        private void showMenu(MouseEvent me) {
            if ( me.isPopupTrigger() ) {
            	menu.show(me.getComponent(), me.getX(), me.getY());
            }
        }
    }
	
	public boolean setContent() {
	    if(!validateProperty())

⌨️ 快捷键说明

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