List of usage examples for java.awt Graphics2D fill
public abstract void fill(Shape s);
From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java
/** * Draws the visual representation of a single wind arrow. */// ww w . j a v a 2s . co m @Override public void drawItem(Graphics2D g2d, XYItemRendererState state, Rectangle2D plotArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { resizeArrowByPlotHeight((int) plotArea.getHeight()); // Needs a new graphics object to use translate() and rotate() Graphics2D g2 = (Graphics2D) g2d.create(); g2.setRenderingHints(renderHints); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); double middleY = plotArea.getCenterY(); WindDataset windData = (WindDataset) dataset; Number x = windData.getX(series, item); Number windDir = windData.getWindDirection(series, item); Number wforce = windData.getWindForce(series, item); double middleX = domainAxis.valueToJava2D(x.doubleValue(), plotArea, domainAxisLocation); g2.translate((int) middleX, (int) middleY); g2.setColor(Color.BLACK); if (wforce.doubleValue() <= zeroWindLimit) { drawCircle(g2); } else { g2.rotate(Math.toRadians(windDir.doubleValue() - 180)); drawArrow(g2, wforce.doubleValue()); if (useArrowHead) { g2.fill(getPolygonHead(arrowHeadSize, arrowHeight)); } else { g2.draw(getCircleHead(arrowHeadSize, arrowHeight)); } } }
From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java
private double drawMean(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, ValueAxis rangeAxis, int row, int column, BoxAndWhiskerCategoryDataset bawDataset, double xx, double aRadius, RectangleEdge location) { double yyAverage; double newARadius = aRadius; // draw mean - SPECIAL AIMS REQUIREMENT... Number yMean = bawDataset.getMeanValue(row, column); if (yMean != null) { yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location); newARadius = state.getBarWidth() / 4; Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx + aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2);//from w w w. j a v a2 s . co m g2.fill(avgEllipse); g2.draw(avgEllipse); } return newARadius; }
From source file:org.gumtree.vis.awt.CompositePanel.java
@Override public BufferedImage getImage() { BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D gc2 = image.createGraphics(); gc2.setBackground(Color.white); gc2.setPaint(Color.white);//from ww w .j a v a 2 s. c o m gc2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight())); for (IPlot plot : plotList) { if (plot instanceof JPanel) { JPanel panel = (JPanel) plot; Rectangle2D panelBounds = panel.getBounds(); Image panelImage = plot.getImage(); gc2.drawImage(panelImage, (int) panelBounds.getMinX(), (int) panelBounds.getMinY(), panel); } } gc2.dispose(); return image; }
From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialValueIndicator.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). *//*ww w. ja v a 2 s. co m*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius()); Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.getFont()); String s = this.getNumberFormat().format(this.getTemplateValue()); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.getFrameAnchor()); // add the insets Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds); // draw the background g2.setPaint(this.getBackgroundPaint()); g2.fill(fb); // draw the border g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(fb); // now find the text anchor point String valueStr = this.getNumberFormat() .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale)); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor()); g2.setPaint(this.getPaint()); g2.setFont(this.getFont()); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor()); }
From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialValueIndicator.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 . com @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius()); Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.getFont()); String s = this.getNumberFormat().format(this.getTemplateValue()); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.getFrameAnchor()); // add the insets Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds); // draw the background g2.setPaint(this.getBackgroundPaint()); g2.fill(fb); // draw the border g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(fb); // now find the text anchor point String valueStr = this.getNumberFormat() .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale)); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor()); g2.setPaint(this.getPaint()); g2.setFont(this.getFont()); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor()); }
From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.AngularHistogramRenderer.java
@Override public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex) { // compute the right color for the paint int length = GuiUtils.getAvailableColors().length; Color color = GuiUtils.getAvailableColors()[index % length]; // get all the data points int numPoints = dataset.getItemCount(seriesIndex); for (int i = 0; i < numPoints; i++) { double theta = dataset.getXValue(seriesIndex, i); // the angle at the center double radius = dataset.getYValue(seriesIndex, i); // the frequency Point p0 = plot.translateToJava2D(0, 0, plot.getAxis(), dataArea); Point p1 = plot.translateToJava2D(theta - binSize, radius, plot.getAxis(), dataArea); Point p2 = plot.translateToJava2D(theta + binSize, radius, plot.getAxis(), dataArea); Polygon poly = new Polygon(new int[] { p0.x, p1.x, p2.x }, new int[] { p0.y, p1.y, p2.y }, 3); g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175)); g2.fill(poly); }//from w ww. j a va 2 s . c o m }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (getChart() == null) { return;/*from ww w .j av a2 s.c o m*/ } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); setChartFieldValue(getChartFieldByName("scaleX"), 1.0); // this.scaleX = 1.0; setChartFieldValue(getChartFieldByName("scaleY"), 1.0); // this.scaleY = 1.0; if (drawWidth < getMinimumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMinimumDrawWidth()); // this.scaleX = drawWidth / getMinimumDrawWidth(); drawWidth = getMinimumDrawWidth(); scale = true; } else if (drawWidth > getMaximumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMaximumDrawWidth()); // this.scaleX = drawWidth / getMaximumDrawWidth(); drawWidth = getMaximumDrawWidth(); scale = true; } if (drawHeight < getMinimumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMinimumDrawHeight()); // this.scaleY = drawHeight / getMinimumDrawHeight(); drawHeight = getMinimumDrawHeight(); scale = true; } else if (drawHeight > getMaximumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMaximumDrawHeight()); // this.scaleY = drawHeight / getMaximumDrawHeight(); drawHeight = getMaximumDrawHeight(); scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if ((Boolean) getChartFieldValueByName("useBuffer")) { // do we need to resize the buffer? if ((getChartFieldValueByName("chartBuffer") == null) || ((Integer) getChartFieldValueByName("chartBufferWidth") != available.getWidth()) || ((Integer) getChartFieldValueByName("chartBufferHeight") != available.getHeight())) { setChartFieldValue(getChartFieldByName("chartBufferWidth"), (int) available.getWidth()); // this.chartBufferWidth = (int) available.getWidth(); setChartFieldValue(getChartFieldByName("chartBufferHeight"), (int) available.getHeight()); // this.chartBufferHeight = (int) available.getHeight(); GraphicsConfiguration gc = g2.getDeviceConfiguration(); setChartFieldValue(getChartFieldByName("chartBuffer"), gc.createCompatibleImage((Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight"), Transparency.TRANSLUCENT)); // this.chartBuffer = gc.createCompatibleImage(this.chartBufferWidth, // this.chartBufferHeight, Transparency.TRANSLUCENT); setRefreshBuffer(true); } // do we need to redraw the buffer? if (getRefreshBuffer()) { setRefreshBuffer(false); // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); Graphics2D bufferG2 = (Graphics2D) ((Image) getChartFieldValueByName("chartBuffer")).getGraphics(); Rectangle r = new Rectangle(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); bufferG2.setPaint(getBackground()); bufferG2.fill(r); if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance( (Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); bufferG2.transform(st); getChart().draw(bufferG2, chartArea, getAnchor(), getChartRenderingInfo()); bufferG2.setTransform(saved); } else { getChart().draw(bufferG2, bufferArea, getAnchor(), getChartRenderingInfo()); } } // zap the buffer onto the panel... g2.drawImage((Image) getChartFieldValueByName("chartBuffer"), insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance((Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); g2.transform(st); } getChart().draw(g2, chartArea, getAnchor(), getChartRenderingInfo()); g2.setTransform(saved); } Iterator iterator = ((List) getChartFieldValueByName("overlays")).iterator(); while (iterator.hasNext()) { Overlay overlay = (Overlay) iterator.next(); overlay.paintOverlay(g2, this); } // redraw the zoom rectangle (if present) - if useBuffer is false, // we use XOR so we can XOR the rectangle away again without redrawing // the chart drawZoomRectangle(g2, !(Boolean) getChartFieldValueByName("useBuffer")); g2.dispose(); setAnchor(null); setVerticalTraceLine(null); setHorizontalTraceLine(null); }
From source file:org.openaltimeter.desktopapp.annotations.XYHeightAnnotation.java
@Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); float anchorX = (float) domainAxis.valueToJava2D(this.getX(), dataArea, domainEdge); float anchorY = (float) rangeAxis.valueToJava2D(this.getY(), dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { float tempAnchor = anchorX; anchorX = anchorY;//from w w w . j a va2 s. com anchorY = tempAnchor; } g2.setFont(getFont()); Shape hotspot = TextUtilities.calculateRotatedStringBounds(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (this.getBackgroundPaint() != null) { g2.setPaint(this.getBackgroundPaint()); g2.fill(hotspot); } g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX + (3.6f * DOT_SIZE), anchorY + (0.2f * DOT_SIZE), getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (this.isOutlineVisible()) { g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(hotspot); } // cross drawing // g2.setPaint(getPaint()); // g2.setStroke(new BasicStroke(1.0f)); // g2.drawLine((int) anchorX - CROSS_SIZE / 2, (int) anchorY, (int) anchorX + CROSS_SIZE / 2, (int) anchorY); // g2.drawLine((int) anchorX, (int) anchorY - CROSS_SIZE / 2, (int) anchorX, (int) anchorY + CROSS_SIZE / 2); // dot drawing g2.setPaint(getPaint()); g2.setStroke(new BasicStroke(1.0f)); Ellipse2D e = new Ellipse2D.Double(anchorX - DOT_SIZE / 2, anchorY - DOT_SIZE / 2, DOT_SIZE, DOT_SIZE); g2.fill(e); String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, hotspot, rendererIndex, toolTip, url); } }
From source file:StrokeChooserPanel.java
/** * Draws a line using the sample stroke. * * @param g the graphics device./*from w ww . j a va 2 s .co m*/ */ public void paintComponent(final Graphics g) { final Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final Dimension size = getSize(); final Insets insets = getInsets(); final double xx = insets.left; final double yy = insets.top; final double ww = size.getWidth() - insets.left - insets.right; final double hh = size.getHeight() - insets.top - insets.bottom; // calculate point one final Point2D one = new Point2D.Double(xx + 6, yy + hh / 2); // calculate point two final Point2D two = new Point2D.Double(xx + ww - 6, yy + hh / 2); // draw a circle at point one final Ellipse2D circle1 = new Ellipse2D.Double(one.getX() - 5, one.getY() - 5, 10, 10); final Ellipse2D circle2 = new Ellipse2D.Double(two.getX() - 6, two.getY() - 5, 10, 10); // draw a circle at point two g2.draw(circle1); g2.fill(circle1); g2.draw(circle2); g2.fill(circle2); // draw a line connecting the points final Line2D line = new Line2D.Double(one, two); if (this.stroke != null) { g2.setStroke(this.stroke); g2.draw(line); } }
From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java
@Override public void resetView() { AttackManager.getSingleton().addManagerListener(this); //setup renderer and general view // ((DoItYourselfAttackTableModel) jAttackTable.getModel()).clear(); HighlightPredicate.ColumnHighlightPredicate colu = new HighlightPredicate.ColumnHighlightPredicate(0, 1, 2, 3, 6);/* w ww. ja va2 s. c om*/ jAttackTable.setRowHeight(24); jAttackTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer()); jAttackTable.setHighlighters(new CompoundHighlighter(colu, HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B))); jAttackTable.setColumnControlVisible(true); jAttackTable.setDefaultEditor(UnitHolder.class, new UnitCellEditor()); jAttackTable.setDefaultEditor(Village.class, new VillageCellEditor()); jAttackTable.setDefaultRenderer(UnitHolder.class, new UnitCellRenderer()); jAttackTable.setDefaultRenderer(Integer.class, new NoteIconCellRenderer(NoteIconCellRenderer.ICON_TYPE.NOTE)); jAttackTable.setDefaultRenderer(Date.class, new ColoredDateCellRenderer()); jAttackTable.setDefaultRenderer(Long.class, new ColoredCoutdownCellRenderer()); jAttackTable.setDefaultEditor(Date.class, new DateSpinEditor()); jAttackTable.setDefaultEditor(Integer.class, new NoteIconCellEditor(NoteIconCellEditor.ICON_TYPE.NOTE)); BufferedImage back = ImageUtils.createCompatibleBufferedImage(5, 5, BufferedImage.BITMASK); Graphics2D g = back.createGraphics(); GeneralPath p = new GeneralPath(); p.moveTo(0, 0); p.lineTo(5, 0); p.lineTo(5, 5); p.closePath(); g.setColor(Color.GREEN.darker()); g.fill(p); g.dispose(); jAttackTable.addHighlighter(new PainterHighlighter(HighlightPredicate.EDITABLE, new ImagePainter(back, HorizontalAlignment.RIGHT, VerticalAlignment.TOP))); DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel model2 = new DefaultComboBoxModel(); for (UnitHolder unit : DataHolder.getSingleton().getUnits()) { model.addElement(unit); model2.addElement(unit); } jUnitBox.setModel(model); jUnitComboBox.setModel(model2); jUnitBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram")); jUnitComboBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram")); jUnitBox.setRenderer(new UnitListCellRenderer()); jAttackTypeComboBox.setRenderer(new StandardAttackListCellRenderer()); DefaultComboBoxModel typeModel = new DefaultComboBoxModel(); for (ManageableType t : StandardAttackManager.getSingleton().getAllElements()) { StandardAttack a = (StandardAttack) t; typeModel.addElement(a); } jAttackTypeComboBox.setModel(typeModel); jUnitComboBox.setRenderer(new UnitListCellRenderer()); jSourceVillage.setValue(new Point(500, 500)); jTargetVillage.setValue(new Point(500, 500)); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jSourceVillage.updateUI(); jTargetVillage.updateUI(); } }); }