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

📄 accordiontreedrawerfinal.java

📁 生物物种进化历程的演示
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		} else if (key == 'D') {		    tj.toggleDimBrite();		} else if (key == 'C') {		    tj.toggleDimColors();		} else if (key == 'j') {		    jump = !jump;		} else if (key == 's') {		    tj.toggleLabelTransp();		} else if (key == 'z') {		    tj.toggleDrawSplits();		} else if (key == 'O') {		    tj.toggleCacheRange();		} else if (key == 'G') {		    tj.toggleGuarVis();		} else if (key == 't') {		    tj.toggleCheckTime();		} else if (key == 'J') {		    stats.flush();		    System.out.println("flushed stats\n");		} else if (key == 'S') {		    tj.toggleDumpStats();		} else if (key == 'F') {		    // the second display loop is so that the entire scene gets drawn, before going on to next iteration		    int i;		    setDumpStats(true);		    setCheckTime(true);		    setCacheRange(true);		    setDrawOrder(BRUTEFORCE);		    for (i = 0; i < 10; i++) {stats.println();stats.println();stats.print("brute checktime cache "+i+" ");display();}		    setCheckTime(false);		    for (i = 0; i < 10; i++) {stats.println();stats.println();stats.print("brute nochecktime cache "+i+" ");display();}		    setDrawOrder(FROMFOCUSCELL);		    for (i = 0; i < 10; i++) {stats.println();stats.println();stats.print("focus nochecktime cache "+i+" ");display();}		    setCheckTime(true);		    for (i = 0; i < 10; i++) {stats.println();stats.println();stats.print("focus checktime cache "+i+" "); display(); while (keepDrawing) display();}		    stats.flush();		    stats.println();		    stats.println("MARK WHOLE TREE");		    stats.println();		    		    tj.clearGroup(TreeJuxtaposer.markGroup[0]);		    tj.doSelectGeom(rootNode, true, TreeJuxtaposer.markGroup[0], this);		    tj.setFocus(rootNode, this);		    for (i = 0; i < 10; i++) {stats.println();stats.println();stats.print("mark checktime cache "+i+" ");display(); while (keepDrawing) display();}		    setCheckTime(false);		    for (i = 0; i < 10; i++) {stats.println();stats.println();stats.print("mark nochecktime cache "+i+" ");display();}		    setCacheRange(false);		    for (i = 0; i < 10; i++) {stats.println();stats.println();stats.print("mark nochecktime nocache "+i+" ");display();}		    setCheckTime(true);		    for (i = 0; i < 10; i++) {stats.println();stats.println();stats.print("mark checktime nocache "+i+" ");display(); while (keepDrawing) display();}		    stats.flush(); stats.println();		    stats.println();stats.println("DONE WITH STATS");		    stats.flush();		    setDumpStats(false);		    System.out.println("done gathering stats");		}	    }	    tj.requestRedrawAll();	    keytarget = NONE;	}	tj.observe();    }	private void newMouseOver(TreeNode originalNode, TreeNode newNode)	{		if( newNode == null ) return;		tj.clearGroup(TreeJuxtaposer.flashGroup);		//System.out.println("Who is this node: " + originalNode);		//System.out.println("Who is this node (current tree): " + newNode);//		String nodeName = newNode.getName();		tj.addNodesToGroup(newNode.key, newNode.key, TreeJuxtaposer.flashGroup, this);		tj.doFlashGeom(newNode, TreeJuxtaposer.flashGroup, this, getX(), getY(), true);		this.changedMarks();		this.pickedNode = newNode;	}	// true if treeNode cells (level 0 of quadtree) overlap horizontally	private boolean inHorizRange(TreeNode a, TreeNode b)	{		final int A = 0, B = 1;		double min[], max[];		min = new double[2];		max = new double[2];		if (a.parent != null)			min[A] = a.parent.getCell().getMax(X);		else			min[A] = -1f;		if (b.parent != null)			min[B] = b.parent.getCell().getMax(X);		else			min[B] = -1f;		max[A] = a.getCell().getMax(X);		max[B] = b.getCell().getMax(X);		if (max[A] <= min[B] || max[B] <= min[A])			return false;		return true;	}		// find the child number of the originalNode as a child of the parent node	private int findChildNumber(TreeNode parentNode, TreeNode originalNode)	{		int originalNodeChildNumber = 0; // number of original node (plus 1 actually)		while (originalNodeChildNumber < parentNode.numberChildren() &&					parentNode.getChild(originalNodeChildNumber++) != originalNode);		if (originalNodeChildNumber > parentNode.numberChildren())		{			System.out.println("Child couldn't find self from parent");		}		return originalNodeChildNumber;	}		// find the right aligned cell that is below (above) the original node, using the parent node as reference	// - the last parameter (boolean) is used to determine whether to search down (true) or up (false)	private TreeNode rightAlignFind(TreeNode parentNode, TreeNode originalNode, int originalNodeChildNumber, boolean goingDown)	{		TreeNode temp = parentNode.getChild(originalNodeChildNumber);		TreeNode prev = temp;		final int TEMP = 0;		final int ORIG = 1;		double rightX[];		rightX = new double[2];		rightX[ORIG] = originalNode.getMaxY();		rightX[TEMP] = temp.getMaxY();//		System.out.println("Firstly: ");//		System.out.println("rightX[ORIG] = " + rightX[ORIG]);//		System.out.println("rightX[TEMP] = " + rightX[TEMP]);			  		while (rightX[TEMP]  < rightX[ORIG] && temp.numberChildren() > 0)		{			prev = temp;			if (goingDown)				temp = temp.getChild(0);			else				temp = temp.getChild(temp.numberChildren() - 1);			rightX[TEMP] = temp.getMaxY();//			System.out.println("rightX[TEMP] = " + rightX[TEMP]);		}		if (rightX[TEMP] == rightX[ORIG] || temp.numberChildren() == 0)			return temp;		else			return prev;	//return null;	}	//	mouseover parent	// do nothing if currently no mouseover or at root node	public void flashLeft()	{		if (tj.getGroup(TreeJuxtaposer.flashGroup).size() == 0)			return;		RangeInTree rangeInTree =			(RangeInTree) tj.getGroup(TreeJuxtaposer.flashGroup).getFirst();		int firstNodeKey = rangeInTree.getMin();		TreeNode originalNode, parentNode;		originalNode = tree.getNodeByKey(firstNodeKey);		if (originalNode == null			|| (parentNode = originalNode.parent()) == null)			return;		mouseOverNode = parentNode; // keep the level for up/down traversal		newMouseOver(originalNode, parentNode);	}		//	mouseover first child 	// do nothing if currently no mouseover or at terminal node	public void flashRight()	{		if (tj.getGroup(TreeJuxtaposer.flashGroup).size() == 0)			return;		RangeInTree rangeInTree =			(RangeInTree) tj.getGroup(TreeJuxtaposer.flashGroup).getFirst();		int firstNodeKey = rangeInTree.getMin();		TreeNode originalNode, childNode = null;		originalNode = tree.getNodeByKey(firstNodeKey);		if (originalNode == null			|| originalNode.numberChildren() == 0			|| (childNode = originalNode.getChild(0)) == null)			return;		mouseOverNode = childNode; // keep the level for up/down traversal		newMouseOver(originalNode, childNode);	}	//	mouseover sibling if at first child, cousin if at last child of common parent	// do nothing if at bottommost node (bottommost has no tree edges below that share X coord)	public void flashDown()	{//		RangeInTree rangeInTree =//			(RangeInTree) tj.getGroup(tj.flashGroup).ranges.getFirst();		RangeInTree rangeInTree =			(RangeInTree) tj.getGroup(TreeJuxtaposer.flashGroup).getFirst();		int firstNodeKey = rangeInTree.getMin();		TreeNode prevParentNode = null,			parentNode = null,			originalNode,			downNode = null;		originalNode = tree.getNodeByKey(firstNodeKey);		downNode = originalNode; // default downNode, idempotent action		if (originalNode == null			|| (parentNode = originalNode.parent()) == null)			return; // no parent (root) or no highlight		int originalNodeChildNumber = findChildNumber(parentNode, originalNode);		// number of original node (plus 1 actually)		if (originalNodeChildNumber > parentNode.numberChildren())			return; // can't find self		if (originalNodeChildNumber < parentNode.numberChildren()) {			// become maximal bigger-numbered-sibling's descendent			//  - of the immediate parent, find the next sibling and traverse down			//    until the last node that has a right edge less than the right edge of			//    the original node is found (so traversal through the leaves of a right-			//    aligned tree is possible since it is better than falling back to the root)			downNode =				rightAlignFind(					parentNode,					mouseOverNode,					originalNodeChildNumber,					true);		} else {			// process cousins			prevParentNode = parentNode.parent;			int parentAsChildNum = 0;			while (prevParentNode != null) {				parentAsChildNum = findChildNumber(prevParentNode, parentNode);				if (parentAsChildNum > prevParentNode.numberChildren())					return;				if (parentAsChildNum < prevParentNode.numberChildren()					|| prevParentNode.parent == null)					break;				parentNode = prevParentNode;				prevParentNode = prevParentNode.parent;			}			if (prevParentNode == null				|| parentAsChildNum == prevParentNode.numberChildren())				return;			downNode =				rightAlignFind(					prevParentNode,					mouseOverNode,					parentAsChildNum,					true);		}		newMouseOver(originalNode, downNode);	}	//	mouseover sibling if at last child, cousin if at first child of common parent	// do nothing if at topmost node	public void flashUp()	{		RangeInTree rangeInTree = tj.getGroup(TreeJuxtaposer.flashGroup).getFirst();		int firstNodeKey = rangeInTree.getMin();		TreeNode prevParentNode = null,			parentNode = null,			originalNode,			upNode = null;		originalNode = tree.getNodeByKey(firstNodeKey);		upNode = originalNode; // default upNode, idempotent action		if (originalNode == null || (parentNode = originalNode.parent()) == null)			return; // no parent (root) or no highlight		int originalNodeChildNumber = findChildNumber(parentNode, originalNode);		// number of original node (plus 1 actually)		if (originalNodeChildNumber > parentNode.numberChildren())			return; // can't find self		if (originalNodeChildNumber > 1) {			// become maximal smaller-numbered-sibling's descendent			//  - of the immediate parent, find the previous sibling and traverse up			//    until the last node that has a right edge less than the right edge of			//    the original node is found (so traversal through the leaves of a right-			//    aligned tree is possible since it is better than falling back to the root)			upNode =				rightAlignFind(					parentNode,					mouseOverNode,					originalNodeChildNumber - 2,					false);		} else {			// process cousins			prevParentNode = parentNode.parent;			int parentAsChildNum = 0;			while (prevParentNode != null) {					parentAsChildNum = findChildNumber(prevParentNode, parentNode);				if (parentAsChildNum > prevParentNode.numberChildren())					return; // can't find parent from prev parent				if ((parentAsChildNum > 1					&& parentAsChildNum <= prevParentNode.numberChildren())					|| prevParentNode.parent == null)					break; // found good common descendent to traverse down				parentNode = prevParentNode;				prevParentNode = prevParentNode.parent;			}			if (prevParentNode == null || parentAsChildNum == 1)				return;			upNode =				rightAlignFind(					prevParentNode,					mouseOverNode,					parentAsChildNum - 2,					false);			//0, false);		}		newMouseOver(originalNode, upNode);	}    public void keyPressed(KeyEvent e) {//	if (keytarget == DEVELOPER) return;	if (tj.getQuasimode()) return;	char key = e.getKeyChar();	int code = e.getKeyCode();//	if (keytarget == DEVELOPER)//	{//	    if (code == KeyEvent.VK_LEFT)			     			    //			{//					tj.drawLL(); //					tj.butterflyFrame.setButtonStatus(0);//			} 		//		 else if (code == KeyEvent.VK_RIGHT)   //			{//				tj.drawRR();//				tj.butterflyFrame.setButtonStatus(1);//			}  //		else if (code == KeyEvent.VK_DOWN)//			{//				// don't support down right now//					//tj.drawDD();//				//tj.butterflyFrame.setButtonStatus(4);//			}		//		else if (code == KeyEvent.VK_UP)//			{//					tj.drawUU(); //				    tj.butterflyFrame.setButtonStatus(3);//			} //		else if(key == '2')//		{//		        tj.drawRL();//			tj.butterflyFrame.setButtonStatus(2);//		}//	} //   else {	if (code == KeyEvent.VK_LEFT)	{//	   if(this.drawDirection == LEFT)		flashLeft();//		if(drawDirection == RIGHT)//		flashRight();//		if(drawDirection == UP)//		flashUp();//		if(drawDirection == DOWN)//		flashDown();	}	else if (code == KeyEvent.VK_RIGHT)	{//		if(drawDirection == LEFT)		flashRight();//		if(drawDirection == RIGHT)//		flashLeft();//		if(drawDirection == UP)//		flashDown();//		if(drawDirection == DOWN)//		flashUp();	}	else if (code == KeyEvent.VK_DOWN)	{//		   if(drawDirection == LEFT || drawDirection == RIGHT)			flashDown();//			if(drawDirection == UP)//			flashLeft();//			if(drawDirection == DOWN)//			flashRight();	}		else if (code == KeyEvent.VK_UP)		{//			if(drawDirection == LEFT || drawDirection == RIGHT)			 flashUp();//			 if(drawDirection == UP)//			 flashRight();//			 if(drawDirection == DOWN)//			 flashLeft();		}	else 	//System.out.println("PRESS " + key + " code " + code);	if (KeyEvent.VK_CONTROL == code || KeyEvent.VK_ALT == code) {	    tj.setQuasimode(true);	    flashBox = null;	    setFlash(null, rubberbandColor, mouseNow[X], mouseNow[Y], true);	    setActionMode(RECT_FREEMOVE);	}  else if (KeyEvent.VK_SHIFT == code) {	    if (keytarget == TreeJuxtaposer.markGroup[0] ||	    	keytarget == TreeJuxtaposer.markGroup[1] ||	    	keytarget == TreeJuxtaposer.markGroup[2] ||	    	keytarget == TreeJuxtaposer.markGroup[3] ||	    	keytarget == TreeJuxtaposer.flashGroup ||	    	keytarget == TreeJuxtaposer.diffGroup ||	    	keytarget == TreeJuxtaposer.foundGroup)	    		setActionGroup(keytarget);	    else setActionGroup(keytargetDefault);	    drawActiveSubtreeBox();	    if (getActionGroup() == TreeJuxtaposer.flashGroup) {		if (null != pickedNode) {		    tj.setFocus(pickedNode, this);		    tj.setQuasimode(true);		    drawActiveSubtreeBox();		    setActionMode(ST_FREEMOVE);		}	    } else {		tj.setQuasimode(true);		drawActiveSubtreeBox();		setActionMode(ST_FREEMOVE);		ArrayList forestRoots = tj.getGroupForest(getActionGroup(), this); // array of TreeNodes		if (!forestRoots.isEmpty()) 		    tj.setFocus(((TreeNode)forestRoots.get(0)), this);	    }	    keytarget = NONE;	}  //  }    }    public void keyReleased(KeyEvent e) {	if (keytarget == DEVELOPER) return;	char key = e.getKeyChar();	int code = e.getKeyCode();	if (KeyEvent.VK_SHIFT == code || KeyEvent.VK_CONTROL == code || KeyEvent.VK_ALT == code) {	    tj.setQuasimode(false);	    actionmodeReset();	}	//System.out.println("RELEASE " + key + " code " + code);    }public void seedQueue() {//	System.out.println("Seeding queue for: " + this);    tj.seedQueue(this);//    System.out.println("Seeded: " + ToDrawQ);}	public ArrayList getColorsForCellGeom(CellGeom c){		return tj.getColorsForRange(c.getKey(), c.getKey(), this);	}	/**	 * @return	 */	public InteractionBox getBaseBox() {		return baseBox;	}	/* (non-Javadoc)	 * @see AccordionTreeDrawer.AccordionTreeDrawer#getRangeByKey(int)	 */	public RangeList getRangeByKey(int key)	{		if (key >= 0 && key < tj.groups.size())			return tj.getGroup(key);		return null;	}	/* (non-Javadoc)	 * @see AccordionDrawer.AccordionDrawer#getColorsForGridCell(AccordionDrawer.GridCell, int)	 */	public ArrayList getColorsForGridCell(GridCell c, int objkey)	{		return null;	}	/* (non-Javadoc)	 * @see AccordionDrawer.AccordionDrawer#getOlduvaiObject()	 */	public OlduvaiObject getOlduvaiObject()	{		return (Tree)tree;	}	/* (non-Javadoc)	 * @see AccordionDrawer.AccordionDrawer#drawReferenceLine()	 */	public void drawReferenceLine()	{		}};

⌨️ 快捷键说明

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