/** * Creates a new figure at the location where the mouse was pressed. */ @Override public void mousePressed(MouseEvent e) { // Note: The search sequence used here, must be // consistent with the search sequence used by the // HandleTracker, SelectAreaTracker, DelegationSelectionTool, SelectionTool. if (typingTarget != null) { endEdit(); if (isToolDoneAfterCreation()) { fireToolDone(); } } else { super.mousePressed(e); // update view so the created figure is drawn before the floating text // figure is overlaid. TextHolderFigure textHolder = (TextHolderFigure)getCreatedFigure(); getView().clearSelection(); getView().addToSelection(textHolder); beginEdit(textHolder); updateCursor(getView(), e.getPoint()); } }
@Override public void actionPerformed(ActionEvent event) { endEdit(); if (isToolDoneAfterCreation()) { fireToolDone(); } } @Override
@Override protected void creationFinished(Figure createdFigure) { beginEdit((TextHolderFigure) createdFigure); updateCursor(getView(), new Point(0,0)); }
@Override public void keyReleased(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_ESCAPE || isToolDoneAfterCreation()) { fireToolDone(); } } @Override
protected void beginEdit(TextHolderFigure textHolder) { if (textField == null) { textField = new FloatingTextField(); textField.addActionListener(this); } if (textHolder != typingTarget && typingTarget != null) { endEdit(); } textField.createOverlay(getView(), textHolder); textField.requestFocus(); typingTarget = textHolder; }
} else { if (createdFigure != null) { getDrawing().remove((Figure)getAddedFigure()); getDrawing().fireUndoableEditHappened(edit);
attributes.put(AttributeKeys.FILL_COLOR, Color.black); attributes.put(AttributeKeys.STROKE_COLOR, null); btn = ButtonFactory.addToolTo(this, editor, textTool = new TextCreationTool(new SVGTextFigure(), attributes), "createText", labels); textTool.setToolDoneAfterCreation(true); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); gbc = new GridBagConstraints();
private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey, Object> attributes; ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.net.Labels"); ButtonFactory.addSelectionToolTo(tb, editor); tb.addSeparator(); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.white); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); attributes.put(AttributeKeys.TEXT_COLOR, Color.black); ButtonFactory.addToolTo(tb, editor, new TextCreationTool(new NodeFigure(), attributes), "edit.createNode", labels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.STROKE_COLOR, new Color(0x000099)); ButtonFactory.addToolTo(tb, editor, new ConnectionTool(new LineConnectionFigure(), attributes), "edit.createLink", labels); }
@Override public void deactivate(DrawingEditor editor) { endEdit(); super.deactivate(editor); } /**
@Override public void updateCursor(DrawingView view, Point p) { if (view.isEnabled()) { view.setCursor(Cursor.getPredefinedCursor(isEditing() ? Cursor.DEFAULT_CURSOR : Cursor.CROSSHAIR_CURSOR)); } else { view.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } } }
private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey,Object> attributes; ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.net.Labels"); ButtonFactory.addSelectionToolTo(tb, editor); tb.addSeparator(); attributes = new HashMap<AttributeKey,Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.white); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); attributes.put(AttributeKeys.TEXT_COLOR, Color.black); ButtonFactory.addToolTo(tb, editor, new TextCreationTool(new NodeFigure(), attributes), "edit.createNode", labels); attributes = new HashMap<AttributeKey,Object>(); attributes.put(AttributeKeys.STROKE_COLOR, new Color(0x000099)); ButtonFactory.addToolTo(tb, editor, new ConnectionTool(new LineConnectionFigure(), attributes), "edit.createLink", labels); }
ButtonFactory.addToolTo(tb, editor, new BezierTool(new BezierFigure()), "edit.createScribble", labels); ButtonFactory.addToolTo(tb, editor, new BezierTool(new BezierFigure(true)), "edit.createPolygon", labels); ButtonFactory.addToolTo(tb, editor, new TextCreationTool(new TextFigure()), "edit.createText", labels); ButtonFactory.addToolTo(tb, editor, new TextAreaCreationTool(new TextAreaFigure()), "edit.createTextArea", labels);
ButtonFactory.addToolTo(tb, editor, new BezierTool(new BezierFigure()), "edit.createScribble", labels); ButtonFactory.addToolTo(tb, editor, new BezierTool(new BezierFigure(true)), "edit.createPolygon", labels); ButtonFactory.addToolTo(tb, editor, new TextCreationTool(new TextFigure()), "edit.createText", labels); ButtonFactory.addToolTo(tb, editor, new TextAreaCreationTool(new TextAreaFigure()), "edit.createTextArea", labels); ButtonFactory.addToolTo(tb, editor, new ImageTool(new ImageFigure()), "edit.createImage", labels);