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

📄 accordiontreedrawerfinal.java

📁 生物物种进化历程的演示
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   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 TreeJuxtaposer;import java.util.*;import java.awt.event.*;import AccordionDrawer.*;import AccordionTreeDrawer.*;/** * A class that fleshes out the abstract methods left in * AccordionTreeDrawer. * * In particular, mouse and keyboard events are mapped to * AccordionTreeDrawer methods. * * @author  Tamara Munzner, Serdar Tasiran, Li Zhang, Yunhong Zhou * @version  * @see     AccordionDrawer.AccordionDrawer * @see     AccordionDrawer.AccordionTreeDrawer */public class AccordionTreeDrawerFinal extends AccordionTreeDrawer {    TreeJuxtaposer tj;    int dragStart[] = new int[2];    int dragEnd[] = new int[2];    int mousePrev[]=new int[2];    int mouseNow[]=new int[2];    TreeNode mouseOverNode;	// actiongroup: what is supposed to grow when grow option (bigger/smaller) is pressed    private int actiongroup;    // markgroup: what is the selection colour that is currently being used    //  (only applies to MARK[0-3], other ints are only associated with actiongroup)    private int markgroup;    /*     * Don't use these and expect it to work since tj.????Group stuff is used elsewhere    final static int MARK0 = 0;    final static int MARK1 = 1;    final static int MARK2 = 2;    final static int MARK3 = 3;    final static int FLASH = 4;    final static int DIFF = 5;    final static int LIST = 6;    */        // which direction to grow    private int growDirection;    final static int HORIZ = 0;    final static int VERT = 1;    final static int ALL = 2;    private int growDirectionDefault = VERT;        // does the selection (marking) of a node select just the node or the subtree    private int selectionResolution;    final static int NODE = 0;    final static int SUBTREE = 1;    private int selectionResolutionDefault = SUBTREE;    	private int keytarget;    // developer mode for keytarget only    final static int DEVELOPER = 11;    // only let the keytarget and actionmode be set to NONE    // any other state that can be seen externally should have real state (default value)    final static int NONE = 12;    private final static int keytargetDefault = TreeJuxtaposer.flashGroup;        private int actionmode;    final static int MOUSEOVER = 0;    final static int ST_FREEMOVE = 1;    final static int ST_FREEMOVEAGAIN = 2;    final static int ST_RESHAPE = 3;    final static int RECT_CREATE = 4;    final static int RECT_FREEMOVE = 5;    final static int RECT_FREEMOVEAGAIN = 6;    final static int RECT_RESHAPE = 7;    private final static int actionmodeDefault = MOUSEOVER;	final static int MOVE_STUCKPOS = 11;    boolean jump;    TreeNode pickedNode;    TreeNode pickedNodeOld;    	/* State accessors and mutators */		/* Action group */	public void setActionGroup(int newActionGroup)	{		//System.out.println("setting action group: " + newActionGroup);		setActionGroupWrapper(newActionGroup, true);	}	public void setActionGroupWrapper(int newActionGroup, boolean repeat)	{		actiongroup = newActionGroup;		if (repeat)		{			Iterator tdIter = tj.treeDrawers.iterator();			while (tdIter.hasNext())			{				AccordionTreeDrawerFinal atd = (AccordionTreeDrawerFinal)tdIter.next();				atd.setActionGroupWrapper(newActionGroup, false);			}		}		tj.observe();	}	public int getActionGroup()	{		return actiongroup;	}		/* Action mode */	public void setActionMode(int newActionMode)	{		//System.out.println("setting action mode: " + newActionMode);		setActionModeWrapper(newActionMode, false);	}	public void setActionModeWrapper(int newActionMode, boolean repeat)	{		actionmode = newActionMode;		if (repeat)		{			Iterator tdIter = tj.treeDrawers.iterator();			while (tdIter.hasNext())			{				AccordionTreeDrawerFinal atd = (AccordionTreeDrawerFinal)tdIter.next();				atd.setActionModeWrapper(newActionMode, false);			}		}		tj.observe();	}	public int getActionMode()	{		return actionmode;	}		public void setGrowDirection(int growDirection)	{		//System.out.println("setting grow direction: " + growDirection);		setGrowDirectionWrapper(growDirection, true);	}	public void setGrowDirectionWrapper(int growDirection, boolean repeat)	{		this.growDirection = growDirection;		if (repeat)		{			Iterator tdIter = tj.treeDrawers.iterator();			while (tdIter.hasNext())			{				AccordionTreeDrawerFinal atd = (AccordionTreeDrawerFinal)tdIter.next();				atd.setGrowDirectionWrapper(growDirection, false);			}		}		tj.observe();	}	public int getGrowDirection()	{		return growDirection;	}		public void setSelectionResolution(int selectionResolution)	{		//System.out.println("setting action target: " + selectionResolution);		setSelectionResolutionWrapper(selectionResolution, true);	}	public void setSelectionResolutionWrapper(int selectionResolution, boolean repeat)	{		this.selectionResolution = selectionResolution;		if (repeat)		{			Iterator tdIter = tj.treeDrawers.iterator();			while (tdIter.hasNext())			{				AccordionTreeDrawerFinal atd = (AccordionTreeDrawerFinal)tdIter.next();				atd.setSelectionResolutionWrapper(selectionResolution, false);			}		}		tj.observe();	}	public int getSelectionResolution()	{		return selectionResolution;	}		public void setMarkGroup(int newMarkGroup)	{		setMarkGroupWrapper(newMarkGroup, true);	}	public void setMarkGroupWrapper(int newMarkGroup, boolean repeat)	{		markgroup = newMarkGroup;		if (repeat)		{			Iterator tdIter = tj.treeDrawers.iterator();			while (tdIter.hasNext())			{				AccordionTreeDrawerFinal atd = (AccordionTreeDrawerFinal)tdIter.next();				atd.setMarkGroupWrapper(newMarkGroup, false);			}		}		tj.observe();	}	public int getMarkGroup()	{		return markgroup;	}    AccordionTreeDrawerFinal(Tree t, int w, int h, TreeJuxtaposer thetj) {	super(t, w, h);	tj = thetj;	setMarkGroup(TreeJuxtaposer.markGroup[0]);	setActionGroup(TreeJuxtaposer.flashGroup);	setActionMode(actionmodeDefault);	keytarget = NONE;	setGrowDirection(growDirectionDefault);	setSelectionResolution(selectionResolutionDefault);	jump = false;	baseBox = null;	splitLine[X].setMaxStuckValue(0.7f); // so you can see the names on the leaves    }    // implement abstract classes    public ArrayList getColorsForRange(int objmin, int objmax) {	return tj.getColorsForRange(objmin, objmax, (AccordionTreeDrawer) this);    }	// implement abstract classes	public ArrayList getColorsForRange(int objmin, int objmax, int a, int b) {	   return tj.getColorsForRange(objmin, objmax, (AccordionTreeDrawer) this);	   }    /**     * Make an InteractionBox from the GridCells nearest to the box of the mousedrag.     * Expects dragStart[X]/Y, dragEnd[X]/Y to be set.      *      * @author Francois Guimbretiere, Tamara Munzner */    private void drawActiveSubtreeBox() {	// turn off original flashbox	flashBox = null;	setFlash(null, rubberbandColor, -1, -1, true);	CellGeom fg = null;	if (getActionGroup() == TreeJuxtaposer.flashGroup) {	    baseBox = makeBox(pickedNode); 	    if (null == baseBox) {//		System.out.println("basebox null");		return;	    }	    flashBox = baseBox;	    if (null != pickedNode)			fg = pickedNode;//	    else if (null != temp && null != temp.item)//		fg = temp.item;	} else {	    ArrayList forestRoots = tj.getGroupForest(getActionGroup(), this); // array of TreeNodes	    if (forestRoots.isEmpty()) {		actionmodeReset();		return;	    }	    TreeNode n = (TreeNode)(forestRoots.get(0));	    baseBox = makeBox(n); // just use the first one, for now	    if (null == baseBox) {//		System.out.println("basebox2 null");		return;	    }	    fg = n;	    flashBox = baseBox;	}	flashBoxWidth=3f;	if (fg == null) fg = tree.getRoot();	tj.setFocus(fg, this);	setFlash(fg, rubberbandColor,-1, -1, true);    }    public void actionmodeReset() {	//System.out.println("reset");		// reason: set action mode to mouseover when exiting other modes	setActionMode(MOUSEOVER);		baseBox = null;	flashBox = null;	pickedNode = null;	pickedNodeOld = null;	flashBoxWidth = 1f;	tj.doFlashGeom(null, TreeJuxtaposer.flashGroup, this, mouseNow[X], mouseNow[Y], false);	//setFlash(null, tj.rubberbandColor, mouseNow[X], mouseNow[Y], true);    	// can't set this null until after setflash...	//flashBoxOld = null;	//flashGeomOld = null;	//flashGeom = null;		// reason?	// setActionGroup(tj.flashGroup);		keytarget = NONE; // squash keys in state machine	//setGrowDirection(growDirectionDefault); // this resets the grow direction to both... why?	tj.setQuasimode(false);	mouseover(mouseNow[X], mouseNow[Y]);    }    private void mouseover(int x, int y) {     	TreeNode pickedGeom = (TreeNode)pickAttached(x,y);	if (null == pickedGeom) return;        mouseOverNode = pickedGeom;    pickedNode = pickedGeom;	if (pickedNode == pickedNodeOld) return;		pickedNodeOld = pickedNode;	tj.doFlashGeom(pickedNode, TreeJuxtaposer.flashGroup, this, x, y, true);	tj.debugFrame.result[DebugFrame.NAV_TYPE].setText(pickedNode.toString());	tj.debugFrame.result[DebugFrame.BCN_SCORE].setText((pickedNode.getBcnScore()).toString());        }	private void reshaperectangle(boolean doOther) {				if (null == baseBox) {			actionmodeReset();			return;		}				// CRFP: return 2 integers, pixel differences for baseBox movable lines in X and Y		int[] rectBox = createRectFromPick(baseBox);				if (rectBox == null)			return;//		System.out.println("RectBox: " + rectBox[0] + " " + rectBox[1]);			int numAnimSteps = 3;		while (transitionAnimating)			endAllTransitions(); // end transitions, new queue is going to be swapped in		Hashtable newToMove = new Hashtable();		for (int xy = X; xy <= Y; xy++)		{			splitLine[xy].moveLine(baseBox.moveLineIndex[xy], // the split to move				rectBox[xy], // move it to the end position				baseBox.stuckLineIndex[xy], // the split to stay				numAnimSteps, newToMove);		}		toMove = newToMove; // swap in new queue		incrementFrameNumber(); // so compute place this frame will update, this can be moved to after transitions are created				if (doOther			&& null != baseBox.item) { // linked navigation to other trees			double changeRatio[] = new double[2];			for (int xy = 0; xy < 2; xy++) {				SplitLine split = getSplitLine(xy);				int movement = baseBox.dragEnd[xy] - baseBox.oldDragEnd[xy];//				System.out.println("movement: " + movement);				if (baseBox.stuckLineIndex[xy] > baseBox.moveLineIndex[xy])					movement *= -1;				changeRatio[xy] = s2w(movement, xy);//				double dragEnd = (double)s2w(rectBox[xy], xy);//				if (dragEnd < split.getMinStuckValue() + minContextPeriphery ||//					dragEnd > split.getMaxStuckValue() - minContextPeriphery)//				{//					System.out.println("drag too far");//					break;//					//				}//				double staticEnd = split.getAbsoluteValue(baseBox.stuckLineIndex[xy]);//				double dragStart = split.getAbsoluteValue(baseBox.moveLineIndex[xy]);//				double oldBoxSize = Math.abs(staticEnd - dragStart);//				double newBoxSize = Math.abs(staticEnd - dragEnd);//////				changeRatio[xy] = newBoxSize - oldBoxSize;//			}			TreeNode n = (TreeNode)baseBox.item;			tj.resizeRectOthers(n, changeRatio, numAnimSteps, this);			tj.requestRedrawAll();		}		else			requestRedraw(); // redraw the frame, this will enact the movements in the move queue		flashBox = baseBox;		setFlash(null, rubberbandColor, mouseNow[X], mouseNow[Y], true);	}    private void remakerectangle() {//	if (null == flashBox) {//	    actionmodeReset(); return;//	}//	// flashbox is leftover from last reshaperectangle.//	/*//	// need to transfer the cells from the last basebox to it.//	flashBox.minc = baseBox.minc;//	flashBox.maxc = baseBox.maxc;//	System.out.println("remake "+flashBox.minc+" "+flashBox.maxc); //	setFlash(null, tj.rubberbandColor, -1, -1, true);//	return;//	*///	// need to remake the baseBox with real cell data//	// using boundaries of last rectmove flashBox//	for (int xy = 0; xy<2; xy++) {//	    // get just inside box//	    dragStart[xy] = flashBox.min[xy]+1;//	    dragEnd[xy] = flashBox.max[xy]-1;//	}//	CellGeom item = baseBox.item;//	baseBox = createBoxFromCells(dragStart, dragEnd);//	baseBox.item = item;//	if (baseBox.minc == null || baseBox.maxc == null) System.out.println("NO CELLS!");//	flashBox = baseBox;//	setFlash(null, rubberbandColor, -1, -1, true);//	// put back dragStart/End to real values//	for (int xy = 0; xy < 2; xy++) {//	    dragStart[xy] = mouseNow[xy];//	    dragEnd[xy] = mouseNow[xy];//	}    }    public void mouseEntered(MouseEvent e) {    	requestRedraw();		if (mouseOutOfWindow(e))			return;	//System.out.println("entered window");	if (!tj.getQuasimode()) requestFocus();	else tj.wantsFocusInQuasi(this);    }    public void mouseExited(MouseEvent e) {		if (mouseOutOfWindow(e))			return;	//System.out.println("left window");	if (!tj.getQuasimode()) transferFocus();	//else tj.lostFocusInQuasi(this);    }	private boolean mouseOutOfWindow(MouseEvent e)	{		return e.getX() <= 0 || e.getX() >= getWinMax(X) || e.getY() <= 0 || e.getY() >= getWinMax(Y);	}	private int closeToStuck()	{		double mouse[] = {s2w(mouseNow[X], X), s2w(mouseNow[Y], Y)};		double fuzz[] = {s2w(pickFuzz, Y), s2w(pickFuzz, Y)};

⌨️ 快捷键说明

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