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.event.MouseEvent; |
22 |
| import java.util.List; |
23 |
| |
24 |
| import javax.swing.JToggleButton; |
25 |
| |
26 |
| import org.ericmignot.modeler.gui.workarea.Item; |
27 |
| import org.ericmignot.modeler.util.action.NotifyableAction; |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| public abstract class ItemPaletteTool extends PaletteTool |
35 |
| { |
36 |
| |
37 |
| protected JToggleButton button; |
38 |
| |
39 |
36
| public ItemPaletteTool()
|
40 |
| { |
41 |
36
| this.button = null;
|
42 |
| } |
43 |
| |
44 |
11
| public boolean shouldItemRegister(Item item)
|
45 |
| { |
46 |
11
| return false;
|
47 |
| } |
48 |
| |
49 |
3
| public boolean shouldWorkAreaRegister()
|
50 |
| { |
51 |
3
| return true;
|
52 |
| } |
53 |
| |
54 |
0
| public void registerItem(Item item)
|
55 |
| { |
56 |
| } |
57 |
| |
58 |
0
| public void unregisterItem(Item item)
|
59 |
| { |
60 |
| } |
61 |
| |
62 |
0
| public void mousePressed(MouseEvent e){}
|
63 |
0
| public void itemPressed(Item item, int x, int y){}
|
64 |
0
| public void itemDragged(int x, int y){}
|
65 |
| |
66 |
0
| public NotifyableAction manageReleased() {return null;}
|
67 |
| |
68 |
0
| public void mouseReleased(MouseEvent e)
|
69 |
| { |
70 |
0
| if (e.isConsumed()) return;
|
71 |
| |
72 |
0
| NotifyableAction action = this.workAreaReleased(e.getX(), e.getY());
|
73 |
0
| if (action != null)
|
74 |
| { |
75 |
0
| if (this.getController() != null)
|
76 |
| { |
77 |
0
| this.getController().treatExecute(action);
|
78 |
| } |
79 |
| } |
80 |
0
| this.fireItemClicked();
|
81 |
0
| e.consume();
|
82 |
| } |
83 |
| |
84 |
14
| public NotifyableAction workAreaReleased(int x, int y)
|
85 |
| { |
86 |
14
| List items = this.getItemsUnder(x, y);
|
87 |
14
| for (int i = 0; i < items.size(); i ++)
|
88 |
| { |
89 |
13
| Item itemUnder = (Item) items.get(i);
|
90 |
13
| if (this.isItemCandidate(itemUnder))
|
91 |
| { |
92 |
13
| NotifyableAction action = this.getAction(itemUnder, x, y);
|
93 |
13
| if (action != null)
|
94 |
| { |
95 |
12
| this.targetedItem = itemUnder;
|
96 |
12
| action.setDoEvent(this.getDoEvent());
|
97 |
12
| action.setUndoEvent(this.getUndoEvent());
|
98 |
12
| return action;
|
99 |
| } |
100 |
| } |
101 |
| } |
102 |
2
| return null;
|
103 |
| } |
104 |
| |
105 |
| public abstract boolean isItemCandidate(Item item); |
106 |
| protected abstract NotifyableAction getAction(Item item, int x, int y); |
107 |
| |
108 |
| } |