📄 treeedge.java
字号:
* * @author Tamara Munzner */ public void drawLabelBig(int x, int y, int fontheight) { AccordionTreeDrawer drawer = (AccordionTreeDrawer) getCell().drawer; if (!horiz || drawer.nogeoms || node.label.length() < 1) return; drawLabelBox(drawer.flashLabelBox, fontheight, true); } /** * Create a LabelBox for the given fontheight * @param x horizontal base location in screen/pixel coordinates * @param y vertical base location in screen/pixel coordinates * @author Tamara Munzner * @see AccordionDrawer.LabelBox */ protected LabelBox makeLabelBox(int fontheight, int x, int y, float[] start, float[] end) { AccordionTreeDrawer d = (AccordionTreeDrawer)getCell().drawer; int X = AccordionDrawer.X, Y = AccordionDrawer.Y; int bottomLeft[] = new int[2]; int topRight[] = new int[2]; int bottomLeftBackground[] = new int[2]; int startPix[] = {d.w2s(start[X], X), d.w2s(start[Y], Y)}; int endPix[] = {d.w2s(end[X], X), d.w2s(end[Y], Y)}; String name = node.label; int namewidth = AccordionDrawer.stringWidth(name, fontheight); // expensive int oldnamewidth = 0; int labelwidth = namewidth+2; int numChars; int[] winSize = {d.getWinsize(X), d.getWinsize(Y)}; int moveover = (node.isLeaf()) ? labelwidth + d.labeloffset[X] : -d.labeloffset[X];// if(d.drawDirection != AccordionDrawer.RIGHT) { topRight[X] = (d.labelposright) ? endPix[X]+moveover : startPix[X]-d.labeloffset[X]; } // either put label right and above junction // or put it left, vertically centered, and right-justified if (!d.labelposright) {// if(d.leftRight == 0 || d.leftRight == 1) topRight[Y] = startPix[Y]-d.labeloffset[Y]-fontheight;// if(d.leftRight == 2)// labelTopRight[1] = d.w2s(1-posStart[0],1)-d.labeloffset[1]-fontheight;// if(d.leftRight == 3)// labelTopRight[1] = d.w2s(posStart[0],1)-d.labeloffset[1]-fontheight; } else topRight[Y] = (node.isLeaf()) ? endPix[Y] - (int)(fontheight/2.0) : endPix[Y]-d.labeloffset[Y] - fontheight; // we pad background label box by one pixel on each side so // that text is never right up against the edge. height // already has enough padding int labelheight = fontheight+2; bottomLeftBackground[X] = topRight[X] - labelwidth; bottomLeftBackground[Y] = topRight[Y] + labelheight; if (x>=0 && y>=0 && d.labelpopup) { bottomLeftBackground[X] = x-(int)(labelwidth/2.0); topRight[X] = bottomLeftBackground[X]+labelwidth; bottomLeftBackground[Y] = y-5; topRight[Y] = bottomLeftBackground[Y]-labelheight; } // if we would start offscreen, nudge over until it's all // onscreen. when the origin of the text string is offscreen, // opengl won't draw anything (sigh). we could truncate the // label text, but it seems more useful to just move the whole // thing over. while we're at it, make sure labels are always // totally onscreen. int labelToEdge = winSize[X] - endPix[X]; if ((bottomLeftBackground[X]) < 0) { bottomLeftBackground[X] = 0; topRight[X] = bottomLeftBackground[X] + labelwidth; } else if (topRight[X] > winSize[X]) { // do nothing - in leaf case, we want to truncate not nudge // as per hillis feedback. } // System.out.println("top right is less than posend ############"+labelTopRight[0]);// System.out.println("pos end ############" + d.w2s(1-posEnd[0], 0)); if (bottomLeftBackground[Y] > winSize[Y]) { bottomLeftBackground[Y] = winSize[Y]; topRight[Y] = bottomLeftBackground[Y]-labelheight; } else if (topRight[Y] < 0) { topRight[Y] = 0; bottomLeftBackground[Y] = labelheight; } // labelbuffer is used for occlusion computations to control // label density, but we don't want to draw the bg box that // big because it would look silly. bottomLeft[Y] = bottomLeftBackground[Y] + d.labelbuffer[Y]; bottomLeft[X] = bottomLeftBackground[X] - d.labelbuffer[X]; return new LabelBox( bottomLeft, topRight, bottomLeftBackground, d.getFrameNum(), name); }//TODO: implement drawing label boxes differently, so they work efficiently/////**// * make label box in vertical direction// * @param fontheight// * @param x// * @param y// * @return// */// private LabelBox makeLabelBoxUp(int fontheight, int x, int y) {// AccordionTreeDrawer d = (AccordionTreeDrawer)getCell().drawer;// int labelBottomLeft[] = new int[2];// int labelTopLeft[] = new int[2];// int labelTopRight[] = new int[2];// int labelBottomRight[] = new int[2];// int labelBottomLeftBG[] = new int[2];// int drawVert = 1;////// String name = node.name; // make name here?// String name = node.label;// int namewidth = AccordionTreeDrawer.bff.stringWidth(name, fontheight);//// int charwidth = (int)namewidth/name.length();//// int charheight = fontheight;// float ratio = 0.0f;// int oldnamewidth = 0;// int labelwidth = namewidth+2;// int labelheight = fontheight+2;// int numChars;// int[] winSize = {d.getWinsize(0), d.getWinsize(1)};// float temp; // temp = posEnd[0];// posEnd[0] = posEnd[1];// posEnd[1] = 1- temp;// temp = posStart[0];// posStart[0]= posStart[1];// posStart[1] = 1-temp;// //// int moveover = (node.isLeaf()) ? labelwidth+d.labeloffset[0] //// : -d.labeloffset[0];// // // either put label right and above junction// // or put it left, vertically centered, and right-justified// if (!d.labelposright)// {//// if(d.leftRight == 0 || d.leftRight == 1)// labelTopRight[1] = d.w2s(posStart[1],1)-d.labeloffset[1]-fontheight;//// if(d.leftRight == 2)//// labelTopRight[1] = d.w2s(1-posStart[0],1)-d.labeloffset[1]-fontheight;//// if(d.leftRight == 3)//// labelTopRight[1] = d.w2s(posStart[0],1)-d.labeloffset[1]-fontheight;// }// else // {// labelBottomLeft[0] = (node.isLeaf()) ? // d.w2s(posEnd[0],0) - (int)(fontheight/2.0) : // d.w2s(posEnd[0],0)-d.labeloffset[0] - fontheight;//// labelBottomRight[0] = labelBottomLeft[0] + labelheight;// }// // we pad background label box by one pixel on each side so// // that text is never right up against the edge. height// // already has enough padding//// // labelBottomLeftBG[0] = d.w2s(posEnd[0], 0);// labelBottomLeftBG[1] = d.w2s(posEnd[1], 1);// labelTopRight[0] = labelBottomLeftBG[0] + labelheight;// labelTopRight[1] = labelBottomLeftBG[1] - labelwidth;// // if (x>=0 && y>=0 && d.labelpopup) {// labelBottomLeftBG[0] = x-(int)(labelwidth/2.0);// labelTopRight[0] = labelBottomLeftBG[0]+labelwidth;// labelBottomLeftBG[1] = y-5;// labelTopRight[1] = labelBottomLeftBG[1]-labelheight;// } //// // if we would start offscreen, nudge over until it's all// // onscreen. when the origin of the text string is offscreen,// // opengl won't draw anything (sigh). we could truncate the// // label text, but it seems more useful to just move the whole// // thing over. while we're at it, make sure labels are always// // totally onscreen.//// if ((labelBottomLeftBG[0]) < 0) {//// labelBottomLeftBG[0] = 0;//// labelTopRight[0] = labelBottomLeftBG[0] + labelheight;// // } else if (labelTopRight[0] > winSize[0]) { // // do nothing - in leaf case, we want to truncate not nudge// // as per hillis feedback.// } //// if (labelBottomLeftBG[1] > winSize[1]) {//// labelBottomLeftBG[1] = winSize[1];//// labelTopRight[1] = labelBottomLeftBG[1]-labelwidth;// } else if (labelTopRight[1] < 0) {//// labelTopRight[1] = 0;//// labelBottomLeftBG[1] = labelTopRight[1]+labelwidth;// } // // // // labelbuffer is used for occlusion computations to control// // label density, but we don't want to draw the bg box that// // big because it would look silly.//// labelBottomLeft[1] = labelBottomLeftBG[1] + d.labelbuffer[1];// labelBottomLeft[0] = labelBottomLeftBG[0] - d.labelbuffer[0];//// if(d.getDrawAngle() < 25.0)// {// float w = labelBottomLeft[1]*(float)Math.cos(Math.toRadians(d.getDrawAngle()));// float h = labelBottomLeft[1]*(float)Math.sin(Math.toRadians(d.getDrawAngle()));// labelTopRight[0] = labelTopRight[0] + (int)w;// labelTopRight[1] = labelBottomLeft[1] - (int)h; //// labelTopRight[1] =labelBottomLeft[1] - labelBottomLeft[1]*(int)h;//// labelTopRight[0] = labelBottomLeft[0] + labelBottomLeft[1]*(int)w;// if(labelTopRight[1]<0) labelTopRight[1] =0;// int cwidth = AccordionTreeDrawer.bff.charWidth(name,fontheight,0);// //labelBottomRight[0] = labelBottomLeft[0] + labelheight;// labelBottomRight[0] = labelBottomLeft[0] + cwidth;// labelBottomRight[1] = labelBottomLeft[1] ;//// float newTR = labelTopRight[1]* java.lang.Math.sin(java.lang.Math.toRadians(30.0));// // labelTopLeft[1] = labelTopRight[1];// labelTopLeft[0] = labelTopRight[0]-labelheight;// lb = new LabelBox(labelBottomLeft, labelBottomRight, labelTopLeft, labelTopRight ,labelBottomLeftBG, d.getFrameNum(), name, labelheight, d.getDrawAngle(), drawVert);// }// else// lb = new LabelBox( labelBottomLeft, labelTopRight, labelBottomLeftBG, d.getFrameNum(), name);//// return lb;// }////// /**// * make label box in vertical direction// * @param fontheight// * @param x// * @param y// * @return// */// private LabelBox makeLabelBoxDown(int fontheight, int x, int y) {//// AccordionTreeDrawer d = (AccordionTreeDrawer)getCell().drawer;// int labelBottomLeft[] = new int[2];// int labelTopLeft[] = new int[2];// int labelTopRight[] = new int[2];// int labelBottomRight[] = new int[2];// int labelBottomLeftBG[] = new int[2];// int drawVert = 1;////// String name = node.name; // make name here?// String name = node.label;// int namewidth = AccordionTreeDrawer.bff.stringWidth(name, fontheight);//// int charwidth = (int)namewidth/name.length();//// int charheight = fontheight;// float ratio = 0.0f;// int oldnamewidth = 0;// int labelwidth = namewidth+2;// int labelheight = fontheight+2;// int numChars;// int[] winSize = {d.getWinsize(0), d.getWinsize(1)};// float temp; // temp = posEnd[1];// posEnd[1] = posEnd[0];// posEnd[0] = 1- temp;// temp = posStart[1];// posStart[1]= posStart[0];// posStart[0] = 1-temp;//// int moveover = (node.isLeaf()) ? labelwidth+d.labeloffset[0] //// : -d.labeloffset[0];// // // either put label right and above junction// // or put it left, vertically centered, and right-justified// if (!d.labelposright)// {//// if(d.leftRight == 0 || d.leftRight == 1)// labelTopRight[1] = d.w2s(posStart[1],1)-d.labeloffset[1]-fontheight;//// if(d.leftRight == 2)//// labelTopRight[1] = d.w2s(1-posStart[0],1)-d.labeloffset[1]-fontheight;//// if(d.leftRight == 3)//// labelTopRight[1] = d.w2s(posStart[0],1)-d.labeloffset[1]-fontheight;// }// else // {// labelBottomLeft[0] = (node.isLeaf()) ? // d.w2s(posEnd[0],0) - (int)(fontheight/2.0) : // d.w2s(posEnd[0],0)-d.labeloffset[0] - fontheight;//// labelBottomRight[0] = labelBottomLeft[0] + labelheight;// }// // we pad background label box by one pixel on each side so// // that text is never right up against the edge. height// // already has enough padding//// // labelBottomLeftBG[0] = d.w2s(posEnd[0], 0);// labelBottomLeftBG[1] = d.w2s(posEnd[1], 1);// labelTopRight[0] = labelBottomLeftBG[0] + labelheight;// labelTopRight[1] = labelBottomLeftBG[1] - labelwidth;// // if (x>=0 && y>=0 && d.labelpopup) {// labelBottomLeftBG[0] = x-(int)(labelwidth/2.0);// labelTopRight[0] = labelBottomLeftBG[0]+labelwidth;// labelBottomLeftBG[1] = y-5;// labelTopRight[1] = labelBottomLeftBG[1]-labelheight;// } //// // if we would start offscreen, nudge over until it's all// // onscreen. when the origin of the text string is offscreen,// // opengl won't draw anything (sigh). we could truncate the// // label text, but it seems more useful to just move the whole// // thing over. while we're at it, make sure labels are always// // totally onscreen.//// if ((labelBottomLeftBG[0]) < 0) {//// labelBottomLeftBG[0] = 0;//// labelTopRight[0] = labelBottomLeftBG[0] + labelheight;// // } else if (labelTopRight[0] > winSize[0]) { // // do nothing - in leaf case, we want to truncate not nudge// // as per hillis feedback.// } //// if (labelBottomLeftBG[1] > winSize[1]) {//// labelBottomLeftBG[1] = winSize[1];//// labelTopRight[1] = labelBottomLeftBG[1]-labelwidth;// } else if (labelTopRight[1] < 0) {//// labelTopRight[1] = 0;//// labelBottomLeftBG[1] = labelTopRight[1]+labelwidth;// } // // // // labelbuffer is used for occlusion computations to control// // label density, but we don't want to draw the bg box that// // big because it would look silly.//// labelBottomLeft[1] = labelBottomLeftBG[1] + d.labelbuffer[1];// labelBottomLeft[0] = labelBottomLeftBG[0] - d.labelbuffer[0];//// if(d.getDrawAngle() < 25.0)// {// float w = labelBottomLeft[1]*(float)Math.cos(Math.toRadians(d.getDrawAngle()));// float h = labelBottomLeft[1]*(float)Math.sin(Math.toRadians(d.getDrawAngle()));// labelTopRight[0] = labelTopRight[0] + (int)w;// labelTopRight[1] = labelBottomLeft[1] - (int)h; //// labelTopRight[1] =labelBottomLeft[1] - labelBottomLeft[1]*(int)h;//// labelTopRight[0] = labelBottomLeft[0] + labelBottomLeft[1]*(int)w;// if(labelTopRight[1]<0) labelTopRight[1] =0;// int cwidth = AccordionTreeDrawer.bff.charWidth(name,fontheight,0);// //labelBottomRight[0] = labelBottomLeft[0] + labelheight;// labelBottomRight[0] = labelBottomLeft[0] + cwidth;// labelBottomRight[1] = labelBottomLeft[1] ;//// float newTR = labelTopRight[1]* java.lang.Math.sin(java.lang.Math.toRadians(30.0));// // labelTopLeft[1] = labelTopRight[1];// labelTopLeft[0] = labelTopRight[0]-labelheight;//// labelBottomLeft[1] = winSize[1] - labelBottomLeft[1];//// labelBottomRight[1] = winSize[1] - labelBottomRight[1];//// labelTopLeft[1] = winSize[1] - labelTopLeft[1];//// labelTopRight[1] = winSize[1] - labelTopRight[1];//// lb = new LabelBox(labelBottomLeft, labelBottomRight, labelTopLeft, labelTopRight ,labelBottomLeftBG, d.getFrameNum(), name, labelheight, d.getDrawAngle(), drawVert);// }// else// lb = new LabelBox( labelBottomLeft, labelTopRight, labelBottomLeftBG, d.getFrameNum(), name);//// return lb;//// } /** * Occlusion check of LabelBox against array of all drawn labels. * {@link #drawnArray AccordionDrawer.drawnArray} is sorted in y - * the skinny direction, to avoid work. We do a binary search to * check for occlusions, so it's log in the number of pixels (with * a very small constant). * * @author Tamara Munzner * @see AccordionDrawer.LabelBox */ private boolean intersectLabelBox(LabelBox lb) { AccordionTreeDrawer d = (AccordionTreeDrawer)getCell().drawer; // the list is sorted by y value. use binary search to see // if it will fit instead of checking against every item. // find an item that has y overlap. check down from there // until no overlap, then check up until no overlap. stop // as soon as there's overlap, of course. boolean intersects = false; ArrayList drawnLabels = d.getDrawnLabels(); int listlength = drawnLabels.size(); //int high = listlength-1; int high=(listlength==1)?listlength: listlength-1; int low = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -