List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:peakmlviewer.dialog.timeseries.EditableChart.java
public void mouseDragged(MouseEvent event) { if (entity != null) { // calculate the new value Point curpoint = event.getPoint(); Rectangle2D plotrect = panel.getChartRenderingInfo().getPlotInfo().getPlotArea(); double value = (Double) dataset.getValue(entity.getRowKey(), entity.getColumnKey()); double newvalue = value - (curpoint.y - prevpoint.y) / plotrect.getHeight(); if (newvalue < 0) newvalue = 0;//from w w w. j a v a 2s .co m else if (newvalue > 1) newvalue = 1; dataset.setValue(newvalue, entity.getRowKey(), entity.getColumnKey()); // set the prevpos to the curpos prevpoint = curpoint; } }
From source file:com.neophob.sematrix.core.generator.Textwriter.java
/** * create image.//from w ww .j a v a 2s .c om * * @param text the text */ public void createTextImage(String text) { //only load if needed if (StringUtils.equals(text, this.text)) { return; } this.text = text; BufferedImage img = new BufferedImage(TEXT_BUFFER_X_SIZE, internalBufferYSize, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); FontRenderContext frc = g2.getFontRenderContext(); TextLayout layout = new TextLayout(text, font, frc); Rectangle2D rect = layout.getBounds(); int h = (int) (0.5f + rect.getHeight()); //head and tailing space maxXPos = (int) (0.5f + rect.getWidth()) + 2 * internalBufferXSize; int ypos = internalBufferYSize - (internalBufferYSize - h) / 2; img = new BufferedImage(maxXPos, internalBufferYSize, BufferedImage.TYPE_BYTE_GRAY); g2 = img.createGraphics(); g2.setColor(new Color(128)); g2.setFont(font); g2.setClip(0, 0, maxXPos, internalBufferYSize); g2.drawString(text, internalBufferXSize, ypos); DataBufferByte dbi = (DataBufferByte) img.getRaster().getDataBuffer(); byte[] textBuffer = dbi.getData(); g2.dispose(); xofs = 0; textAsImage = new int[maxXPos * internalBufferYSize]; for (int i = 0; i < textAsImage.length; i++) { if (textBuffer[i] > 10) { textAsImage[i] = 127; } else { textAsImage[i] = 0; } } //clear internalbuffer Arrays.fill(this.internalBuffer, 0); }
From source file:org.locationtech.udig.mapgraphic.scale.ScaleDenomMapGraphic.java
public void draw(MapGraphicContext context) { ViewportGraphics g = context.getGraphics(); IBlackboard mapblackboard = context.getMap().getBlackboard(); double scaleDenom = context.getViewportModel().getScaleDenominator(); // scale may be set by printing engine Object value = mapblackboard.get("scale"); //$NON-NLS-1$ if (value != null && value instanceof Double) { scaleDenom = ((Double) value).doubleValue(); }//w w w.j ava2 s. c om FontStyle fs = getFontStyle(context); g.setFont(fs.getFont()); Point loc = getGraphicLocation(context); ScaleDenomStyle background = getStyle(context); String denomStr = NUMBER_FORMAT.format(scaleDenom); String str = "1:" + denomStr; //$NON-NLS-1$ //check if a prefix is provided if (StringUtils.trimToNull(background.getLabel()) != null) { str = background.getLabel() + " " + str; } Rectangle2D bnds = g.getStringBounds(str); int x = loc.x; int y = loc.y; if (x < 0) { x = context.getMapDisplay().getWidth() + x - (int) bnds.getWidth(); } if (y < 0) { y = context.getMapDisplay().getHeight() + y - (int) bnds.getHeight(); } //draw rectangle if (background.getColor() != null) { context.getGraphics().setColor(background.getColor()); g.fillRect(x - 2, y - 2, (int) bnds.getWidth() + 4, (int) bnds.getHeight() + 4); } g.setColor(fs.getColor()); g.drawString(str, x + (int) bnds.getWidth() / 2, y + (g.getFontHeight() - g.getFontAscent()), ViewportGraphics.ALIGN_MIDDLE, ViewportGraphics.ALIGN_MIDDLE); }
From source file:haven.Utils.java
static Coord textsz(Graphics g, String text) { java.awt.FontMetrics m = g.getFontMetrics(); java.awt.geom.Rectangle2D ts = m.getStringBounds(text, g); return (new Coord((int) ts.getWidth(), (int) ts.getHeight())); }
From source file:com.epiq.bitshark.ui.FrequencyDomainMouseMarker.java
/** * Draws the marker/* w w w . j a va 2 s . c o m*/ * @param g2 * @param rect */ public void draw(Graphics2D g2, Rectangle2D rect) { g2.setColor(outlineColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fillOval((int) Math.round(rect.getX()), (int) Math.round(rect.getY()), (int) Math.round(rect.getWidth()), (int) Math.round(rect.getHeight())); }
From source file:Clip.java
/** * Set the clip contents, and set the status to valid and in use. * @param r the clip contents to copy/*from w w w . ja v a 2 s.c o m*/ */ public void setClip(Rectangle2D r) { setClip(r.getX(), r.getY(), r.getWidth(), r.getHeight()); }
From source file:org.jfree.experimental.chart.plot.dial.SimpleDialFrame.java
/** * Returns the shape for the window for this dial. Some dial layers will * request that their drawing be clipped within this window. * * @param frame the reference frame (<code>null</code> not permitted). * * @return The shape of the dial's window. *//*from ww w . j ava2s. c om*/ public Shape getWindow(Rectangle2D frame) { Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); return new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight()); }
From source file:ucar.unidata.idv.control.chart.MyTimeSeriesPlot.java
/** * Override this method because it gets called after the graphics clip * has been reset./*from w ww .j a va2 s. c o m*/ * TODO: We end up drawing the annotations twice. Figure something out to * only draw once. * * @param g2 the graphics * @param dataArea the data area */ public void drawOutline(Graphics2D g2, Rectangle2D dataArea) { super.drawOutline(g2, dataArea); Shape originalClip = g2.getClip(); double y = dataArea.getY(); Rectangle2D.Double newClip = new Rectangle2D.Double(dataArea.getX(), 0, dataArea.getWidth(), dataArea.getHeight() + y); g2.clip(newClip); drawAnnotations(g2, dataArea, null); g2.clip(originalClip); }
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 va2s .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:org.uva.itast.blended.omr.scanners.BarcodeScanner.java
/** * Generates an expanded boundingbox in milimeters * /*from w ww.j av a 2s. c om*/ * @see {@link #BARCODE_AREA_PERCENT} * @see {@value #BARCODE_AREA_PERCENT} * @param rect * @return milimeteres */ protected Rectangle2D getExpandedArea(Rectangle2D rect, double percent) { Rectangle expandedRect = new Rectangle(); expandedRect.setFrame((rect.getX() - rect.getWidth() * (percent) / 2), (rect.getY() - rect.getHeight() * (percent) / 2), (rect.getWidth() * (1 + percent)), (rect.getHeight() * (1 + percent))); return expandedRect; }