List of usage examples for java.awt Graphics2D drawLine
public abstract void drawLine(int x1, int y1, int x2, int y2);
(x1, y1)
and (x2, y2)
in this graphics context's coordinate system. From source file:peakml.util.jfreechart.FastTimePlot.java
@Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {//from w w w . ja v a2 s . co m // add the plot area to the info (used amongst other by the axis for zooming) if (info != null) info.setPlotArea(area); // add the insets (if any) RectangleInsets insets = getInsets(); insets.trim(area); // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming) AxisSpace space = new AxisSpace(); space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space); space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(area, null); if (info != null) info.setDataArea(dataArea); // flood fill the whole area with the background color drawBackground(g2, dataArea); // draw the axis xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info); yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info); // sanity check if (dataseries.size() == 0) return; // clip the draw area Shape originalclip = g2.getClip(); g2.clip(dataArea); // draw all the values int index = 0; for (Data data : dataseries.values()) { g2.setColor(new Color(data.color == -1 ? colormap.getColor(index++) : data.color)); for (int i = 0; i < data.size - 1; ++i) { g2.drawLine((int) xaxis.valueToJava2D(data.time[i], dataArea, RectangleEdge.BOTTOM), (int) yaxis.valueToJava2D(data.values[i], dataArea, RectangleEdge.LEFT), (int) xaxis.valueToJava2D(data.time[i + 1], dataArea, RectangleEdge.BOTTOM), (int) yaxis.valueToJava2D(data.values[i + 1], dataArea, RectangleEdge.LEFT)); } } // reset g2.setClip(originalclip); }
From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java
/** * Draw the graphical representation of the Graph * * @param g the Graphics//from ww w . j a v a 2 s.c o m * @param nodeList the list of graphNodes */ private void DrawGraph(Graphics2D g, List<GraphNode> nodeList) { g.setFont(font); if (showRightClickHelp) { drawHelp(g); } for (GraphNode n : nodeList) { if (n == selectedNode) n.drawNode(g, selColor); else n.drawNode(g, opColor); } // first pass sets the Size in drawNode according to string length for (GraphNode n : nodeList) { // connect source nodes g.setColor(Color.red); final NodeSource[] nSources = n.getNode().getSources(); for (NodeSource nSource : nSources) { final GraphNode srcNode = graphEx.getGraphNodeList().findGraphNode(nSource.getSourceNodeId()); if (srcNode != null) n.drawConnectionLine(g, srcNode); } } if (showHeadHotSpot && selectedNode != null) { selectedNode.drawHeadHotspot(g, Color.red); } if (showTailHotSpot && selectedNode != null) { selectedNode.drawTailHotspot(g, Color.red); } if (connectingSourceFromHead && connectSourceTargetNode != null) { final Point p1 = connectSourceTargetNode.getPos(); final Point p2 = connectingSourcePos; if (p1 != null && p2 != null) { g.setColor(Color.red); g.drawLine(p1.x, p1.y + connectSourceTargetNode.getHalfNodeHeight(), p2.x, p2.y); } } else if (connectingSourceFromTail && connectSourceTargetNode != null) { final Point p1 = connectSourceTargetNode.getPos(); final Point p2 = connectingSourcePos; if (p1 != null && p2 != null) { g.setColor(Color.red); g.drawLine(p1.x + connectSourceTargetNode.getWidth(), p1.y + connectSourceTargetNode.getHalfNodeHeight(), p2.x, p2.y); } } }
From source file:org.oscarehr.common.web.PregnancyAction.java
public ActionForward getFundalImage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { List<Point2D.Double> points = new ArrayList<Point2D.Double>(); int index = 1; while (true) { String ga = request.getParameter("ga" + index); String cm = request.getParameter("fh" + index); if (ga == null || cm == null) break; String weeks = null;//from w w w .j av a 2 s . c o m String offset = null; try { weeks = ga.substring(0, ga.indexOf("w")); offset = "0"; if (ga.indexOf("+") != -1) offset = ga.substring(ga.indexOf("+") + 1); } catch (Exception e) { MiscUtils.getLogger().warn("Error", e); } if (weeks != null && offset != null) { try { double gaa = Integer.parseInt(weeks) + (Integer.parseInt(offset) / 7); double cma = Double.parseDouble(cm); Point2D.Double p = new Point2D.Double(gaa, cma); points.add(p); } catch (NumberFormatException e) { MiscUtils.getLogger().warn("Error", e); } } index++; } File file = new File(request.getSession().getServletContext().getRealPath("/") + "WEB-INF/classes/oscar/form/prop/fundal_graph.png"); BufferedImage bufferedImage = ImageIO.read(file); Graphics2D g = bufferedImage.createGraphics(); g.setColor(Color.black); g.setStroke(new BasicStroke(2)); int xStart = 23; //each week is 10.25pixels int yStart = 318; //each height is 10.6pixels int width = 7; int height = 7; int startingWeek = 20; int startingHeight = 15; Point2D.Double lastPoint = null; for (Point2D.Double p : points) { if (p.x < startingWeek || p.x > 42) continue; if (p.y < startingHeight || p.y > 45) continue; Rectangle r = new Rectangle((int) (xStart + (10.25 * (p.x - startingWeek)) - (width / 2)), (int) (yStart - (10.60 * (p.y - startingHeight)) - (height / 2)), width, height); g.fill(r); if (lastPoint != null) { g.drawLine((int) (xStart + (10.25 * (lastPoint.x - startingWeek))), (int) (yStart - (10.60 * (lastPoint.y - startingHeight))), (int) (xStart + (10.25 * (p.x - startingWeek))), (int) (yStart - (10.60 * (p.y - startingHeight)))); } lastPoint = p; } g.dispose(); response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); ImageIO.write(bufferedImage, "png", outputStream); outputStream.close(); return null; }
From source file:org.tsho.dmc2.core.chart.CowebRenderer.java
private void animateCowebPlot(Graphics2D g2, Rectangle2D dataArea) { Graphics2D g2bisec = (Graphics2D) g2.create(); g2bisec.setColor(Color.blue); Stroke stroke = new BasicStroke(3f); Stroke origStroke = g2.getStroke(); Color color = Color.BLACK; g2blink = (Graphics2D) g2.create(); g2blink.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2blink.setXORMode(color);/*from ww w .java 2s. c om*/ g2blink.setStroke(stroke); if (plot.isAlpha()) { g2bisec.setComposite(AlphaComposite.SrcOver); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getForegroundAlpha())); } /* transients */ stepper.setInitialValue(initialValue); stepper.initialize(); state = STATE_TRANSIENTS; for (int index = 0; index < transients; index++) { stepper.step(); if (stopped) { state = STATE_STOPPED; return; } } state = STATE_RUNNING; Range xDataRange = plot.getDataRange(domainAxis); int transX, transY, transX1, transY1; transX = (int) this.domainAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.BOTTOM); transY = (int) this.rangeAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.LEFT); transX1 = (int) this.domainAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.BOTTOM); transY1 = (int) this.rangeAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.LEFT); g2bisec.drawLine(transX, transY, transX1, transY1); //renderer.reset(); recurseCoweb(g2, dataArea); }
From source file:org.viafirma.util.QRCodeUtil.java
/** * Genera codigo de firma para impresin formado por el texto, el cdigo qr * del texto y un cdigo de barras con el cdigo de firma. * // w w w . j a v a 2 s. com * @param text * @param codFirma * @return * @throws ExcepcionErrorInterno */ public byte[] generate(String text, String url, String textoQR, String codFirma) throws ExcepcionErrorInterno { // Comprobamos el tamao del texto. No recomendamos textos de mas de 120 // caracteres if (textoQR.length() > MAX_TEXT_SIZE) { log.warn("El tamao del texto '" + text + "' ha excedido el tamao mximo. " + text.length() + ">" + MAX_TEXT_SIZE); textoQR = textoQR.substring(textoQR.lastIndexOf(" ")); log.warn("El texto sera recortado: '" + textoQR + "'"); } // Generamos la sufperficie de dibujo BufferedImage imagenQR = new BufferedImage(ANCHO_ETIQUETA, ALTO_ETIQUETA, BufferedImage.TYPE_INT_RGB); Graphics2D g = imagenQR.createGraphics(); // El fondo es blanco g.setBackground(Color.WHITE); g.clearRect(0, 0, ANCHO_ETIQUETA, ALTO_ETIQUETA); g.setColor(Color.BLACK); g.setStroke(new BasicStroke(2f)); // Pintamos la caja de borde g.draw(new java.awt.Rectangle(MARGEN_CAJA, MARGEN_CAJA, ANCHO_ETIQUETA - MARGEN_CAJA * 2, ALTO_ETIQUETA - MARGEN_CAJA * 2)); g.draw(new java.awt.Rectangle(MARGEN_CAJA + 3, MARGEN_CAJA + 3, ANCHO_ETIQUETA - MARGEN_CAJA * 2 - 6, ALTO_ETIQUETA - MARGEN_CAJA * 2 - 6)); // Generamos el cdigo QR Qrcode x = new Qrcode(); x.setQrcodeErrorCorrect('L'); x.setQrcodeEncodeMode('B'); // Modo Binario byte[] d = textoQR.getBytes(); // Generamos el cdigo QR boolean[][] s = x.calQrcode(d); for (int i = 0; i < s.length; i++) { for (int j = 0; j < s.length; j++) { if (s[j][i]) { g.fillRect(j * SIZE_QR + MARGEN, i * SIZE_QR + MARGEN, SIZE_QR, SIZE_QR); } } } int marjenSeparador = MARGEN + SIZE_QR * s.length + MARGEN_CAJA; int marjenTexto = marjenSeparador + MARGEN_CAJA; // Linea de separacin entre el QR cdigo y el texto g.drawLine(marjenSeparador - 3, MARGEN_CAJA + 3, marjenSeparador - 3, ALTO_ETIQUETA - MARGEN_CAJA - 3); g.drawLine(marjenSeparador, MARGEN_CAJA + 3, marjenSeparador, ALTO_ETIQUETA - MARGEN_CAJA - 3); // Linea de separacin entre texto y cdigo de barras. int marjenCodigoBarras = MARGEN + MAX_ROWS * FONT_SIZE; // Pintamos una pequea linea de separacin g.drawLine(marjenSeparador, marjenCodigoBarras, ANCHO_ETIQUETA - MARGEN_CAJA - 3, marjenCodigoBarras); g.drawLine(marjenSeparador, marjenCodigoBarras - 3, ANCHO_ETIQUETA - MARGEN_CAJA - 3, marjenCodigoBarras - 3); // Escribimos el texto List<String> parrafos = split(text); g.setFont(new Font(g.getFont().getName(), Font.BOLD, FONT_SIZE)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (int i = 0; i < parrafos.size(); i++) { String linea = parrafos.get(i); // Pintamos la nueva linea de texto g.drawString(linea, marjenTexto, MARGEN + 3 + (FONT_SIZE * i + 1)); } g.setFont(new Font(g.getFont().getName(), Font.BOLD, FONT_SIZE - 4)); // Pintamos el texto final de una sola lnea( Generalmente el MD5 ) //if(url.length()) if (!url.equals("")) { g.drawString("Custodia del documento: ", marjenTexto, marjenCodigoBarras - 10 * 2); g.drawString(url, marjenTexto, marjenCodigoBarras - 6); } marjenCodigoBarras += MARGEN_CAJA; // Generamos el cdigo de barras try { // int marjenCodigoBarras=MARGEN+MAX_ROWS*FONT_SIZE; BarcodeFactory.createCode39(codFirma, true).draw(g, marjenTexto, marjenCodigoBarras); } catch (Exception e1) { // TODO e1.printStackTrace(); } // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_OFF); // Finalizamos la superficie de dibujo g.dispose(); ByteArrayOutputStream out = new ByteArrayOutputStream(); // Generamos la imagen try { ImageIO.write(imagenQR, "png", out); // ImageIO.write(imagenQR, "png", new // FileOutputStream("/tmp/imagen.png")); out.close(); } catch (Exception e) { throw new ExcepcionErrorInterno(CodigoError.ERROR_INTERNO, e); } return out.toByteArray(); }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
@Override public void renderCellLD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {/*ww w . j av a 2s . c om*/ try { g2D.setColor(UI.colorBlack2); g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); g2D.setColor(barColorNormal); g2D.setStroke(UI.stroke1_5); //This is the //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue)); //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight)); if (rowNode.isSingleNode() && columnNode.isSingleNode()) { double value = (v - _minValue) / (_maxValue - _minValue); if (v >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * value), (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * value)); } else { // double min = percentile.evaluate(valueArray, 0); // double max = percentile.evaluate(valueArray, 100) double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode); if (fiveVal == null) { g2D.setColor(UI.colorBlack1); g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); } double range = _maxValue - _minValue; double minP = (fiveVal[0] - _minValue) / range; double maxP = (fiveVal[4] - _minValue) / range; double medianP = (fiveVal[2] - _minValue) / range; double q1P = (fiveVal[1] - _minValue) / range; double q3P = (fiveVal[3] - _minValue) / range; try { // if (cellWidth >= 2 && cellHeight >= 2) { g2D.drawLine((int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * minP)); if (fiveVal[2] >= disectBound) { g2D.setColor(UI.colorLightGreen4); } else { g2D.setColor(UI.colorOrange2); } g2D.fillRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth), (int) (cellHeight * (q3P - q1P))); if (fiveVal[2] >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } // g2D.setColor(barColorNormal); //g2D.drawRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth), (int) (cellHeight * (q3P - q1P))); g2D.drawLine((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * medianP), (int) (anchorX + cellWidth), (int) (anchorY + cellHeight - cellHeight * medianP)); // } else { // // if (fiveVal[2] >= medianP) { // g2D.setColor(barColorNormal); // } else { // g2D.setColor(barColorBelow); // } // //// System.out.println("painted rect"); //// System.out.println((int) cellWidth + " " + ((int) cellHeight)); // g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); // } } catch (Exception e) { System.err.println("Boxplot render exception"); } } // if(cellWidth>=4 && cellHeight >=){ // g2D.setColor(UI.colorBlack1); // g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); // } } catch (Exception e) { } } }
From source file:edu.cuny.jfree.chart.annotations.CategoryIntervalAnnotation.java
public void draw(final Graphics2D g2, final CategoryPlot plot, final Rectangle2D dataArea, final CategoryAxis domainAxis, final ValueAxis rangeAxis) { final AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getForegroundAlpha());/* w w w . j a va 2 s.com*/ final Composite oldComposite = g2.getComposite(); g2.setComposite(alphaComposite); final CategoryDataset dataset = plot.getDataset(); final int catIndex = dataset.getColumnIndex(category); final int catCount = dataset.getColumnCount(); double lineX1 = 0.0D; double lineY = 0.0D; double lineX2 = 0.0D; final PlotOrientation orientation = plot.getOrientation(); final RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); final RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); if (orientation == PlotOrientation.HORIZONTAL) { lineY = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); lineX1 = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge); lineX2 = rangeAxis.valueToJava2D(value2, dataArea, rangeEdge); } else if (orientation == PlotOrientation.VERTICAL) { lineY = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge); lineX1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); lineX2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); } g2.setPaint(paint); g2.setStroke(stroke); g2.drawLine((int) lineX1, (int) lineY, (int) lineX2, (int) lineY); g2.setComposite(oldComposite); }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
@Override public void renderCellSD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {/* ww w. j a v a 2s.c om*/ try { g2D.setColor(UI.colorBlack2); g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); g2D.setColor(barColorNormal); // g2D.setStroke(null); g2D.setStroke(UI.stroke1_5); //This is the //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue)); //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight)); if (rowNode.isSingleNode() && columnNode.isSingleNode()) { double medianP = (v - _minValue) / (_maxValue - _minValue); if (v >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * medianP), (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * medianP)); } else { // double min = percentile.evaluate(valueArray, 0); // double max = percentile.evaluate(valueArray, 100) double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode); if (fiveVal == null) { g2D.setColor(UI.colorBlack1); g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); } double range = _maxValue - _minValue; double minP = (fiveVal[0] - _minValue) / range; double maxP = (fiveVal[4] - _minValue) / range; double medianP = (fiveVal[2] - _minValue) / range; double q1P = (fiveVal[1] - _minValue) / range; double q3P = (fiveVal[3] - _minValue) / range; try { g2D.drawLine((int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * minP)); if (fiveVal[2] >= disectBound) { g2D.setColor(UI.colorLightGreen4); } else { g2D.setColor(UI.colorOrange2); } g2D.fillRect((int) (anchorX + cellWidth / 4), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth / 2), (int) (cellHeight * (q3P - q1P))); if (fiveVal[2] >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } // g2D.setColor(barColorNormal); g2D.drawRect((int) (anchorX + cellWidth / 4), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth / 2), (int) (cellHeight * (q3P - q1P))); g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * medianP), (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * medianP)); } catch (Exception e) { System.err.println("Boxplot render exception"); } } g2D.setColor(UI.colorBlack1); g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); } catch (Exception e) { } } }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private static void drawArrowToDestination(final Graphics2D gfx, final Rectangle2D start, final Rectangle2D destination, final Stroke lineStroke, final Stroke arrowStroke, final float arrowSize) { final double startx = start.getCenterX(); final double starty = start.getCenterY(); final Point2D arrowPoint = Utils.findRectEdgeIntersection(destination, startx, starty); if (arrowPoint != null) { gfx.setStroke(arrowStroke);//from www . java2 s. co m double angle = findLineAngle(arrowPoint.getX(), arrowPoint.getY(), startx, starty); final double arrowAngle = Math.PI / 12.0d; final double x1 = arrowSize * Math.cos(angle - arrowAngle); final double y1 = arrowSize * Math.sin(angle - arrowAngle); final double x2 = arrowSize * Math.cos(angle + arrowAngle); final double y2 = arrowSize * Math.sin(angle + arrowAngle); final double cx = (arrowSize / 2.0f) * Math.cos(angle); final double cy = (arrowSize / 2.0f) * Math.sin(angle); final GeneralPath polygon = new GeneralPath(); polygon.moveTo(arrowPoint.getX(), arrowPoint.getY()); polygon.lineTo(arrowPoint.getX() + x1, arrowPoint.getY() + y1); polygon.lineTo(arrowPoint.getX() + x2, arrowPoint.getY() + y2); polygon.closePath(); gfx.fill(polygon); gfx.setStroke(lineStroke); gfx.drawLine((int) startx, (int) starty, (int) (arrowPoint.getX() + cx), (int) (arrowPoint.getY() + cy)); } }
From source file:savant.view.swing.GraphPane.java
@Override protected void paintComponent(Graphics g) { if (tracks != null && tracks.length > 0) { LOG.trace("GraphPane.paintComponent(" + tracks[0].getName() + ")"); }/*from www. ja v a2s . com*/ super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; boolean trueRender = render(g2); GraphPaneController gpc = GraphPaneController.getInstance(); int h = getHeight(); // Aiming adjustments. if (gpc.isAiming() && mouseInside) { g2.setColor(Color.BLACK); Font thickfont = g2.getFont().deriveFont(Font.BOLD, 15.0F); g2.setFont(thickfont); int genomeX = gpc.getMouseXPosition(); double genomeY = gpc.getMouseYPosition(); String target = ""; target += "X: " + MiscUtils.numToString(genomeX); if (!Double.isNaN(genomeY)) { target += " Y: " + MiscUtils.numToString(genomeY); } g2.drawLine(mouseX, 0, mouseX, h); if (genomeY != -1) { g.drawLine(0, mouseY, this.getWidth(), mouseY); } g2.drawString(target, mouseX + 5, mouseY - 5); } double x1 = transformXPos(gpc.getMouseClickPosition()); double x2 = transformXPos(gpc.getMouseReleasePosition()); double width = x1 - x2; selectionRect = new Rectangle2D.Double(width < 0 ? x1 : x2, 0.0, Math.max(2.0, Math.abs(width)), h); if (gpc.isPanning()) { // Panning adjustments (none). } else if (gpc.isZooming() || gpc.isSelecting()) { // Zooming adjustments. Rectangle2D rectangle = new Rectangle2D.Double(selectionRect.getX(), selectionRect.getY() - 10.0, selectionRect.getWidth(), selectionRect.getHeight() + 10.0); g2.setColor(Color.gray); g2.setStroke( new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3f, new float[] { 4f }, 4f)); g2.draw(rectangle); if (gpc.isZooming()) { g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_ZOOM_FILL)); } else if (gpc.isSelecting()) { g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_SELECTION_FILL)); } g2.fill(selectionRect); } // Plumbing adjustments. Range xRange = getXRange(); if (gpc.isPlumbing()) { g2.setColor(Color.BLACK); double spos = transformXPos(gpc.getMouseXPosition()); g2.draw(new Line2D.Double(spos, 0, spos, h)); double rpos = transformXPos(gpc.getMouseXPosition() + 1); g2.draw(new Line2D.Double(rpos, 0, rpos, h)); } // Spotlight if (gpc.isSpotlight() && !gpc.isZooming()) { int center = gpc.getMouseXPosition(); int left = center - gpc.getSpotlightSize() / 2; int right = left + gpc.getSpotlightSize(); g2.setColor(new Color(0, 0, 0, 200)); // draw left of spotlight if (left >= xRange.getFrom()) { g2.fill(new Rectangle2D.Double(0.0, 0.0, transformXPos(left), h)); } // draw right of spotlight if (right <= xRange.getTo()) { double pix = transformXPos(right); g2.fill(new Rectangle2D.Double(pix, 0, getWidth() - pix, h)); } } if (isLocked()) { drawMessage((Graphics2D) g, "Locked"); } if (trueRender) { gpc.delistRenderingGraphpane(this); } }