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

📄 umltree.java

📁 java写的多功能文件编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		public TreePath getPathFrom(Node ancestor)		{			Enumeration e = pathFromAncestorEnumeration(ancestor);			Vector pathList = new Vector();			int depth = 0;			Node curNode;			while (e.hasMoreElements()) {				depth++;				curNode = (Node) e.nextElement();				pathList.addElement(curNode); //  patch for jdk1.1				// pathList.add(curNode); // jdk1.2 only ???			}			// for JDK 1.1			Node[] pathArray = new Node[pathList.size()];			pathList.copyInto(pathArray);			return new TreePath(pathArray);			// for JDI 1.2			//return new TreePath( pathList.toArray() );		} // getPathFrom(Node): TreePath		//---------------------------------------------------------------------		public final boolean isVisible(Options.FilterIro filterOpt)		{			if (userObject instanceof UML.Element) {							return ( (UML.Element) getUserObject() ).isVisible(filterOpt);			} else {				return true;			}		}		//---------------------------------------------------------------------		public final UML.Element getElement() {			if (userObject instanceof UML.Element) {				return (UML.Element) userObject;			} else {				return null;			}		}//		public String getName() {  // implement later//			return userObject.toString();//		}		//---------------------------------------------------------------------		public UML.Type getElementType() 		{				if (userObject instanceof UML.Element) {				return ( (UML.Element) userObject).getElementType();			} else {				return null;			}		}		//---------------------------------------------------------------------		public void setName(String name)		{			if (userObject instanceof UML.Element) {				( (UML.Element) userObject).setName(name);			} else {				userObject = name;			}		}		//---------------------------------------------------------------------		/**		 * Returns visible index of the current node, or -1 if it is not		 * visible based on the specified filter options.		 */		public final int getVisibleIndex(Options.FilterIro filterOpt)		{			Node parent = (Node) this.getParent();			if(parent == null) return -1;			Vector children = parent.children;			int visibleIndex = -1;			for(int i = 0; i < children.size(); i++) {				Node curNode = (Node) children.elementAt(i);				Object nodeObject = curNode.userObject;				if ( ( (UML.Element) nodeObject).isVisible(filterOpt) ) {					visibleIndex++;					if (curNode == this) return visibleIndex;				}				if (curNode == this) return -1;			}			throw new ArrayIndexOutOfBoundsException("index unmatched");		} // getVisibleIndex(int, Options.FilterIro): int//		//---------------------------------------------------------------------//		public int getVisibleIndex(Options.FilterIro filterOpt)//		{//            TreeNode parent = this.getParent();//            if(parent == null) return -1;////			int visibleIndex = -1;//			Enumeration enum = parent.children();////			while (enum.hasMoreElements()) {//				Node curNode = (Node) enum.nextElement();//				Object nodeObject = curNode.userObject;//				if ( ( (UML.Element) nodeObject).isVisible(filterOpt) ) {//					visibleIndex++;//					if (curNode == this) return visibleIndex;//				}////				if (curNode == this) return -1;//			}////			throw new ArrayIndexOutOfBoundsException("index unmatched");////		} // getVisibleIndex(int, Options.FilterIro): int		//---------------------------------------------------------------------		/**		 * Creates and returns a forward-order enumeration of this node's		 * visible children.		 *		 * @return	an Enumeration of this node's visible children		 */		public Object[] getVisibleChildrenObject(Options.FilterIro filterOpt)		{			int count = getChildCount(filterOpt);			if (count > 0) {				Object[] visibleChildNodes = new Object[count];				int[]    visibleChildIndxs = new int[count];				int visibleIndex = -1;				for(int i = 0; i < children.size(); i++) {					Node curNode = (Node) children.elementAt(i);					Object nodeObject = curNode.userObject;					if ( ( (UML.Element) nodeObject).isVisible(filterOpt) ) {						visibleIndex++;						visibleChildIndxs[visibleIndex] = visibleIndex;						visibleChildNodes[visibleIndex] = curNode;					}				}				return new Object[] { visibleChildIndxs, visibleChildNodes };				} else {				return null;			}		} // getVisibleChildrenObject(Options.FilterIro): Object[]		//---------------------------------------------------------------------		/**		 * Returns the child of this node with the specified visible index		 * based on the specified filter options.		 */		public final Node getChildAt(int index, Options.FilterIro filterOpt)		{			if (children == null) {				throw new ArrayIndexOutOfBoundsException("node has no children");			}			int realIndex    = -1;			int visibleIndex = -1;			Enumeration enum = children.elements();			while (enum.hasMoreElements()) {				Object nodeObject = ( (Node) enum.nextElement()).userObject;				if ( ( (UML.Element) nodeObject).isVisible(filterOpt) ) {					visibleIndex++;				}				realIndex++;				if (visibleIndex == index) {					return (Node)children.elementAt(realIndex);				}			}			throw new ArrayIndexOutOfBoundsException("index unmatched");		}		//---------------------------------------------------------------------		/**		 * Returns a count of the number of visible children of this node		 * based on the specified filter options.		 */		public final int getChildCount(Options.FilterIro filterOpt)		{			if (children == null) {				return 0;			}			int count = 0;			Enumeration enum = children.elements();			while (enum.hasMoreElements()) {				Object nodeObject = ( (Node) enum.nextElement()).userObject;				if ( ( (UML.Element) nodeObject).isVisible(filterOpt) ) {					count++;				}			}			return count;		}	} // class UMLTree.Node extends DefaultMutableTreeNode	//=========================================================================	static class CellRenderer extends DefaultTreeCellRenderer	{		private static Font standardFont = new Font("Helvetica", Font.PLAIN, 12);		private static Font italicFont   = new Font("Helvetica", Font.ITALIC, 12);		private boolean isUnderlined;		private Options.DisplayIro options;		private Options.DisplayIro inverseOptions;		public CellRenderer(Options.DisplayIro options)		{			super();			this.options = options;		}		//-------------------------------------------------------------------------		public Component getTreeCellRendererComponent(JTree tree, Object value,				boolean sel,				boolean expanded,				boolean leaf,				int row,				boolean hasFocus )		{			Component r = super.getTreeCellRendererComponent(tree, value, sel,							expanded, leaf,							row, hasFocus);			isUnderlined = false;			if (r instanceof JLabel) {				JLabel lab = (JLabel) r;				lab.setToolTipText(null);				tree.setToolTipText(null);				UMLTree.Node node = (UMLTree.Node) value;				Object uObj = node.getUserObject();				if ( uObj != null && uObj instanceof UML.Element ) {					UML.Element e = (UML.Element) uObj;					UML.Type type = e.getElementType();					if (type != null) {						// label						lab.setText(e.toString(options));						if ( options.getAbstractItalic() && e.isAbstract() ) {							lab.setFont( italicFont );						} else {							lab.setFont( standardFont );						}						if (options.getStaticUlined() && e.isStatic() ) {							isUnderlined = true;						}						// tips						inverseOptions = options.getInverseOptions();						lab.setToolTipText(e.toString(inverseOptions) + " ");						tree.setToolTipText(e.toString(inverseOptions) + " ");//						if ( options.getAbstractItalic() && e.isAbstract() ) {//							lab.setFont( italicFont );//							tree.setFont( italicFont );////						} else {//							lab.setFont( standardFont );//							tree.setFont( standardFont );//						}						// icon						Icon icon = (Icon) type.getIcon();						if (icon != null) {							lab.setIcon(icon) ;						}					}				} else {					// for strings (e.g. root)					lab.setFont(standardFont);				}			}			return r;		} // getTreeCellRendererComponent(JTree, Object, boolean, boolean, boolean, int, boolean): Component	 	//-------------------------------------------------------------------------	 	protected void paintComponent(Graphics g)	 	{	 		super.paintComponent(g);	 		if ( this.isUnderlined) {		 		int x = getIcon().getIconWidth() + Math.max(0, getIconTextGap() - 1);			    g.setColor(Color.black);		 		g.drawLine(x, getHeight() - 2, getWidth() - 2, getHeight() - 2);	 		}	 	} // paintComponent(Graphics) // void	} // class UMLTree.CellRenderer extends DefaultTreeCellRenderer} // class UMLTree extends JTree

⌨️ 快捷键说明

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