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

📄 rangeintree.java

📁 生物物种进化历程的演示
💻 JAVA
字号:
/*   Copyright (c) 2002 Compaq Computer Corporation      SOFTWARE RELEASE      Permission is hereby granted, free of charge, to any person obtaining   a copy of this software and associated documentation files (the   "Software"), to deal in the Software without restriction, including   without limitation the rights to use, copy, modify, merge, publish,   distribute, sublicense, and/or sell copies of the Software, and to   permit persons to whom the Software is furnished to do so, subject to   the following conditions:      - Redistributions of source code must retain the above copyright     notice, this list of conditions and the following disclaimer.      - Redistributions in binary form must reproduce the above copyright     notice, this list of conditions and the following disclaimer in the     documentation and/or other materials provided with the distribution.      - Neither the names of Compaq Research, Compaq Computer Corporation     nor the names of its contributors may be used to endorse or promote     products derived from this Software without specific prior written     permission.      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.    IN NO EVENT SHALL COMPAQ COMPUTER CORPORATION BE LIABLE FOR ANY CLAIM,   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR   THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/package AccordionTreeDrawer;import java.awt.Color;/** * A class representing a range (ordered pair (min,max)) of TreeNode * indices in a Tree.	   *  * @author  Tamara Munzner, Serdar Tasiran, Li Zhang, Yunhong Zhou * */public class RangeInTree implements Comparable {    int min;    int max;    AccordionTreeDrawer atd;        public RangeInTree(int minimum, int maximum, AccordionTreeDrawer t) {	min = minimum; 	max = maximum;	atd = t;    }    public int getMin() { return min; }    public int getMax() { return max; }    public AccordionTreeDrawer getTree() { return atd; }    public int getSmallest(int small) {if (small < min) return small; return min;} 	public int getLargest(int large) {if (large > max) return large; return max;}	public String toString()	{		return "(" +atd.getKey() +":" + min + "->" + max + ")";	}		// no longer used, comparison function works	public RangeInTree intersects(RangeInTree r){	// if we're marking and it's the same sequence, intersection might happen	// or if we're drawing, all intersections are valid, even across sequences	if (RangeList.returnObject)		System.out.print("checking for intersect " + r + " with " + this);	if (r.atd == atd) // intersect, sequence ownership doesn't matter here, should check sequence when determining color	{		if (r.max + 1 < min || max + 1 < r.min) // side by side is overlap, so add 1 (join adjacent groups)			return null; // no intersection		if (r.min <= min)		{			if (r.max >= max)				return new RangeInTree(r.min, r.max, atd); // r.min < min, r.max > max, this is in r			else				return new RangeInTree(r.min, max, atd); // r.min < min, max > r.max, r starts first, this finishes		}		else // min < r.min		{			if (r.max >= max)				return new RangeInTree(min, r.max, atd); // r.max > max, this starts first, r finishes			else				return new RangeInTree(min, max, atd); // max > r.max, r is in this		}	}	return null; // diff asd and/or ranges don't intersect}		// min and max are cell indices	public double getSize(AccordionDrawer.SplitLine splitLine, int frameNum)	{		int minCellSplit = min-1;		int maxCellSplit = max;		return splitLine.getAbsoluteValue(maxCellSplit, frameNum) -			splitLine.getAbsoluteValue(minCellSplit, frameNum); 	}		/* (non-Javadoc)	 * @see java.lang.Comparable#compareTo(java.lang.Object)	 */	public static boolean doAdj = true; // for adjacent matches	public int compareTo(Object o) {	    int add = doAdj ? 1 : 0;		RangeInTree other = (RangeInTree)o;		int atdKey = atd.getKey();		int otherKey = other.getTree().getKey();		if (atdKey < otherKey)		{//		    System.out.print(atdKey + "T<" + otherKey + ":");			return -1; // this tree is less		}		if (atdKey > otherKey)		{//		    System.out.print(atdKey + "T>" + otherKey + ":");			return 1; // this tree is greater		}					// same tree		if (max + add < other.getMin())		{//		    System.out.print(max+add + "N<" + other.getMin() + ":");			return -1; // this range is less, +1 since adjacent ranges should be combined and are "equal"		}		if (min > other.getMax() + add)		{//		    System.out.print(min + "N>" + other.getMax() + ":");			return 1; // this range is greater, +1 since adjacent ranges should be combined and are "equal"		}		if (RangeList.returnObject)			RangeList.matchRange = other;//		System.out.println(min+"/"+max+"="+other.getMin()+"/"+other.getMax()+":");		return 0; // some overlap, adjacent or identical ranges	}		public boolean equals(Object o)	{		return compareTo(o) == 0;	}		// brute force range draw	// never called	public void draw(Color c)	{		int currMin = min, currMax = max;		Tree t = atd.getTree();		while (currMin <= currMax)		{			TreeNode tn = t.getNodeByKey(currMin);			tn.drawInCell(c, atd.hiliteplane - .004*c.getAlpha());			currMin++;		}	}		// return the range of splitlines that represent min,max nodes in the Y direction (across the leaves)	// ranges that call this should be ranges of any tree node that we want to turn into a split line range	public RangeInTree getSplitLineRange(int xy, boolean horiz)	{		TreeNode minNode;		if (horiz)			minNode = atd.getNodeByKey(min);		else			minNode = atd.getNodeByKey(min).getLeftmostLeaf();		TreeNode maxNode = atd.getNodeByKey(max).getRightmostLeaf();		int newMinLine = minNode.getCell().getMinLine(xy)+(horiz?0:1); // turn line into cell index		int newMaxLine = maxNode.getCell().getMaxLine(xy);		RangeInTree splitLineRange = new RangeInTree(newMinLine, newMaxLine, atd);		return splitLineRange;	}	};

⌨️ 快捷键说明

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