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

📄 umltree.java

📁 java写的多功能文件编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * UMLTree.java * Copyright (c) 1999 George Latkiewicz	(georgel@arvotek.net) * * 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 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */import java.util.*;import java.awt.*;import javax.swing.*;//import java.awt.font.*; // JDK 1.2 specific, required for underline                          // (but only for the elegant way that doesn't work in 1.2.1 anyway).						  // therefore not currently implemented.import javax.swing.tree.*;import org.jext.Utilities;//=============================================================================public class UMLTree extends JTree{	//-------------------------------------------------------------------------	/**	 * Constructor for a UMLTree, automatically sets the new UMLTree's	 * associated UMLModel to null.	 */	public UMLTree()	{		super.setModel(null);		putClientProperty("JTree.lineStyle", "Angled");		setVisibleRowCount(15);	} // UMLTree(TreeModel): <init>	//-------------------------------------------------------------------------	/**	 * This is the method that is called whenever the results of a new parse	 * need to be displayed, or when filter options have changed on the	 * currently parsed and displayed UMLTree.	 */	public void display(Model tm, Options options, JBrowseParser.Results results)	{		Options.DisplayIro displayOpt = options.getDisplayOptions();		Options.FilterIro  filterOpt  =	options.getFilterOptions();		setCellRenderer(new CellRenderer( displayOpt ) );		tm.setFilterOptions(filterOpt);		super.setModel(tm);		tm.reload();		expandRow(0);		TreePath tp = results.getTopLevelPath();		if (tp != null) {			expandPath(tp);		}	} // display(TreeModel, Options, JBrowseParser.Results): void//	//-------------------------------------------------------------------------//	/**//	 * This updates only the nodes that are currently visible in the JTree.//	 * This is the method that is called whenever the display options have//	 * changed on the currently parsed and displayed UMLTree.//	 *///	public void updateVisible(Options options)//	{//		int lastRow = getRowCount() - 1;//		Model tm = (Model) getModel();////		if (lastRow > 200 ) {////System.out.println("Too many rows to update individually (" + lastRow + ") will reload.");//			display(tm, options);//			return;//		}//////System.out.println("getRowCount(): " + getRowCount() + ", getVisibleRowCount(): " + getVisibleRowCount());////System.out.println("Will update " + lastRow + " rows");////		Options.FilterIro  filterOpt  =	options.getFilterOptions();//		TreeNode parent = null;//		Object[] cChildren = new Object[1];//		int[] childIndices = new int[1];////		for (int i = 0; i <= lastRow; i++) {////			Node node =  (Node) getPathForRow(i).getLastPathComponent();////			parent = node.getParent();//			int anIndex = node.getVisibleIndex(filterOpt);////			if(anIndex != -1) {////				// i.e. is a visible child//				childIndices[0] = anIndex;//				cChildren[0] = node;////				tm.fireTreeNodesChanged(parent, childIndices, cChildren);//////				tm.nodesChanged(parent, childIndices);//			}//		}//	} // updateVisible(Node): void	//-------------------------------------------------------------------------	public void updateVisibleToggled(Options options)	{		Model tm = (Model) getModel();		Options.FilterIro  filterOpt = options.getFilterOptions();		TreePath aPath;		Node aNode;		Object[] cChildrenObject;		aPath = getPathForRow(0);		Enumeration e = getDescendantToggledPaths(aPath);		//System.out.println("updateVisibleToggled called for root path: " + aPath);				while ( e.hasMoreElements() ) {			aPath = (TreePath) e.nextElement();			//System.out.println( aPath );			aNode = (Node) aPath.getLastPathComponent();						cChildrenObject = aNode.getVisibleChildrenObject(filterOpt);			if (cChildrenObject != null) {				tm.fireTreeNodesChanged(aNode, (int[]) cChildrenObject[0],						(Object[]) cChildrenObject[1] );			}		}	} // updateVisibleToggled(Node): void	//=========================================================================	static class Model extends DefaultTreeModel	{		private Options.FilterIro filterOpt = null;		// Overrides:		//    getChild() & getChildCount()		// Constructors		public Model(TreeNode root)		{			super(root);		}		// Filter state accessors		public void setFilterOptions(Options.FilterIro filterOpt)		{			this.filterOpt = filterOpt;		}		public Options.FilterIro getFilterOptions() { return filterOpt; }		final void fireTreeNodesChanged(TreeNode parent, int[] childIndices, Object[] children)		{			super.fireTreeNodesChanged(this, getPathToRoot(parent), childIndices, children);		}		// Overridded methods to provide InvisibleTreeModel behaviour		//---------------------------------------------------------------------		public Object getChild(Object parent, int index)		{			if (filterOpt != null) {					return ( (Node) parent).getChildAt(index, filterOpt);			}			return ( (Node) parent).getChildAt(index);		}		//---------------------------------------------------------------------		public int getChildCount(Object parent)		{			if (filterOpt != null) {					return ( (Node) parent).getChildCount(filterOpt);			}			return ( (Node) parent).getChildCount();		}		//---------------------------------------------------------------------		public boolean isLeaf(Object node)		{			if (getChildCount(node) > 0 )				return false;			else				return true;		}//		/**//		 * This method updates the immediate children of the passed node. It works//		 * well but is very slow on large trees, you should seriously//		 * consider using the associated UMLTree's updateVisible() method//		 * instead.//		 *///		public void updateVisibleChildren(Node parent)//		{//			for(int i = 0; i < parent.getChildCount(filterOpt); i++ ) {//				Node child = parent.getChildAt(i, filterOpt);//				nodeChanged(child);//				if ( child.getChildCount(filterOpt) > 0 ) {//					updateChildren(child);//				}//			}////		} // updateVisibleChildren(Node): void//////		/**//		 * This method updates all children of the passed node. That are not//		 * invisible (although they may not be in the curently displayed portion//		 * of the JTree.//		 * It works well but is very slow on large trees, you should seriously//		 * consider using the associated UMLTree's updateVisible() method//		 * instead.//		 *///		public void updateVisibleChildren(Node parent)//		{//			for(int i = 0; i < parent.getChildCount(filterOpt); i++ ) {//				Node child = parent.getChildAt(i, filterOpt);//				nodeChanged(child);//				if ( child.getChildCount(filterOpt) > 0 ) {//					updateVisibleChildren(child);//				}//			}////		} // updateVisibleChildren(Node): void	} // public class InvisibleTreeModel extends DefaultTreeModel	//=========================================================================	static class Node extends DefaultMutableTreeNode	{		private Object pos = null;		public Node(UML.Element userObject) {			super(userObject);		}		public Node(String userObject) {			super(userObject);		}		public final void setPosition(Object pos) {			this.pos = pos;		}		public final Object getPosition() {			return pos;		}				public final void alphaSort()		{			ArrayList sortedList = new ArrayList();			UMLTree.Node node;			UML.Element elm;			if (children != null && children.size() > 0)			{				HashMap methods = new HashMap(children.size());				for (int i = 0; i < children.size(); i++)				{					node = (Node)(children.get(i));					elm = node.getElement();					try					{						UML.Operation operation = (UML.Operation)elm;						Options.Display display = new Options.Display();						display.setShowArguments(true);												String add = operation.getName() + "(" +						 operation.listArgs((Options.DisplayIro)display) + ")";						 						methods.put(add, node);					}//end try 					catch(ClassCastException cce)					{						if (elm.isInterface() || elm.isClass())						{							node.alphaSort();						}//end if class or interface						sortedList.add(node);					}//end catch				}//end for i . . .				 				String[] methodNames =				 (String[])(methods.keySet().toArray(new String[methods.size()]));				Arrays.sort(methodNames);				for (int j = 0; j < methodNames.length; j++)				{					sortedList.add(methods.get(methodNames[j]));				}//end for j . . .								children.removeAllElements();				children.addAll(sortedList);			}//end if children != null && children.size() > 0				}//end alphaSort		//---------------------------------------------------------------------		/**		 * Returns the TreePath from the specified ancestor Node to this		 * node.		 */

⌨️ 快捷键说明

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