/** * Convenience method for computing the total stroke miter limit from the * STROKE_MITER_LIMIT, and IS_STROKE_MITER_LIMIT factor. */ public static double getStrokeTotalMiterLimit(Figure f) { if (f.get(IS_STROKE_MITER_LIMIT_FACTOR)) { return f.get(STROKE_MITER_LIMIT) * f.get(STROKE_WIDTH); } else { return f.get(STROKE_MITER_LIMIT); } }
protected Rectangle2D.Double getTransformedBounds() { Figure owner = getOwner(); Rectangle2D.Double bounds = owner.getBounds(); if (owner.get(TRANSFORM) != null) { Rectangle2D r = owner.get(TRANSFORM). createTransformedShape(bounds).getBounds2D(); bounds.x = r.getX(); bounds.y = r.getY(); bounds.width = r.getWidth(); bounds.height = r.getHeight(); } return bounds; }
public java.util.List<Figure> findFiguresWithin(Rectangle2D.Double bounds) { LinkedList<Figure> contained = new LinkedList<Figure>(); for (Figure f : children) { Rectangle2D r = f.getBounds(); if (f.get(TRANSFORM) != null) { r = f.get(TRANSFORM).createTransformedShape(r).getBounds2D(); } if (f.isVisible() && bounds.contains(r)) { contained.add(f); } } return contained; }
private Color getStrokeColor(Figure f) { return f.get(STROKE_COLOR); } private float getStrokeWidth(Figure f) {
@Override protected Rectangle basicGetBounds() { Shape bounds = getOwner().getBounds(); if (getOwner().get(TRANSFORM) != null) { bounds = getOwner().get(TRANSFORM).createTransformedShape(bounds); } bounds = view.getDrawingToViewTransform().createTransformedShape(bounds); Rectangle r = bounds.getBounds(); r.grow(2, 2); return r; }
private Locator getLocator(Figure f) { return f.get(LAYOUT_LOCATOR); } }
@Override public void trackStart(Point anchor, int modifiersEx) { oldValue = getOwner().get(ORIENTATION); centerBox = view.drawingToView(getOwner().getBounds()); centerBox.grow(centerBox.width / -3, centerBox.height / -3); }
public static Stroke getStroke(Figure f) { double strokeWidth = f.get(STROKE_WIDTH); if (strokeWidth == 0) { strokeWidth = 1; } return new BasicStroke((float) strokeWidth); }
/** * Gets the value of the attribute denoted by this AttributeKey from * a Figure. * * @param f A figure. * @return The value of the attribute. */ @Nullable public T get(Figure f) { return f.get(this); }
@Override public double getDecorationRadius(Figure f) { double strokeWidth = f.get(STROKE_WIDTH); double scaleFactor; if (strokeWidth > 1f) { scaleFactor = 1d + (strokeWidth - 1d) / 2d; } else { scaleFactor = 1d; } return getDecoratorPathRadius(f) * scaleFactor; }
@Nullable public static Font getFont(Figure f) { Font prototype = f.get(FONT_FACE); if (prototype == null) { return null; } if (getFontStyle(f) != Font.PLAIN) { return prototype.deriveFont(getFontStyle(f), f.get(FONT_SIZE).floatValue()); } else { return prototype.deriveFont(f.get(FONT_SIZE).floatValue()); } }
private Path2D.Double getTransformedDecoratorPath(Figure f, Point2D.Double p1, Point2D.Double p2) { Path2D.Double path = getDecoratorPath(f); double strokeWidth = f.get(STROKE_WIDTH); AffineTransform transform = new AffineTransform(); transform.translate(p1.x, p1.y); transform.rotate(Math.atan2(p1.x - p2.x, p2.y - p1.y)); // transform.rotate(Math.PI / 2); if (strokeWidth > 1f) { transform.scale(1d + (strokeWidth - 1d) / 2d, 1d + (strokeWidth - 1d) / 2d); } path.transform(transform); return path; }
public Insets2D.Double getInsets(Figure child) { Insets2D.Double value = child.get(CompositeFigure.LAYOUT_INSETS); return (value == null) ? new Insets2D.Double() : (Insets2D.Double) value.clone(); } }
private <T> void set(final F fig, final AttributeKey<T> key, final T value) { if (MiscUtils.equal(value, fig.get(key))) { // NB: Do not trigger an attribute change event if value already matches. return; } fig.set(key, value); }
@Override public void updateOverlay(final F figure, final OverlayView view) { final Color strokeColor = figure.get(AttributeKeys.STROKE_COLOR); final Overlay overlay = view.getData(); overlay.setLineColor(AWTColors.getColorRGB(strokeColor)); // The line style is intentionally omitted here because it is ambiguous and // because there is no UI for setting it by the JHotDraw UI. // FIXME - is this next line dangerous for drawing attributes? width could // conceivably be 0. overlay.setLineWidth(figure.get(AttributeKeys.STROKE_WIDTH)); final Color fillColor = figure.get(AttributeKeys.FILL_COLOR); overlay.setFillColor(AWTColors.getColorRGB(fillColor)); overlay.setAlpha(fillColor.getAlpha()); }
protected Point getLocation() { if (getBezierFigure().getNodeCount() > index) { Point2D.Double p = getBezierFigure().getPoint(index, controlPointIndex); if (getTransformOwner().get(TRANSFORM) != null) { getTransformOwner().get(TRANSFORM).transform(p, p); } return view.drawingToView(p); } else { return new Point(10, 10); } }
@Override public String getToolTipText(Point p) { return (getOwner().get(LINK)!=null) ? ResourceBundleUtil.getBundle("org.jhotdraw.samples.svg.Labels").// getString("handle.link.toolTipText") : null; }
@Override protected Color getInitialColor() { Color initialColor = null; DrawingView v = getEditor().getActiveView(); if (v != null) { Figure f = v.getDrawing(); initialColor = f.get(key); } if (initialColor == null) { initialColor = super.getInitialColor(); } return initialColor; }