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;
}
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;
}
Aggregations