|
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 |
| |
|
21 |
| import java.awt.BorderLayout; |
|
22 |
| import java.awt.FlowLayout; |
|
23 |
| import java.awt.event.ActionEvent; |
|
24 |
| import java.awt.event.ActionListener; |
|
25 |
| |
|
26 |
| import javax.swing.ButtonGroup; |
|
27 |
| import javax.swing.JPanel; |
|
28 |
| import javax.swing.JToggleButton; |
|
29 |
| import javax.swing.border.EtchedBorder; |
|
30 |
| |
|
31 |
| import org.ericmignot.modeler.gui.Controller; |
|
32 |
| import org.ericmignot.modeler.gui.StaticValues; |
|
33 |
| import org.ericmignot.modeler.util.graphic.GraphicHelper; |
|
34 |
| |
|
35 |
| public class Palette extends JPanel |
|
36 |
| { |
|
37 |
| private Controller controller; |
|
38 |
| private JPanel buttonPanel; |
|
39 |
| private ButtonGroup buttonGroup; |
|
40 |
| private PaletteTool selectedPaletteTool; |
|
41 |
| |
|
42 |
118
| public Palette(Controller controller)
|
|
43 |
| { |
|
44 |
118
| this.controller = controller;
|
|
45 |
118
| this.selectedPaletteTool = null;
|
|
46 |
| |
|
47 |
118
| this.setBorder(new EtchedBorder());
|
|
48 |
| |
|
49 |
118
| this.buttonPanel = new JPanel();
|
|
50 |
118
| this.buttonPanel.setOpaque(false);
|
|
51 |
118
| this.buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 0));
|
|
52 |
118
| this.setLayout(new BorderLayout());
|
|
53 |
118
| this.add(this.buttonPanel, BorderLayout.CENTER);
|
|
54 |
118
| this.setBackground(GraphicHelper.buildColor(StaticValues.getInstance().get("Design.Palette.BackgroundColor", "236, 233, 216")));
|
|
55 |
| |
|
56 |
118
| this.buttonGroup = new ButtonGroup();
|
|
57 |
| } |
|
58 |
| |
|
59 |
10
| public void addPaletteTool(final PaletteTool paletteTool)
|
|
60 |
| { |
|
61 |
10
| JToggleButton button = paletteTool.getButton();
|
|
62 |
10
| this.buttonPanel.add(button);
|
|
63 |
10
| this.buttonGroup.add(button);
|
|
64 |
| |
|
65 |
10
| button.addActionListener(new ActionListener()
|
|
66 |
| { |
|
67 |
0
| public void actionPerformed(ActionEvent e)
|
|
68 |
| { |
|
69 |
0
| Palette.this.firePaletteToolSelected(paletteTool);
|
|
70 |
| } |
|
71 |
| }); |
|
72 |
10
| if (buttonGroup.getButtonCount() == 1)
|
|
73 |
| { |
|
74 |
6
| button.setSelected(true);
|
|
75 |
| } |
|
76 |
| } |
|
77 |
| |
|
78 |
9
| private void firePaletteToolSelected(PaletteTool paletteTool)
|
|
79 |
| { |
|
80 |
9
| if (paletteTool != this.selectedPaletteTool)
|
|
81 |
| { |
|
82 |
9
| if (this.controller != null)
|
|
83 |
| { |
|
84 |
5
| if (this.selectedPaletteTool != null)
|
|
85 |
| { |
|
86 |
1
| this.controller.treatPaletteToolDeselected(this.selectedPaletteTool);
|
|
87 |
| } |
|
88 |
5
| this.controller.treatPaletteToolSelected(paletteTool);
|
|
89 |
| } |
|
90 |
9
| this.selectedPaletteTool = paletteTool;
|
|
91 |
| } |
|
92 |
| |
|
93 |
| } |
|
94 |
| |
|
95 |
9
| public void selectPaletteTool(PaletteTool paletteTool)
|
|
96 |
| { |
|
97 |
| |
|
98 |
9
| this.buttonGroup.setSelected(paletteTool.getButton().getModel(), true);
|
|
99 |
9
| firePaletteToolSelected(paletteTool);
|
|
100 |
| } |
|
101 |
| |
|
102 |
359
| public PaletteTool getSelectedPaletteTool()
|
|
103 |
| { |
|
104 |
359
| return this.selectedPaletteTool;
|
|
105 |
| } |
|
106 |
| } |