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

📄 datasetattributesoperatorproperty.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		jScrollPane1.getViewport().setBackground(Color.white);
		jScrollPane1.getViewport().add(jTable1, null);

		m_ButtonReset.setText(Resource.srcStr("m_ButtonReset"));
		m_ButtonApply.setText(Resource.srcStr("m_ButtonApply"));
		m_ButtonClose.setSelected(false);
		m_ButtonClose.setText(Resource.srcStr("m_ButtonClose"));
		jPanel1.add(m_ButtonApply);
		jPanel1.add(m_ButtonReset);
		jPanel1.add(m_ButtonClose);
		jPanel1.setBorder(new EmptyBorder(4,0,0,0));
		
		m_ButtonReset.addActionListener(this);
		m_ButtonApply.addActionListener(this);
		m_ButtonClose.addActionListener(this);

		JTableHeader tableHeader = jTable1.getTableHeader();
		tableHeader.setReorderingAllowed(false);
	
		initContent();
		getContent();
		TableModel = new DataSetAttributesTableModel(m_MetaDataTableContent, m_MetaDataTableHeader, m_TargetIndex);
		jTable1.setModel(TableModel);		
		addListener();
		this.setSize(350, 250);

		this.addInternalFrameListener(this);
	}

	private String maptoText(String aName) {
		if(aName.equals(DataSetAttributesOperatorProperty.NUMERIC)) {
			return DataSetAttributesOperatorProperty.NUMERIC_Text;
		}
		else if(aName.equals(DataSetAttributesOperatorProperty.CATEGORICAL)) {
			return DataSetAttributesOperatorProperty.CATEGORICAL_Text;
		}
		if(aName.equals(DataSetAttributesOperatorProperty.STRING)) {
			return DataSetAttributesOperatorProperty.STRING_Text;
		}
		else if(aName.equals(DataSetAttributesOperatorProperty.DOUBLE)) {
			return DataSetAttributesOperatorProperty.DOUBLE_Text;
		}
		else if(aName.equals(DataSetAttributesOperatorProperty.USE)) {
			return DataSetAttributesOperatorProperty.USE_Text;
		}
		else if(aName.equals(DataSetAttributesOperatorProperty.NOT_USE)) {
			return DataSetAttributesOperatorProperty.NOT_USE_Text;
		}
		else if(aName.equals(DataSetAttributesOperatorProperty.TARGET)) {
			return DataSetAttributesOperatorProperty.TARGET_Text;
		}
		return aName;
	}
	
	private String maptoName(String aText) {
		if(aText.equals(DataSetAttributesOperatorProperty.NUMERIC_Text)) {
			return DataSetAttributesOperatorProperty.NUMERIC;
		}
		else if(aText.equals(DataSetAttributesOperatorProperty.CATEGORICAL_Text)) {
			return DataSetAttributesOperatorProperty.CATEGORICAL;
		}
		if(aText.equals(DataSetAttributesOperatorProperty.STRING_Text)) {
			return DataSetAttributesOperatorProperty.STRING;
		}
		else if(aText.equals(DataSetAttributesOperatorProperty.DOUBLE_Text)) {
			return DataSetAttributesOperatorProperty.DOUBLE;
		}
		else if(aText.equals(DataSetAttributesOperatorProperty.USE_Text)) {
			return DataSetAttributesOperatorProperty.USE;
		}
		else if(aText.equals(DataSetAttributesOperatorProperty.NOT_USE_Text)) {
			return DataSetAttributesOperatorProperty.NOT_USE;
		}
		else if(aText.equals(DataSetAttributesOperatorProperty.TARGET_Text)) {
			return DataSetAttributesOperatorProperty.TARGET;
		}
		return aText;
	}
	
	private void addListener()
	{
		jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
		  public void mouseReleased(MouseEvent e) {		  		  
			if (e.isPopupTrigger()){
				
			  Point clickedPosition = e.getPoint();
			  int select = jTable1.rowAtPoint(clickedPosition); 
			  if (select != jTable1.getSelectedRow())
			  	jTable1.setRowSelectionInterval(select, select);
			  
			  int m_postion = jTable1.columnAtPoint(clickedPosition);
			  switch(m_postion){
		         case m_Type_Col: // Type header
		         {
		         	 String type = maptoName((String)TableModel.getValueAt(select,m_postion));
					  JPopupMenu popup = new JPopupMenu();
					  
					  /* pop up menu of numeric attribute */
//					  JMenu itemNumChangeDataType = new JMenu("Change Data Type");
//					  JMenuItem itemNumDouble = new JMenuItem(DOUBLE);
//					  itemNumDouble.addActionListener(new ActionListener() {
//						  public void actionPerformed(ActionEvent event) {
//							//Add code here	
//						  	((DataSetAttributesTableModel) jTable1.getModel()).setValueAt(DOUBLE, jTable1.getSelectedRow(),2);				
//							
//						  }
//						});
//					  itemNumChangeDataType.add(itemNumDouble);
					  
					  JMenu itemNumToCat = new JMenu(Resource.srcStr("TOCATEGORY"));
					  JMenuItem itemNumString = new JMenuItem(STRING_Text);
					  itemNumString.addActionListener(new ActionListener() {
						  public void actionPerformed(ActionEvent event) {
							  TableModel.setValueAt(CATEGORICAL_Text, jTable1.getSelectedRow(),1);				
						  	//Add code here
							  TableModel.setValueAt(STRING_Text, jTable1.getSelectedRow(),2);				
						  	
						    //m_dataType[jTable1.getSelectedRow()] =CategoricalAttribute.STRING;
						  }
						});
					  itemNumToCat.add(itemNumString);
					  
					  /* pop up menu of categorical attribute */
//					  JMenu itemCatChangeDataType = new JMenu("Change Data Type");
//					  JMenuItem itemCatString = new JMenuItem(STRING);
//					  itemCatString.addActionListener(new ActionListener() {
//						  public void actionPerformed(ActionEvent event) {
//						  //Add code here	
//						  	((DataSetAttributesTableModel) jTable1.getModel()).setValueAt(STRING, jTable1.getSelectedRow(),2);				
//							
//						  	// m_dataType[jTable1.getSelectedRow()] =CategoricalAttribute.STRING;
//						 }
//						});
//					  itemCatChangeDataType.add(itemCatString);
					  
					  JMenu itemCatToNum = new JMenu(Resource.srcStr("TONUMERIC"));
					  JMenuItem itemCatDouble = new JMenuItem(DOUBLE_Text);
					  itemCatDouble.addActionListener(new ActionListener() {
						  public void actionPerformed(ActionEvent event) {
							TableModel.setValueAt(NUMERIC_Text, jTable1.getSelectedRow(),m_Type_Col );
							//Add code here	
							// m_dataType[jTable1.getSelectedRow()] =NumericAttribute.DOUBLE ;
							TableModel.setValueAt(DOUBLE_Text, jTable1.getSelectedRow(),2);				
							
						  }
						});
					  itemCatToNum.add(itemCatDouble);
					  
					
					 if (type.equals(NUMERIC ))
					  {	/* popup.add(itemNumChangeDataType); */
					  	popup.add(itemNumToCat);
					  }
					  else if (type.equals(CATEGORICAL ))
					  { /* popup.add(itemCatChangeDataType); */
					  	popup.add(itemCatToNum);
					  }
					   popup.show(e.getComponent(), e.getX(), e.getY());	

		         }
		         	break;
		         case 3: // Role header
		         	{
			      	  String role = (String)TableModel.getValueAt(select, 3);
					  JPopupMenu popup = new JPopupMenu();
					  
					  JMenuItem itemTarget = new JMenuItem(TARGET_Text);
					  itemTarget.addActionListener(new ActionListener() {
						  public void actionPerformed(ActionEvent event) {
							  TableModel.setValueAt(TARGET_Text, jTable1.getSelectedRow(), 3);					
						  }
						});
					   
					   JMenuItem itemUse = new JMenuItem(Resource.srcStr("SettoUse"));
					   itemUse.addActionListener(new ActionListener() {
					   		public void actionPerformed(ActionEvent event) {
					   			TableModel.setValueAt(USE_Text, jTable1.getSelectedRow(), 3);
						  	}
					   });
					   
					   JMenuItem itemNotUse = new JMenuItem(Resource.srcStr("SettoNotuse"));
					   itemNotUse.addActionListener(new ActionListener() {
					   		public void actionPerformed(ActionEvent event) {
					   			TableModel.setValueAt(NOT_USE_Text, jTable1.getSelectedRow(), 3);
					   		}
					   });
					   
					   popup.add(itemUse);
					   popup.add(itemNotUse);
					   popup.add(itemTarget);
					   if (role.equals(TARGET))
					   	itemTarget.setEnabled(false);
					   if (role.equals(USE))
					   	itemUse.setEnabled(false);
					   if (role.equals(NOT_USE))
					   	itemNotUse.setEnabled(false);
					   	
					   popup.show(e.getComponent(), e.getX(), e.getY());	
			         }
		         	break;
		         	
		         default: return; 
		      }

			
			 /* << remarked by joyce 2005/01/20
			  * if (jTable1.columnAtPoint(clickedPosition)!=m_MetaDataTableHeader.length-1)
			  	return;
			  
			  String role = ((DataSetAttributesTableModel) jTable1.getModel()).getValueAt(select);
			  JPopupMenu popup = new JPopupMenu();
			  
			  JMenuItem itemTarget = new JMenuItem("Set as Target");
			  itemTarget.addActionListener(new ActionListener() {
				  public void actionPerformed(ActionEvent event) {
					((DataSetAttributesTableModel) jTable1.getModel()).setValueAt(TARGET, jTable1.getSelectedRow());					
				  }
				});
			   
			   JMenuItem itemUse = new JMenuItem("Set to Use");
			   itemUse.addActionListener(new ActionListener() {
			   		public void actionPerformed(ActionEvent event) {
						((DataSetAttributesTableModel) jTable1.getModel()).setValueAt(USE, jTable1.getSelectedRow());
				  	}
			   });
			   
			   JMenuItem itemNotUse = new JMenuItem("Set to Not use");
			   itemNotUse.addActionListener(new ActionListener() {
			   		public void actionPerformed(ActionEvent event) {
						((DataSetAttributesTableModel) jTable1.getModel()).setValueAt(NOT_USE, jTable1.getSelectedRow());
			   		}
			   });
			   
			   popup.add(itemUse);
			   popup.add(itemNotUse);
			   popup.add(itemTarget);
			   if (role.equals(TARGET))
			   	itemTarget.setEnabled(false);
			   if (role.equals(USE))
			   	itemUse.setEnabled(false);
			   if (role.equals(NOT_USE))
			   	itemNotUse.setEnabled(false);
			   	
			   popup.show(e.getComponent(), e.getX(), e.getY());			  
			   */ //>>>>
			}
		  }

		  //public void mouseEntered(MouseEvent e) {}

		  //public void mouseExited(MouseEvent e) {}
		});		
	}
	
	public void resetLocale() {
		String old_NUMERIC_Text = NUMERIC_Text;
		String old_CATEGORICAL_Text = CATEGORICAL_Text;
		String old_STRING_Text = STRING_Text;
		String old_DOUBLE_Text = DOUBLE_Text;
		String old_USE_Text = USE_Text;
		String old_NOT_USE_Text = NOT_USE_Text;
		String old_TARGET_Text = TARGET_Text;
		
		
		NUMERIC_Text = Resource.srcStr("NUMERIC");
		CATEGORICAL_Text = Resource.srcStr("CATEGORICAL");
		STRING_Text = Resource.srcStr("STRING");
		DOUBLE_Text = Resource.srcStr("DOUBLE");
		USE_Text = Resource.srcStr("USE");
		NOT_USE_Text = Resource.srcStr("NOT_USE");
		TARGET_Text = Resource.srcStr("TARGET");
		
		int row = jTable1.getRowCount();
		int colum = jTable1.getColumnCount();
		int i,j;
		String value;
		for(i=0;i<row;i++) {
			for(j=1;j<colum;j++) {
				value = (String) jTable1.getValueAt(i, j);
				if(value.equals(old_NUMERIC_Text)) {
					jTable1.setValueAt(NUMERIC_Text, i, j);
				}
				else if(value.equals(old_CATEGORICAL_Text)) {
					jTable1.setValueAt(CATEGORICAL_Text, i, j);
				}
				else if(value.equals(old_STRING_Text)) {
					jTable1.setValueAt(STRING_Text, i, j);
				}
				else if(value.equals(old_DOUBLE_Text)) {
					jTable1.setValueAt(DOUBLE_Text, i, j);
				}
				else if(value.equals(old_USE_Text)) {
					jTable1.setValueAt(USE_Text, i, j);
				}
				else if(value.equals(old_NOT_USE_Text)) {
					jTable1.setValueAt(NOT_USE_Text, i, j);
				}
				else if(value.equals(old_TARGET_Text)) {
					jTable1.setValueAt(TARGET_Text, i, j);
				}
			}
		}
	}
}

/**
 * TableModel is a special kind of TableModel for showing Operator property.
 */
class DataSetAttributesTableModel extends DefaultTableModel implements TableModelListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1897871330163347413L;
	
	Class[] types;
	boolean[] canEdit;
	Object[][] m_TableContent;
	int m_Target = -1;
	String m_PrevRole = DataSetAttributesOperatorProperty.USE_Text;
	boolean m_Modified = false;
	

	/**
	 * Constructs a TableMode.
	 * @param a_TableContent an Object array storing table content.
	 * @param a_TableHeader an Object array storing header names.
	 */
	public DataSetAttributesTableModel(Object[][] a_TableContent, Object[] a_TableHeader, int a_Target) {
		super(a_TableContent, a_TableHeader);
		m_Target = a_Target;
		types = new Class[a_TableHeader.length];
		canEdit = new boolean[a_TableHeader.length];
		for (int i=0; i<a_TableHeader.length; i++)
		{
			types[i] = String.class;			
			canEdit[i] = false;
		}
		m_TableContent = a_TableContent;
		addTableModelListener(this);
	}

	/**
	 * Gets content of a row.
	 * @param rowIndex index of the row.
	 * @return String[] a String array of size 2 with the first element stores
	 * text of (rowIndex, 0) cell the table content; the second element stores
	 * text of (rowIndex, 1) cell in the table content.
	 */
	public Object getValueAt(int rowIndex, int colIndex) {
		return (String) super.getValueAt(rowIndex, colIndex);
	}
	
	public void setValueAt(String value, int rowIndex, int colIndex) {

		if (value.equals(DataSetAttributesOperatorProperty.TARGET_Text))
		{	
		    if(m_Target!=rowIndex)
		 	{
		        if(m_Target >=0)
		            super.setValueAt(m_PrevRole, m_Target, colIndex);
				m_Target = rowIndex;
				m_PrevRole = (String)getValueAt(rowIndex, 3);
			}
		}else if (colIndex == 3){
		    if (m_Target==rowIndex){
		        m_Target = -1;
		    	m_PrevRole = value;
		    }
		}
		super.setValueAt(value, rowIndex, colIndex);		
		m_Modified = true;		
	}

	/**
	 * @see javax.swing.event.TableModelListener#tableChanged(TableModelEvent)
	 */
	public void tableChanged(TableModelEvent e) {
		int row = e.getFirstRow();
		int column = e.getColumn();
		DataSetAttributesTableModel model = (DataSetAttributesTableModel) e.getSource();
		//		String data = model.getValueAt(row, column);
		Object data = model.getValueAt(row, column);
		m_TableContent[row][column] = data;
	}

	/**
	 * @see javax.swing.table.TableModel#getColumnClass(int)
	 */
	@SuppressWarnings("unchecked")
	public Class getColumnClass(int columnIndex) {
		return types[columnIndex];
	}

	/**
	 * @see javax.swing.table.TableModel#isCellEditable(int, int)
	 */
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return canEdit[columnIndex];
	}
	
	public boolean isModified()
	{
		return m_Modified;
	}
	
}

⌨️ 快捷键说明

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