Package diva.canvas

Examples of diva.canvas.FigureLayer


            // Account for the scaling in the pane.
            Point2D transformedPoint = new Point2D.Double();
            pane.getTransformContext().getInverseTransform().transform(point,
                    transformedPoint);

            FigureLayer layer = pane.getForegroundLayer();

            // Find the figure under the point.
            // NOTE: Unfortunately, FigureLayer.getCurrentFigure() doesn't
            // work with a drop target (I guess it hasn't seen the mouse events),
            // so we have to use a lower level mechanism.
            double halo = layer.getPickHalo();
            double width = halo * 2;
            Rectangle2D region = new Rectangle2D.Double(transformedPoint.getX()
                    - halo, transformedPoint.getY() - halo, width, width);
            CanvasComponent figureUnderMouse = layer.pick(region);

            // Find a user object belonging to the figure under the mouse
            // or to any figure containing it (it may be a composite figure).
            Object objectUnderMouse = null;

View Full Code Here


        } else if (source instanceof JGraph) {
            // This is an absurdly convoluted way to get the info we need.
            // But there seems to be no other way.
            // This is an architectural flaw in vergil.
            GraphPane pane = ((JGraph) source).getGraphPane();
            FigureLayer layer = pane.getForegroundLayer();
            CanvasComponent currentFigure = layer.getCurrentFigure();
            GraphController controller = pane.getGraphController();
            GraphModel model = controller.getGraphModel();

            if (currentFigure != null) {
                _target = null;

                while ((_target == null) && (currentFigure != null)) {
                    Object object = currentFigure;

                    if (object instanceof Figure) {
                        object = ((Figure) currentFigure).getUserObject();
                    }

                    _target = (NamedObj) model.getSemanticObject(object);
                    currentFigure = currentFigure.getParent();
                }

                // NOTE: _target may end up null here!
                if (_target == null) {
                    throw new InternalErrorException(
                            "Internal error: Figure has no associated Ptolemy II object!");
                }
            } else {
                _target = (NamedObj) model.getRoot();
            }

            _sourceType = HOTKEY_TYPE;

            // FIXME: set _x and _y.  How to do this?
            _x = 0;
            _y = 0;

            // Set the parent.
            CanvasPane canvasPane = layer.getCanvasPane();
            parent = canvasPane.getCanvas();
        } else {
            _sourceType = null;
            _target = null;
            parent = null;
View Full Code Here

            FSMGraphModel model = (FSMGraphModel) getGraphModel();
            model.getArcModel().setTail(link, sourceObject);

            try {
                // add it to the foreground layer.
                FigureLayer layer = getGraphPane().getForegroundLayer();
                Site headSite;
                Site tailSite;

                // Temporary sites.  One of these will get removed later.
                headSite = new AutonomousSite(layer, event.getLayerX(), event
                        .getLayerY());
                tailSite = new AutonomousSite(layer, event.getLayerX(), event
                        .getLayerY());

                // Render the edge.
                Connector c = getEdgeController(link).render(link, layer,
                        tailSite, headSite);

                // get the actual attach site.
                tailSite = getEdgeController(link).getConnectorTarget()
                        .getTailSite(c, source, event.getLayerX(),
                                event.getLayerY());

                if (tailSite == null) {
                    throw new RuntimeException("Invalid connector target: "
                            + "no valid site found for tail of new connector.");
                }

                // And reattach the connector.
                c.setTailSite(tailSite);

                // Add it to the selection so it gets a manipulator, and
                // make events go to the grab-handle under the mouse
                Figure ef = getFigure(link);
                getSelectionModel().addSelection(ef);

                ConnectorManipulator cm = (ConnectorManipulator) ef.getParent();
                GrabHandle gh = cm.getHeadHandle();
                layer.grabPointer(event, gh);
            } catch (Exception ex) {
                MessageHandler.error("Drag connection failed:", ex);
            }
        }
View Full Code Here

     * each possible anchor point. Note that the labels appear to
     * be in the wrong locations: but they are the anchor of the
     * label itself, not the displayed square, so they are correct.
     */
    public void createLabels() {
        FigureLayer layer = graphicsPane.getForegroundLayer();

        // The data to display
        int[] anchors = { SwingConstants.CENTER, SwingConstants.NORTH,
                SwingConstants.NORTH_EAST, SwingConstants.EAST,
                SwingConstants.SOUTH_EAST, SwingConstants.SOUTH,
                SwingConstants.SOUTH_WEST, SwingConstants.WEST,
                SwingConstants.NORTH_WEST };

        String[] labels = { "center", "north", "north-east", "east",
                "south-east", "south", "south-west", "west", "north-west" };

        String[] fonts = { "Dialog", "DialogInput", "Monospaced", "Serif",
                "SansSerif", "Symbol", "Times", "Courier", "Helvetica" };

        int[] styles = { Font.PLAIN, Font.BOLD, Font.ITALIC,
                Font.BOLD | Font.ITALIC, Font.PLAIN, Font.BOLD, Font.ITALIC,
                Font.BOLD | Font.ITALIC, Font.PLAIN };

        // Draw a rectangle to position them
        BasicRectangle square = new BasicRectangle(160, 80, 120, 120);
        square.setStrokePaint(Color.gray);
        layer.add(square);

        // Create the labels
        for (int i = 0; i < anchors.length; i++) {
            LabelFigure labelFigure = new LabelFigure(labels[i], fonts[i],
                    styles[i], 20);

            // Set the anchor
            labelFigure.setAnchor(anchors[i]);

            // Move the anchor to the right location
            Point2D pt = CanvasUtilities.getLocation(square.getBounds(),
                    CanvasUtilities.reverseDirection(anchors[i]));
            labelFigure.translateTo(pt);

            // Add to the layer
            layer.add(labelFigure);
            labelFigure.setInteractor(defaultInteractor);

            // Draw a small circle there so we can see it
            Figure mark = new BasicEllipse(pt.getX() - 2, pt.getY() - 2, 4, 4,
                    Color.red);
            layer.add(mark);
        }
    }
View Full Code Here

    /** Create a couple of figures with labels attached to them.
     * This simple illustrates the fact that labels can be easily
     * attached to any arbitrary figure.
     */
    public void createLabeledWrappers() {
        FigureLayer layer = graphicsPane.getForegroundLayer();

        Figure a = new BasicEllipse(420, 100, 100, 50);
        LabelWrapper wrapperA = new LabelWrapper(a, "Foo!\nBar!\nBaz!");
        layer.add(wrapperA);
        wrapperA.setInteractor(defaultInteractor);

        Figure b = new BasicRectangle(460, 200, 50, 40, Color.green);
        LabelWrapper wrapperB = new LabelWrapper(b, "Bar!");
        wrapperB.setAnchor(SwingConstants.SOUTH_WEST);
        wrapperB.getLabel().setAnchor(SwingConstants.NORTH_WEST);
        layer.add(wrapperB);
        wrapperB.setInteractor(defaultInteractor);
    }
View Full Code Here

    /** Create instances of Vector Figures and make them
     * draggable and resizeable.
     */
    public void createFigures() {
        FigureLayer layer = graphicsPane.getForegroundLayer();

        // Create a controller to do the work.
        BasicController controller = new BasicController(graphicsPane);
        SelectionInteractor defaultInteractor = controller
                .getSelectionInteractor();
        BoundsManipulator manip = new BoundsManipulator();
        defaultInteractor.setPrototypeDecorator(manip);

        // Create a simple Vector Figure that draws a cross
        VectorFigure one = new VectorFigure();
        one.add(new Line2D.Double(0.0, 0.0, 100.0, 100.0));
        one.add(new Line2D.Double(100.0, 0.0, 0.0, 100.0));
        layer.add(one);
        one.setInteractor(defaultInteractor);

        // Here's a more complicated one, where we explicitly set the
        // shape to be a circle.
        VectorFigure two = new VectorFigure();
        Shape circle = new Ellipse2D.Double(0.0, 0.0, 100.0, 100.0);

        // Draw some filled circles
        two.fillMode();
        two.setShape(circle);
        two.add(Color.blue);
        two.add(circle);

        two.add(Color.yellow);
        two.add(new Ellipse2D.Double(10.0, 10.0, 80.0, 80.0));

        two.add(Color.red);
        two.add(new Ellipse2D.Double(20.0, 20.0, 60.0, 60.0));

        // Draw some lines
        two.lineMode();
        two.add(Color.black);
        two.add(new Line2D.Double(14.65, 14.65, 85.35, 85.35));
        two.add(new Line2D.Double(85.35, 14.65, 14.65, 85.35));

        two.translate(200, 100);
        layer.add(two);
        two.setInteractor(defaultInteractor);
    }
View Full Code Here

    /** Create instances of the class defined
     * in this file. To make the demo a little more interesting,
     * make them draggable.
     */
    public void createFigures() {
        FigureLayer layer = graphicsPane.getForegroundLayer();

        // Create a controller to do the work.
        BasicController controller = new BasicController(graphicsPane);
        SelectionInteractor defaultInteractor = controller
                .getSelectionInteractor();
        BoundsManipulator manip = new BoundsManipulator();
        defaultInteractor.setPrototypeDecorator(manip);

        // Create a custom rectangle and make it draggable
        AbstractFigure blue = new CustomRectangle(10.0, 10.0, 50.0, 50.0);
        layer.add(blue);
        blue.setInteractor(defaultInteractor);
        blue.setToolTipText("Blue figure 1");

        // Create a custom rectangle and make it draggable
        AbstractFigure blue2 = new CustomRectangle(100.0, 100.0, 100.0, 50.0);
        layer.add(blue2);
        blue2.setInteractor(defaultInteractor);
        blue2.setToolTipText("Blue figure 2");

        // Create an image figure and make it draggable
        Image img = Toolkit.getDefaultToolkit().getImage(IMAGE_FILE_NAME);
        MediaTracker tracker = new MediaTracker(canvas);
        tracker.addImage(img, 0);

        try {
            tracker.waitForID(0);
        } catch (InterruptedException e) {
            System.err.println(e + "... in FigureTutorial");
        }

        ImageFigure imgFig = new ImageFigure(img);
        imgFig.translate(300, 100);
        layer.add(imgFig);
        imgFig.setInteractor(defaultInteractor);
        imgFig.setToolTipText("Image figure");
    }
View Full Code Here

    }

    /** Create a collection of terminals an an icon
     */
    public void createTerminals(IconFigure iconFigure) {
        FigureLayer layer = graphicsPane.getForegroundLayer();

        // NORTH
        StraightTerminal north = new StraightTerminal();

        //Site connectNorth = north.getConnectSite();
        Blob blobNorth = new Blob();
        blobNorth.setSizeUnit(5.0);
        north.setEnd(blobNorth);
        iconFigure.addTerminal(north, SwingConstants.NORTH, 50);

        // SOUTH
        StraightTerminal south = new StraightTerminal();

        //Site connectSouth = south.getConnectSite();
        Blob blobSouth = new Blob();
        blobSouth.setStyle(Blob.BLOB_DIAMOND);
        blobSouth.setSizeUnit(5.0);
        blobSouth.setFilled(false);
        south.setEnd(blobSouth);
        iconFigure.addTerminal(south, SwingConstants.SOUTH, 50);

        // WEST
        StraightTerminal west = new StraightTerminal();

        //Site connectWest = west.getConnectSite();
        Arrowhead arrowWest = new Arrowhead();
        west.setEnd(arrowWest);
        iconFigure.addTerminal(west, SwingConstants.WEST, 50);

        // EAST
        StraightTerminal east = new StraightTerminal();

        //Site connectEast = east.getConnectSite();
        Arrowhead arrowEast = new Arrowhead();
        arrowEast.setFlipped(true);
        east.setEnd(arrowEast);
        iconFigure.addTerminal(east, SwingConstants.EAST, 50);

        // Make sure it's clean now
        layer.repaint();
    }
View Full Code Here

    /** Create an icon. The icon's graphic is created
     * by directly calling the PaintedShape API.
     */
    public void createIcon1() {
        FigureLayer layer = graphicsPane.getForegroundLayer();

        // Create the graphic
        PaintedList graphic = new PaintedList();

        Polygon2D polygon = new Polygon2D.Double();
        polygon.moveTo(30, 50);
        polygon.lineTo(70, 80);
        polygon.lineTo(70, 20);
        graphic.add(new PaintedShape(polygon, Color.red, 1.0f));

        Line2D line1 = new Line2D.Double(10, 50, 30, 50);
        graphic.add(new PaintedPath(line1));

        Line2D line2 = new Line2D.Double(70, 50, 90, 50);
        graphic.add(new PaintedPath(line2));

        // Create the icon
        BasicRectangle background = new BasicRectangle(0, 0, 100, 100,
                Color.green.brighter().brighter());
        IconFigure _icon1 = new IconFigure(background, graphic);
        layer.add(_icon1);
        _icon1.setInteractor(defaultInteractor);

        // Add its terminals
        createTerminals(_icon1);
        _icon1.translate(100, 100);
View Full Code Here

    /** Create an icon. The icon's graphic is created
     * by using GraphicsParse.
     */
    public void createIcon2() {
        FigureLayer layer = graphicsPane.getForegroundLayer();

        // Use a hash-table
        PaintedFigure g = new PaintedFigure();

        HashMap map = new HashMap();
        map.put("coords", "30 50 70 80 70 20");
        map.put("fill", "red");
        map.put("width", "1");
        g.add(GraphicsParser.createPaintedObject("polygon", map));

        //Line2D line1 = new Line2D.Double(10,50,30,50);
        //f.add(new PaintedPath(line1));
        //Line2D line2 = new Line2D.Double(70,50,90,50);
        //f.add(new PaintedPath(line2));
        layer.add(g);
        g.setInteractor(defaultInteractor);
        g.translate(100, 0);
    }
View Full Code Here

TOP

Related Classes of diva.canvas.FigureLayer

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.