Package diva.canvas

Examples of diva.canvas.CompositeFigure


    protected Figure _renderNode(Object node) {
        Figure nf = super._renderNode(node);

        if (nf instanceof CompositeFigure) {
            // This cast should be safe...
            CompositeFigure cf = (CompositeFigure) nf;
            Figure backgroundFigure = cf.getBackgroundFigure();

            // This might be null because the node is hidden.
            if (backgroundFigure != null) {
                BasicFigure bf = new BasicFigure(backgroundFigure.getBounds(),
                        4.0f);
                bf.setStrokePaint(_HIGHLIGHT_COLOR);
                // Put the highlighting in the background,
                // behind the actor label.
                int index = cf.getFigureCount();
                if (index < 0) {
                    index = 0;
                }
                cf.add(index, bf);
            }

            return cf;
        }
View Full Code Here


            throws NameDuplicationException, IllegalActionException {
        super(container, name);
    }

    public Figure createFigure() {
        CompositeFigure figure = (CompositeFigure) super.createFigure();
        Iterator<?> subfigures = figure.figures();
        while (subfigures.hasNext()) {
            Figure subfigure = (Figure) subfigures.next();
            if (subfigure instanceof LabelFigure) {
                ((LabelFigure) subfigure).setFillPaint(Color.RED);
            }
View Full Code Here

     @return A new figure.
     */
    public Figure createBackgroundFigure() {
        // If this icon itself contains any visible attributes, then
        // compose their background figures to make this one.
        CompositeFigure figure = null;
        Iterator attributes = attributeList().iterator();

        while (attributes.hasNext()) {
            Attribute attribute = (Attribute) attributes.next();

            // There is a level of indirection where the "subIcon" is a
            // "visible attribute" containing an attribute named "_icon"
            // that actually has the icon.
            Iterator subIcons = attribute.attributeList(EditorIcon.class)
                    .iterator();

            while (subIcons.hasNext()) {
                EditorIcon subIcon = (EditorIcon) subIcons.next();

                if (figure == null) {
                    // NOTE: This used to use a constructor that
                    // takes a "background figure" argument, which would
                    // then treat this first figure specially.  This is not
                    // right since getShape() on the figure will then return
                    // only the shape of the composite, which results in the
                    // wrong selection region being highlighted.
                    figure = new CompositeFigure();
                }

                Figure subFigure = subIcon.createBackgroundFigure();

                // Translate the figure to the location of the subfigure,
                // if there is a location. Also, center it if necessary.
                try {
                    // NOTE: This is inelegant, but only the subclasses
                    // have the notion of centering.
                    // FIXME: Don't use FilledShapeAttribute... promote
                    // centered capability to a base class.
                    if (attribute instanceof FilledShapeAttribute
                            && subFigure instanceof BasicFigure) {
                        boolean centeredValue = ((BooleanToken) ((FilledShapeAttribute) attribute).centered
                                .getToken()).booleanValue();

                        if (centeredValue) {
                            ((BasicFigure) subFigure).setCentered(true);
                        }
                    }

                    Locatable location = (Locatable) attribute.getAttribute(
                            "_location", Locatable.class);

                    if (location != null) {
                        double[] locationValue = location.getLocation();
                        CanvasUtilities.translateTo(subFigure,
                                locationValue[0], locationValue[1]);
                    }
                } catch (IllegalActionException e) {
                    throw new InternalErrorException(e);
                }

                figure.add(subFigure);
            }
        }

        if (figure == null) {
            // There are no component figures.
View Full Code Here

     *   and a label.
     */
    public Figure createFigure() {
        Figure background = createBackgroundFigure();
        Rectangle2D backBounds = background.getBounds();
        CompositeFigure figure = new CompositeFigure(background);

        NamedObj container = (NamedObj) getContainerOrContainerToBe();

        // Create the label, unless this is a visible attribute,
        // which typically carries no label.
        // NOTE: backward compatibility problem...
        // Old style annotations now have labels...
        if (!_isPropertySet(container, "_hideName")) {
            String name = container.getDisplayName();

            // Do not add a label figure if the name is null.
            if ((name != null) && !name.equals("")) {
                if (!_isPropertySet(container, "_centerName")) {
                    LabelFigure label = new LabelFigure(name, _labelFont, 1.0,
                            SwingConstants.SOUTH_WEST);

                    // Shift the label slightly right so it doesn't
                    // collide with ports.
                    label.translateTo(backBounds.getX() + 5, backBounds.getY());
                    figure.add(label);
                } else {
                    LabelFigure label = new LabelFigure(name, _labelFont, 1.0,
                            SwingConstants.CENTER);
                    label.translateTo(backBounds.getCenterX(), backBounds
                            .getCenterY());
                    figure.add(label);
                }
            }
        }

        // If specified by a preference, then show parameters.
        Token show = PtolemyPreferences.preferenceValueLocal(container,
                "_showParameters");

        if (show instanceof StringToken) {
            String value = ((StringToken) show).stringValue();
            boolean showOverriddenParameters = value
                    .equals("Overridden parameters only");
            boolean showAllParameters = value.equals("All");

            if ((showOverriddenParameters && !_isPropertySet(container,
                    "_hideAllParameters"))
                    || showAllParameters) {
                StringBuffer parameters = new StringBuffer();
                Iterator settables = container.attributeList(Settable.class)
                        .iterator();

                while (settables.hasNext()) {
                    Settable settable = (Settable) settables.next();

                    if (settable.getVisibility() != Settable.FULL) {
                        continue;
                    }

                    if (!showAllParameters
                            && !((NamedObj) settable).isOverridden()) {
                        continue;
                    }

                    if (!showAllParameters
                            && _isPropertySet((NamedObj) settable, "_hide")) {
                        continue;
                    }

                    String name = settable.getName();
                    String displayName = settable.getDisplayName();
                    parameters.append(displayName);

                    if (showAllParameters && !name.equals(displayName)) {
                        parameters.append(" (" + name + ")");
                    }

                    parameters.append(": ");
                    parameters.append(settable.getExpression());

                    if (settables.hasNext()) {
                        parameters.append("\n");
                    }
                }

                LabelFigure label = new LabelFigure(parameters.toString(),
                        _parameterFont, 1.0, SwingConstants.NORTH_WEST);

                // Shift the label slightly right so it doesn't
                // collide with ports.
                label.translateTo(backBounds.getX() + 5, backBounds.getY()
                        + backBounds.getHeight());
                figure.add(label);
            }
        }

        return figure;
    }
View Full Code Here

        protected Figure _renderNode(Object node) {
            if ((node != null) && !_hide(node)) {
                Figure nf = super._renderNode(node);
                GraphModel model = getController().getGraphModel();
                Object object = model.getSemanticObject(node);
                CompositeFigure cf = _getCompositeFigure(nf);

                if (object instanceof NamedObj && cf != null && !_transformed
                        && _results != null
                        && _results.get(_currentPosition).containsValue(object)) {
                    Rectangle2D bounds = cf.getBackgroundFigure().getBounds();
                    float padding = _HIGHLIGHT_PADDING;
                    BasicFigure bf = new BasicRectangle(bounds.getX() - padding,
                            bounds.getY() - padding,
                            bounds.getWidth() + padding * 2.0,
                            bounds.getHeight() + padding * 2.0,
                            _HIGHLIGHT_THICKNESS);
                    bf.setStrokePaint(_HIGHLIGHT_COLOR);

                    int index = cf.getFigureCount();
                    if (index < 0) {
                        index = 0;
                    }
                    cf.add(index, bf);
                }
                return nf;
            }

            return super._renderNode(node);
View Full Code Here

     *  The figure will be an instance of LabelFigure that renders the
     *  container name and value, separated by a colon.
     *  @return A new CompositeFigure consisting of the label.
     */
    public Figure createFigure() {
        CompositeFigure background = new CompositeFigure(super
                .createBackgroundFigure());
        Nameable container = getContainer();

        if (container instanceof Settable) {
            String name = container.getDisplayName();
            String value = ((Settable) container).getExpression();
            LabelFigure label = new LabelFigure(name + ": " + value,
                    _labelFont, 1.0, SwingConstants.SOUTH_WEST);
            background.add(label);
            return background;
        } else {
            String name = container.getName();
            LabelFigure label = new LabelFigure(name, _labelFont, 1.0,
                    SwingConstants.SOUTH_WEST);
            background.add(label);
            return background;
        }
    }
View Full Code Here

     *  The figure will be an instance of LabelFigure that renders the
     *  value of the specified attribute of the container.
     *  @return A new CompositeFigure consisting of the label.
     */
    public Figure createFigure() {
        CompositeFigure result = (CompositeFigure) super.createFigure();
        String truncated = _displayString();

        LabelFigure label = new LabelFigure(truncated, _labelFont, 1.0,
                SwingConstants.CENTER);
        Rectangle2D backBounds = result.getBackgroundFigure().getBounds();
        label.translateTo(backBounds.getCenterX(), backBounds.getCenterY());
        result.add(label);

        _addLiveFigure(label);
        return result;
    }
View Full Code Here

                } else {
                    southPorts.add(port);
                }
            }

            CompositeFigure figure = (CompositeFigure) getLayoutTarget()
                    .getVisualObject(node);

            _reOrderPorts(westPorts);
            _placePortFigures(figure, westPorts, SwingConstants.WEST);
            _reOrderPorts(eastPorts);
View Full Code Here

            } else {
                return new RoundedRectangle(0, 0, width, height, _getFill(),
                        _getLineWidth(), _roundingValue, _roundingValue);
            }
        } else {
            CompositeFigure result;
            if (_roundingValue == 0.0) {
                result = new CompositeFigure(new BasicRectangle(-_spacingValue,
                        -_spacingValue, width + 2 * _spacingValue, height + 2
                                * _spacingValue, null, _getLineWidth()));
                result.add(new BasicRectangle(0, 0, width, height, _getFill(),
                        _getLineWidth()));
            } else {
                result = new CompositeFigure(new RoundedRectangle(
                        -_spacingValue, -_spacingValue, width + 2
                                * _spacingValue, height + 2 * _spacingValue,
                        null, _getLineWidth(), _roundingValue + _spacingValue,
                        _roundingValue + _spacingValue));
                result.add(new RoundedRectangle(0, 0, width, height,
                        _getFill(), _getLineWidth(), _roundingValue,
                        _roundingValue));
            }
            return result;
        }
View Full Code Here

                } catch (IllegalActionException e) {
                    // Ignore.
                }
            }

            CompositeFigure result = new CompositeFigure(figure);

            if (relation instanceof IORelation) {
                if (((IORelation) relation).getWidth() > 1) {
                    // Restore width and height to the default to get a reasonable slash.
                    width = 12.0;
                    height = 12.0;

                    Line2D.Double line = new Line2D.Double(-width / 2,
                            height / 2, width / 2, -height / 2);
                    Figure lineFigure = new BasicFigure(line, Color.black);
                    result.add(lineFigure);

                    LabelFigure label = new LabelFigure(""
                            + ((IORelation) relation).getWidth(),
                            _relationLabelFont, 0, SwingConstants.SOUTH_WEST);
                    label.translateTo((width / 2) + 1.0, (-height / 2) - 1.0);
                    result.add(label);
                }
            }

            return result;
        }
View Full Code Here

TOP

Related Classes of diva.canvas.CompositeFigure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.