List of usage examples for java.awt.geom Rectangle2D getWidth
public abstract double getWidth();
From source file:net.fenyo.gnetwatch.GUI.BasicComponent.java
/** * Paints axis.// ww w .jav a 2s . co m * @param none. * @return long current time displayed at the axis bottom. */ // AWT thread private long paintAxis() { backing_g.setColor(new Color(50, 50, 50)); backing_g.fillRect(axis_margin_left, axis_margin_top, dimension.width - axis_margin_left - axis_margin_right + 1, dimension.height - axis_margin_top - axis_margin_bottom + 1); backing_g.setColor(Color.YELLOW); backing_g.drawLine(axis_margin_left, dimension.height - axis_margin_bottom, dimension.width - axis_margin_right, dimension.height - axis_margin_bottom); backing_g.drawLine(axis_margin_left, axis_margin_top, axis_margin_left, dimension.height - axis_margin_bottom); backing_g.setColor(Color.YELLOW.darker()); backing_g.drawLine(axis_margin_left + 1, axis_margin_top, dimension.width - axis_margin_right, axis_margin_top); backing_g.drawLine(dimension.width - axis_margin_right, axis_margin_top, dimension.width - axis_margin_right, dimension.height - axis_margin_bottom - 1); int vinterval_pos = dimension.height - axis_margin_bottom - pixels_per_vinterval; backing_g.setColor(Color.YELLOW.darker().darker().darker()); while (vinterval_pos + 9 * (pixels_per_vinterval / 10) > axis_margin_top) { int cpt = 10; while (--cpt > 0) if (vinterval_pos + cpt * (pixels_per_vinterval / 10) > axis_margin_top) backing_g.drawLine(axis_margin_left + 1, vinterval_pos + cpt * (pixels_per_vinterval / 10), dimension.width - axis_margin_right - 1, vinterval_pos + cpt * (pixels_per_vinterval / 10)); vinterval_pos -= pixels_per_vinterval; } final long now; if (manual_mode) now = manual_now; else now = System.currentTimeMillis(); final long time_to_display = now - now % _getDelayPerInterval(); final int pixels_offset = (pixels_per_interval * (int) (now % _getDelayPerInterval())) / (int) _getDelayPerInterval(); final int last_interval_pos = dimension.width - axis_margin_right - pixels_offset; backing_g.setClip(axis_margin_left, 0, dimension.width - axis_margin_left - axis_margin_right, dimension.height); int current_interval_pos = last_interval_pos + pixels_per_interval; long current_time_to_display = time_to_display + _getDelayPerInterval(); boolean stop = false; while (stop == false) { backing_g.setColor(Color.YELLOW.darker()); backing_g.drawLine(current_interval_pos, axis_margin_top, current_interval_pos, dimension.height - axis_margin_bottom + std_separator); int cpt = 10; backing_g.setColor(Color.YELLOW.darker().darker().darker()); while (--cpt > 0) if (current_interval_pos - cpt * (pixels_per_interval / 10) > axis_margin_left) backing_g.drawLine(current_interval_pos - cpt * (pixels_per_interval / 10), axis_margin_top + 1, current_interval_pos - cpt * (pixels_per_interval / 10), dimension.height - axis_margin_bottom - 1); final String current_time_str = formatTime(current_time_to_display); final String current_date_str = formatDate(current_time_to_display); final TextLayout current_layout = new TextLayout(current_time_str, backing_g.getFont(), backing_g.getFontRenderContext()); final TextLayout current_layout_date = new TextLayout(current_date_str, backing_g.getFont(), backing_g.getFontRenderContext()); final Rectangle2D current_bounds = current_layout.getBounds(); final Rectangle2D current_bounds_date = current_layout_date.getBounds(); backing_g.setColor(Color.YELLOW.darker()); backing_g.drawString(current_time_str, current_interval_pos - (int) (current_bounds.getWidth() / 2), dimension.height - axis_margin_bottom + (int) current_bounds.getHeight() + 2 * std_separator); backing_g.setColor(Color.YELLOW.darker().darker()); backing_g.drawString(current_date_str, current_interval_pos - (int) (current_bounds_date.getWidth() / 2), 3 + ((int) current_bounds.getHeight()) + dimension.height - axis_margin_bottom + (int) current_bounds.getHeight() + 2 * std_separator); if (current_interval_pos - current_bounds.getWidth() / 2 < axis_margin_left) stop = true; current_interval_pos -= pixels_per_interval; current_time_to_display -= _getDelayPerInterval(); } backing_g.setClip(null); vinterval_pos = dimension.height - axis_margin_bottom - pixels_per_vinterval; int value = value_per_vinterval; while (vinterval_pos > axis_margin_top) { backing_g.setColor(Color.YELLOW.darker()); backing_g.drawLine(axis_margin_left - std_separator, vinterval_pos, dimension.width - axis_margin_right, vinterval_pos); final String value_str; if (value >= 1000000) value_str = "" + value / 1000000 + "M"; else if (value >= 1000) value_str = "" + value / 1000 + "k"; else value_str = "" + value; final TextLayout current_layout = new TextLayout(value_str, backing_g.getFont(), backing_g.getFontRenderContext()); final Rectangle2D current_bounds = current_layout.getBounds(); backing_g.setColor(Color.YELLOW.darker()); backing_g.drawString(value_str, axis_margin_left - (int) current_bounds.getWidth() - 2 * std_separator, vinterval_pos + (int) (current_bounds.getHeight() / 2)); vinterval_pos -= pixels_per_vinterval; value += value_per_vinterval; } return now; }
From source file:org.gumtree.vis.awt.CompositePanel.java
@Override public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) { Rectangle2D compositeBounds = getBounds(); double xRatio = area.getWidth() / compositeBounds.getWidth(); double yRatio = area.getHeight() / compositeBounds.getHeight(); for (IPlot plot : plotList) { if (plot instanceof JPanel) { Rectangle2D plotBounds = ((JPanel) plot).getBounds(); Rectangle2D newArea = new Rectangle2D.Double(area.getMinX() + plotBounds.getMinX() * xRatio, area.getMinY() + plotBounds.getMinY() * yRatio, plotBounds.getWidth() * xRatio, plotBounds.getHeight() * yRatio); plot.draw(g2, newArea, shiftX, shiftY); }/*from ww w . j a v a 2 s . c o m*/ } }
From source file:de.codesourcery.planning.swing.DateAxis.java
public BoundingBox render(ITimelineCallback callback, boolean layoutOnly) { final Calendar cal = Calendar.getInstance(); cal.setTime(startDate);//from w w w . j a v a 2 s . co m cal.set(Calendar.MILLISECOND, 0); Date currentDate = cal.getTime(); final Date endDate = duration.addTo(startDate); BoundingBox lastLabel = null; final int labelSpacing = 10; final Graphics2D graphics = callback.getGraphics(); final int fontHeight = graphics.getFontMetrics().getHeight(); final double scalingFactor = getXScalingFactor(callback.getBoundingBox()); final BoundingBox box = callback.getBoundingBox(); double x = callback.getBoundingBox().getX(); final int tickToLabelSpacing = 2; final int tickLength = fontHeight; final int axisHeight = fontHeight + tickLength + tickToLabelSpacing; final double xIncrement = Math.floor(tickDuration.toSeconds() * scalingFactor); final Color oldColor = graphics.getColor(); // while (currentDate.compareTo(endDate) <= 0) { final int currentX = (int) Math.floor(x); if (lastLabel == null || lastLabel.getMaxX() < x) { final String labelText = callback.getLabelProvider().getTimelineLabel(currentDate); if (!StringUtils.isBlank(labelText)) { final Rectangle2D stringBounds = callback.getStringBounds(labelText); if (!layoutOnly) { graphics.setColor(Color.BLACK); // draw tick final Stroke oldStroke = graphics.getStroke(); graphics.setStroke(new BasicStroke(2.0f)); graphics.drawLine(currentX, box.getY() + axisHeight, currentX, box.getY() + fontHeight + tickToLabelSpacing); graphics.setStroke(oldStroke); // draw label callback.drawString(Color.BLACK, currentX, box.getY(), labelText); } final BoundingBox labelBox = new BoundingBox(currentX, box.getY(), currentX + (int) stringBounds.getWidth() + labelSpacing, box.getY() + (int) stringBounds.getHeight()); if (lastLabel == null) { lastLabel = labelBox; } else { lastLabel.add(labelBox); } } } else { // draw short tick if (!layoutOnly) { final int halfTickHeight = (int) Math.floor(tickLength / 2.0d); graphics.drawLine(currentX, box.getY() + axisHeight, currentX, box.getY() + axisHeight - halfTickHeight); } } // draw part of axis if (!layoutOnly) { graphics.drawLine((int) x, box.getY() + axisHeight, (int) (x + xIncrement), box.getY() + axisHeight); } x += xIncrement; currentDate = tickDuration.addTo(currentDate); } callback.getGraphics().setColor(oldColor); final BoundingBox result = lastLabel != null ? lastLabel : new BoundingBox(0, 0, 0, 0); result.incHeight(axisHeight); return result; }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java
/** * Handles a mouse dragged event by updating the zoom rectangle displayed * in the ChartViewer./*from ww w . j a v a 2 s . com*/ * * @param canvas the JavaFX canvas (<code>null</code> not permitted). * @param e the mouse event (<code>null</code> not permitted). */ @Override public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) { if (this.startPoint == null) { //no initial zoom rectangle exists but the handler is set //as life handler unregister canvas.clearLiveHandler(); return; } boolean hZoom, vZoom; Plot p = canvas.getChart().getPlot(); if (!(p instanceof Zoomable)) { return; } Zoomable z = (Zoomable) p; if (z.getOrientation().isHorizontal()) { hZoom = z.isRangeZoomable(); vZoom = z.isDomainZoomable(); } else { hZoom = z.isDomainZoomable(); vZoom = z.isRangeZoomable(); } Rectangle2D dataArea = canvas.findDataArea(this.startPoint); double x = this.startPoint.getX(); double y = this.startPoint.getY(); double w = 0; double h = 0; if (hZoom && vZoom) { // selected rectangle shouldn't extend outside the data area... double xmax = Math.min(e.getX(), dataArea.getMaxX()); double ymax = Math.min(e.getY(), dataArea.getMaxY()); w = xmax - this.startPoint.getX(); h = ymax - this.startPoint.getY(); } else if (hZoom) { double xmax = Math.min(e.getX(), dataArea.getMaxX()); y = dataArea.getMinY(); w = xmax - this.startPoint.getX(); h = dataArea.getHeight(); } else if (vZoom) { double ymax = Math.min(e.getY(), dataArea.getMaxY()); x = dataArea.getMinX(); w = dataArea.getWidth(); h = ymax - this.startPoint.getY(); } viewer.showZoomRectangle(x, y, w, h); }
From source file:org.pentaho.di.core.gui.SwingDirectGC.java
public SwingDirectGC(Graphics2D gc, Rectangle2D rect, int iconsize, int xOffset, int yOffset) throws KettleException { this.image = null; this.gc = gc; this.observer = null; this.stepImages = SwingGUIResource.getInstance().getStepImages(); this.entryImages = SwingGUIResource.getInstance().getEntryImages(); this.iconsize = iconsize; this.area = new Point((int) rect.getWidth(), (int) rect.getHeight()); this.xOffset = xOffset; this.yOffset = yOffset; init();/* w w w . j a v a 2s . co m*/ }
From source file:net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.java
protected TextLine toTextLine(int measureIndex, Rectangle2D measuredBounds) { SimpleTextLine textLine = new SimpleTextLine(); textLine.setAscent((float) -measuredBounds.getY()); textLine.setDescent((float) (measuredBounds.getMaxY() - fontInfo.fontInfo.leading)); textLine.setLeading(fontInfo.fontInfo.leading); textLine.setCharacterCount(measureIndex - paragraphPosition); textLine.setAdvance((float) measuredBounds.getWidth()); textLine.setLeftToRight(paragraphLeftToRight); // update the paragraph position paragraphPosition = measureIndex;/*from w w w.j a v a2 s .c om*/ return textLine; }
From source file:de.codesourcery.planning.swing.PlanningCanvas.java
protected BoundingBox renderTitle(RenderContext ctx, boolean layoutOnly) { final String label = this.labelProvider.getTitle(); if (StringUtils.isBlank(label)) { return null; }/*from w w w . j av a2 s . c o m*/ final Rectangle2D labelBox = ctx.getLabelBounds(label); final int labelWidth = (int) labelBox.getWidth(); final int xCenter = ctx.viewport.getX() + (ctx.viewport.getWidth() / 2); final int xDraw = (int) Math.round(xCenter - (labelWidth / 2.0d)); final int yDraw = ctx.viewport.getY(); ctx.currentY += labelBox.getHeight() + ctx.options.getTitleYOffset(); if (!layoutOnly) { ctx.drawLabel(xDraw, yDraw, label); return null; } return createBoundingBox(ctx.viewport.getX(), ctx.viewport.getY(), labelBox) .incHeight(ctx.options.getTitleYOffset()); // include Y offset in bounding box }
From source file:com.lfx.web.WebChartXYPlot.java
/** * Draws the gridlines for the plot, if they are visible. *//from w w w . j a v a 2 s . c o m * @param g2 the graphics device. * @param dataArea the data area. * @param ticks the ticks. * * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List) */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { Composite oldcomp = g2.getComposite(); Paint bandPaint = getBackgroundPaint(); if (bandPaint != null && bandPaint instanceof java.awt.Color) { // g2.setComposite(AlphaComposite.SrcO); java.awt.Color bandcolor = (java.awt.Color) (bandPaint); boolean fillBand = false; ValueAxis axis = getRangeAxis(); double previous = axis.getLowerBound(); Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); if (!tick.getTickType().equals(TickType.MAJOR)) continue; double current = tick.getValue(); double y1 = axis.valueToJava2D(previous, dataArea, getRangeAxisEdge()); double y2 = axis.valueToJava2D(current, dataArea, getRangeAxisEdge()); Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, dataArea.getWidth(), y1 - y2); if (fillBand) g2.setPaint(bandcolor); else g2.setPaint(bandcolor.darker()); g2.fill(band); previous = current; fillBand = !fillBand; } double end = axis.getUpperBound(); double y1 = axis.valueToJava2D(previous, dataArea, getRangeAxisEdge()); double y2 = axis.valueToJava2D(end, dataArea, getRangeAxisEdge()); Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, dataArea.getWidth(), y1 - y2); if (fillBand) g2.setPaint(bandcolor); else g2.setPaint(bandcolor.darker()); g2.fill(band); } else { super.drawRangeGridlines(g2, dataArea, ticks); } g2.setComposite(oldcomp); }
From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java
public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) { state = STATE_RUNNING;/*from w w w .java 2 s .c o m*/ gridWidth = (int) dataArea.getWidth(); gridHeight = (int) dataArea.getHeight(); //imageX,imageY correspond to point(0,0) int imageX = (int) dataArea.getX() + 1; int imageY = (int) dataArea.getY() + 1; DataBufferInt dataBuffer; image = new BufferedImage(gridWidth, gridHeight, BufferedImage.TYPE_INT_RGB); WritableRaster raster = image.getRaster(); grid = ((DataBufferInt) raster.getDataBuffer()).getData(); ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); xEpsilon = Math.abs((domainAxis.getUpperBound() - domainAxis.getLowerBound()) / (double) gridWidth); yEpsilon = Math.abs((rangeAxis.getUpperBound() - rangeAxis.getLowerBound()) / (double) gridHeight); int numPoints = gridHeight * gridWidth; int index = 0; int rate = numPoints / 100; if (justClearedSet) { if (criticalSetFound) { this.clearDisplay(); g2.drawImage(image, null, imageX, imageY); } justClearedSet = false; return; } if (!notYetRendered) { plotCopiedDisplay(); g2.drawImage(image, null, imageX, imageY); } notYetRendered = false; if (criticalSetFound && !findCriticalSetAgain) { if (this.chooseSegmentsSet) chooseSegments(g2, image, imageX, imageY); if (this.plotAttractorSet) plotAttractor(g2, image, imageX, imageY); if (this.iterateChosenSegmentsSet) iterateChosenSegments(g2, image, imageX, imageY); if (this.hideAttractorSet) hideAttractor(g2, image, imageX, imageY); } else { this.disableAllActionsExceptStop(); det = new AbsorbingAreaRenderer.ImplicitDeterminant(gridWidth, gridHeight, epsilon, g2, image, imageX, imageY); gridBackup = new int[grid.length]; copyDisplay(); criticalSetFound = true; findCriticalSetAgain = false; g2.drawImage(image, null, imageX, imageY); this.enableAllActionsExceptStop(); } }
From source file:com.lfx.web.WebChartXYPlot.java
/** * Draws the gridlines for the plot's primary range axis, if they are * visible.//from w w w . j a va2s . c om * * @param g2 the graphics device. * @param area the data area. * @param ticks the ticks. * * @see #drawDomainGridlines(Graphics2D, Rectangle2D, List) */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { Composite oldcomp = g2.getComposite(); Paint bandPaint = getBackgroundPaint(); if (bandPaint != null && bandPaint instanceof java.awt.Color) { g2.setComposite(AlphaComposite.SrcIn); java.awt.Color bandcolor = (java.awt.Color) (bandPaint); boolean fillBand = true; ValueAxis axis = getDomainAxis(); double previous = axis.getLowerBound(); Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); if (!tick.getTickType().equals(TickType.MAJOR)) continue; double current = tick.getValue(); double y1 = axis.valueToJava2D(previous, dataArea, getDomainAxisEdge()); double y2 = axis.valueToJava2D(current, dataArea, getDomainAxisEdge()); Rectangle2D band = new Rectangle2D.Double(y1, dataArea.getMinY(), y2 - y1, dataArea.getWidth()); if (fillBand) g2.setPaint(bandcolor); else g2.setPaint(bandcolor.darker()); g2.fill(band); previous = current; fillBand = !fillBand; } double end = axis.getUpperBound(); double y1 = axis.valueToJava2D(previous, dataArea, getDomainAxisEdge()); double y2 = axis.valueToJava2D(end, dataArea, getDomainAxisEdge()); Rectangle2D band = new Rectangle2D.Double(y1, dataArea.getMinY(), y2 - y1, dataArea.getWidth()); if (fillBand) g2.setPaint(bandcolor); else g2.setPaint(bandcolor.darker()); g2.fill(band); } else { super.drawDomainGridlines(g2, dataArea, ticks); } g2.setComposite(oldcomp); }