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

📄 accordiontreedrawer.java

📁 生物物种进化历程的演示
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
									   // drawing flash, redrawing old flash		doingFlash = true;				Color objCol = (null == flashCol) ? objectColor : flashCol;		if (doBox && flashGeom != null)			flashBox = makeBox(flashGeom);		// order matters: 1) undraw old box 2) dump old pixels		//		  3) save new pixels 4) draw box		if (doBox && flashBoxOld != null)			flashBoxOld.undraw();		int flashBoxBuffer = getLineThickness()/2 + 2; // added to the top/bottom/sides of each line		int bufferedWidth = 2 * flashBoxBuffer + getLineThickness();		boolean drawlabelsreal = drawlabels;		drawlabels = false;				if (null != flashGeomOld)		{			// draw in old flash cell			TreeNode tno = (TreeNode)flashGeomOld;			TreeEdge[] teo = {tno.getEdge(X), tno.getEdge(Y)};			for (int xy = X; xy <= Y; xy++)			{				if (null == teo[xy]) continue;				if (teo[xy].horiz && tno.label.length() > 0)				{					if (flashLabelBox != null) 					{					// draw back around the old label					gl.glRasterPos3d(s2w(flashLabelBox.pos(X), X),						s2w(flashLabelBox.pos(Y), Y), getLabelplane());					gl.glDrawPixels(flashLabelBox.size(X), flashLabelBox.size(Y),						GLEnum.GL_RGB, GLEnum.GL_FLOAT, labelPixels);					}				}				// draw back old highlighted lines				int length[] = {teo[xy].horiz ? lineLength[xy] : bufferedWidth,						teo[xy].horiz ? bufferedWidth : lineLength[xy]};					gl.glRasterPos3d(s2w(linePos[xy][X], X),					s2w(linePos[xy][Y], Y), getLabelplane());				gl.glDrawPixels(length[X], // length if horiz, else width					length[Y], // width if horiz, else length					GLEnum.GL_RGB, GLEnum.GL_FLOAT, linePixel[xy]);			} // end for loop		} // end if (null != flashGeomOld)		if (null != flashGeom)		{			// read old cells, draw in new flash cell			// read pixels			TreeNode tn = (TreeNode)flashGeom;			TreeEdge[] te = {tn.getEdge(X), tn.getEdge(Y)};			gl.glReadBuffer(GLEnum.GL_FRONT);						for (int xy = X; xy <= Y; xy++)			{				if (te[xy] == null) continue;				float[] posStart = new float[2];				float[] posEnd = new float[2];				te[xy].setPositions(posStart, posEnd);				int[] posStartPix = {w2s(posStart[X],X), w2s(posStart[Y],Y)};				int[] posEndPix = {w2s(posEnd[X],X), w2s(posEnd[Y],Y)};				if (te[xy].horiz && tn.label.length() > 0) // get the horizontal edge to save the pixels under the new big label				{					flashLabelBox = te[X].makeLabelBox(popupFontHeight, flashX, flashY, posStart, posEnd);					drawnlabelsize[X] = flashLabelBox.size(X);					drawnlabelsize[Y] = flashLabelBox.size(Y);					labelPixels = new float[drawnlabelsize[0] * 3 * drawnlabelsize[1]];					// 	read pixels under new label from frontbuffer					gl.glReadPixels(flashLabelBox.pos(X),						getWinsize(Y) - flashLabelBox.pos(Y),						drawnlabelsize[X], drawnlabelsize[Y],						GLEnum.GL_RGB, GLEnum.GL_FLOAT, labelPixels);				}				else if (te[xy].horiz)				{					flashLabelBox = null;					labelPixels = null;				}				// assert: start < end				if (te[xy].horiz)				{//					posStart[Y] = posEnd[Y] = (float)tn.getMidY(); // debug, remove later					posStartPix[Y] = posEndPix[Y] = w2s(tn.getMidY(),Y);				}				else // te is vert, has children since it's not null				{					posStartPix[Y] = w2s(tn.getChild(0).getMidY(),Y);					posEndPix[Y] = w2s(tn.getChild(tn.numberChildren()-1).getMidY(),Y);				}				lineLength[xy] = posEndPix[xy] - posStartPix[xy] + 2 * flashBoxBuffer;				linePos[xy][X] = posStartPix[X] - flashBoxBuffer;				if (linePos[xy][X] < 0) linePos[xy][X] = 0;								linePos[xy][Y] = posEndPix[Y] + flashBoxBuffer; // note: Y coords reversed!				if (linePos[xy][Y] > getWinsize(Y)) linePos[xy][Y] = getWinsize(Y);								int length[] = {te[xy].horiz ? lineLength[xy] : bufferedWidth, 						te[xy].horiz ? bufferedWidth : lineLength[xy]};				linePixel[xy] = new float[3*length[X]*length[Y]];				// read under the new drawing, direction xy				gl.glReadPixels(linePos[xy][X], getWinsize(Y) - linePos[xy][Y],						length[X], length[Y],						GLEnum.GL_RGB, GLEnum.GL_FLOAT, linePixel[xy]);				flag = true; // first frame flag			}						// don't draw flash for now, debug			for (int xy = X; xy <= Y; xy++)			{				if (te[xy] == null) continue;								if (te[xy].horiz)// && flashLabelBox != null)					// draw in label					if (flashLabelBox != null)						te[xy].drawLabelBig(flashX, flashY, popupFontHeight);				te[xy].drawInCell(flashCol, interactionplane);			}					} // finished saving pixels and drawing in flash cells					if (doBox && flashBox != null)			flashBox.draw(rubberbandColor, flashBoxWidth, interactionplane);		drawlabels = drawlabelsreal;		if (doBox)			flashBoxOld = flashBox;		flashGeomOld = flashGeom;		flashXOld = flashX;		flashYOld = flashY;		setDoubleBuffer(doubleBufferedOriginal, false); // no redraw		drawEnd(false); // no swap		doingFlash = false;	}    /**	 * Decide what GridCells to enqueue for drawing based on tree topology. We	 * want to add parents and children of current CellGeom. We should find the	 * GridCell corresponding to the higher-level TreeEdge associated with a	 * TreeNode, not the level0 GridCell of the TreeNode itself.	 * 	 * @author Tamara Munzner	 */   	// TODO: decide whether or not this function is useful anymore   	//  - we don't enqueue cells for drawing anymore    public void drawNextFancy(CellGeom g) {//	TreeNode tn;//	if (g instanceof TreeEdge) {//	    tn = ((TreeEdge)g).node;//	} else if (g instanceof TreeNode) {//	    tn = (TreeNode)g;//	} else {//	    return;//	} //	TreeNode par = tn.parent();//	TreeLeafGridCell c;//	if (null != par && null != par.edges[X]) {//	    c = (TreeLeafGridCell)par.edges[X].getCell();//	    c.possiblyEnqueue();//	} //	if (null != tn.children) {//	    Iterator iter = tn.children.iterator();//	    while (iter.hasNext()) {//		TreeNode tn2 = (TreeNode) iter.next();//		if (null != tn2.edges[X]) {//		    c = (TreeLeafGridCell)tn2.edges[X].getCell();//		    c.possiblyEnqueue();//		}//	    }//	}    }    public TreeSet listOfLeaves = null;    	protected void drawPreNewFrame() {			if (!groupPass && !textPass) // ok for no snapshots or for the basePass	{		countDrawnFrame = 0;		countDrawnScene = 0;		cumFrameTime = 0;		listOfLeaves = splitLine[Y].makePixelRanges(pixelDiv); // divide into block size / 4		pixelSize = getPixelSize(Y);//	DebugFrame.setStateMachine(DebugFrame.GL_DEPTH _TEST, true);		gl.glEnable(GLEnum.GL_DEPTH_TEST);		gl.glDepthFunc(GLEnum.GL_LEQUAL);	}	if (basePass) // first pass of text output	{//		System.out.println("staring new output");		int xSize = winsize[X];		int ySize = winsize[Y];		try		{			snapShotWriter.write("%!PS-Adobe-2.0 EPSF-2.0\n" +			"%%BoundingBox: 0 0 " + xSize + " " + ySize + "\n" +			"%%Magnification: 1.0000\n" +			"%%EndComments\n" +						"gsave\n" +						"newpath " +			"0 " + ySize + " moveto " +			"0 0 lineto " +			xSize + " 0 lineto " +			xSize + " " + ySize + " lineto " +			"closepath " +			"clip newpath\n" +			"1 -1 scale\n" +			"0 -" + ySize + " translate\n");		}		catch (IOException ioe)		{			System.out.println("Error: unable to write to file: " + snapShotWriter.toString());		}	}    }	protected void drawPreContFrame() {	countDrawnFrame = 0;    }	protected void drawPostScene() {//	drawPostFrame();	gl.glDisable(GLEnum.GL_DEPTH_TEST); // do flash and everything else on top?	if (textPass) // end of the last pass	{		try		{			snapShotWriter.write("grestore\n" +			"showpage\n");			takeSnapshot = false;			textPass = false;			snapShotWriter.close();		}		catch (IOException ioe)		{			System.out.println("Error: can not write to file: " + snapShotWriter);		}	}//	commented so now isn't needed, if needed, pass it properly, not a state machine!//	if (dumpstats) {//	    stats.println(" scene "+countDrawnScene+" frametimeCum "+cumFrameTime+" sceneTIME "+(now-continueStart));//	    //stats.flush();//	}    }	protected void drawPostFrame() {	long now = ignoreProgressive ? 0 : System.currentTimeMillis();				countDrawnScene += countDrawnFrame;	long frameTime = now-dynamicStart;	cumFrameTime += frameTime;	if (dumpstats) stats.print(" df "+countDrawnFrame+" frameTIME "+frameTime);    }	protected void drawBruteForce() {	drawPreNewFrame();	drawBruteForceRecurse(rootNode);	drawPostScene();    }    /**      * Draw a tree edge, recurse to draw its children.     * Ignores highlighting, just for benchmarking.     * @author Tamara Munzner     */   	// never called    private void drawBruteForceRecurse(TreeNode n) {    	System.out.println("DBFR");	if (checktime && (0 == countDrawnFrame%100)) {	    now = System.currentTimeMillis();				    if (now-dynamicStart > dynamicTime) {		return;	    }	}	n.drawInCell(objectColor, objplane);	Iterator iter = n.children.iterator();	while (iter.hasNext()) {	    TreeNode child = (TreeNode)iter.next();	    if (null != child) drawBruteForceRecurse(child);	}    }    public Tree getTree() { return tree;}    public Canvas getCanvas() { return this;}    public TreeNode getNodeByKey(int key) { return tree.getNodeByKey(key);}    public TreeNode getNodeByName(String name) { return tree.getNodeByName(name);}    public int getLabelBuffer(int xy) {return labelbuffer[xy];}    public void setLabelBuffer(int buffer) {	if (buffer < 1) buffer = 1;	labelbuffer[X] = buffer;	labelbuffer[Y] = buffer;	requestRedraw();    }    public void setLabelBuffer(int buffer, int xy) {	if (buffer < 1) buffer = 1;	labelbuffer[xy] = buffer;	requestRedraw();    }    public void increaseLabelBuffer(int xy) {	setLabelBuffer(labelbuffer[xy]+1, xy);    }    public void increaseLabelBuffer() {	setLabelBuffer(labelbuffer[X]+1);    }    public void decreaseLabelBuffer(int xy) {	setLabelBuffer(labelbuffer[xy]-1, xy);    }    public void decreaseLabelBuffer() {	setLabelBuffer(labelbuffer[X]-1);    }    public int getMaxFontHeight() {return maxFontHeight;}    public void setMaxFontHeight(int fontheight) {	if (fontheight < 1) fontheight = 1;	maxFontHeight = fontheight;	tree.setNodeFontSize(maxFontHeight, minFontHeight);	popupFontHeight = maxFontHeight;	requestRedraw();    }    public void increaseMaxFontHeight() {	setMaxFontHeight(maxFontHeight+1);    }    public void decreaseMaxFontHeight() {	setMaxFontHeight(maxFontHeight-1);    }    public int getMinFontHeight() {return minFontHeight;}    public void setMinFontHeight(int fontheight) {	if (fontheight < 1) fontheight = 1;	minFontHeight = fontheight;	tree.setNodeFontSize(maxFontHeight, minFontHeight);	requestRedraw();    }    public void increaseMinFontHeight() {	setMinFontHeight(minFontHeight+1);    }    public void decreaseMinFontHeight() {	setMinFontHeight(minFontHeight-1);    }	public void startNewFrameAccordionXDrawer()	{		drawnLabels.clear();	}	public Color getObjectColor() { return objectColor; }	public void setObjectColor(Color objectColor) { this.objectColor = objectColor;}	/* (non-Javadoc)	 * @see AccordionDrawer.AccordionDrawer#subpixelDraw(AccordionDrawer.GridCell)	 */	public void subpixelDraw(GridCell c) {		// TODO Auto-generated method stub, needed to match accordionDrawer abstract class

⌨️ 快捷键说明

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