|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| package org.ericmignot.modeler.gui.palette; |
|
20 |
| |
|
21 |
| import java.awt.Point; |
|
22 |
| |
|
23 |
| import javax.swing.ImageIcon; |
|
24 |
| import javax.swing.JToggleButton; |
|
25 |
| |
|
26 |
| import org.ericmignot.modeler.action.MoveAction; |
|
27 |
| import org.ericmignot.modeler.action.SimplePointCreationAction; |
|
28 |
| import org.ericmignot.modeler.data.Link; |
|
29 |
| import org.ericmignot.modeler.data.SimplePoint; |
|
30 |
| import org.ericmignot.modeler.gui.StaticValues; |
|
31 |
| import org.ericmignot.modeler.gui.workarea.Item; |
|
32 |
| import org.ericmignot.modeler.gui.workarea.LinkItem; |
|
33 |
| import org.ericmignot.modeler.util.action.ActionException; |
|
34 |
| import org.ericmignot.modeler.util.action.NotifyableAction; |
|
35 |
| |
|
36 |
| public class SimplePointCreationTool extends DragAndDropPaletteTool |
|
37 |
| { |
|
38 |
| protected SimplePoint createdPoint; |
|
39 |
| |
|
40 |
0
| public JToggleButton getButton()
|
|
41 |
| { |
|
42 |
0
| if (this.button == null)
|
|
43 |
| { |
|
44 |
0
| this.button = new JToggleButton(
|
|
45 |
| StaticValues.getInstance().get("Design.Palette.LinkPoint", "Link Point"), |
|
46 |
| new ImageIcon(this.getClass().getClassLoader().getResource( |
|
47 |
| "org/ericmignot/modeler/gui/palette/point.gif"))); |
|
48 |
0
| this.button.setToolTipText(StaticValues.getInstance().get("Design.Palette.LinkPointTooltip", "Link point creation tool"));
|
|
49 |
| } |
|
50 |
0
| return this.button;
|
|
51 |
| } |
|
52 |
| |
|
53 |
6
| public boolean isItemCandidate(Item item)
|
|
54 |
| { |
|
55 |
6
| return (item != null && (item instanceof LinkItem));
|
|
56 |
| } |
|
57 |
| |
|
58 |
6
| protected NotifyableAction getAction(Item item, int x, int y)
|
|
59 |
| { |
|
60 |
6
| if (((LinkItem)item).acceptPointForUserInteraction(x, y))
|
|
61 |
| { |
|
62 |
6
| SimplePoint newPoint = new SimplePoint();
|
|
63 |
6
| newPoint.setCenter(x, y);
|
|
64 |
6
| SimplePointCreationAction action = new SimplePointCreationAction(
|
|
65 |
| (Link) item.getBusinessObject(), |
|
66 |
| newPoint, |
|
67 |
| this.getController().getModel() |
|
68 |
| ); |
|
69 |
6
| return action;
|
|
70 |
| } |
|
71 |
0
| return null;
|
|
72 |
| } |
|
73 |
| |
|
74 |
6
| protected void mousePressedImpl()
|
|
75 |
| { |
|
76 |
6
| try {
|
|
77 |
6
| this.createdPoint = (SimplePoint) this.mousePressedAction.execute(null);
|
|
78 |
| } catch (ActionException e) { |
|
79 |
0
| e.printStackTrace();
|
|
80 |
| } |
|
81 |
| } |
|
82 |
| |
|
83 |
4
| protected void mouseDraggedImpl(Point delta)
|
|
84 |
| { |
|
85 |
4
| MoveAction action = new MoveAction(this.createdPoint, delta);
|
|
86 |
4
| try {
|
|
87 |
4
| action.execute(null);
|
|
88 |
| } catch (ActionException e) { |
|
89 |
0
| e.printStackTrace();
|
|
90 |
| } |
|
91 |
| } |
|
92 |
| |
|
93 |
| } |