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

📄 caselisttree.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	public void registerInterest(Observer a_Observer) {
		m_Observers.add(a_Observer);
	}

	/**
	 * Builds the Tree by adding available Cases as nodes of the tree.
	 * Categorize the Cases based on the grouping category set.
	 */
	private void buildTree() {
		String category = null;
		DefaultMutableTreeNode parentNode = null;
		CaseNode childNode = null;
		for (int i = 0; i < m_CaseInformation.length; i++) {
			if (category == null
				|| !category.equalsIgnoreCase(
					getCategory(m_CaseInformation[i]))) {
				category = getCategory(m_CaseInformation[i]);
				parentNode = new DefaultMutableTreeNode(category);
				m_RootNode.add(parentNode);
			}
			childNode =
				new CaseNode(
					m_CaseInformation[i].getCaseID(),
//					<<21/02/2005 Mark Li: Add Case Name
					m_CaseInformation[i].getCaseName() + "( ID:" + getFormatedCaseID(m_CaseInformation[i].getCaseID()) + " )");
//			21/02/2005 Mark Li: Add Case Name>>		
			 String[] ArrayTemp = new String[parentNode.getChildCount()+1];
			    int j = 0;
			    for(; j< parentNode.getChildCount(); j++){
			        ArrayTemp[j] = parentNode.getChildAt(j).toString();			          
			    }
			    ArrayTemp[j] = childNode.getUserObject().toString();
			    Arrays.sort(ArrayTemp);
			    int indexChild = Arrays.binarySearch(ArrayTemp,childNode.getUserObject().toString());
			parentNode.insert(childNode,indexChild);			
//			parentNode.add(childNode);
		}
	}
//	<<21/02/2005 Mark Li: Add Case Name
	/**
	 * Retrieve the case ID that does not start with zero 
	 * @param aCaseID the ID of the case
	 * @return the ID of the case that does not start with zero
	 */
	public static String getFormatedCaseID(String aCaseID){
		if(aCaseID == null) return null;
		int i = 0;
		for (; aCaseID.charAt(i) == '0'; i++);
		return aCaseID.substring(i);
	}
//	21/02/2005 Mark Li: Add Case Name>>
	
//<<21/03/2005 mark Li : Add function to remove the node
	/**
	 * Remove the chile node according to the corresponding Case ID
	 * @param aCaseID the ID of the case that need to delete
	 * @return NULL
	 */
	public void removeChildNode(String aCaseID) {
		DefaultMutableTreeNode parentNode = null;
		CaseNode childNode = null;
		dirty = true;

		/* Locate the Company */
		for (int j = 0; j < m_RootNode.getChildCount(); j++) {
			parentNode = (DefaultMutableTreeNode) m_RootNode.getChildAt(j);
			/* Locate the node of case in the corresponding Company */
			for (int k = 0; k < parentNode.getChildCount(); k++) {
				childNode = (CaseNode) parentNode.getChildAt(k);
				String comparedCaseID = childNode.getCaseID();
				if (comparedCaseID.equals(aCaseID)) {
					/* Delete the node from Parent node */
					m_Model.removeNodeFromParent(childNode);
					if (parentNode.getChildCount() == 0) {
						m_Model.removeNodeFromParent(parentNode);
					}
				}
			}
		}
	}
	
	
	public void addChildNode(String aCaseID) {
		String category = null;
		DefaultMutableTreeNode parentNode = null;
		CaseNode childNode = null;

		CaseInfoList list = CaseInfoListHandler.getInstance().getCaseInfoList(
				true);
		CaseInformation insertCaseInformation = list.getCaseInfo(aCaseID);
		childNode = new CaseNode(insertCaseInformation.getCaseID(),
				insertCaseInformation.getCaseName() + "( ID:"
						+ getFormatedCaseID(insertCaseInformation.getCaseID())
						+ " )");

		category = getCategory(insertCaseInformation);

		for (int i = 0; i < m_RootNode.getChildCount(); i++) {
			parentNode = (DefaultMutableTreeNode) m_RootNode.getChildAt(i);
			if (parentNode == null) {
				//There is no parent node here
				parentNode = new DefaultMutableTreeNode(category);
				m_Model.insertNodeInto(parentNode, m_RootNode, m_RootNode
						.getChildCount());
				m_Model.insertNodeInto(childNode, parentNode, parentNode
						.getChildCount());
				scrollPathToVisible(new TreePath(childNode.getPath()));
				return;
			} else if (parentNode != null
					&& category.compareToIgnoreCase(parentNode.toString()) < 0) {
				//Here the added category is less than the current parent Node
				parentNode = new DefaultMutableTreeNode(category);
				m_Model.insertNodeInto(parentNode, m_RootNode, i);
				m_Model.insertNodeInto(childNode, parentNode, parentNode
						.getChildCount());
				scrollPathToVisible(new TreePath(childNode.getPath()));
				return;
			} else if (parentNode != null
					&& category.equals(parentNode.toString())) {
				//Here the added category is equal to the current parent Node
			    String[] ArrayTemp = new String[parentNode.getChildCount()+1];
			    int j = 0;
			    for(; j< parentNode.getChildCount(); j++){
			        ArrayTemp[j] = parentNode.getChildAt(j).toString();			          
			    }
			    ArrayTemp[j] = childNode.getUserObject().toString();
			    Arrays.sort(ArrayTemp);
			    int indexChild = Arrays.binarySearch(ArrayTemp,childNode.getUserObject().toString());
				m_Model.insertNodeInto(childNode, parentNode, indexChild);
				scrollPathToVisible(new TreePath(childNode.getPath()));
				return;
			} else if (i == (m_RootNode.getChildCount()-1)
					&& category.compareToIgnoreCase(parentNode.toString()) > 0) {
				//Here the added category is more than all the parent nodes
				parentNode = new DefaultMutableTreeNode(category);
				m_Model.insertNodeInto(parentNode, m_RootNode, m_RootNode
						.getChildCount());
				m_Model.insertNodeInto(childNode, parentNode, parentNode
						.getChildCount());
				scrollPathToVisible(new TreePath(childNode.getPath()));
				return;
			}
		}
	}
//	21/03/2005 mark Li : Add function to remove the node>>	

//<<31/03/2005 Mark Li : Update the management bar when re-open the Case List Panel	
	public void TreeSelectedUpdate(){
		DefaultMutableTreeNode node =
			(DefaultMutableTreeNode) this.getLastSelectedPathComponent();		
		if (node == null)
			return;
		if (node.isLeaf()) {		
			//System.out.println(((CaseNode) node).getCaseID());
			//System.out.println("display " + ((CaseNode) node).getCaseID());
			for (int i = 0; i < m_Observers.size(); i++) {
				Observer observer = (Observer) m_Observers.elementAt(i);
				if (observer instanceof CaseInformationPanel)
				{
					((CaseInformationPanel) observer).displayCaseDetail(
							((CaseNode) node).getCaseID(), false);
				}
				else
				{				
					observer.sendNotify("select|" + ((CaseNode) node).getCaseID());
				}
			}			
		}	
	}
//	31/03/2005 Mark Li : Update the management bar when re-open the Case List Panel	
	/**
	 * Gets the category used to group the available Cases in this tree.
	 * @param a_Case CaseInformation of a Case to be used to obtain value of
	 * this Case based on the current category set.
	 * @return category of the Case represented by the CaseInformation.
	 */
	private String getCategory(CaseInformation a_Case) {
		if (m_CurrentGroup == CaseInformationComparator.INDUSTRY)
			return a_Case.getIndustry();
		else if (m_CurrentGroup == CaseInformationComparator.PROBLEM_TYPE)
			return a_Case.getProblemType();
		else if (
			m_CurrentGroup == CaseInformationComparator.BUSINESS_OBJECTIVE)
			return a_Case.getBusinessObjective();
		else if (m_CurrentGroup == CaseInformationComparator.DATAMINING_GOAL)
			return a_Case.getDataMiningGoal();
		else if (m_CurrentGroup == CaseInformationComparator.COMPANY_NAME)
			return a_Case.getCompanyName();
		else
			return null;
	}
}

//<<23/03/2005 Mark Li: Remove Refresh button in CaseListTree
///**
// * RefreshMenu is a right-click popup menu.
// */
//class RefreshMenu extends JPopupMenu implements ActionListener {
//
//	private CaseListTree m_Tree;
//	private JMenuItem m_Refresh = new JMenuItem("Refresh");
//
//	/**
//	 * Constructs a RefreshMenu.
//	 * @param a_Tree CaseListTree that this RefreshMenu will be shown while right-clicking
//	 * the tree.
//	 */
//	public RefreshMenu(CaseListTree a_Tree) {
//		super();
//		m_Tree = a_Tree;
//		add(m_Refresh);
//		addSeparator();
//		m_Refresh.addActionListener(this);
//	}
//
//	/**
//	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
//	 */
//	public void actionPerformed(ActionEvent e) {
//		m_Tree.setTreeModel(true);
//	}
//}
//23/03/2005 Mark Li: Remove Refresh button in CaseListTree>>

/**
 * CaseNode is a special kind of leaf node of the CaseListTree.
 */
class CaseNode extends DefaultMutableTreeNode {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String m_CaseID;

	/**
	 * Constructs a CaseNode.
	 * @param a_CaseID ID of the Case this CaseNode represents.
	 * @param m_NodeName name of this node to be shown in the CaseListTree.
	 */
	public CaseNode(String a_CaseID, String m_NodeName) {
		super(m_NodeName);
		m_CaseID = a_CaseID;
	}

	/**
	 * Gets ID of the Case this CaseNode belongs to
	 * @return ID of the Case.
	 */
	public String getCaseID() {
		return m_CaseID;
	}
}

⌨️ 快捷键说明

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