1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.ericmignot.modeler.gui.palette; |
19 |
| |
20 |
| import java.awt.event.MouseEvent; |
21 |
| import java.util.List; |
22 |
| |
23 |
| import javax.swing.JToggleButton; |
24 |
| |
25 |
| import org.ericmignot.modeler.gui.Controller; |
26 |
| import org.ericmignot.modeler.gui.StaticValues; |
27 |
| import org.ericmignot.modeler.gui.workarea.Item; |
28 |
| import org.ericmignot.modeler.util.action.NotifyableAction; |
29 |
| import org.ericmignot.modeler.util.graphic.Tool; |
30 |
| |
31 |
| public abstract class PaletteTool extends Tool |
32 |
| { |
33 |
| private Controller controller; |
34 |
| private String doEvent; |
35 |
| private String undoEvent; |
36 |
| |
37 |
| protected Item targetedItem; |
38 |
| |
39 |
90
| public PaletteTool()
|
40 |
| { |
41 |
90
| this.setDoEvent(null);
|
42 |
90
| this.setUndoEvent(null);
|
43 |
| } |
44 |
| |
45 |
111
| public void setDoEvent(String event)
|
46 |
| { |
47 |
111
| this.doEvent = event;
|
48 |
| } |
49 |
| |
50 |
30
| public String getDoEvent()
|
51 |
| { |
52 |
30
| return this.doEvent;
|
53 |
| } |
54 |
30
| public String getUndoEvent()
|
55 |
| { |
56 |
30
| return undoEvent;
|
57 |
| } |
58 |
| |
59 |
111
| public void setUndoEvent(String undoEvent)
|
60 |
| { |
61 |
111
| this.undoEvent = undoEvent;
|
62 |
| } |
63 |
| |
64 |
201
| public Controller getController()
|
65 |
| { |
66 |
201
| return controller;
|
67 |
| } |
68 |
| |
69 |
62
| public void setController(Controller controller)
|
70 |
| { |
71 |
62
| this.controller = controller;
|
72 |
| } |
73 |
| public abstract JToggleButton getButton(); |
74 |
| public abstract boolean shouldItemRegister(Item item); |
75 |
| public abstract boolean shouldWorkAreaRegister(); |
76 |
| public abstract void registerItem(Item item); |
77 |
| public abstract void unregisterItem(Item item); |
78 |
| |
79 |
16
| protected Item getItemUnder(int x, int y)
|
80 |
| { |
81 |
16
| return this.getController().getWorkArea().getItemAt(x, y);
|
82 |
| } |
83 |
14
| protected List getItemsUnder(int x, int y)
|
84 |
| { |
85 |
14
| return this.getController().getWorkArea().getItemsAt(x, y);
|
86 |
| } |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
0
| public void mousePressed(MouseEvent e)
|
93 |
| { |
94 |
0
| if (e.isConsumed()) return;
|
95 |
0
| this.itemPressed((Item) e.getSource(), e.getX(), e.getY());
|
96 |
0
| e.consume();
|
97 |
| } |
98 |
| public abstract void itemPressed(Item item, int x, int y); |
99 |
| |
100 |
0
| public void mouseDragged(MouseEvent e)
|
101 |
| { |
102 |
0
| if (e.isConsumed()) return;
|
103 |
0
| this.itemDragged(e.getX(), e.getY());
|
104 |
0
| e.consume();
|
105 |
| } |
106 |
| public abstract void itemDragged(int x, int y); |
107 |
| |
108 |
0
| public void mouseReleased(MouseEvent e)
|
109 |
| { |
110 |
0
| if (e.isConsumed()) return;
|
111 |
0
| this.targetedItem = (Item) e.getSource();
|
112 |
0
| if (this.itemReleased() != null)
|
113 |
| { |
114 |
0
| e.consume();
|
115 |
| } |
116 |
| } |
117 |
| |
118 |
24
| public final NotifyableAction itemReleased()
|
119 |
| { |
120 |
24
| NotifyableAction action = this.manageReleased();
|
121 |
24
| if (action != null)
|
122 |
| { |
123 |
18
| action.setDoEvent(this.getDoEvent());
|
124 |
18
| action.setUndoEvent(this.getUndoEvent());
|
125 |
18
| if (this.getController() != null)
|
126 |
| { |
127 |
18
| this.getController().treatExecute(action);
|
128 |
| } |
129 |
| } |
130 |
24
| this.fireItemClicked();
|
131 |
24
| return action;
|
132 |
| } |
133 |
| |
134 |
25
| public void fireItemClicked()
|
135 |
| { |
136 |
25
| if (this.targetedItem == null
|
137 |
| || this.getController().getWorkArea().getComponentZOrder(this.targetedItem) == -1) |
138 |
| { |
139 |
17
| return;
|
140 |
| } |
141 |
8
| String javascriptCall = StaticValues.getInstance().get("Interface.ObjectClicked", null);
|
142 |
8
| if (javascriptCall != null)
|
143 |
| { |
144 |
0
| if (javascriptCall.indexOf("xml") != -1)
|
145 |
| { |
146 |
0
| javascriptCall = javascriptCall.replaceAll("xml", "\"" + this.targetedItem.getBusinessObject().getXML() + "\"");
|
147 |
| } |
148 |
0
| this.getController().getInteroperable().fireEvent(javascriptCall);
|
149 |
| } |
150 |
| } |
151 |
| |
152 |
| |
153 |
| |
154 |
| |
155 |
| |
156 |
| public abstract NotifyableAction manageReleased(); |
157 |
| |
158 |
| |
159 |
| } |