📄 basicparalleldisplayui.java
字号:
//if (i > 0) curx -= stepx/4; //if (i == (numDimensions-1)) curx -= stepx/4; g2.setColor(new Color(1.0f, 1.0f, 1.0f, 0.8f)); g2.fillRect((int)curx, 0, stepx/2, height); g2.setColor(new Color(0.0f, 0.0f, 0.0f, 0.4f)); g2.drawRect((int)curx, 0, stepx/2, height); float xscale = comp.getAxisScale(i); float xoffset = comp.getAxisOffset(i); // include records right at the border xoffset -= xscale * 0.00005f; xscale += xscale * 0.0001f; int j; int baseWidth = 0; //TODO: this is not nice... we should cache the float calculations if (comp.getIntPreference("histogramWidth") != ParallelDisplay.HISTO_TOTALREC){ if (comp.getIntPreference("histogramWidth") == ParallelDisplay.HISTO_BINREC){ for (j=0; j<bins; j++){ float upper = xoffset + (j*stepy / height) * xscale; float lower = xoffset + ((j+1)*stepy / height) * xscale; int count = comp.getNumRecordsInRange(i, Math.min(lower, upper), Math.max(lower, upper)); if (count > baseWidth) baseWidth = count; } } else if(comp.getIntPreference("histogramWidth") == ParallelDisplay.HISTO_BRUSHREC){ for (j=0; j<bins; j++){ float upper = xoffset + (j*stepy / height) * xscale; float lower = xoffset + ((j+1)*stepy / height) * xscale; int count = comp.getNumBrushedInRange(i, Math.min(lower, upper), Math.max(lower, upper)); if (count > baseWidth) baseWidth = count; } } else { //unknown preference baseWidth = comp.getNumRecords(); } } else { baseWidth = comp.getNumRecords(); } for (j=0; j<bins; j++){ float upper = xoffset + (j*stepy / height) * xscale; float lower = xoffset + ((j+1)*stepy / height) * xscale; float count = comp.getNumRecordsInRange(i, Math.min(lower, upper), Math.max(lower, upper)); float hwidth = ((count/baseWidth) * stepx/2); if (hwidth > stepx/2) { hwidth = stepx/2; } g2.setColor(new Color(0.0f, 0.0f, 0.0f, 0.4f)); g2.fillRect((int)(curx + stepx/4 - hwidth/2), (int)(j*stepy), (int)hwidth, (int)stepy + 1); count = comp.getNumBrushedInRange(i, Math.min(lower, upper), Math.max(lower, upper)); hwidth = ((count/baseWidth) * stepx/2); g2.setColor(new Color(0.0f, 0.0f, 0.0f, 0.6f)); g2.fillRect((int)(curx + stepx/4 - hwidth/2), (int)(j*stepy), (int)hwidth, (int)stepy + 1); } } } //hovering over record if ((comp.getBoolPreference("hoverLine")) && ( hoverRecord != -1)){ //System.out.println("Painting record " + i); Color col = new Color(1.0f, 1.0f, 0.8f); Font oldfont = g2.getFont(); Font newfont = new Font(oldfont.getName(), Font.PLAIN, oldfont.getSize() - 2); g2.setFont(newfont); GeneralPath rPath = new GeneralPath(); float yval = getYValue(hoverRecord, 0, comp); rPath.moveTo(0, yval); for (int j=1; j<numDimensions; j++){ yval = getYValue(hoverRecord, j, comp); rPath.lineTo(stepx * j, yval); } g2.setStroke(new BasicStroke(2.5f)); g2.draw(rPath); g2.setStroke(new BasicStroke(1.5f)); g2.setColor(Color.red); g2.draw(rPath); g2.setFont(oldfont); } if ((comp.getBoolPreference("hoverText")) && ( hoverRecord != -1)){ Color col = new Color(1.0f, 1.0f, 0.8f); for (int j=0; j<numDimensions; j++){ float yval = getYValue(hoverRecord, j, comp); drawTooltip(g2,comp.getAxisLabel(j) + "=\n" + comp.getValue(hoverRecord, j), stepx * j, (int)yval, col); } } //dragging axis if (dragAxis) { AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f); g2.setComposite(ac); g2.setStroke(new BasicStroke(0.5f)); g2.drawLine(dragX - borderH, 0, dragX - borderH, height); } //tooltips if ((comp.getBoolPreference("hoverLine")) && (metaText != null)){ drawTooltip(g2, metaText, metaX, metaY + 10, new Color(0.7f, 0.7f, 1.0f)); } g2.translate(-borderH, -borderV); } /** * Helper function to trigger rendering of a given region. */ void renderRegion(int startAxis, int stopAxis){ if (startAxis < 0) startAxis = 0; if (stopAxis >= numDimensions) stopAxis = numDimensions-1; renderThread.setRegion(startAxis, stopAxis); renderThread.render(); if (brushImg != null){ //if we do this, we have to add another buffer img for the brush in paint() //brushThread.setRegion(startAxis, stopAxis); brushThread.render(); } } /** * Helper function to trigger rendering of the whole display. */ void renderAll(){ renderRegion(0, numDimensions - 1); } /** * Helper function to trigger rendering of the brush image. */ void renderBrush(){ brushThread.setRegion(0, numDimensions - 1); brushThread.render(); } /** * Draws the given record on the given Graphics object. This method is called by the * RenderThread and can be overridden to modify the look of the rendering. * * @param g2 The Graphics2D object to draw the record on. * @param comp The ParallelDisplay component to get the record data from. * @param num The id of the record to draw. * @param startAxis The start axis to draw from. * @param stopAxis The stop axis to draw to. */ void drawRecord(Graphics2D g2, ParallelDisplay comp, int num, int startAxis, int stopAxis){ GeneralPath rPath = new GeneralPath(); rPath.moveTo(stepx * startAxis,getYValue(num, startAxis, comp)); for (int j=startAxis+1; j<=stopAxis; j++){ rPath.lineTo(stepx * j, getYValue(num, j, comp)); } g2.draw(rPath); } /** * Helper function to draw a "tooltip" on the given graphics object. * * @param g2 The Graphics2D Object to draw on. * @param text The (multiline) text of the tooltip. * @param x The x coordinate. * @param y The y coordinate. * @param col The background color. */ private void drawTooltip(Graphics2D g2, String text, int x, int y, Color col){ int i; int mheight, mwidth = 0; int numLines, lineHeight; StringTokenizer tok = new StringTokenizer(text,"\n"); numLines = tok.countTokens(); String lines[] = new String[numLines]; for (i=0; i<numLines; i++){ lines[i] = tok.nextToken(); int tempwidth = g2.getFontMetrics().stringWidth(lines[i]) + 6; if (tempwidth > mwidth) mwidth = tempwidth; } lineHeight = g2.getFontMetrics().getHeight(); mheight = numLines * lineHeight + 2; x += 10; y += 10; if (x + mwidth > width) x -= (mwidth + 20); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f); g2.setComposite(ac); g2.setStroke(new BasicStroke(0.5f)); g2.setColor(new Color(0.2f, 0.2f, 0.2f)); g2.drawRect(x, y, mwidth, mheight); g2.setColor(col); g2.fillRect(x+1, y+1, mwidth-1, mheight-1); g2.setColor(Color.black); ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER); g2.setComposite(ac); for (i=0; i<numLines; i++){ g2.drawString(lines[i], x + 3, y + (i+1) * lineHeight - 4); } } /** * Helper function to draw an arrow. * * @param g2 The Graphics2D Object to draw on. * @param x The x coordinate. * @param y The y coordinate. * @param size The size in pixels. * @param horizontal If true, the arrow is drawn horizontally, if false vertically. * @param topright If true, the arrowhead is top/right, if false bottom/left. */ private void drawArrow(Graphics2D g2, int x, int y, int size, boolean horizontal, boolean topright){ if (horizontal){ g2.drawLine(x-size/2, y, x+size/2, y); if (topright){ g2.drawLine(x + size/4, y-size/4, x+size/2, y); g2.drawLine(x + size/4, y+size/4, x+size/2, y); } else{ g2.drawLine(x - size/4, y-size/4, x-size/2, y); g2.drawLine(x - size/4, y+size/4, x-size/2, y); } } else { g2.drawLine(x, y-size/2, x, y+size/2); if (topright){ g2.drawLine(x + size/4, y-size/4, x, y-size/2); g2.drawLine(x - size/4, y-size/4, x, y-size/2); } else{ g2.drawLine(x + size/4, y+size/4, x, y+size/2); g2.drawLine(x - size/4, y+size/4, x, y+size/2); } } } /** * Helper function, returns the y value (on screen) for a given record. Scale * factors and translation is applied. * * @param record The recordnumber. * @param axis The axis to calculate the y value for. * @param comp our "parent" component. */ private float getYValue(int record, int axis, ParallelDisplay comp){ float value = comp.getValue(record, axis); value -= comp.getAxisOffset(axis); value *= (comp.getHeight() - 2 * borderV) / comp.getAxisScale(axis); return value; } // record old coordinates for dragging int oldMouseX, oldMouseY; int activeAxis = -1; float oldScale, oldOffset; //0.0 - 1.0 value of loacion of click on axis float clickValue; // actual value of point clicked on axis float clickAxisValue; int clickModifiers; boolean tempBrushSwap = false; /** * Invoked when the mouse exits the component. * * @param e The mouse event. */ public void mouseExited(MouseEvent e) { } /** * Invoked when a mouse button has been released on a component. Checks * if something has been dragged and finishes the drag process. * * @param e The mouse event. */ public void mouseReleased(MouseEvent e) { ParallelDisplay comp = (ParallelDisplay)e.getComponent(); //System.out.println("mouse released"); if (e.isPopupTrigger()){ //System.out.println("showing popup..."); comp.popupMenu.show(comp, e.getX(), e.getY()); return; } switch (comp.getEditMode()){ case ParallelDisplay.REORDER: dragAxis = false; break; case ParallelDisplay.BRUSH: if (!angularPhase1){ inBrush = false; inAngularBrush = false; comp.setCurrentBrush(tempBrush); tempBrushSwap = true; } break; } } private int brushmode = 0; private static final int BRUSH_NORMAL = 0; private static final int BRUSH_ADD = 1; private static final int BRUSH_SUBTRACT = 2; private static final int BRUSH_INTERSECT = 3; private boolean inAngularBrush = false; private boolean angularPhase1 = false; private int angularRefX = 0; private int angularRefY = 0; private int angularCurX = 0; private int angularCurY = 0; private int angularStartX = 0; private int angularStartY = 0; private float angularAngle1 = 0.0f; private float angularAngle2 = 0.0f; private int angularRegion = 0; private int hoverRegion = 0; /** * Invoked when a mouse button has been pressed on a component. * Checks if the user starts dragging something. * * @param e The mouse event. */ public void mousePressed(MouseEvent e) { ParallelDisplay comp = (ParallelDisplay)e.getComponent(); if (e.isPopupTrigger()){ comp.popupMenu.show(comp, e.getX(), e.getY()); return; } oldMouseX = e.getX(); oldMouseY = e.getY(); activeAxis = hoverAxis; clickModifiers = e.getModifiers(); if (activeAxis != -1){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -