List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:LinesDashes1.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; float[] dash1 = { 2f, 0f, 2f }; g2d.drawLine(20, 40, 250, 40);// ww w . ja v a 2 s. co m BasicStroke bs1 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash1, 2f); //BasicStroke bs2 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash2,2f); //float[] dash3 = { 4f, 0f, 2f }; //BasicStroke bs3 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash3,2f); //float[] dash4 = { 4f, 4f, 1f }; //BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash4,2f); g2d.setStroke(bs1); g2d.drawLine(20, 80, 250, 80); }
From source file:ucar.unidata.idv.control.chart.TrackSegment.java
/** * Draws the wayPoint./* w ww . j a v a 2s.c om*/ * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info an optional info object that will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { super.setGraphicsState(g2); if (!getPlotWrapper().okToDraw(this)) { return; } WayPoint leftWayPoint = getLeft(); WayPoint rightWayPoint = getRight(); g2.setStroke(new BasicStroke()); int x1 = leftWayPoint.getXFromValue(dataArea, domainAxis); int x2 = rightWayPoint.getXFromValue(dataArea, domainAxis); int top = (int) (dataArea.getY()); int bottom = (int) (dataArea.getY() + dataArea.getHeight()); FontMetrics fm = g2.getFontMetrics(); int width = fm.stringWidth(getName()); int height = fm.getAscent() + fm.getDescent(); if (getSelected()) { g2.setColor(Color.red); } else { g2.setColor(Color.black); } // int y = bottom-3; y = top - 2; int textLeft = x1 + (x2 - x1) / 2 - width / 2; g2.drawString(getName(), textLeft, y); g2.setStroke(new BasicStroke(2.0f)); g2.drawLine(x1, top + 1, x2, top + 1); g2.setStroke(new BasicStroke(1.0f)); g2.setColor(Color.gray); g2.drawLine(x1, top, x1, bottom - WayPoint.ANNOTATION_WIDTH); g2.drawLine(x2, top, x2, bottom - WayPoint.ANNOTATION_WIDTH); }
From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java
/** * Draws zoom rectangle (if present)./* w w w .jav a2 s. c om*/ * The drawing is performed in XOR mode, therefore * when this method is called twice in a row, * the second call will completely restore the state * of the canvas. * * @param g2 the graphics device. */ private void drawCoElutionRegion(Graphics2D g2) { // Set XOR mode to draw the zoom rectangle if (g2 == null) return; Paint origColor = g2.getPaint(); // g2.setXORMode(Color.gray); g2.setXORMode(new Color(30, 10, 30, 5)); if (this.coElutionRegion != null) { g2.fill(this.coElutionRegion); g2.setPaint(Color.white); g2.setStroke(new BasicStroke(3.0f)); g2.draw(this.coElutionRegion); } g2.setPaintMode(); g2.setPaint(origColor); }
From source file:ucar.unidata.idv.control.chart.RangeFilter.java
/** * Draws the annotation./*from w w w . ja v a2s. com*/ * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info an optional info object that will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { super.setGraphicsState(g2); if (!getPlotWrapper().okToDraw(this)) { return; } g2.setStroke(new BasicStroke()); boolean selected = getSelected(); if (attached != null) { selected |= attached.getSelected(); } if (selected) { g2.setColor(COLOR_SELECTED); } else { g2.setColor(getColor()); } y = (int) rangeAxis.valueToJava2D(rangeValue, dataArea, RectangleEdge.LEFT); int width = (int) ANNOTATION_WIDTH; int width2 = (int) (ANNOTATION_WIDTH / 2); x = (int) dataArea.getX(); // System.err.println("x/y:" + x +"/" +y); int[] xs; int[] ys; if (type == TYPE_LESSTHAN) { xs = new int[] { x, x + width, x + width2, x }; ys = new int[] { y, y, y + width, y }; } else { xs = new int[] { x, x + width, x + width2, x }; ys = new int[] { y, y, y - width, y }; } g2.fillPolygon(xs, ys, xs.length); g2.setColor(Color.gray); g2.drawLine(x + width, y, (int) (dataArea.getX() + dataArea.getWidth()), y); if ((attached != null) && (type == TYPE_LESSTHAN)) { int otherY = (int) rangeAxis.valueToJava2D(attached.rangeValue, dataArea, RectangleEdge.LEFT); g2.drawLine(x + width2, y + width, x + width2, otherY - width); } }
From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * *//*from w w w .j a va 2s. c om*/ protected void drawDateAxis(Graphics2D g2, double cursor, Rectangle2D plotArea) { g2.setPaint(this.getBackgroundColor()); g2.setStroke(this.getCladeBranchStroke()); /** * The interpretation of cursor depends on what edge is passed in. * RectangleEdge.RIGHT uses the cursor as the x position. * <code>PhyloDataAxis.draw()</code> uses <code>RectangleEdge.RIGHT</code> * * See <code>org.jfree.chart.axis.ValueAxis.drawAxisLine</code>. */ fDateAxis.draw(g2, cursor, plotArea); }
From source file:org.jfree.experimental.chart.plot.dial.DialCap.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *//*w w w. ja v a 2 s. c o m*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setPaint(this.fillPaint); Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight()); g2.fill(e); g2.setPaint(this.outlinePaint); g2.setStroke(this.outlineStroke); g2.draw(e); }
From source file:ucar.unidata.idv.control.chart.MyScatterPlot.java
/** * Draws the fast scatter plot on a Java 2D graphics device (such as the * screen or a printer).// w ww.j a v a 2s . c o m * a * @param g2 the graphics device. * @param dataArea the data area * @param index which data set * @param info collects chart drawing information (<code>null</code> * permitted). * @param crosshairState crosshairState * * @return did something */ public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { if (index >= series.size()) { return false; } XYDataset dataset = getDataset(index); g2.setStroke(new BasicStroke()); // getRendererForDataset(dataset).getSeriesStroke(0)); ScatterPlotChartWrapper.MyRenderer renderer = (ScatterPlotChartWrapper.MyRenderer) getRendererForDataset( dataset); g2.setPaint(renderer.getSeriesPaint(0)); int shape = renderer.shape; PlotOrientation orientation = getOrientation(); int seenCnt = 0; int xx = (int) dataArea.getMinX(); int ww = (int) dataArea.getWidth(); int yy = (int) dataArea.getMaxY(); int hh = (int) dataArea.getHeight(); ValueAxis rangeAxis = getRangeAxisForDataset(index); ValueAxis domainAxis = getDomainAxisForDataset(index); double domainMin = domainAxis.getLowerBound(); double domainLength = domainAxis.getUpperBound() - domainMin; double rangeMin = rangeAxis.getLowerBound(); double rangeLength = rangeAxis.getUpperBound() - rangeMin; int boxWidth = 6; double[][] data = (double[][]) series.get(index); double[] d1 = data[0]; double[] d2 = data[1]; int size = d1.length; Hashtable seen = new Hashtable(); int lastX = 0; int lastY = 0; //TODO: Check for clipping //TODO: Try to create a GeneralPath with the points //and cal g2.draw just once GeneralPath path = new GeneralPath(); long t1 = System.currentTimeMillis(); for (int i = 0; i < size; i++) { int transX = (int) (xx + ww * (d1[i] - domainMin) / domainLength); int transY = (int) (yy - hh * (d2[i] - rangeMin) / rangeLength); Object key = transX + "_" + transY; if (seen.get(key) != null) { seenCnt++; continue; } seen.put(key, key); if (crosshairState != null) { crosshairState.updateCrosshairPoint(d1[i], d2[i], transX, transY, orientation); } switch (shape) { case LineState.SHAPE_VLINE: if (i > 1) { g2.drawLine(lastX, lastY, transX, transY); } lastX = transX; lastY = transY; case LineState.SHAPE_POINT: path.append(new Rectangle((int) transX, (int) transY, 1, 1), false); break; case LineState.SHAPE_LARGEPOINT: path.append(new Rectangle((int) transX, (int) transY, 2, 2), false); break; case LineState.SHAPE_RECTANGLE: path.append( new Rectangle((int) transX - boxWidth / 2, (int) transY - boxWidth / 2, boxWidth, boxWidth), false); break; case LineState.SHAPE_X: g2.drawLine(transX - boxWidth / 2, transY - boxWidth / 2, transX + boxWidth - boxWidth / 2, transY + boxWidth - boxWidth / 2); g2.drawLine(transX + boxWidth - boxWidth / 2, transY - boxWidth / 2, transX - boxWidth / 2, transY + boxWidth - boxWidth / 2); break; case LineState.SHAPE_PLUS: g2.drawLine(transX + boxWidth / 2, transY, transX + boxWidth / 2, transY + boxWidth); g2.drawLine(transX, transY + boxWidth / 2, transX + boxWidth, transY + boxWidth / 2); break; } } g2.fill(path); long t2 = System.currentTimeMillis(); // System.out.println ("time:" + (t2-t1)); return true; }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void paintEllipse2D(Graphics2D g2d, double x, double y, double width, double height, Color linecoler, int thickness, Color fillColor, float alpha) throws Exception { g2d.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); //int x, int y, int width, int height if (linecoler != null) { g2d.setPaint(linecoler);//from w w w. ja va 2 s . com g2d.draw(new Ellipse2D.Double(x, y, width, height)); } if (fillColor != null) { g2d.setPaint(fillColor); g2d.fill(new Ellipse2D.Double(x, y, width, height)); } }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void paintRect2D(Graphics2D g2d, double x, double y, double width, double height, Color linecoler, int thickness, Color fillColor, float alpha) throws Exception { g2d.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); //int x, int y, int width, int height if (linecoler != null) { g2d.setPaint(linecoler);/*from w w w. j a va 2 s . co m*/ g2d.draw(new Rectangle2D.Double(x, y, width, height)); } if (fillColor != null) { g2d.setPaint(fillColor); g2d.fill(new Rectangle2D.Double(x, y, width, height)); } }
From source file:ScribbleDragAndDrop.java
/** * The component draws itself by drawing each of the Scribble objects. *///from w w w. j a va2 s . co m public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setStroke(linestyle); // Specify wide lines int numScribbles = scribbles.size(); for (int i = 0; i < numScribbles; i++) { Scribble s = (Scribble) scribbles.get(i); g2.draw(s); // Draw the scribble } }