Package diva.canvas

Examples of diva.canvas.CompositeFigure


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

        String name = "No Name";
        NamedObj container = getContainer();
        if (container != null) {
            name = container.getDisplayName();
        }
        LabelFigure label = new LabelFigure(name, _labelFont, 1.0,
                SwingConstants.CENTER);
        Rectangle2D backBounds = result.getBackgroundFigure().getBounds();
        label.translateTo(backBounds.getCenterX(), backBounds.getCenterY());
        result.add(label);
        return result;
    }
View Full Code Here


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

        // If there is no string to display now, then create a string
        // with a single blank.
        if (truncated == null) {
            truncated = " ";
        }

        // NOTE: This violates the Diva MVC architecture!
        // This attribute is part of the model, and should not have
        // a reference to this figure.  By doing so, it precludes the
        // possibility of having multiple views on this model.
        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

     @param nf The figure that should be a CompositeFigure itself, or be a
     *   TerminalFigure whose getFigure() method returns a CompositeFigure.
     *  @return The CompositeFigure, or null of it cannot be found.
     */
    protected static CompositeFigure _getCompositeFigure(Figure nf) {
        CompositeFigure cf;

        // Try to get a composite figure that we can add the
        // annotation to.  This is complicated by the fact that
        // ExternalIOPortController wraps its figure in a
        // TerminalFigure, and that there is nothing in the API
View Full Code Here

     @return the newly created figure.
     */
    protected Figure _renderNode(java.lang.Object node) {
        if ((node == null) || _hide(node)) {
            // Return an empty figure.
            Figure newFigure = new CompositeFigure();
            newFigure.setVisible(false);
            newFigure.setInteractor(getNodeInteractor());
            newFigure.setUserObject(node);
            getController().setFigure(node, newFigure);
            return newFigure;
        } else {
            Figure nf = super._renderNode(node);
            GraphModel model = getController().getGraphModel();
            Object object = model.getSemanticObject(node);
            CompositeFigure cf = _getCompositeFigure(nf);

            if (_decoratable
                    && object instanceof NamedObj
                    && (((NamedObj) object).getDerivedLevel() < Integer.MAX_VALUE)
                    && (cf != null)) {
                // float[] dash = { 2.0f, 5.0f };
                Stroke stroke = new BasicStroke(2f, /* width */
                BasicStroke.CAP_SQUARE, /* cap   */
                BasicStroke.JOIN_MITER, /* join  */
                10.0f); /* mitre limit */
                // To get a dashed line, add the following two arguments above:
                // dash, /* dash  */
                // 0.0f); /* dash_phase  */
                // Pad the figure so that this highlight composes properly
                // with other highlights.
                Rectangle2D bounds = cf.getBackgroundFigure().getBounds();
                double padding = 3.0;
                bounds = new Rectangle2D.Double(bounds.getX() - padding, bounds
                        .getY()
                        - padding, bounds.getWidth() + padding * 2.0, bounds
                        .getHeight()
                        + padding * 2.0);
                BasicFigure bf = new BasicFigure(bounds);
                bf.setStroke(stroke);
                bf.setStrokePaint(CLASS_ELEMENT_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 nf;
        }
    }
View Full Code Here

                if (ioPort.isMultiport()) {
                    int numberOfLinks = ioPort.linkedRelationList().size();

                    if (numberOfLinks > 1) {
                        // The diagonal is necessary.
                        CompositeFigure compositeFigure = new CompositeFigure(
                                figure) {
                            // Override this because we want to show the type.
                            // It doesn't work to set it once because the type
                            // has not been resolved, and anyway, it may
                            // change. NOTE: This is copied from above.
                            public String getToolTipText() {
                                String tipText = port.getName();
                                String displayName = port.getDisplayName();
                                if (!tipText.equals(displayName)) {
                                    tipText = displayName + " (" + tipText
                                            + ")";
                                }
                                StringAttribute _explAttr = (StringAttribute) (port
                                        .getAttribute("_explanation"));

                                if (_explAttr != null) {
                                    tipText = _explAttr.getExpression();
                                } else if (port instanceof Typeable) {
                                    try {
                                        tipText = tipText + ", type:"
                                                + ((Typeable) port).getType();
                                    } catch (IllegalActionException ex) {
                                        // System.out.println("Tooltip failed: " + ex);
                                    }
                                }
                                return tipText;
                            }
                        };

                        // Line depends on the orientation.
                        double startX;

                        // Line depends on the orientation.
                        double startY;

                        // Line depends on the orientation.
                        double endX;

                        // Line depends on the orientation.
                        double endY;
                        Rectangle2D bounds = figure.getShape().getBounds2D();
                        double x = bounds.getX();
                        double y = bounds.getY();
                        double width = bounds.getWidth();
                        double height = bounds.getHeight();
                        int extent = numberOfLinks - 1;

                        if (direction == SwingConstants.EAST) {
                            startX = x + width;
                            startY = y + (height / 2);
                            endX = startX
                                    + (extent * MULTIPORT_CONNECTION_SPACING);
                            endY = startY
                                    + (extent * MULTIPORT_CONNECTION_SPACING);
                        } else if (direction == SwingConstants.WEST) {
                            startX = x;
                            startY = y + (height / 2);
                            endX = startX
                                    - (extent * MULTIPORT_CONNECTION_SPACING);
                            endY = startY
                                    - (extent * MULTIPORT_CONNECTION_SPACING);
                        } else if (direction == SwingConstants.NORTH) {
                            startX = x + (width / 2);
                            startY = y;
                            endX = startX
                                    - (extent * MULTIPORT_CONNECTION_SPACING);
                            endY = startY
                                    - (extent * MULTIPORT_CONNECTION_SPACING);
                        } else {
                            startX = x + (width / 2);
                            startY = y + height;
                            endX = startX
                                    + (extent * MULTIPORT_CONNECTION_SPACING);
                            endY = startY
                                    + (extent * MULTIPORT_CONNECTION_SPACING);
                        }

                        Line2D line = new Line2D.Double(startX, startY, endX,
                                endY);
                        Figure lineFigure = new BasicFigure(line, fill,
                                (float) 2.0);
                        compositeFigure.add(lineFigure);
                        figure = compositeFigure;
                    }
                }
                // Wrap the figure in a TerminalFigure to set the direction that
                // connectors exit the port. Note that this direction is the
View Full Code Here

        nf.setMinimumIntegerDigits(2);
        nf.setMinimumFractionDigits(2);
        nf.setMaximumFractionDigits(2);

        // The measure-band figure (made up of sub figures below)
        mband = new CompositeFigure();

        // Diagonal line
        mbandLine = new BasicFigure(new GeneralPath(), 1.0f);
        mbandLine.setStrokePaint(Color.white);
        mband.add(mbandLine);
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.