Search in sources :

Example 1 with RubberBandRectShape

use of cbit.gui.graph.RubberBandRectShape in project vcell by virtualcell.

the class ReactionCartoonTool method mousePressed.

@Override
public void mousePressed(MouseEvent event) {
    if (getReactionCartoon() == null) {
        return;
    }
    try {
        int eventX = event.getX();
        int eventY = event.getY();
        startPointWorld = new java.awt.Point((int) (eventX * 100.0 / getReactionCartoon().getZoomPercent()), (int) (eventY * 100.0 / getReactionCartoon().getZoomPercent()));
        startShape = getReactionCartoon().pickWorld(startPointWorld);
        if (event.isPopupTrigger()) {
            // Mac popup
            popupMenu(getReactionCartoon().getSelectedShape(), eventX, eventY);
        } else if (event.getButton() != MouseEvent.BUTTON1) {
            // this may be a win, linux popup menu gesture on mouseRELEASED, let it pass through
            return;
        } else if (mode == Mode.STRUCTURE) {
            final RXContainerDropTargetInfo selectedContainerDropTargetInfo = getSelectedContainerDropTargetInfo();
            if (selectedContainerDropTargetInfo != null) {
                JPopupMenu jPopupMenu = new JPopupMenu();
                JMenuItem menuItem = new JMenuItem("Add Compartment");
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        addStructure(false, selectedContainerDropTargetInfo);
                    }
                });
                jPopupMenu.add(menuItem);
                menuItem = new JMenuItem("Add Membrane");
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        addStructure(true, selectedContainerDropTargetInfo);
                    }
                });
                jPopupMenu.add(menuItem);
                jPopupMenu.show(event.getComponent(), event.getX(), event.getY());
            }
        } else if (mode == Mode.SELECT) {
            // User force select
            boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
            selectEventFromWorld(startPointWorld, bShift);
            if (startShape instanceof ReactionContainerShape) {
                // setup potential compartment 'drag'
                rectShape = new RubberBandRectShape(startPointWorld, startPointWorld, getReactionCartoon());
                Rectangle labelOutlineRectangle = ((ReactionContainerShape) startShape).getLabelOutline(startShape.getAbsX(), startShape.getAbsY());
                bStartRxContainerLabel = labelOutlineRectangle.contains(startPointWorld.x, startPointWorld.y);
                if (bStartRxContainerLabel) {
                    lastRXContainerDropTargetInfoMap = updateRXContainerDropTargetInfoMap(startPointWorld);
                    // popup menu or name double-click
                    if (dragStructTimer != null) {
                        dragStructTimer.stop();
                    }
                    dragStructTimer = new Timer(500, new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            activateDropTargetEnable();
                            getGraphPane().repaint();
                        }
                    });
                    dragStructTimer.setRepeats(false);
                    dragStructTimer.start();
                }
            }
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mousePressed: uncaught exception");
        e.printStackTrace(System.out);
    }
}
Also used : ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) ActionEvent(java.awt.event.ActionEvent) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) ActionListener(java.awt.event.ActionListener) Timer(javax.swing.Timer) JMenuItem(javax.swing.JMenuItem)

Example 2 with RubberBandRectShape

use of cbit.gui.graph.RubberBandRectShape in project vcell by virtualcell.

the class PathwayGraphTool method mouseDragged.

@Override
public void mouseDragged(MouseEvent event) {
    if ((event.getModifiers() & (InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        return;
    }
    boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
    boolean bCntrl = (event.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
    try {
        switch(mode) {
            case SELECT:
                {
                    Point worldPoint = screenToWorld(event.getX(), event.getY());
                    if (bMoving) {
                        List<Shape> selectedShapes = getGraphModel().getSelectedShapes();
                        // constrain to stay within the corresponding parent for the
                        // "movingShape" as well as all other selected (hence
                        // moving) shapes.
                        Point movingParentLoc = movingShape.getParent().getSpaceManager().getAbsLoc();
                        Dimension movingParentSize = movingShape.getParent().getSpaceManager().getSize();
                        worldPoint.x = Math.max(movingOffsetWorld.x + movingParentLoc.x, Math.min(movingOffsetWorld.x + movingParentLoc.x + movingParentSize.width - movingShape.getSpaceManager().getSize().width, worldPoint.x));
                        worldPoint.y = Math.max(movingOffsetWorld.y + movingParentLoc.y, Math.min(movingOffsetWorld.x + movingParentLoc.y + movingParentSize.height - movingShape.getSpaceManager().getSize().height, worldPoint.y));
                        for (Shape shape : selectedShapes) {
                            if (shape != movingShape && shape instanceof BioPaxShape) {
                                Point selectedParentLoc = shape.getParent().getSpaceManager().getAbsLoc();
                                Dimension selectedParentSize = shape.getParent().getSpaceManager().getSize();
                                int selectedMovingOffsetX = movingOffsetWorld.x + (movingShape.getSpaceManager().getAbsLoc().x - shape.getSpaceManager().getAbsLoc().x);
                                int selectedMovingOffsetY = movingOffsetWorld.y + (movingShape.getSpaceManager().getAbsLoc().y - shape.getSpaceManager().getAbsLoc().y);
                                worldPoint.x = Math.max(selectedMovingOffsetX + selectedParentLoc.x, Math.min(selectedMovingOffsetX + selectedParentLoc.x + selectedParentSize.width - shape.getSpaceManager().getSize().width, worldPoint.x));
                                worldPoint.y = Math.max(selectedMovingOffsetY + selectedParentLoc.y, Math.min(selectedMovingOffsetY + selectedParentLoc.y + selectedParentSize.height - shape.getSpaceManager().getSize().height, worldPoint.y));
                            }
                        }
                        getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        Point newMovingPoint = new Point(worldPoint.x - movingOffsetWorld.x, worldPoint.y - movingOffsetWorld.y);
                        int deltaX = newMovingPoint.x - movingPointWorld.x;
                        int deltaY = newMovingPoint.y - movingPointWorld.y;
                        movingPointWorld = newMovingPoint;
                        movingShape.getSpaceManager().setRelPos(movingPointWorld.x - movingParentLoc.x, movingPointWorld.y - movingParentLoc.y);
                        // them also
                        for (Shape shape : selectedShapes) {
                            if (shape != movingShape) {
                                shape.getSpaceManager().move(deltaX, deltaY);
                            }
                        }
                        getGraphPane().invalidate();
                        ((JViewport) getGraphPane().getParent()).revalidate();
                        getGraphPane().repaint();
                    } else if (bRectStretch) {
                        // constrain to stay within parent
                        Point parentLoc = rectShape.getParent().getSpaceManager().getAbsLoc();
                        Dimension parentSize = rectShape.getParent().getSpaceManager().getSize();
                        worldPoint.x = Math.max(1, Math.min(parentSize.width - 1, worldPoint.x - parentLoc.x)) + parentLoc.x;
                        worldPoint.y = Math.max(1, Math.min(parentSize.height - 1, worldPoint.y - parentLoc.y)) + parentLoc.y;
                        getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        // getGraphPane().repaint();
                        Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                        AffineTransform oldTransform = g.getTransform();
                        g.scale(0.01 * getGraphModel().getZoomPercent(), 0.01 * getGraphModel().getZoomPercent());
                        g.setXORMode(Color.white);
                        rectShape.setEnd(endPointWorld);
                        rectShape.paint(g, 0, 0);
                        endPointWorld = worldPoint;
                        rectShape.setEnd(endPointWorld);
                        rectShape.paint(g, 0, 0);
                        g.setTransform(oldTransform);
                    } else {
                        Shape shape = (getGraphModel().getSelectedShape() != null ? getGraphModel().getSelectedShape() : getGraphModel().pickWorld(worldPoint));
                        if (!bCntrl && !bShift && shape instanceof BioPaxShape) {
                            bMoving = true;
                            movingShape = shape;
                            movingPointWorld = shape.getSpaceManager().getAbsLoc();
                            movingOffsetWorld = new Point(worldPoint.x - movingPointWorld.x, worldPoint.y - movingPointWorld.y);
                        } else if (shape instanceof PathwayContainerShape || bShift || bCntrl) {
                            bRectStretch = true;
                            endPointWorld = new Point(worldPoint.x + 1, worldPoint.y + 1);
                            rectShape = new RubberBandRectShape(worldPoint, endPointWorld, getGraphModel());
                            rectShape.setEnd(endPointWorld);
                            if (!(shape instanceof PathwayContainerShape)) {
                                shape.getParent().addChildShape(rectShape);
                            } else {
                                shape.addChildShape(rectShape);
                            }
                            Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                            AffineTransform oldTransform = g.getTransform();
                            g.scale(0.01 * getGraphModel().getZoomPercent(), 0.01 * getGraphModel().getZoomPercent());
                            g.setXORMode(Color.white);
                            rectShape.paint(g, 0, 0);
                            g.setTransform(oldTransform);
                        }
                    }
                    break;
                }
            default:
                {
                    break;
                }
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mouseDragged: uncaught exception");
        e.printStackTrace(System.out);
    }
}
Also used : RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) PathwayContainerShape(cbit.vcell.client.desktop.biomodel.pathway.shapes.PathwayContainerShape) Shape(cbit.gui.graph.Shape) BioPaxShape(cbit.vcell.client.desktop.biomodel.pathway.shapes.BioPaxShape) BioPaxShape(cbit.vcell.client.desktop.biomodel.pathway.shapes.BioPaxShape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) AffineTransform(java.awt.geom.AffineTransform) List(java.util.List) PathwayContainerShape(cbit.vcell.client.desktop.biomodel.pathway.shapes.PathwayContainerShape) Point(java.awt.Point) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 3 with RubberBandRectShape

use of cbit.gui.graph.RubberBandRectShape in project vcell by virtualcell.

the class WorkflowCartoonTool method mouseDragged.

@Override
public void mouseDragged(java.awt.event.MouseEvent event) {
    if ((event.getModifiers() & (InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        return;
    }
    boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
    boolean bCntrl = (event.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
    // 
    try {
        switch(mode) {
            case SELECT:
                {
                    Point worldPoint = screenToWorld(event.getX(), event.getY());
                    if (bMoving) {
                        List<Shape> selectedShapes = getGraphModel().getSelectedShapes();
                        // constrain to stay within the corresponding parent for the
                        // "movingShape" as well as all other selected (hence
                        // moving) shapes.
                        Point movingParentLoc = movingShape.getParent().getSpaceManager().getAbsLoc();
                        Dimension movingParentSize = movingShape.getParent().getSpaceManager().getSize();
                        worldPoint.x = Math.max(movingOffsetWorld.x + movingParentLoc.x, Math.min(movingOffsetWorld.x + movingParentLoc.x + movingParentSize.width - movingShape.getSpaceManager().getSize().width, worldPoint.x));
                        worldPoint.y = Math.max(movingOffsetWorld.y + movingParentLoc.y, Math.min(movingOffsetWorld.x + movingParentLoc.y + movingParentSize.height - movingShape.getSpaceManager().getSize().height, worldPoint.y));
                        for (Shape selectedShape : selectedShapes) {
                            if (selectedShape != movingShape) {
                                Point selectedParentLoc = selectedShape.getParent().getSpaceManager().getAbsLoc();
                                Dimension selectedParentSize = selectedShape.getParent().getSpaceManager().getSize();
                                int selectedMovingOffsetX = movingOffsetWorld.x + (movingShape.getSpaceManager().getAbsLoc().x - selectedShape.getSpaceManager().getAbsLoc().x);
                                int selectedMovingOffsetY = movingOffsetWorld.y + (movingShape.getSpaceManager().getAbsLoc().y - selectedShape.getSpaceManager().getAbsLoc().y);
                                worldPoint.x = Math.max(selectedMovingOffsetX + selectedParentLoc.x, Math.min(selectedMovingOffsetX + selectedParentLoc.x + selectedParentSize.width - selectedShape.getSpaceManager().getSize().width, worldPoint.x));
                                worldPoint.y = Math.max(selectedMovingOffsetY + selectedParentLoc.y, Math.min(selectedMovingOffsetY + selectedParentLoc.y + selectedParentSize.height - selectedShape.getSpaceManager().getSize().height, worldPoint.y));
                            }
                        }
                        getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        Point newMovingPoint = new Point(worldPoint.x - movingOffsetWorld.x, worldPoint.y - movingOffsetWorld.y);
                        int deltaX = newMovingPoint.x - movingPointWorld.x;
                        int deltaY = newMovingPoint.y - movingPointWorld.y;
                        movingPointWorld = newMovingPoint;
                        movingShape.getSpaceManager().setRelPos(movingPointWorld.x - movingParentLoc.x, movingPointWorld.y - movingParentLoc.y);
                        // them also
                        if (selectedShapes != null) {
                            for (Shape selectedShape : selectedShapes) {
                                if (selectedShape != movingShape) {
                                    selectedShape.getSpaceManager().move(deltaX, deltaY);
                                }
                            }
                        }
                        getGraphPane().invalidate();
                        ((JViewport) getGraphPane().getParent()).revalidate();
                        getGraphPane().repaint();
                    } else if (bRectStretch) {
                        // constain to stay within parent
                        Point parentLoc = rectShape.getParent().getSpaceManager().getAbsLoc();
                        Dimension parentSize = rectShape.getParent().getSpaceManager().getSize();
                        worldPoint.x = Math.max(1, Math.min(parentSize.width - 1, worldPoint.x - parentLoc.x)) + parentLoc.x;
                        worldPoint.y = Math.max(1, Math.min(parentSize.height - 1, worldPoint.y - parentLoc.y)) + parentLoc.y;
                        getGraphPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        // getGraphPane().repaint();
                        Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                        java.awt.geom.AffineTransform oldTransform = g.getTransform();
                        g.scale(0.01 * getGraphModel().getZoomPercent(), 0.01 * getGraphModel().getZoomPercent());
                        g.setXORMode(Color.white);
                        rectShape.setEnd(endPointWorld);
                        rectShape.paint(g, 0, 0);
                        endPointWorld = worldPoint;
                        rectShape.setEnd(endPointWorld);
                        rectShape.paint(g, 0, 0);
                        g.setTransform(oldTransform);
                    } else {
                        Shape shape = (getGraphModel().getSelectedShape() != null ? getGraphModel().getSelectedShape() : getGraphModel().pickWorld(worldPoint));
                        if (!bCntrl && !bShift && (ShapeUtil.isMovable(shape))) {
                            bMoving = true;
                            movingShape = shape;
                            movingPointWorld = shape.getSpaceManager().getAbsLoc();
                            movingOffsetWorld = new Point(worldPoint.x - movingPointWorld.x, worldPoint.y - movingPointWorld.y);
                        } else if (shape instanceof ContainerShape || bShift || bCntrl) {
                            bRectStretch = true;
                            endPointWorld = new Point(worldPoint.x + 1, worldPoint.y + 1);
                            rectShape = new RubberBandRectShape(worldPoint, endPointWorld, getGraphModel());
                            rectShape.setEnd(endPointWorld);
                            if (!(shape instanceof ContainerShape)) {
                                shape.getParent().addChildShape(rectShape);
                            } else {
                                shape.addChildShape(rectShape);
                            }
                            Graphics2D g = (Graphics2D) getGraphPane().getGraphics();
                            AffineTransform oldTransform = g.getTransform();
                            g.scale(0.01 * getGraphModel().getZoomPercent(), 0.01 * getGraphModel().getZoomPercent());
                            g.setXORMode(Color.white);
                            rectShape.paint(g, 0, 0);
                            g.setTransform(oldTransform);
                        }
                    }
                    break;
                }
            default:
                {
                    break;
                }
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mouseDragged: uncaught exception");
        e.printStackTrace(System.out);
    }
}
Also used : RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) NodeShape(cbit.gui.graph.NodeShape) EdgeShape(cbit.gui.graph.EdgeShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) Point(java.awt.Point) Dimension(java.awt.Dimension) AffineTransform(java.awt.geom.AffineTransform) Graphics2D(java.awt.Graphics2D) ContainerShape(cbit.gui.graph.ContainerShape) AffineTransform(java.awt.geom.AffineTransform) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)3 Point (java.awt.Point)3 Shape (cbit.gui.graph.Shape)2 Dimension (java.awt.Dimension)2 Graphics2D (java.awt.Graphics2D)2 AffineTransform (java.awt.geom.AffineTransform)2 List (java.util.List)2 ContainerShape (cbit.gui.graph.ContainerShape)1 EdgeShape (cbit.gui.graph.EdgeShape)1 NodeShape (cbit.gui.graph.NodeShape)1 BioPaxShape (cbit.vcell.client.desktop.biomodel.pathway.shapes.BioPaxShape)1 PathwayContainerShape (cbit.vcell.client.desktop.biomodel.pathway.shapes.PathwayContainerShape)1 ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 Rectangle (java.awt.Rectangle)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 JMenuItem (javax.swing.JMenuItem)1