List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:com.att.aro.main.PacketPlots.java
/** * The utility method that creates the packet plots from a packet series map *//* ww w. j a v a 2 s. c o m*/ private XYPlot createPlot() { // Create the plot renderer YIntervalRenderer renderer = new YIntervalRenderer() { private static final long serialVersionUID = 1L; public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double x = intervalDataset.getXValue(series, item); double yLow = intervalDataset.getStartYValue(series, item); double yHigh = intervalDataset.getEndYValue(series, item); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); Paint p = getItemPaint(series, item); Stroke s = getItemStroke(series, item); Line2D line = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(yyLow, xx, yyHigh, xx); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yyLow, xx, yyHigh); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); // add an entity for the item... if (entities != null) { if (entityArea == null) { entityArea = line.getBounds(); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null); entities.add(entity); } } }; renderer.setAdditionalItemLabelGenerator(null); renderer.setBaseShape(new Rectangle()); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.GRAY); // Create the plot XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); plot.getRangeAxis().setVisible(false); return plot; }
From source file:figs.treeVisualization.gui.PhyloDateAxis.java
/** * Draws the axis line, tick marks and tick mark labels. * /*from ww w . j av a 2 s .co m*/ * @param g2 the graphics device. * @param cursor the cursor. * @param plotArea the plot area. * @param dataArea the data area. * @param edge the edge that the axis is aligned with. * * * Original method is in <code>org.jfree.chart.axis.ValueAxis</code> */ protected void drawTickMarksAndLabels(Graphics2D g2, double cursor, Rectangle2D dataArea) { //AxisState state = new AxisState(cursor); RectangleEdge edge = RectangleEdge.RIGHT; drawAxisLine(g2, cursor, dataArea); double ol = getTickMarkOutsideLength(); double il = getTickMarkInsideLength(); // Their's miss the first and last label //List ticks = refreshTicks(g2, state, dataArea, edge); List ticks = refreshTicksVertical(g2, dataArea); g2.setFont(getTickLabelFont()); Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); if (isTickLabelsVisible()) { g2.setPaint(getTickLabelPaint()); float[] anchorPoint = calculateAnchorPoint(tick, cursor, dataArea, edge); TextUtilities.drawRotatedString(tick.getText(), g2, anchorPoint[0], anchorPoint[1], tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor()); } if (isTickMarksVisible()) { float xx = (float) valueToJava2D(tick.getValue(), dataArea, edge); Line2D mark = null; g2.setStroke(getTickMarkStroke()); g2.setPaint(getTickMarkPaint()); if (edge == RectangleEdge.LEFT) { mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx); } else if (edge == RectangleEdge.RIGHT) { mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx); } else if (edge == RectangleEdge.TOP) { mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il); } else if (edge == RectangleEdge.BOTTOM) { mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il); } g2.draw(mark); } } // end tick list iterator }
From source file:Chart.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // compute the minimum and maximum values if (values == null) return; double minValue = 0; double maxValue = 0; for (double v : values) {//from ww w. j a v a 2s . co m if (minValue > v) minValue = v; if (maxValue < v) maxValue = v; } if (maxValue == minValue) return; int panelWidth = getWidth(); int panelHeight = getHeight(); Font titleFont = new Font("SansSerif", Font.BOLD, 20); Font labelFont = new Font("SansSerif", Font.PLAIN, 10); // compute the extent of the title FontRenderContext context = g2.getFontRenderContext(); Rectangle2D titleBounds = titleFont.getStringBounds(title, context); double titleWidth = titleBounds.getWidth(); double top = titleBounds.getHeight(); // draw the title double y = -titleBounds.getY(); // ascent double x = (panelWidth - titleWidth) / 2; g2.setFont(titleFont); g2.drawString(title, (float) x, (float) y); // compute the extent of the bar labels LineMetrics labelMetrics = labelFont.getLineMetrics("", context); double bottom = labelMetrics.getHeight(); y = panelHeight - labelMetrics.getDescent(); g2.setFont(labelFont); // get the scale factor and width for the bars double scale = (panelHeight - top - bottom) / (maxValue - minValue); int barWidth = panelWidth / values.length; // draw the bars for (int i = 0; i < values.length; i++) { // get the coordinates of the bar rectangle double x1 = i * barWidth + 1; double y1 = top; double height = values[i] * scale; if (values[i] >= 0) y1 += (maxValue - values[i]) * scale; else { y1 += maxValue * scale; height = -height; } // fill the bar and draw the bar outline Rectangle2D rect = new Rectangle2D.Double(x1, y1, barWidth - 2, height); g2.setPaint(Color.RED); g2.fill(rect); g2.setPaint(Color.BLACK); g2.draw(rect); // draw the centered label below the bar Rectangle2D labelBounds = labelFont.getStringBounds(names[i], context); double labelWidth = labelBounds.getWidth(); x = x1 + (barWidth - labelWidth) / 2; g2.drawString(names[i], (float) x, (float) y); } }
From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java
/** * {@inheritDoc}/*from w w w. ja v a 2s .c o m*/ */ @Override public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryWidth = categoryEnd - categoryStart; double xx = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); xx = retrieveXx(state, dataArea, row, categoryWidth, xx, seriesCount, categoryCount); Paint p = null; if (this.getPlotColor() != null) { p = PaintUtilities.stringToColor(getPlotColor()); // coin plot should all be one color } else { p = getItemPaint(row, column); } if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); double aRadius = 0; // average radius RectangleEdge location = drawRectangles(g2, state, dataArea, plot, rangeAxis, row, column, bawDataset, xx); g2.setPaint(getArtifactPaint()); if (this.isDisplayMean()) { aRadius = drawMean(g2, state, dataArea, rangeAxis, row, column, bawDataset, xx, aRadius, location); } if (this.isDisplayMedian()) { // draw median... Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null) { double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian)); } } double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius; double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius; g2.setPaint(p); drawOutliers(g2, state, dataArea, rangeAxis, row, column, bawDataset, xx, aRadius, location, maxAxisValue, minAxisValue); }
From source file:org.gumtree.vis.awt.JChartPanel.java
/** * Draws a vertical line used to trace the mouse position to the horizontal * axis.//from www.j a v a 2 s . co m * * @param g2 the graphics device. * @param x the x-coordinate of the trace line. */ private void drawHorizontalAxisTrace(Graphics2D g2, int x) { Rectangle2D dataArea = getScreenDataArea(); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { g2.setPaint(getAxisTraceColor()); g2.setStroke(new BasicStroke(0.25f)); g2.draw(new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY())); } }
From source file:org.gumtree.vis.awt.JChartPanel.java
/** * Draws a horizontal line used to trace the mouse position to the vertical * axis./*ww w .j a v a 2s . c om*/ * * @param g2 the graphics device. * @param y the y-coordinate of the trace line. */ private void drawVerticalAxisTrace(Graphics2D g2, int y) { Rectangle2D dataArea = getScreenDataArea(); if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) { g2.setPaint(getAxisTraceColor()); g2.setStroke(new BasicStroke(0.25f)); g2.draw(new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y)); } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
protected void paintAnnotations(Graphics2D g2d) { DecimalFormat mz_df = new DecimalFormat("0.0"); // set font/*from w w w.j ava 2 s.co m*/ Font old_font = g2d.getFont(); Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE); // compute bboxes PositionManager pman = new PositionManager(); BBoxManager bbman = new BBoxManager(); computeRectangles(pman, bbman); // compute connections computeConnections(); // paint connections for (AnnotationObject a : theDocument.getAnnotations()) { boolean selected = !is_printing && selections.contains(a); // paint arrow Polygon connection = connections.get(a); if (connection != null) { g2d.setColor(theOptions.CONNECTION_LINES_COLOR); g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH)) : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH)); g2d.draw(connection); g2d.setStroke(new BasicStroke(1)); } // paint control point if (selected) { g2d.setColor(Color.black); Point2D cp = connections_cp.get(a); if (cp != null) { int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH); g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s)); } } } // paint glycans for (AnnotationObject a : theDocument.getAnnotations()) { boolean highlighted = a.isHighlighted(); boolean selected = !is_printing && selections.contains(a); // set scale theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a)); // paint highlighted region if (highlighted) { Rectangle c_bbox = rectangles_complete.get(a); g2d.setColor(theOptions.HIGHLIGHTED_COLOR); g2d.setXORMode(Color.white); g2d.fill(c_bbox); g2d.setPaintMode(); g2d.setColor(Color.black); g2d.draw(c_bbox); } // paint glycan for (Glycan s : a.getStructures()) theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman); // paint MZ text g2d.setFont(new_font); g2d.setColor(theOptions.MASS_TEXT_COLOR); String mz_text = mz_df.format(a.getPeakPoint().getX()); Rectangle mz_bbox = rectangles_text.get(a); g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height); // paint selection if (selected) { // paint rectangle Rectangle c_bbox = rectangles_complete.get(a); g2d.setStroke(new BasicStroke(highlighted ? 2 : 1)); g2d.setColor(Color.black); g2d.draw(c_bbox); g2d.setStroke(new BasicStroke(1)); // paint resize points Polygon p1 = new Polygon(); int cx1 = right(c_bbox); int cy1 = top(c_bbox); p1.addPoint(cx1, cy1); p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1); p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p1); Polygon p2 = new Polygon(); int cx2 = left(c_bbox); int cy2 = top(c_bbox); p2.addPoint(cx2, cy2); p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2); p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p2); } } g2d.setFont(old_font); }
From source file:umontreal.iro.lecuyer.charts.EmpiricalRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis./*from ww w . j ava2s . c o m*/ * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (!getItemVisible(series, item)) return; PlotOrientation orientation = plot.getOrientation(); java.awt.Paint seriesPaint = getItemPaint(series, item); java.awt.Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(seriesPaint); g2.setStroke(seriesStroke); double x0 = dataset.getXValue(series, item); double y0 = dataset.getYValue(series, item); if (java.lang.Double.isNaN(y0)) return; org.jfree.ui.RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); org.jfree.ui.RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double x1 = 0, y1 = 0; if (item < dataset.getItemCount(series) - 1) { x1 = dataset.getXValue(series, item + 1); y1 = dataset.getYValue(series, item + 1); } else { x1 = dataArea.getMaxX(); y1 = dataArea.getMaxY(); } boolean useFillPaint = getUseFillPaint(); ; boolean drawOutlines = getDrawOutlines(); if (!java.lang.Double.isNaN(y0)) { double transX1; double transY1; if (item < dataset.getItemCount(series) - 1) { transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); } else { transX1 = x1; transY1 = y1; } Line2D line = state.workingLine; if (orientation == PlotOrientation.HORIZONTAL) { line.setLine(transY0, transX0, transY0, transX1); g2.draw(line); } else if (orientation == PlotOrientation.VERTICAL) { line.setLine(transX0, transY0, transX1, transY0); g2.draw(line); } } if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) shape = ShapeUtilities.createTranslatedShape(shape, transY0, transX0); else if (orientation == PlotOrientation.VERTICAL) shape = ShapeUtilities.createTranslatedShape(shape, transX0, transY0); if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (useFillPaint) g2.setPaint(getItemFillPaint(series, item)); else g2.setPaint(getItemPaint(series, item)); g2.fill(shape); } if (drawOutlines) { if (getUseOutlinePaint()) g2.setPaint(getItemOutlinePaint(series, item)); else g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } if (isItemLabelVisible(series, item)) { double xx = transX0; double yy = transY0; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY0; yy = transX0; } drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y0 < 0.0D); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x0, y0, domainAxisIndex, rangeAxisIndex, transX0, transY0, orientation); if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { int r = getDefaultEntityRadius(); java.awt.Shape shape = orientation != PlotOrientation.VERTICAL ? ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transY0 - (double) r, transX0 - (double) r, 2 * r, 2 * r))) : ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transX0 - (double) r, transY0 - (double) r, 2 * r, 2 * r))); if (shape != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) tip = generator.generateToolTip(dataset, series, item); String url = null; if (getURLGenerator() != null) url = getURLGenerator().generateURL(dataset, series, item); XYItemEntity entity = new XYItemEntity(shape, dataset, series, item, tip, url); entities.add(entity); } } } }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * {@inheritDoc}//www.j av a 2 s . c o m */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); if (message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING || message.getSeverity() == MaritimeTextingNotificationSeverity.ALERT || message.getSeverity() == MaritimeTextingNotificationSeverity.SAFETY) { g2.setStroke(new BasicStroke(2.0f)); switch (message.getSeverity()) { case WARNING: g2.setColor(WARN_COLOR); case ALERT: g2.setColor(ALERT_COLOR); case SAFETY: g2.setColor(SAFETY_COLOR); default: g2.setColor(WARN_COLOR); } // g2.setColor(message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING ? WARN_COLOR : ALERT_COLOR); g2.draw(area); } }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected void paintSelectionRectangle(final Graphics2D g2) { final Point origin = selectionHandler.getSelectionRectangleOrigin(); final Point target = selectionHandler.getSelectionRectangleTarget(); if (origin == null || target == null) { return;/* w w w.j a v a2 s . c o m*/ } g2.setColor(Color.BLUE); g2.setStroke(SELECTION_STROKE); final double y1 = Math.min(origin.getY(), target.getY()); final double x1 = Math.min(origin.getX(), target.getX()); final double y2 = Math.max(origin.getY(), target.getY()); final double x2 = Math.max(origin.getX(), target.getX()); g2.draw(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1)); }