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

📄 treeedge.java

📁 生物物种进化历程的演示
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	int current = -1;	int prevcurrent = -2;	int foundIndex = -1;	LabelBox found;	//while ((low < high) && (current != prevcurrent) && (!intersects)) {	while ((low < high) && (!intersects) && (current<=high) && (foundIndex < 0))	{	    prevcurrent = current;	    current = (int)((high+low)/2.0);	    if (current == prevcurrent && low+1 == high) {			low=high;			current = high;	    }		if(current == listlength) current = current-1;	    LabelBox prevlab = (LabelBox) drawnLabels.get(current);	    //System.out.println("lb bl " + lb.bl[1] + " p tr " + prevlab.tr[1] + " lb tr " + lb.tr[1] + " p bl " + prevlab.bl[1]);	    if (lb.compareBtoT(prevlab, low, high)) high = current;	    else if (prevlab.compareBtoT(lb, low, high)) low = current;	    else { // check intersections		found = prevlab;		foundIndex = current;		//System.out.println("found: " + foundIndex);		// we're doing a bit more work than necessary by		// checking against prevlab from last iteration,		// but it's the easiest way to ensure corner cases		// work		while (!intersects && prevlab.bottomBiggerThanTop(lb) && current >= 0) { 		    // check down from found		    // i.e. index in sorted list gets smaller, so		    // y values get smaller also		    prevlab = (LabelBox) drawnLabels.get(current);		    intersects = lb.intersectBoxes(prevlab);		    current--;		    //System.out.println("cur-- now " + current);		}		//current = foundIndex+1;		current = foundIndex;		while (!intersects && lb.bottomBiggerThanTop(prevlab) && current <= listlength-1) { 		    // check up from found		    prevlab = (LabelBox) drawnLabels.get(current);		    intersects = lb.intersectBoxes(prevlab);		    current++;		    //System.out.println("cur++ now " + current);		}	    }	    //System.out.println("low " + low + " high " + high + " cur " + current + " prevcur " + prevcurrent + " intersects " + intersects); 	}	return intersects;    }    /** Draw a LabelBox.      * @author	 Tamara Munzner, Li Zhang     * @param	 lb LabelBox to use     * @param    fontheight Size of font to use, in points/pixels.     * @param	 drawBig whether to draw maximum size ignoring occlusions     */    private void drawLabelBox(LabelBox lb, int fontheight, boolean drawBig)     {    	int X = AccordionDrawer.X, Y = AccordionDrawer.Y;		AccordionTreeDrawer d = (AccordionTreeDrawer)getCell().drawer;		GLFunc gl = (GLFunc) d.getGraphicsStuff();		ArrayList drawnLabels = d.getDrawnLabels();		if (!drawBig)		{	    	drawnLabels.add(lb);	    	Collections.sort(drawnLabels);		}				int[] pos = { lb.pos(0), lb.pos(1) };		int[] topRightPos = { lb.topRightPos(0), lb.topRightPos(1) };		// highlighted node drawing == drawBig		double labelplane = d.getLabelplane();		if (d.labeldrawback || drawBig) {			float thecol[] = new float[3];			if (drawBig)				d.getLabelBackHiColor().getRGBColorComponents(thecol);			else				d.getLabelBackColor().getRGBColorComponents(thecol);			if (!drawBig && d.labeltransp) {				gl.glColor4f(thecol[0], thecol[1], thecol[2], .5f);			} else {				gl.glColor3f(thecol[0], thecol[1], thecol[2]);			}//			if (d.drawDirection != AccordionDrawer.RIGHT) {				gl.glBegin(GLEnum.GL_POLYGON);				gl.glVertex3d(d.s2w(pos[0], 0), d.s2w(pos[1], 1), labelplane);				gl.glVertex3d(d.s2w(topRightPos[0], 0), d.s2w(pos[1], 1),						labelplane);				gl.glVertex3d(d.s2w(topRightPos[0], 0),						d.s2w(topRightPos[1], 1), labelplane);				gl.glVertex3d(d.s2w(pos[0], 0), d.s2w(topRightPos[1], 1),						labelplane);				gl.glEnd();//			}//			if (d.drawDirection == AccordionDrawer.RIGHT) {//				gl.glBegin(GLEnum.GL_POLYGON);//				gl.glVertex3d(d.s2w(pos[0], 0), d.s2w(pos[1], 1), labelplane);//				gl.glVertex3d(d.s2w(topRightPos[0], 0), d.s2w(pos[1], 1),//						labelplane);//				gl.glVertex3d(d.s2w(topRightPos[0], 0), d//						.s2w(topRightPos[1], 1), labelplane);//				gl.glVertex3d(d.s2w(pos[0], 0), d.s2w(topRightPos[1], 1),//						labelplane);//				gl.glEnd();//			}		}		int descent = AccordionDrawer.getDescent(fontheight);		String name = lb.getName();		double b[] = { d.s2w(pos[X] + 1, X), d.s2w(pos[Y] - descent - 1, Y)};		if (drawBig) // no shadow on highlight		{			d.setColorGL(d.getLabelHiColor());			d.drawText(b[X], b[Y], name, fontheight, d.getLabelColor(), labelplane, null);		}		else if (!d.labeldrawback) // shadow, not big, or background box		{			d.drawText(b[X], b[Y], name, fontheight, d.getLabelColor(), labelplane, d.getLabelBackColor());		}		else // not big, background box so no shadow needed			d.drawText(b[X], b[Y], name, fontheight, d.getLabelColor(), labelplane, null);	}	// TODO: is there a better way of drawing labels in different directions?//	//	///**// * draw label box in vertical direction// * @param d// * @param gl// * @param lb// * @param fontheight// * @param drawBig// *///private void drawLabelBoxUp(AccordionTreeDrawer d,GLFunc gl, LabelBox lb, int fontheight, boolean drawBig)//	{//		int[] pos = {lb.pos(0), lb.pos(1)};       //		int[] topRightPos = {lb.topRightPos(0), lb.topRightPos(1)};//		//String name = lb.getName();//		String name = getName();//		int cwidth;//        float[][] p = new float[name.length()][];////		for(int i=0; i<name.length(); i++)////		{////		 cwidth= AccordionTreeDrawer.bff.charWidth(name,fontheight,i);////		 xInterval[i] = cwidth;         ////		 float t =  cwidth*(float)java.lang.Math.tan(java.lang.Math.toRadians(d.getDrawAngle()));////		 yInterval[i] = (int)t;////		}////		d.xInterval = xInterval;////		d.yInterval = yInterval;//		if (drawBig) { // save off the pixels we're about to overwrite////			d.drawnlabelsize[0] =fontheight+6;//			d.drawnlabelsize[1] =fontheight;//			d.drawnlabelpos[0] = d.s2w(pos[0]-3,0);//			d.drawnlabelpos[1] = d.s2w(pos[1],1);//	        int x=pos[0]-3;//	        int y=pos[1];//	        for(int i = 0; i<name.length(); i++)//	        {//			d.pixels = new float[d.drawnlabelsize[0]*3*d.drawnlabelsize[1]*3];//            p[i]=d.pixels;//			gl.glReadBuffer(GLEnum.GL_FRONT);//			gl.glReadPixels(x,d.getWinsize(1)-y,d.drawnlabelsize[0],d.drawnlabelsize[1], GLEnum.GL_RGB, GLEnum.GL_FLOAT, p[i]);////			x+=xInterval[i];////			y-=yInterval[i];//	        }//	        d.pal = p;//	//		}////		//		// padding of one pixel on right and bottom, and make sure//		// we leave enough vertical room for character parts that//		// descend below font baseline.//		double labelplane = d.getLabelplane();//		if (d.labeldrawback || drawBig) {//			float thecol[] = new float[3];//			if (drawBig) d.getLabelBackHiColor().getRGBColorComponents(thecol);//			else d.getLabelBackColor().getRGBColorComponents(thecol);//			if (!drawBig && d.labeltransp) {//			gl.glColor4f(thecol[0], thecol[1], thecol[2], .5f);//		//		//		//			} else {//			gl.glColor3f(thecol[0], thecol[1], thecol[2]);//			}////            int x=0;//            int y=0;//            int c;//            for(int i=0; i<lb.getName().length(); i++)//            {//			//			c=10;//			gl.glDisable(GLEnum.GL_DEPTH _TEST);//			gl.glBegin(GLEnum.GL_POLYGON);//			gl.glVertex3d(d.s2w(pos[0]+x-3,0), d.s2w(pos[1]-y,1), labelplane);//			gl.glVertex3d(d.s2w(pos[0]+x+c+3,0), d.s2w(pos[1]-y,1), labelplane);//			gl.glVertex3d(d.s2w(pos[0]+x+c+3,0), d.s2w(pos[1]-y-fontheight,1), labelplane);//			gl.glVertex3d(d.s2w(pos[0]+x-3,0), d.s2w(pos[1]-y-fontheight,1), labelplane);//			gl.glEnd();//			gl.glEnable(GLEnum.GL_DEPTH _TEST);////			x+=xInterval[i];////			y+=yInterval[i];//            }////		}//		int descent = AccordionTreeDrawer.bff.getDescent(fontheight);//		if (drawBig) //			d.setColorGL(d.getLabelHiColor());//		else {//			if (!d.labeldrawback) {//			// first draw 4X (nw/ne/sw/se) in outline color //			d.setColorGL(d.getLabelBackColor());//			int by = pos[1]-descent-1;//			int bx = pos[0] ;//	//		}//			d.setColorGL(d.getLabelColor());//		}//	//			int x=0;//			int y =descent+1 ;	//			for(int i=0; i<name.length(); i++)//			{				            //				gl.glRasterPos3d((float)d.s2w(pos[0] +x,0), (float)d.s2w(pos[1]-y,1),   //				(float)labelplane);//				AccordionTreeDrawer.bff.drawString(gl, name.substring(i,i+1), fontheight);//				////                x+=xInterval[i];////                y+=yInterval[i];//			}//	}//	//// draw in down direction//	//private void drawLabelBoxDown(AccordionTreeDrawer d,GLFunc gl, LabelBox lb, int fontheight, boolean drawBig)//	{//		int[] pos = {lb.pos(0), lb.pos(1)};//		int[] topRightPos = {lb.topRightPos(0), lb.topRightPos(1)};//		String name = lb.getName();//		float[][] p = new float[name.length()][]; 		//		int cwidth;//////		for(int i=0; i<name.length(); i++)////		{////			 cwidth= AccordionTreeDrawer.bff.charWidth(name,fontheight,i);////			 xInterval[i] = cwidth;         ////			 float t =  cwidth*(float)Math.tan(java.lang.Math.toRadians(d.getDrawAngle()));////		 	yInterval[i] = (int)t;////		}////		////		d.xInterval = xInterval;////		d.yInterval = yInterval;//		if (drawBig) { // save off the pixels we're about to overwrite//   //			d.drawnlabelsize[0] =fontheight+6;//			d.drawnlabelsize[1] =lb.size(0)+2;//			d.drawnlabelpos[0] = d.s2w(pos[0]-3,0);//			d.drawnlabelpos[1] = d.s2w(pos[1]+fontheight+4,1);//			int x=pos[0]-3;//			int y=pos[1]+fontheight+4;//			for(int i = 0; i<lb.getName().length(); i++)//			{//				d.pixels = new float[d.drawnlabelsize[0]*3*d.drawnlabelsize[1]*3];////    	    	p[i] = d.pixels;//				gl.glReadBuffer(GLEnum.GL_FRONT);////				gl.glReadPixels(x,d.getWinsize(1)-y,d.drawnlabelsize[0],d.drawnlabelsize[1], GLEnum.GL_RGB, GLEnum.GL_FLOAT, p[i]);////				x+=xInterval[i];////				y+=yInterval[i];//				if(y>d.getWinsize(1)) y=d.getWinsize(1)-1;//			}//             d.pal = p;//	//		}////		//		// padding of one pixel on right and bottom, and make sure//		// we leave enough vertical room for character parts that//		// descend below font baseline.//		double labelplane = d.getLabelplane();//		if (d.labeldrawback || drawBig) {//			float thecol[] = new float[3];//			if (drawBig) d.getLabelBackHiColor().getRGBColorComponents(thecol);//			else d.getLabelBackColor().getRGBColorComponents(thecol);//			if (!drawBig && d.labeltransp) {//			gl.glColor4f(thecol[0], thecol[1], thecol[2], .5f);//			//			//			} else {//			gl.glColor3f(thecol[0], thecol[1], thecol[2]);//			}//			int x=0;//			int y=0;//			int c;//			for(int i=0; i<lb.getName().length(); i++)//			{//				//c=AccordionTreeDrawer.bff.charWidth(lb.getName(),fontheight,i);//				c=10;//				gl.glDisable(GLEnum.GL_DEPTH _TEST);//				gl.glBegin(GLEnum.GL_POLYGON);//				gl.glVertex3d(d.s2w(pos[0]+x-3,0), d.s2w(pos[1]+y,1), labelplane);//				gl.glVertex3d(d.s2w(pos[0]+x+c+3,0), d.s2w(pos[1]+y,1), labelplane);//				gl.glVertex3d(d.s2w(pos[0]+x+c+3,0), d.s2w(pos[1]+y+fontheight,1), labelplane);//				gl.glVertex3d(d.s2w(pos[0]+x-3,0), d.s2w(pos[1]+y+fontheight,1), labelplane);//				gl.glEnd();//				gl.glEnable(GLEnum.GL_DEPTH _TEST);////				x+=xInterval[i];////				y+=yInterval[i];//			}//	//		//		}//		int descent = AccordionTreeDrawer.bff.getDescent(fontheight);//		if (drawBig) //			d.setColorGL(d.getLabelHiColor());//		else {//			if (!d.labeldrawback) {//			// first draw 4X (nw/ne/sw/se) in outline color //			d.setColorGL(d.getLabelBackColor());//		int by = pos[1]+descent+10;//			int bx = pos[0] ;//	////		}//			d.setColorGL(d.getLabelColor());//		}//	//			int x=0;//			int y =descent+1 ;	//			for(int i=0; i<name.length(); i++)//			{				            //				gl.glRasterPos3d((float)d.s2w(pos[0] +x,0), (float)d.s2w(pos[1]+y+10,1),   //				(float)labelplane);//				AccordionTreeDrawer.bff.drawString(gl, name.substring(i,i+1), fontheight);////				x+=xInterval[i];////				y+=yInterval[i];//			//			}//	}// TODO: this is actually only required by treenode//	/**//	 * Determines whether the window coordinates (x,y) fall on this TreeEdge//	 * There is a "snap" factor, determined by the pickFuzz field of//	 * the enclosing cell.//	 *//	 * @author   Tamara Munzner//	 * @see      AccordionDrawer.GridCell//	 * @see      AccordionDrawer.AccordionTreeDrawer//	 */			//	// convert everything to window coords (0,1)//	// x and y are initially pixels//	public boolean pick(int x, int y)//	{//		GridCell c = getCell();//		AccordionTreeDrawer d = (AccordionTreeDrawer)c.drawer;//		if (horiz)//		{ // horizontal line, check in Y direction//			double pickFuzzAbsolute = d.s2w(d.pickFuzz, AccordionDrawer.Y);//			double yAbsolute = d.s2w(y, AccordionDrawer.Y);//			return yAbsolute > c.getMin(AccordionDrawer.Y) - pickFuzzAbsolute &&//				yAbsolute < c.getMax(AccordionDrawer.Y) + pickFuzzAbsolute;//		}//		else//		{//			double pickFuzzAbsolute = d.s2w(d.pickFuzz, AccordionDrawer.X);//			double xAbsolute = d.s2w(x, AccordionDrawer.X);//			return xAbsolute > c.getMin(AccordionDrawer.X) - pickFuzzAbsolute &&//				xAbsolute < c.getMax(AccordionDrawer.X) + pickFuzzAbsolute;////		}//	}	public void close()	{	}		public String toString()	{		GridCell c = getCell();		if (horiz)		{			return "X" + c.getMin(AccordionDrawer.X) + "->" + c.getMax(AccordionDrawer.X) + "@Y" + node.getMidY();		}		else		{			return "Y" + c.getMin(AccordionDrawer.Y) + "->" + c.getMax(AccordionDrawer.Y) + "@X" + c.getMax(AccordionDrawer.X);		}	}	};

⌨️ 快捷键说明

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