List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java
private void drawArrow(Graphics2D g, double speed) { int startX = -(arrowWidth / 2); int startY = -(arrowHeight / 2); // draw main arrow line g.fill(new Rectangle2D.Double(startX, startY, arrowWidth, arrowHeight)); // drawing speed feathers (representing 25 ms each) int featherOffset = 0; int featherHeight = arrowHeight / featherPadding; int flagFeathers = (int) speed / 25; int[] flagFeatherX = { 1, -featherWidth, 1 }; for (int i = 0; i < flagFeathers; i++) { if (i > 0) featherOffset += 1; // more space if multiple flags int yValue = (arrowHeight / 2) - (featherOffset * featherHeight); int flagSize = (int) (featherHeight * 1.5f); int[] flagFeatherY = { yValue, (yValue - flagSize / 2), yValue - flagSize }; g.fill(new Polygon(flagFeatherX, flagFeatherY, 3)); featherOffset += 1;// w ww . j a va2 s . co m } // Add space between flag-feather and next if (flagFeathers > 0) featherOffset++; double remainingSpeed = speed - (flagFeathers * 25); // draw full feathers (representing 5 ms each) int fullFeathers = (int) remainingSpeed / 5; g.setStroke(new BasicStroke(arrowWidth)); for (int i = 0; i < fullFeathers; i++) { int yValue = (arrowHeight / 2) - (featherOffset * featherHeight); yValue -= (arrowWidth / 2); // allign with start of arrow int[] x = { 1, -featherWidth }; int[] y = { yValue, yValue }; g.draw(new Polygon(x, y, 2)); featherOffset += 1; } remainingSpeed = remainingSpeed - (fullFeathers * 5); // draw half feathers (representing 2.5 ms each) int halfFeathers = (int) (remainingSpeed / 2.5); // never draw half-feathers at the start if (featherOffset == 0) featherOffset = 1; for (int i = 0; i < halfFeathers; i++) { int yValue = (arrowHeight / 2) - (featherOffset * featherHeight); yValue -= (arrowWidth / 2); // allign with start of arrow int[] x = { 1, (-featherWidth / 2) }; int[] y = { yValue, yValue }; g.draw(new Polygon(x, y, 2)); featherOffset += 1; } g.setStroke(new BasicStroke(1)); }
From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialPointer.java
/** * Draws the pointer.//ww w. j ava 2 s.c om * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame. * @param view the dial's view. */ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setStroke(new BasicStroke(1.0f)); Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius()); Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius()); double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale); DialScale scale = plot.getScaleForDataset(this.getDatasetIndex()); double angle = scale.valueToAngle(value); Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN); Point2D pt1 = arc1.getEndPoint(); Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN); Point2D pt2 = arc2.getStartPoint(); Point2D pt3 = arc2.getEndPoint(); Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN); Point2D pt4 = arc3.getStartPoint(); GeneralPath gp = new GeneralPath(); gp.moveTo((float) pt1.getX(), (float) pt1.getY()); gp.lineTo((float) pt2.getX(), (float) pt2.getY()); gp.lineTo((float) pt4.getX(), (float) pt4.getY()); gp.lineTo((float) pt3.getX(), (float) pt3.getY()); gp.closePath(); g2.setPaint(this.fillPaint); g2.fill(gp); g2.setPaint(this.getOutlinePaint()); Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY()); // g2.draw(line); line.setLine(pt2, pt3); g2.draw(line); line.setLine(pt3, pt1); g2.draw(line); line.setLine(pt2, pt1); g2.draw(line); line.setLine(pt2, pt4); g2.draw(line); line.setLine(pt3, pt4); g2.draw(line); }
From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialPointer.java
/** * Draws the pointer.// w ww .ja va2s. c om * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame. * @param view the dial's view. */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setStroke(new BasicStroke(1.0f)); Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius()); Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius()); double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale); DialScale scale = plot.getScaleForDataset(this.getDatasetIndex()); double angle = scale.valueToAngle(value); Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN); Point2D pt1 = arc1.getEndPoint(); Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN); Point2D pt2 = arc2.getStartPoint(); Point2D pt3 = arc2.getEndPoint(); Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN); Point2D pt4 = arc3.getStartPoint(); GeneralPath gp = new GeneralPath(); gp.moveTo((float) pt1.getX(), (float) pt1.getY()); gp.lineTo((float) pt2.getX(), (float) pt2.getY()); gp.lineTo((float) pt4.getX(), (float) pt4.getY()); gp.lineTo((float) pt3.getX(), (float) pt3.getY()); gp.closePath(); g2.setPaint(this.fillPaint); g2.fill(gp); g2.setPaint(this.getOutlinePaint()); Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY()); // g2.draw(line); line.setLine(pt2, pt3); g2.draw(line); line.setLine(pt3, pt1); g2.draw(line); line.setLine(pt2, pt1); g2.draw(line); line.setLine(pt2, pt4); g2.draw(line); line.setLine(pt3, pt4); g2.draw(line); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse exited' event./* www . ja v a 2 s. com*/ * <P> * This method does nothing, but is required for implementation of the MouseListener * interface. * * @param e the mouse event. */ public void mouseExited(MouseEvent e) { Graphics2D g2 = (Graphics2D) getGraphics(); Rectangle2D dataArea = getScaledDataArea(); g2.setXORMode(java.awt.Color.orange); if (verticalTraceLine != null) { g2.draw(verticalTraceLine); verticalTraceLine = null; } if (horizontalTraceLine != null) { g2.draw(horizontalTraceLine); horizontalTraceLine = null; } }
From source file:org.squidy.designer.zoom.impl.DataTypeShape.java
@Override protected void paintShapeZoomedOut(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); if (dataTypes != null && dataTypes.size() > 0) { int i = 0; alreadyPaintedHighLevelDataTypes.clear(); for (Class<? extends IData> type : dataTypes) { if (type.isAssignableFrom(IData.class)) { continue; }/* w ww. j a va 2 s .c o m*/ Class<? extends IData> highLevelDataType = DataUtility.getHighLevelDataType(type); if (alreadyPaintedHighLevelDataTypes.contains(highLevelDataType)) { continue; } Color color; if (!COLOR_CACHE.containsKey(highLevelDataType)) { DataType dataType = highLevelDataType.getAnnotation(DataType.class); int[] colorScheme = dataType.color(); color = new Color(colorScheme[0], colorScheme[1], colorScheme[2], colorScheme[3]); COLOR_CACHE.put(highLevelDataType, color); } else { color = COLOR_CACHE.get(highLevelDataType); } translationArrow.setToTranslation(i * 750, 0); paintContext.pushTransform(translationArrow); g.setColor(color); g.fill(arrowShape); g.setStroke(STROKE_ARROW_BOLD); g.setColor(Color.BLACK); g.draw(arrowShape); paintContext.popTransform(translationArrow); alreadyPaintedHighLevelDataTypes.add(highLevelDataType); i++; } } else { drawNoDataType(g); } // g.setColor(Color.BLACK); // g.setStroke(StrokeUtils.getBasicStroke(105f)); // g.draw(getGlobalBoundsZoomedIn()); }
From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileToolDynamicRangePanel.java
@Override public void draw(Graphics2D g) { updateSelectionData();// ww w.j a v a 2 s.c o m float tra = (transparance.getValue() / (float) (transparance.getMaximum())); Composite oldcomp = g.getComposite(); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, tra)); Line2D.Double line = new Line2D.Double(); for (int i = 0; i < selectionData.length - 1; i++) { double x1 = view.getImage().getImage().getWidth() / (double) (selectionData.length - 1) * i; double y1 = view.getImage().getImage().getHeight() * (1 - getSelectionValue(i)); double x2 = view.getImage().getImage().getWidth() / (double) (selectionData.length - 1) * (i + 1); double y2 = view.getImage().getImage().getHeight() * (1 - getSelectionValue(i + 1)); if (getUseData(i)) { g.setColor(getPointColorSelected()); } else { g.setColor(getPointColorNotSelected()); } line.x1 = x1; line.x2 = x2; line.y1 = y1; line.y2 = y2; g.draw(line); if (showOffset.isSelected()) { if (getUseData(i)) { g.setColor(getOffsetColor()); double offset = (Double) this.offset.getValue(); line.y1 += offset; line.y2 += offset; g.draw(line); } } } // Draw each point for (int i = 0; i < value.length; i++) { g.setColor(getCrossColor()); double x = view.getImage().getImage().getWidth() / (double) (value.length - 1) * i; double y = view.getImage().getImage().getHeight() * (1 - value[i]); DrawTools.drawCross(g, new Point2D.Double(x, y), pointSize * 2); } g.setComposite(oldcomp); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse released' event./*from w ww . j a v a 2 s .com*/ * <P> * On Windows, we need to check if this is a popup trigger, but only if we * haven't already been tracking a zoom rectangle. * * @param e Information about the event. */ public void mouseReleased(MouseEvent e) { if (zoomRectangle != null) { // if (Math.abs(e.getX() - zoomPoint.getX()) >= MINIMUM_DRAG_ZOOM_SIZE) { if (Math.abs(e.getX() - zoomPoint.getX()) >= 7) { if (e.getX() < zoomPoint.getX() || e.getY() < zoomPoint.getY()) { autoRangeBoth(); } else { double x, y, w, h; Rectangle2D scaledDataArea = getScaledDataArea(); //for a mouseReleased event, (horizontalZoom || verticalZoom) //will be true, so we can just test for either being false; //otherwise both are true if (!verticalZoom) { x = zoomPoint.getX(); y = scaledDataArea.getMinY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = scaledDataArea.getHeight(); } else if (!horizontalZoom) { x = scaledDataArea.getMinX(); y = zoomPoint.getY(); w = scaledDataArea.getWidth(); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } else { x = zoomPoint.getX(); y = zoomPoint.getY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } g2.dispose(); this.zoomRectangle = null; } // notify a redraw event CoreStatusEvent ev = new CoreStatusEvent(this); ev.setType(CoreStatusEvent.REDRAW); ((AbstractDmcPlot) chart.getPlot()).notifyCoreStatusListeners(ev); } else if (e.isPopupTrigger()) { if (popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Draws a vertical line used to trace the mouse position to the horizontal axis. * * @param x the x-coordinate of the trace line. *///from ww w.j a va 2 s. co m private void drawHorizontalAxisTrace(int x) { Graphics2D g2 = (Graphics2D) getGraphics(); Rectangle2D dataArea = getScaledDataArea(); g2.setXORMode(java.awt.Color.orange); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { if (verticalTraceLine != null) { g2.draw(verticalTraceLine); verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } else { verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } g2.draw(verticalTraceLine); } else { if (horizontalTraceLine != null) { g2.draw(horizontalTraceLine); horizontalTraceLine = null; } if (verticalTraceLine != null) { g2.draw(verticalTraceLine); verticalTraceLine = null; } } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Draws a horizontal line used to trace the mouse position to the vertical axis. * * @param y the y-coordinate of the trace line. *//*from w ww.j a va 2 s . c o m*/ private void drawVerticalAxisTrace(int y) { Graphics2D g2 = (Graphics2D) getGraphics(); Rectangle2D dataArea = getScaledDataArea(); g2.setXORMode(java.awt.Color.orange); if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) { if (horizontalTraceLine != null) { g2.draw(horizontalTraceLine); horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } else { horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } g2.draw(horizontalTraceLine); } else { if (verticalTraceLine != null) { g2.draw(verticalTraceLine); verticalTraceLine = null; } if (horizontalTraceLine != null) { g2.draw(horizontalTraceLine); horizontalTraceLine = null; } } }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/**Pinta la lista de ROis Visibles sobre el grafico*/ public void drawsROIs(Graphics2D g2) { Iterator iterator = roiList.getList().iterator(); ROIChart roiDraw = null;// w w w . ja v a2 s. c o m while (iterator.hasNext()) { roiDraw = (ROIChart) iterator.next(); if (activeROI.equals(roiDraw)) { g2.setPaint(roiDraw.getColor()); for (int i = 0; i < roiDraw.getShapesList().size(); i++) { g2.fill((Shape) roiDraw.getShapesList().get(i)); } } else if (roiDraw.getShapesList().size() > 0) { g2.setPaint(roiDraw.getColor()); for (int i = 0; i < roiDraw.getShapesList().size(); i++) { g2.setPaint(roiDraw.getColor()); g2.draw((Shape) roiDraw.getShapesList().get(i)); } } } }