📄 accordiondrawer.java
字号:
toMove = new Hashtable(); keepDrawing = false; showalg = false; colorgrid = false; biggrid = true; nogrid = true; noflash = false; showdiffs = true; drawlabels = true; draworder = FROMFOCUSCELL; guarvis = true; labelposright = true; labeldrawback = false; // draw the background box of a label labelpopup = false; dimcolors = false; dimbrite = true; linkednav = true; labeltransp = false; checktime = true; stoprendering = false; doingFlash = false; mouseDragging = false; transitionAnimating = false; linethickness = 1; flashBoxWidth = 1; numAnimSteps = 10; inflateIncr = 0.15; gridplane = -1.0f; objplane = -.5f; hiliteplane = -.3f; labelbgplane = -.25f; labelplane = -.2f; interactionplane = objplane -.1f; count = 0; focusCell = null; } // the number of objects per pixel to guarantee gapless rendering// protected double pixelDiv = 1.0/10; /** * set the size of a block * @param newSize the new block size, in pixels, can be fractional */ public void newPixelDiv(double newSize, int y) { minCellDims[y] = newSize;// pixelDiv = 1.0/newSize; } public double getPixelSize(int y) { double returnValue = s2w(minCellDims[y], y); if (returnValue <= 0) System.out.println("Error: pixel size is non-positive: " + returnValue); return returnValue; } public void endAllTransitions() { Enumeration enum = toMove.elements(); while (enum.hasMoreElements()) { SplitTransition st = (SplitTransition)enum.nextElement(); st.end(); toMove.remove(st); } transitionAnimating = false; } public void initSplitLines() { splitLine[X] = new SplitLine(this, true, SplitLine.defaultMinStuckValue, SplitLine.defaultMaxStuckValue,getBottomGrid(true)); // horizontal splitline splitLine[Y] = new SplitLine(this, false, SplitLine.defaultMinStuckValue, SplitLine.defaultMaxStuckValue, getBottomGrid(false)); // vertical splitline } /** * clear all the data structures initiated in AD, called when tree(s) get deleted from AD * @see TreeJuxtaposer.TreeJuxtaposer.deleteTree * */ public void shutdown() { ToDrawQ=null; focusCell = null; defaultFocusCell=null; rootCell = null; toMove=null; flashBox=null; flashBoxOld=null; flashGeom=null; flashGeomOld=null; stats=null; drawnLabels.clear(); drawnLabels = null; bottomSize = null; minCellDims = null; System.out.println("clean accordionDrawer"); } protected void finalize() throws Throwable { try { shutdown(); } finally {// System.out.println("finally clean the AccordionDrawer");// super.finalize(); } } public void setKey(int i) { key = i;} public int getKey() { return key;} public Object getGraphicsStuff() { return gl; } /////////////////////////////////////////////////////////////////////////// // init function public void init() { float thecol[] = new float[3]; backgroundColor.getRGBColorComponents(thecol); glc = glj.getGLCapabilities(); gl.glClearColor( thecol[0], thecol[1], thecol[2], 1.0f); //gl.glEnable(GL_DEPTH_TEST); //gl.glDepthFunc(GL_LEQUAL); // leave depthfunc at LEQUAL all the time so that label // backgrounds and label strings can both be in the same // plane. no need to have it be LESS glut = new GLUTFuncLightImplWithFonts(gl, glu); gl.glLogicOp(GLEnum.GL_XOR); reshape(winsize[0],winsize[1]); // no redraw yet (keep manualReshape false) bff.setupGL(gl); System.out.println("in init!! " + winsize[0] + " " + winsize[1]); } /////////////////////////////////////////////////////////////////////////// // display function public void display() { if (winsize[X] < 0 || winsize[Y] < 0) { System.out.println("don't draw when the size is negative!"); return; }//if (false) // cancel the direct call to display? redraw(); } /** * Reshapes the drawing area to new width w and height h in pixels * * @author Tamara Munzner, Serdar Tasiran, Li Zhang, Yunhong Zhou * * * @see AccordionDrawer.GridCell */ public boolean manualReshape = false; public void reshape(int w, int h) { if (w < 0 || h < 0) { System.out.println("either width or height is < 0: " + w + " " + h); return; } if (w != winsize[X] || h != winsize[Y]) { manualReshape = true;// w = winsize[X];//// h = winsize[Y];// System.out.println("debug");// try{// throw new Exception();// }// catch(Exception e)// {// e.printStackTrace();// } } System.out.println("reshape: " + w + " " + h); winsize[0] = w; winsize[1] = h; int gridMax = gridDepth[0] > gridDepth[1] ? gridDepth[0] : gridDepth[1]; gl.glViewport(0, 0, winsize[0], winsize[1]); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho( 0.0f, 1.0f, 0.0f, 1.0f, .01f, gridMax+4.0f ); gl.glScalef(1.0f, -1.0f, 1.0f); gl.glTranslatef(0.0f, -1.0f, 0.0f); gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity();// if (manualReshape) requestRedraw();// else// System.out.println("reshape but no redraw"); manualReshape = false; } /** * Redraws the entire canvas * * @author Tamara Munzner, Serdar Tasiran, Li Zhang, Yunhong Zhou * * * @see AccordionDrawer.GridCell */ public void redraw() { incrementFrameNumber(); // necessary for application forced repaints if (!loaded || !drawStart(false)) return; // not loaded or no swap if (keepDrawing){// && !keepMoving) { continueFrame(); } else{// if (!keepMoving) { startNewFrame(); } drawEnd(startFrame); // swap only after first frame //getDoubleBuffer()); } /** Redraw immediately, do not continue filling in details. * @author Tamara Munzner */ public void requestRedraw() {// System.out.println("redrawing movement: " + keepMoving + " framenum: " + frameNum); incrementFrameNumber(); if (!showalg) keepDrawing = false; // glj is not null (sometimes) when this is called explicitly by us, but is null when: // - gl window opens (is created, deiconified) // - we add a drawer to the canvas (or maybe the canvas is displayed the first time) // - mouse entries (perhaps related to the first time, not every time) // - canvas gains focus (again, first time) // so, to make things robust, we need to check/free it either here, or before we get here, // to make sure there are no external events that may cause us to redraw (perhaps a drawing pass that // doesn't quite make it to the gljfree command will cause instability by leaving glj around) if (glj != null) glj.gljFree(); repaint(); } /** Enqueue a redraw request, but don't stop what we're in the * middle of doing. * @author Tamara Munzner */ public void requestRedrawEventually() {// System.out.println("rre"); repaint(); } public void setDoubleBuffer(boolean value, boolean clear) { doublebuffer = value;//System.out.println("setting double buffer: " + value + " and clearing: " + clear); if (doublebuffer) { if (startFrame) {// System.out.println("GL_BACK"); gl.glDrawBuffer(GL_BACK); } else if (continueFrame) // the first continue frame call to this function leaves startframe on {// System.out.println("GL_FRONT"); gl.glDrawBuffer(GL_FRONT); }// else// {//// System.out.println("not start, not first continue");// } if (glc != null) {// System.out.println("turning on double buffered"); glc.setDoubleBuffered(true); } if (clear) { gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } } else { // no double buffer, for drawing during flash/rubberband gl.glDrawBuffer(GL_FRONT); if (glc != null) glc.setDoubleBuffered(false);else System.out.println("glc is null, not setting new db value"); if (clear) gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } } public boolean getDoubleBuffer() { return doublebuffer;} public abstract void drawFrame(); public abstract void drawRange(int min, int max); public abstract void drawDensity(int min, int max); /** * Starts a new frame and draws the contents of the * AccordionDrawer (enclosed in the rootCell) in a new frame. * * @author Tamara Munzner, Serdar Tasiran, Li Zhang, Yunhong Zhou * * * @see AccordionDrawer.GridCell */ void startNewFrame() { drawnLabels.clear(); flashGeomOld = null; flashBoxOld = null; // set flag for first frame atrifact flag = false; // we need these flags for later on to // draw pixels later on in the correct buffer startFrame = true; continueFrame = false; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // all rendering state changes should be set // locally - means: never put a rendering state // change anywhere in the code if you don't want // to draw something at this point // once you finished rendering, change the state back // to the original state // see InteractionBox.java for instance //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! dynamicStart = System.currentTimeMillis(); continueStart = dynamicStart; drawPreNewFrame(); seedQueue(); setDoubleBuffer(doDoubleBuffer, !takeSnapshot); // this does a clear when not taking a picture drawFrame(); } public void setFlashBox(InteractionBox interactionBox) { flashBox = interactionBox; } protected void continueFrame() {// while(keepDrawing && !keepMoving) { continueFrame = true; if (startFrame) // first continue frame? { startFrame = false; setDoubleBuffer(doDoubleBuffer, false); } dynamicStart = System.currentTimeMillis(); if (dumpstats) stats.print(" inbetween "+(dynamicStart-now)); drawPreContFrame(); drawFrame(); } } private void doShowAlg(GridCell c) { // delete for now - reimplmentation later on } /* * to clear the last frame */ public void clearLens() { if (null == glj || !glj.gljMakeCurrent()) return; // int diffPos[] = new int[2];// diffPos[X] = lens.pos[X] - lens.oldPos[X];// diffPos[Y] = lens.pos[Y] - lens.oldPos[Y];// // gl.glDrawBuffer(GL_FRONT);// glc.setDoubleBuffered(false);// gl.glDepthMask(false);// // for(int i = 0; i <= lens.size[Y]; i++)// {// gl.glRasterPos3d(s2w(lens.oldPos[X] - lens.size[X]/2, X), s2w(lens.oldPos[Y] + lens.size[Y]/2 -i, Y), labelplane );// gl.glDrawPixels(lens.size[X], 1, GLEnum.GL_RGB, GLEnum.GL_FLOAT, xlenspixels[i]);// }// gl.glFlush();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -