List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
private void renderPopup(HashMap<String, Object> pPopupInfo, Graphics2D pG2D) { Point location = (Point) pPopupInfo.get("popup.location"); String label = (String) pPopupInfo.get("popup.label"); if (location == null || label == null) { return;// w ww . java 2 s .c o m } pG2D.setColor(new Color(255, 255, 204)); Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(label, pG2D); pG2D.fillRect(location.x, location.y - (int) labelBounds.getHeight(), (int) labelBounds.getWidth() + 5, (int) labelBounds.getHeight() + 5); pG2D.setColor(Color.BLACK); pG2D.drawRect(location.x, location.y - (int) labelBounds.getHeight(), (int) labelBounds.getWidth() + 5, (int) labelBounds.getHeight() + 5); pG2D.drawString(label, location.x + 2, location.y); }
From source file:XMLWriteTest.java
/** * Writers an SVG document of the current drawing. * @param writer the document destination *///from ww w .ja va2 s.co m public void writeDocument(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartDocument(); writer.writeDTD("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20000802//EN\" " + "\"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd\">"); writer.writeStartElement("svg"); writer.writeAttribute("width", "" + getWidth()); writer.writeAttribute("height", "" + getHeight()); for (int i = 0; i < rects.size(); i++) { Color c = colors.get(i); Rectangle2D r = rects.get(i); writer.writeEmptyElement("rect"); writer.writeAttribute("x", "" + r.getX()); writer.writeAttribute("y", "" + r.getY()); writer.writeAttribute("width", "" + r.getWidth()); writer.writeAttribute("height", "" + r.getHeight()); writer.writeAttribute("fill", colorToString(c)); } writer.writeEndDocument(); // closes svg element }
From source file:com.epiq.bitshark.ui.IVQPanel.java
public IVQPanel() { initComponents();/*from w w w .j a v a2s .c o m*/ initGraph(); JPanel holderPanel = new JPanel() { @Override public void paint(Graphics g) { Range newDomain = null; // x Range newRange = null; // y Range currentDomainRange = plot.getDomainAxis().getRange(); Range currentRangeRange = plot.getRangeAxis().getRange(); if (plot.getDomainAxis().isAutoRange()) { plot.getDomainAxis().setAutoRange(false); } if (plot.getRangeAxis().isAutoRange()) { plot.getRangeAxis().setAutoRange(false); } Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double width = dataArea.getWidth(); double height = dataArea.getHeight(); double domainScale = 1; double rangeScale = 1; // scale the domain values up to match the pixels if (width > height) { domainScale = width / height; double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound(); newDomain = new Range(-(extent * domainScale) / 2, (extent * domainScale) / 2); } else if (height > width) { rangeScale = height / width; double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound(); newRange = new Range(-(extent * rangeScale) / 2, (extent * rangeScale) / 2); } if (newDomain == null) { double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound(); newDomain = new Range(-(extent) / 2, (extent) / 2); } if (newRange == null) { double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound(); newRange = new Range(-(extent) / 2, (extent) / 2); } if (newDomain != null) { plot.getDomainAxis().setRange(newDomain, true, false); } if (newRange != null) { plot.getRangeAxis().setRange(newRange, true, false); } Graphics2D g2 = (Graphics2D) g.create(); super.paint(g2); g2.dispose(); } }; holderPanel.setLayout(new BorderLayout()); holderPanel.add(chartPanel, BorderLayout.CENTER); mainPanel.add(holderPanel, BorderLayout.CENTER); headerPanel.setBackgroundPainter(Common.getHeaderPainter()); chartLabel.setUI(new BasicLabelUI()); }
From source file:org.jfree.chart.demo.GanttRenderer2.java
protected double calculateBarW0(CategoryPlot categoryplot, PlotOrientation plotorientation, Rectangle2D rectangle2d, CategoryAxis categoryaxis, CategoryItemRendererState categoryitemrendererstate, int i, int j) { double d = 0.0D; if (plotorientation == PlotOrientation.HORIZONTAL) d = rectangle2d.getHeight(); else//from w ww . j ava 2 s .com d = rectangle2d.getWidth(); double d1 = categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()); int k = getRowCount(); int l = getColumnCount(); if (k > 1) { double d2 = (d * getItemMargin()) / (double) (l * (k - 1)); double d3 = calculateSeriesWidth(d, categoryaxis, l, k); d1 = (d1 + (double) i * (d3 + d2) + d3 / 2D) - categoryitemrendererstate.getBarWidth() / 2D; } else { d1 = categoryaxis.getCategoryMiddle(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()) - categoryitemrendererstate.getBarWidth() / 2D; } return d1; }
From source file:savant.view.tracks.TrackRenderer.java
/** * Simplest kind of legend is just a list of coloured lines with names next to them. *///www . ja va 2 s.c o m protected void drawSimpleLegend(Graphics2D g2, int x, int y, ColourKey... keys) { ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); g2.setFont(LEGEND_FONT); for (ColourKey k : keys) { String legendString = k.getName(); g2.setColor(cs.getColor(k)); g2.setStroke(TWO_STROKE); Rectangle2D stringRect = LEGEND_FONT.getStringBounds(legendString, g2.getFontRenderContext()); g2.drawLine(x - 25, y - (int) stringRect.getHeight() / 2, x - 5, y - (int) stringRect.getHeight() / 2); g2.setColor(cs.getColor(ColourKey.INTERVAL_LINE)); g2.setStroke(ONE_STROKE); g2.drawString(legendString, x, y); y += LEGEND_LINE_HEIGHT; } }
From source file:gda.plots.BlockWrapper.java
/** * JFreeChart will actually call this from its drawTitle method expecting the Block to draw itself at this point. * Our JComponent will already have been drawn as a consequence of being a simple child of the ChartPanel (which * extends JPanel). However we can use the information passed to the Block here to get the JComponents bounds set * correctly.//from w ww . ja va2s . com * * @param g2 * the Graphics2D into which to draw (not used here) * @param area * the Rectangle2D into which the object should draw itself) * @param params * some parameters not yet understood * @return an Object else null */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { logger.debug("BW area is " + area); logger.debug("BW params is " + params); logger.debug("BW g2 is " + g2); logger.debug("BW g2.transform is " + g2.getTransform()); jc.setBounds((int) Math.round(area.getX()), (int) Math.round(area.getY()), (int) Math.round(area.getWidth()), (int) Math.round(area.getHeight())); return null; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java
private AbstractImageMapEntry createMapEntry(final Shape area, final Rectangle2D dataArea) { if (buggyDrawArea) { if (area instanceof Ellipse2D) { final Ellipse2D ellipse2D = (Ellipse2D) area; if (ellipse2D.getWidth() == ellipse2D.getHeight()) { return new CircleImageMapEntry((float) (ellipse2D.getCenterX() + dataArea.getX()), (float) (ellipse2D.getCenterY() + dataArea.getY()), (float) (ellipse2D.getWidth() / 2)); }//from w w w .j a v a 2s. co m } else if (area instanceof Rectangle2D) { final Rectangle2D rect = (Rectangle2D) area; return (new RectangleImageMapEntry((float) (rect.getX() + dataArea.getX()), (float) (rect.getY() + dataArea.getY()), (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight()))); } } else { if (area instanceof Ellipse2D) { final Ellipse2D ellipse2D = (Ellipse2D) area; if (ellipse2D.getWidth() == ellipse2D.getHeight()) { return new CircleImageMapEntry((float) (ellipse2D.getCenterX()), (float) (ellipse2D.getCenterY()), (float) (ellipse2D.getWidth() / 2)); } } else if (area instanceof Rectangle2D) { final Rectangle2D rect = (Rectangle2D) area; return (new RectangleImageMapEntry((float) (rect.getX()), (float) (rect.getY()), (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight()))); } } final Area a = new Area(area); if (buggyDrawArea) { a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY())); } if (dataArea.isEmpty() == false) { a.intersect(new Area(dataArea)); } final PathIterator pathIterator = a.getPathIterator(null, 2); final FloatList floats = new FloatList(100); final float[] coords = new float[6]; while (pathIterator.isDone() == false) { final int retval = pathIterator.currentSegment(coords); if (retval == PathIterator.SEG_MOVETO || retval == PathIterator.SEG_LINETO) { floats.add(coords[0]); floats.add(coords[1]); } pathIterator.next(); } if (floats.size() == 0) { return null; } return (new PolygonImageMapEntry(floats.toArray())); }
From source file:org.pentaho.reporting.libraries.pixie.wmf.WmfFile.java
public synchronized void draw(final Graphics2D graphics, final Rectangle2D bounds) { // this adjusts imageWidth and imageHeight scaleToFit((float) bounds.getWidth(), (float) bounds.getHeight()); // adjust translation if needed ... graphics.translate(bounds.getX(), bounds.getY()); // adjust to the image origin graphics.translate(-imageX, -imageY); this.graphics = graphics; for (int i = 0; i < records.size(); i++) { try {//from w w w. j a v a2s. c om final MfCmd command = (MfCmd) records.get(i); command.setScale((float) imageWidth / (float) maxWidth, (float) imageHeight / (float) maxHeight); command.replay(this); } catch (Exception e) { logger.warn("Error while processing image record #" + i, e); } } resetStates(); }
From source file:XMLWriteTest.java
/** * Creates an SVG document of the current drawing. * @return the DOM tree of the SVG document *///www . j a v a 2 s . c o m public Document buildDocument() { Document doc = builder.newDocument(); Element svgElement = doc.createElement("svg"); doc.appendChild(svgElement); svgElement.setAttribute("width", "" + getWidth()); svgElement.setAttribute("height", "" + getHeight()); for (int i = 0; i < rects.size(); i++) { Color c = colors.get(i); Rectangle2D r = rects.get(i); Element rectElement = doc.createElement("rect"); rectElement.setAttribute("x", "" + r.getX()); rectElement.setAttribute("y", "" + r.getY()); rectElement.setAttribute("width", "" + r.getWidth()); rectElement.setAttribute("height", "" + r.getHeight()); rectElement.setAttribute("fill", colorToString(c)); svgElement.appendChild(rectElement); } return doc; }
From source file:gda.plots.DataMagnifierWindow.java
/** * The SimplePlot will call this method when the Rectangle to be magnified has changed. * /*w w w . j a va 2 s .c o m*/ * @param magnifyRectangle * the Rectangle to be magnified */ @Override public void update(Rectangle2D magnifyRectangle) { // The magnifyRectangle will be in Java coordinates, need to calculate // the axis limits required. This mechanism was copied from the zooming // methods within JFreeChart. double hLower = 0.0; double hUpper = 0.0; double vLower = 0.0; double vUpper = 0.0; double a; double b; Rectangle2D scaledDataArea; if (magnifyRectangle != null) { scaledDataArea = simplePlot.getScreenDataArea(); hLower = (magnifyRectangle.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); hUpper = (magnifyRectangle.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); vLower = (scaledDataArea.getMaxY() - magnifyRectangle.getMaxY()) / scaledDataArea.getHeight(); vUpper = (scaledDataArea.getMaxY() - magnifyRectangle.getMinY()) / scaledDataArea.getHeight(); Range r = simplePlot.getChart().getXYPlot().getDomainAxis().getRange(); a = r.getLowerBound() + hLower * r.getLength(); b = r.getLowerBound() + hUpper * r.getLength(); Range newR = new Range(Math.min(a, b), Math.max(a, b)); magnifiedPlot.getDomainAxis().setRange(newR); r = simplePlot.getChart().getXYPlot().getRangeAxis().getRange(); a = r.getLowerBound() + vLower * r.getLength(); b = r.getLowerBound() + vUpper * r.getLength(); newR = new Range(Math.min(a, b), Math.max(a, b)); magnifiedPlot.getRangeAxis().setRange(newR); repaint(); } }