List of usage examples for java.awt Shape getBounds
public Rectangle getBounds();
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java
/** * Creates a continuous legend item for one item in dimensionSet, i.e. dimensionSet must be a * set containing exactly one value./*from ww w .j a v a 2s . c o m*/ * * @param dateFormat * format used to format minValue and maxValue as dates, or null if they should be * displayed numerically instead of as dates * @throws ChartPlottimeException */ private LegendItem createContinuousLegendItem(PlotInstance plotInstance, Set<PlotDimension> dimensionSet, double minValue, double maxValue, DateFormat dateFormat) { PlotConfiguration plotConfiguration = plotInstance.getCurrentPlotConfigurationClone(); PlotDimension dimension = dimensionSet.iterator().next(); DefaultDimensionConfig dimensionConfig = (DefaultDimensionConfig) plotConfiguration .getDimensionConfig(dimension); DimensionConfigData dimensionConfigData = plotInstance.getPlotData() .getDimensionConfigData(dimensionConfig); // String label = dimensionConfig.getLabel(); // if(label == null) { // label = I18N.getGUILabel("plotter.unnamed_value_label"); // } String label = ""; if (dimension == PlotDimension.COLOR) { ColorProvider colorProvider = dimensionConfigData.getColorProvider(); if (!colorProvider.supportsNumericalValues()) { throw new RuntimeException( "Color provider for continuous legend item does not support numerical values."); } // shape dimensions final int width = 50; final int height = 10; // create item paint // first disable logarithmic scale on color provider ( -> linear gradient in legend) // ContinuousColorProvider continuousColorProvider = null; // if (dimensionConfig.isLogarithmic() && colorProvider instanceof // ContinuousColorProvider) { // continuousColorProvider = (ContinuousColorProvider)colorProvider; // continuousColorProvider.setLogarithmic(false); // } // calculate gradient float fractions[] = new float[width]; Color colors[] = new Color[width]; for (int i = 0; i < width; ++i) { float fraction = i / (width - 1.0f); double fractionValue; if (colorProvider instanceof ContinuousColorProvider && ((ContinuousColorProvider) colorProvider).isColorMinMaxValueDifferentFromOriginal( ((ContinuousColorProvider) colorProvider).getMinValue(), ((ContinuousColorProvider) colorProvider).getMaxValue())) { fractionValue = ((ContinuousColorProvider) colorProvider).getMinValue() + fraction * (((ContinuousColorProvider) colorProvider).getMaxValue() - ((ContinuousColorProvider) colorProvider).getMinValue()); } else { fractionValue = minValue + fraction * (maxValue - minValue); } colors[i] = colorProvider.getColorForValue(fractionValue); fractions[i] = fraction; } LinearGradientPaint shapeFillPaint = new LinearGradientPaint(new Point(0, 0), new Point(width, 0), fractions, colors, CycleMethod.REPEAT); // reset color provider to logarithmic if necessary // if (continuousColorProvider != null && dimensionConfig.isLogarithmic()) { // continuousColorProvider.setLogarithmic(true); // } // create item shape Rectangle itemShape = new Rectangle(width, height); if (colorProvider instanceof ContinuousColorProvider) { return createFlankedShapeLegendItem(label, ((ContinuousColorProvider) colorProvider).getMinValue(), ((ContinuousColorProvider) colorProvider).getMaxValue(), itemShape, shapeFillPaint, true, dateFormat); } else { return createFlankedShapeLegendItem(label, minValue, maxValue, itemShape, shapeFillPaint, true, dateFormat); } } else if (dimension == PlotDimension.SHAPE) { // shape provider probably never supports numerical values return null; } else if (dimension == PlotDimension.SIZE) { SizeProvider sizeProvider = dimensionConfigData.getSizeProvider(); if (!sizeProvider.supportsNumericalValues()) { throw new RuntimeException( "Size provider for continuous legend item does not support numerical values."); } double minScalingFactor = sizeProvider.getMinScalingFactor(); double maxScalingFactor = sizeProvider.getMaxScalingFactor(); ContinuousSizeProvider legendSizeProvider = new ContinuousSizeProvider(minScalingFactor, maxScalingFactor, MIN_LEGEND_ITEM_SCALING_FACTOR, MAX_LEGEND_ITEM_SCALING_FACTOR, false); int legendItemCount = 4; Area composedShape = new Area(); Shape originalShape = UNDEFINED_SHAPE; if (dimensionSet.contains(PlotDimension.SIZE) && dimensionSet.size() == 1) { originalShape = UNDEFINED_SHAPE_AND_COLOR; } double maxHeight = originalShape.getBounds().getHeight() * MAX_LEGEND_ITEM_SCALING_FACTOR; for (int i = 0; i < legendItemCount; ++i) { double fraction = minScalingFactor + ((double) i / legendItemCount * (maxScalingFactor - minScalingFactor)); double legendScalingFactor = legendSizeProvider.getScalingFactorForValue(fraction); double composedWidth = composedShape.getBounds().getWidth(); AffineTransform t = new AffineTransform(); t.scale(legendScalingFactor, legendScalingFactor); Shape shape = t.createTransformedShape(originalShape); t = new AffineTransform(); double shapeWidth = shape.getBounds().getWidth(); double shapeHeight = shape.getBounds().getHeight(); t.translate(composedWidth + shapeWidth * .1, (maxHeight - shapeHeight) / 2.0); t.translate(-shape.getBounds().getMinX(), -shape.getBounds().getMinY()); shape = t.createTransformedShape(shape); composedShape.add(new Area(shape)); } return createFlankedShapeLegendItem(label, minValue, maxValue, composedShape, UNDEFINED_COLOR_PAINT, false, dateFormat); } else { throw new RuntimeException("Unsupported dimension. Execution path should never reach this line."); } }
From source file:org.pmedv.core.components.RelativeImageView.java
/** * Provides a mapping from the document model coordinate space to the * coordinate space of the view mapped to it. * /*from w ww . jav a 2 s . c om*/ * @param pos * the position to convert * @param a * the allocated region to render into * @param b * Position Bias * @return the bounding box of the given position * @exception BadLocationException * if the given position does not represent a valid location * in the associated document * @see View#modelToView */ public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException { int p0 = getStartOffset(); int p1 = getEndOffset(); if ((pos >= p0) && (pos <= p1)) { Rectangle r = a.getBounds(); if (pos == p1) { r.x += r.width; } r.width = 0; return r; } return null; }
From source file:org.csstudio.utility.batik.SVGHandler.java
protected void doRender() { if (disposed) { return;// w ww. j ava2 s . c om } updateMatrix(); changeColor(colorToChange, colorToApply); gvtRoot = builder.build(bridgeContext, svgDocument); // get the 'width' and 'height' attributes of the SVG document float width = 400, height = 400; float docWidth = (float) bridgeContext.getDocumentSize().getWidth(); float docHeight = (float) bridgeContext.getDocumentSize().getHeight(); if (canvasWidth > 0 && canvasHeight > 0) { width = canvasWidth; height = canvasHeight; } else if (canvasHeight > 0) { width = (docWidth * canvasHeight) / docHeight; height = canvasHeight; } else if (canvasWidth > 0) { width = canvasWidth; height = (docHeight * canvasWidth) / docWidth; } else { width = docWidth; height = docHeight; } // compute the preserveAspectRatio matrix AffineTransform renderingTransform = null; AffineTransform Px = null; SVGSVGElement root = svgDocument.getRootElement(); String viewBox = root.getAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (viewBox != null && viewBox.length() != 0) { String aspectRatio = root.getAttributeNS(null, SVGConstants.SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE); Px = ViewBox.getPreserveAspectRatioTransform(root, viewBox, aspectRatio, width, height, bridgeContext); } else { // no viewBox has been specified, create a scale transform float xscale = width / docWidth; float yscale = height / docHeight; float scale = Math.min(xscale, yscale); Px = AffineTransform.getScaleInstance(scale, scale); } Shape curAOI = new Rectangle2D.Float(0, 0, width, height); CanvasGraphicsNode cgn = getCanvasGraphicsNode(gvtRoot); if (cgn != null) { cgn.setViewingTransform(Px); renderingTransform = new AffineTransform(); } else { renderingTransform = Px; } if (renderer != null) { renderer.dispose(); renderer = null; } renderer = createImageRenderer(); int w = (int) (curAOI.getBounds().width + 0.5); int h = (int) (curAOI.getBounds().height + 0.5); renderer.updateOffScreen(w, h); renderer.setTree(gvtRoot); renderer.setTransform(renderingTransform); renderer.setDoubleBuffered(false); renderer.clearOffScreen(); renderer.repaint(curAOI); if (updateManager != null) { updateManager.setGVTRoot(gvtRoot); } needRender = false; }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Labels the specified non-self-loop edge with the specified label. * Uses the font specified by this instance's * <code>EdgeFontFunction</code>. (If the font is unspecified, the existing * font for the graphics context is used.) Positions the * label between the endpoints according to the coefficient returned * by this instance's edge label closeness function. *///from ww w. j a v a2s .c om protected void labelEdge(Graphics2D g2d, Edge e, String label, int x1, int x2, int y1, int y2) { int distX = x2 - x1; int distY = y2 - y1; double totalLength = Math.sqrt(distX * distX + distY * distY); double closeness = edgeLabelClosenessFunction.getNumber(e).doubleValue(); int posX = (int) (x1 + (closeness) * distX); int posY = (int) (y1 + (closeness) * distY); int xDisplacement = (int) (LABEL_OFFSET * (distY / totalLength)); int yDisplacement = (int) (LABEL_OFFSET * (-distX / totalLength)); Component component = prepareRenderer(graphLabelRenderer, label, isPicked(e), e); Dimension d = component.getPreferredSize(); Shape edgeShape = edgeShapeFunction.getShape(e); double parallelOffset = 1; parallelOffset += parallelEdgeIndexFunction.getIndex(e); if (edgeShape instanceof Ellipse2D) { parallelOffset += edgeShape.getBounds().getHeight(); parallelOffset = -parallelOffset; } parallelOffset *= d.height; AffineTransform old = g2d.getTransform(); AffineTransform xform = new AffineTransform(old); xform.translate(posX + xDisplacement, posY + yDisplacement); double dx = x2 - x1; double dy = y2 - y1; if (graphLabelRenderer.isRotateEdgeLabels()) { double theta = Math.atan2(dy, dx); if (dx < 0) { theta += Math.PI; } xform.rotate(theta); } if (dx < 0) { parallelOffset = -parallelOffset; } xform.translate(-d.width / 2, -(d.height / 2 - parallelOffset)); g2d.setTransform(xform); rendererPane.paintComponent(g2d, component, screenDevice, 0, 0, d.width, d.height, true); g2d.setTransform(old); }
From source file:savant.view.swing.GraphPane.java
private void renderCurrentSelected(Graphics2D g2) { // Temporarily shift the origin g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(0, getOffset());//from w w w .j a v a 2s. c om for (Track t : tracks) { if (t.getRenderer().hasMappedValues()) { List<Shape> currentSelected = t.getRenderer().getCurrentSelectedShapes(this); if (currentSelected.size() > 0) { boolean arcMode = t.getDrawingMode() == DrawingMode.ARC_PAIRED; for (Shape selectedShape : currentSelected) { if (selectedShape != currentOverShape) { if (arcMode) { g2.setColor(Color.GREEN); g2.draw(selectedShape); } else { //g2.setColor(Color.GREEN); g2.setColor(new Color(0, 255, 0, 150)); g2.fill(selectedShape); if (selectedShape.getBounds().getWidth() > 5) { g2.setColor(Color.BLACK); g2.draw(selectedShape); } } } } } break; } } if (currentOverShape != null) { if (tracks[0].getDrawingMode() == DrawingMode.ARC_PAIRED) { g2.setColor(Color.RED); g2.draw(currentOverShape); //get record pair BAMIntervalRecord rec1 = (BAMIntervalRecord) currentOverRecord; BAMIntervalRecord rec2 = ((BAMTrack) tracks[0]).getMate(rec1); //mate //render reads with mismatches ((BAMTrackRenderer) tracks[0].getRenderer()).renderReadsFromArc(g2, this, rec1, rec2, prevRange); } else { g2.setColor(new Color(255, 0, 0, 150)); g2.fill(currentOverShape); if (currentOverShape.getBounds() != null && currentOverShape.getBounds().getWidth() > 5 && currentOverShape.getBounds().getHeight() > 3) { g2.setColor(Color.BLACK); g2.draw(currentOverShape); } } } //shift the origin back g2.translate(0, -getOffset()); }
From source file:savant.view.tracks.BAMTrackRenderer.java
private Shape renderRead(Graphics2D g2, GraphPaneAdapter gp, BAMIntervalRecord rec, int level, Range range, double readHeight) { SAMRecord samRec = rec.getSAMRecord(); boolean reverseStrand = samRec.getReadNegativeStrandFlag(); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); Color readColor = cs.getColor(reverseStrand ? ColourKey.REVERSE_STRAND : ColourKey.FORWARD_STRAND); Color override = rec.getColor(); if (override != null) { readColor = override;/*w w w. j a v a 2s. co m*/ } if ((Boolean) instructions.get(DrawingInstruction.MAPPING_QUALITY)) { int alpha = getConstrainedAlpha(samRec.getMappingQuality()); readColor = new Color(readColor.getRed(), readColor.getGreen(), readColor.getBlue(), alpha); } // cutoffs to determine when not to draw double leftMostX = gp.transformXPos(range.getFrom()); double rightMostX = gp.transformXPos(range.getTo() + 1); //y = gp.transformYPos(0) - (level + 1)*unitHeight; double x = gp.transformXPos(rec.getInterval().getStart()); double y = gp.transformYPos(0) - (level + 1) * readHeight - gp.getOffset(); double w = rec.getInterval().getLength() * gp.getUnitWidth(); // cut off x and w so no drawing happens off-screen double x2; if (rightMostX < x + w) { x2 = rightMostX; } else { x2 = x + w; } if (leftMostX > x) { x = leftMostX; } w = x2 - x; Shape pointyBar = getPointyBar(reverseStrand, x, y, w, readHeight); // Only fill in the read if we're not going to slam bases on top of it. boolean baseQuality = (Boolean) instructions.get(DrawingInstruction.BASE_QUALITY); if (lastMode != DrawingMode.SEQUENCE && !baseQuality) { g2.setColor(readColor); g2.fill(pointyBar); } // Render individual bases/mismatches as appropriate for the current mode. if (lastMode != DrawingMode.STANDARD || baseQuality) { renderBases(g2, gp, samRec, level, refSeq, range, readHeight); } // Draw outline, if there's room if (pointyBar.getBounds().getHeight() >= 4.0) { g2.setColor(cs.getColor(ColourKey.INTERVAL_LINE)); g2.draw(pointyBar); } return pointyBar; }
From source file:DefaultGraphics2D.java
/** * Returns the bounding rectangle of the current clipping area. This method * refers to the user clip, which is independent of the clipping associated * with device bounds and window visibility. If no clip has previously been * set, or if the clip has been cleared using <code>setClip(null)</code>, * this method returns <code>null</code>. The coordinates in the rectangle * are relative to the coordinate system origin of this graphics context. * // w w w. ja v a 2 s .c o m * @return the bounding rectangle of the current clipping area, or * <code>null</code> if no clip is set. * @see java.awt.Graphics#getClip * @see java.awt.Graphics#clipRect * @see java.awt.Graphics#setClip(int, int, int, int) * @see java.awt.Graphics#setClip(Shape) * @since JDK1.1 */ public Rectangle getClipBounds() { Shape c = getClip(); if (c == null) return null; else return c.getBounds(); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java
private CustomLegendItem createValueSourceLegendItem(PlotConfiguration plotConfig, ValueSource valueSource) { Set<PlotDimension> dimensions = new HashSet<PlotDimension>(); for (PlotDimension dimension : PlotDimension.values()) { switch (dimension) { case DOMAIN: case VALUE: break; default://from ww w .j ava2s .c o m if (valueSource.useSeriesFormatForDimension(plotConfig, dimension)) { dimensions.add(dimension); } } } if (dimensions.isEmpty()) { return null; } SeriesFormat format = valueSource.getSeriesFormat(); String description = ""; String toolTipText = ""; String urlText = ""; boolean shapeVisible = true; Shape shape; boolean shapeFilled = true; Paint fillPaint = UNDEFINED_COLOR_PAINT; boolean shapeOutlineVisible = true; Paint outlinePaint = PlotConfiguration.DEFAULT_OUTLINE_COLOR; Stroke outlineStroke = DEFAULT_OUTLINE_STROKE; boolean lineVisible = format.getLineStyle() != LineStyle.NONE && format.getSeriesType() == SeriesFormat.VisualizationType.LINES_AND_SHAPES; // configure fill paint and line paint Paint linePaint; String label = valueSource.toString(); if (label == null) { label = ""; } if (dimensions.contains(PlotDimension.COLOR)) { Color color = format.getItemColor(); fillPaint = format.getAreaFillPaint(color); linePaint = fillPaint; } else { if (format.getAreaFillStyle() == FillStyle.NONE) { fillPaint = new Color(0, 0, 0, 0); linePaint = fillPaint; } else if (format.getAreaFillStyle() == FillStyle.SOLID) { fillPaint = UNDEFINED_COLOR_PAINT; linePaint = UNDEFINED_LINE_COLOR; } else { fillPaint = format.getAreaFillPaint(UNDEFINED_COLOR); linePaint = fillPaint; } } VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType(); if (seriesType == VisualizationType.LINES_AND_SHAPES) { if (dimensions.contains(PlotDimension.SHAPE)) { shape = format.getItemShape().getShape(); } else if (dimensions.contains(PlotDimension.COLOR)) { shape = UNDEFINED_SHAPE; } else { shape = UNDEFINED_SHAPE_AND_COLOR; } if (dimensions.contains(PlotDimension.SIZE)) { AffineTransform transformation = new AffineTransform(); double scalingFactor = format.getItemSize(); transformation.scale(scalingFactor, scalingFactor); shape = transformation.createTransformedShape(shape); } } else if (seriesType == VisualizationType.BARS) { shape = BAR_SHAPE; } else if (seriesType == VisualizationType.AREA) { shape = AREA_SHAPE; } else { throw new RuntimeException("Unknown SeriesType. This should not happen."); } // configure line shape float lineLength = 0; if (lineVisible) { lineLength = format.getLineWidth(); if (lineLength < 1) { lineLength = 1; } if (lineLength > 1) { lineLength = 1 + (float) Math.log(lineLength) / 2; } // line at least 30 pixels long, and show at least 2 iterations of stroke lineLength = Math.max(lineLength * 30, format.getStrokeLength() * 2); // line at least 2x longer than shape width if (shape != null) { lineLength = Math.max(lineLength, (float) shape.getBounds().getWidth() * 2f); } } // now create line shape and stroke Shape line = new Line2D.Float(0, 0, lineLength, 0); BasicStroke lineStroke = format.getStroke(); if (lineStroke == null) { lineStroke = new BasicStroke(); } // unset line ending decoration to prevent drawing errors in legend { BasicStroke s = lineStroke; lineStroke = new BasicStroke(s.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, s.getMiterLimit(), s.getDashArray(), s.getDashPhase()); } return new CustomLegendItem(label, description, toolTipText, urlText, shapeVisible, shape, shapeFilled, fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, line, lineStroke, linePaint); }