📄 accordiontreedrawer.java
字号:
}// public void setDrawAngle(float angle){// drawAngle = angle;// requestRedraw();// }//// public float getDrawAngle(){// return drawAngle;// } public int leafDrawCount; public int internalDrawCount; static long startRender; public static int dequeueChunkPerTimeCheck = 20; public void drawFrame() {// System.out.println("draw frame");// splitLine[Y].drawTicks(); // check to see if layout is correct // ~5 seconds for 190k nodes// splitLine[Y].drawAllRanges();// // ~15 seconds for 190k nodes// for (int i = 0; i < tree.nodes.size(); i++)// {// TreeNode tn = (TreeNode)tree.nodes.get(i);// tn.drawInCell(null, interactionplane);//// System.out.println("Drawing: " + tn.getCell());// } // Helpful for debugging queue if (startFrame) { leafDrawCount = internalDrawCount = 0;// System.out.println("Draw queue size: " + ToDrawQ.size() + " chunks: " + dequeueChunkPerTimeCheck); startRender = System.currentTimeMillis();// System.out.println(basePass + " " + groupPass + " " + textPass); } doFrameMove();// drawGroups(); int xy = splitLine[Y].isHorizontal() ? X : Y;// double pixelSize = getPixelSize(xy); long now = ignoreProgressive ? 0 : System.currentTimeMillis(); while ((takeSnapshot || ignoreProgressive || now - dynamicStart < dynamicTime) && ToDrawQ.size() > 0) { for (int i = 0; ToDrawQ.size() > 0 && i < dequeueChunkPerTimeCheck; i++) { Object obj = ToDrawQ.get(0); if (obj instanceof RangeInTree) { RangeInTree r = (RangeInTree)obj; // range of leaf nodes if (r.atd != this) { System.out.println("Wrong ATD: " + r + " " + this);// RangeInTree r2 = r.getSplitLineRange(Y); // r.atd.drawRange(r.min-1, r.max); } else {// System.out.println("DrawRange: " + (r.min-1) + " " + r.max);// RangeInTree r2 = r.getSplitLineRange(Y); drawRange(r.min, r.max); } } else if (obj instanceof TreeNode) { TreeNode subTreeRoot = (TreeNode)obj; // treenode that is marked, could have marked children, could be taller than a pixel if (subTreeRoot.getCell().drawer != this) { System.out.println("Wrong ATD: " + subTreeRoot.getCell().drawer + " " + this); } subTreeRoot.drawDescend(frameNum, objplane, subTreeRoot.getLeftmostLeaf().key, subTreeRoot.getRightmostLeaf().key);// subTreeRoot.drawInCell(getColorsForRange(subTreeRoot.key, subTreeRoot.key), objplane); if (!subTreeRoot.isRoot()) subTreeRoot.parent.drawAscend(frameNum, objplane); } else System.out.println("what am I in the todrawQ: " + ToDrawQ.get(0).getClass().getName()); ToDrawQ.remove(0); } // end the for loop (done chunks per frame)// System.out.println("Check the time"); now = ignoreProgressive ? 0 : System.currentTimeMillis(); } // Queue debugging if (ToDrawQ.size() >= 0) {// System.out.println(leafDrawCount + " leaves, " +// internalDrawCount + " internals, in " + // (System.currentTimeMillis() - startRender) + " ms");// System.out.println("Draw queue size: " + ToDrawQ.size()); } //System.out.println("After drawing: leaves: " + leafDrawCount + "\tinternals: " + internalDrawCount);// //requestRedraw();// drawPostFrame();// //gl.glFlush();//// //System.out.println(" bla " + keepMoving + " " + ToDrawQ.size());// if (keepMoving) {// requestRedraw();// drawPostFrame();// } else if (keepMoving) { keepDrawing = false; incrementFrameNumber(); requestRedrawEventually(); } else if (ToDrawQ.size() > 0) { keepDrawing = true; incrementFrameNumber(); requestRedrawEventually(); } else { keepDrawing = false; System.out.println(leafDrawCount + " leaves, " + internalDrawCount + " internals, in " + (System.currentTimeMillis() - startRender) + " ms"); if (colorgrid || drawBackground) splitLine[Y].drawBackground(null, frameNum); drawPostScene(); } } /* (non-Javadoc) * @see AccordionDrawer.AccordionDrawer#drawRange(int, int) * * * * */ // min and max are splitLines indexed in Y, surround leaf cells // it's known that the distance between min and max is no more than a pixel // - get the min/max cells, use tree.leaf array // - min is the min index into tree.leaf // - max is the max index into tree.leaf // - find parents of all cells (binary recursion, if min.parent != max.parent, recurse on half) // cache drawn frame in each cell so we stop at already drawn ancestor double pixelSize; // set by drawprenewframe public void drawRange(int min, int max) { if (min == max) { System.out.println("no range"); return; // no split range } TreeNode minChild = tree.getLeaf(min+1); if (min + 1 == max) // single node in a pixel, no sub pixel drawing { ArrayList colorsForRange = getColorsForRange(minChild.key, minChild.key); minChild.drawInCell(colorsForRange, objplane); minChild.getCell().setDrawnFrame(frameNum); if (minChild.parent != null) minChild.parent.drawAscend(frameNum, objplane); return; } TreeNode maxChild = tree.getLeaf(max); // rendering fix// Vector subpixelForest = new Vector(); // store each subtree root in this vector that is larger than a vertical pixel, debugging int currMin = minChild.key;// double pixelSize = getPixelSize(Y); // div pixelDiv (integer > 2, <=? 4) to cover gaps left if using real pixel size // remember the left most node for drawing (leftmost is closest to the root on the ancestor side of the node) int leftMostPosition = minChild.getCell().getMinLine(X); TreeNode leftMostNode = minChild; // init // remember the left most node that is colored for drawing // different from uncolored node since uncolored portions aren't drawn when this node isn't as far left as // some other node for this pixel, but need to draw some colored single pixel node if it isn't the farthest // node to the left int leftMostColorPosition = minChild.getCell().getMaxLine(X); TreeNode leftMostColorNode = null; // init Color leftMostColor = null; TreeNode currRootNode = getNodeByKey(currMin).parent; while (currMin <= maxChild.key) { // ascend tree to pixelSize TreeNode prevRootNode = null; // last subpixel node double currCellSize = currRootNode.getCell().getSize(Y); double prevCellSize = 0; while (currCellSize < pixelSize)// && currRootNode.rightmostLeaf.key <= maxChild.key) // need ranges that start on the edge of cells? { prevRootNode = currRootNode; currRootNode = currRootNode.parent; prevCellSize = currCellSize; currCellSize = currRootNode.getCell().getSize(Y); } if (prevRootNode == null) // ok now, since we start currRootNode at one up from leaf { prevRootNode = currRootNode;// System.out.println("something is wrong"); } if (prevRootNode != null) { // add ascended node, for debugging// subpixelForest.add(prevRootNode); ArrayList colors = getColorsForCellGeom(prevRootNode); int minLinePositionCheck = prevRootNode.getCell().getMinLine(X); if (minLinePositionCheck < leftMostPosition) { leftMostPosition = minLinePositionCheck; leftMostNode = prevRootNode; } if (colors.size() > 0 && (minLinePositionCheck < leftMostColorPosition || leftMostColor.getAlpha() < ((Color)colors.get(0)).getAlpha())) { leftMostColorPosition = minLinePositionCheck; leftMostColorNode = prevRootNode; leftMostColor = (Color)colors.get(0); }// prevRootNode.drawDescend(frameNum, objplane, minChild.key, maxChild.key); // pick any child in the min/max range and draw to the leaves// if (!prevRootNode.isRoot())// prevRootNode.parent.drawAscend(frameNum, objplane); } // set up next round int temp = currRootNode.rightmostLeaf.key+1; // some key in the next tree over TreeNode tempNode = getNodeByKey(temp); // the next subtree root if (tempNode != null) { currMin = tempNode.leftmostLeaf.key; currRootNode = tempNode.leftmostLeaf; } else // beyond range of nodes currMin = temp; } // colored node isn't the leftmost? need to draw in the colored node separately if (leftMostColorNode != null && leftMostColorPosition != leftMostPosition) { leftMostColorNode.drawDescend(frameNum, objplane, minChild.key, maxChild.key); if (!leftMostColorNode.isRoot()) leftMostColorNode.parent.drawAscend(frameNum, objplane); } // the uncolored choice for this pixel or the colored choice is the same: leftMostNode.drawDescend(frameNum, objplane, minChild.key, maxChild.key); // pick any child in the min/max range and draw to the leaves if (!leftMostNode.isRoot()) leftMostNode.parent.drawAscend(frameNum, objplane); } public void addToDrawQueue(Object r) { if (r != null) { if (r instanceof RangeInTree) ToDrawQ.add(((RangeInTree)r).getSplitLineRange(Y, false)); else if (r instanceof TreeNode) ToDrawQ.add(r); } } public abstract ArrayList getColorsForRange(int min, int max); public abstract RangeList getRangeByKey(int key); public void drawDensity( int minObj, int maxObj) { // only applies to sequences } /** * @return */ public TreeNode getLeaf(int leafNum) { return tree.getLeaf(leafNum); } public void splitRangeHelp(Vector drawQueue, double pixelSize, RangeInTree rit) { int half = (rit.min + rit.max) / 2; if ((getLeaf(rit.max).getCell().getMax(Y) - getLeaf(rit.min).getCell().getMin(Y) < pixelSize) || (rit.min == rit.max)) { drawQueue.add(rit); return; } RangeInTree min = new RangeInTree(rit.min, half, rit.atd); RangeInTree max = new RangeInTree(half+1, rit.max, rit.atd); splitRangeHelp(drawQueue, pixelSize, min); splitRangeHelp(drawQueue, pixelSize, max); } public void splitRanges(double pixelSize) { Vector newDrawQueue = new Vector(); Iterator iter = ToDrawQ.iterator(); while (iter.hasNext()) { Object nextObj = iter.next(); if (nextObj instanceof RangeInTree) { RangeInTree rit = (RangeInTree)nextObj; splitRangeHelp(newDrawQueue, pixelSize, rit); } else if (nextObj instanceof TreeNode) newDrawQueue.add(nextObj); } ToDrawQ = newDrawQueue; } public void splitRanges(int interval) { Vector newDrawQueue = new Vector(); Iterator iter = ToDrawQ.iterator(); while (iter.hasNext()) { Object nextObj = iter.next(); if (nextObj instanceof RangeInTree) { RangeInTree rit = (RangeInTree)nextObj; if (rit.max - rit.min + 1 < interval) newDrawQueue.add(rit); else { int i = rit.min; for (i = rit.min; i < rit.max - interval; i += interval) newDrawQueue.add(new RangeInTree(i, i + interval - 1, rit.atd)); newDrawQueue.add(new RangeInTree(i, rit.max, rit.atd)); } } else if (nextObj instanceof TreeNode) newDrawQueue.add(nextObj); } ToDrawQ = newDrawQueue; } public int getBottomGrid( boolean horizontal ) { return ( horizontal ? bottomSize[AccordionDrawer.X] : bottomSize[AccordionDrawer.Y]) - 1; } /** * @return Returns the listOfLeaves. */ public TreeSet getListOfLeaves() { return listOfLeaves; }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -