Search in sources :

Example 1 with GraphResizeManager

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

the class ReactionCartoonTool method getDropTargetRectangleMap.

private HashMap<Rectangle, Boolean> getDropTargetRectangleMap(boolean bZoomAdjust, boolean bExcludeNonActionDropTargets) {
    GraphResizeManager graphResizeManager = getGraphModel().getResizeManager();
    HashMap<Rectangle, Boolean> dropTargetRectangleMap = new HashMap<Rectangle, Boolean>();
    for (RXContainerDropTargetInfo rxContainerDropTargetInfo : lastRXContainerDropTargetInfoMap.keySet()) {
        if (bExcludeNonActionDropTargets && (startShape == rxContainerDropTargetInfo.dropShape || startShape == rxContainerDropTargetInfo.closestNeighborShape)) {
            continue;
        }
        Rectangle dropTargetRectangle = rxContainerDropTargetInfo.absoluteRectangle;
        if (bZoomAdjust) {
            dropTargetRectangle = new Rectangle((int) graphResizeManager.zoom(rxContainerDropTargetInfo.absoluteRectangle.x), (int) graphResizeManager.zoom(rxContainerDropTargetInfo.absoluteRectangle.y), (int) graphResizeManager.zoom(rxContainerDropTargetInfo.absoluteRectangle.width), (int) graphResizeManager.zoom(rxContainerDropTargetInfo.absoluteRectangle.height));
        }
        dropTargetRectangleMap.put(dropTargetRectangle, lastRXContainerDropTargetInfoMap.get(rxContainerDropTargetInfo));
    }
    return dropTargetRectangleMap;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Rectangle(java.awt.Rectangle) GraphResizeManager(cbit.gui.graph.GraphResizeManager)

Example 2 with GraphResizeManager

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

the class ReactionCartoonTool method editInPlace.

private void editInPlace(final Shape selectedShape, Point worldPoint) {
    if (getGraphPane().getComponentCount() > 0) {
        // remove any existing editor
        getGraphPane().remove(0);
    }
    Rectangle labelOutline = null;
    // What kind of thing is being edited
    if (selectedShape instanceof ReactionContainerShape) {
        labelOutline = ((ReactionContainerShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
        if (!labelOutline.contains(worldPoint)) {
            return;
        }
    } else if (selectedShape instanceof SpeciesContextShape) {
        labelOutline = ((SpeciesContextShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
    } else if (selectedShape instanceof SimpleReactionShape) {
        labelOutline = ((SimpleReactionShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
    } else if (selectedShape instanceof FluxReactionShape) {
        labelOutline = ((FluxReactionShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
    } else if (selectedShape instanceof ReactionRuleDiagramShape) {
        labelOutline = ((ReactionRuleDiagramShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
    } else {
        return;
    }
    // Add press 'Enter' action, 'Escape' action, editor gets focus and mouse 'Exit' parent action
    if (true) {
        final JTextField jTextField = new JTextField(selectedShape.getLabel());
        jTextField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    // Type specific edit actions
                    if (selectedShape instanceof ReactionContainerShape) {
                        ((ReactionContainerShape) selectedShape).getStructure().setName(jTextField.getText(), true);
                    } else if (selectedShape instanceof SpeciesContextShape) {
                        ((SpeciesContextShape) selectedShape).getSpeciesContext().setName(jTextField.getText());
                    } else if (selectedShape instanceof SimpleReactionShape) {
                        ((SimpleReactionShape) selectedShape).getReactionStep().setName(jTextField.getText());
                    } else if (selectedShape instanceof FluxReactionShape) {
                        ((FluxReactionShape) selectedShape).getReactionStep().setName(jTextField.getText());
                    } else if (selectedShape instanceof ReactionRuleDiagramShape) {
                        ((ReactionRuleDiagramShape) selectedShape).getReactionRule().setName(jTextField.getText());
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                    DialogUtils.showErrorDialog(ReactionCartoonTool.this.getGraphPane(), e2.getMessage());
                }
                stopEditing();
            }
        });
        // just to be sure
        ReactionCartoonTool.this.getGraphPane().removeMouseListener(myStopEditAdapter);
        ReactionCartoonTool.this.getGraphPane().addMouseListener(myStopEditAdapter);
        getGraphModel().removeGraphListener(myGraphListener);
        getGraphModel().addGraphListener(myGraphListener);
        InputMap im = jTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        ActionMap am = jTextField.getActionMap();
        im.put(KeyStroke.getKeyStroke("ESCAPE"), "cancelChange");
        am.put("cancelChange", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                stopEditing();
            }
        });
        GraphResizeManager grm = getGraphModel().getResizeManager();
        jTextField.setBounds((int) grm.zoom(labelOutline.x), (int) grm.zoom(labelOutline.y), Math.max((int) grm.zoom(labelOutline.width + 2), 100), Math.max((int) grm.zoom(labelOutline.height + 2), 20));
        getGraphPane().add(jTextField);
        getGraphPane().validate();
        jTextField.requestFocus();
    }
    return;
}
Also used : ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) ActionMap(javax.swing.ActionMap) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ActionEvent(java.awt.event.ActionEvent) Rectangle(java.awt.Rectangle) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) JTextField(javax.swing.JTextField) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ActionListener(java.awt.event.ActionListener) InputMap(javax.swing.InputMap) GraphResizeManager(cbit.gui.graph.GraphResizeManager) AbstractAction(javax.swing.AbstractAction)

Aggregations

GraphResizeManager (cbit.gui.graph.GraphResizeManager)2 Rectangle (java.awt.Rectangle)2 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)1 ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)1 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)1 SimpleReactionShape (cbit.vcell.graph.SimpleReactionShape)1 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyVetoException (java.beans.PropertyVetoException)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 AbstractAction (javax.swing.AbstractAction)1 ActionMap (javax.swing.ActionMap)1 InputMap (javax.swing.InputMap)1 JTextField (javax.swing.JTextField)1 UserCancelException (org.vcell.util.UserCancelException)1 UtilCancelException (org.vcell.util.UtilCancelException)1