1 | |
package org.jtheque.films.view.impl.toolbars; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.core.managers.Managers; |
20 | |
import org.jtheque.core.managers.view.able.IViewManager; |
21 | |
import org.jtheque.core.utils.ui.Borders; |
22 | |
import org.jtheque.films.view.impl.actions.realizer.AcCancelRealizer; |
23 | |
import org.jtheque.films.view.impl.actions.realizer.AcDeleteRealizer; |
24 | |
import org.jtheque.films.view.impl.actions.realizer.AcEditRealizer; |
25 | |
import org.jtheque.films.view.impl.actions.realizer.AcNewRealizer; |
26 | |
import org.jtheque.films.view.impl.actions.realizer.AcSaveRealizer; |
27 | |
import org.jtheque.primary.view.able.ToolbarView; |
28 | |
import org.jtheque.primary.view.able.ViewMode; |
29 | |
import org.jtheque.utils.ui.GridBagUtils; |
30 | |
|
31 | |
import javax.swing.Box; |
32 | |
import javax.swing.JButton; |
33 | |
import javax.swing.JPanel; |
34 | |
import java.awt.Color; |
35 | |
import java.awt.GridBagConstraints; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public final class JPanelRealizerToolBar extends JPanel implements ToolbarView { |
43 | |
private static final long serialVersionUID = -688094676844153411L; |
44 | |
|
45 | |
private final JButton buttonAdd; |
46 | |
private final JButton buttonEdit; |
47 | |
private final JButton buttonSave; |
48 | |
private final JButton buttonCancel; |
49 | |
private final JButton buttonDelete; |
50 | |
|
51 | 0 | private ViewMode mode = ViewMode.VIEW; |
52 | |
|
53 | 0 | private final GridBagUtils gbc = new GridBagUtils(); |
54 | |
|
55 | |
public JPanelRealizerToolBar() { |
56 | 0 | super(); |
57 | |
|
58 | 0 | setBackground(Color.white); |
59 | 0 | setBorder(Borders.DIALOG_BORDER); |
60 | |
|
61 | 0 | buttonSave = new JButton(new AcSaveRealizer()); |
62 | 0 | buttonCancel = new JButton(new AcCancelRealizer()); |
63 | 0 | buttonDelete = new JButton(new AcDeleteRealizer()); |
64 | 0 | buttonAdd = new JButton(new AcNewRealizer()); |
65 | 0 | buttonEdit = new JButton(new AcEditRealizer()); |
66 | |
|
67 | 0 | add(Box.createHorizontalGlue(), gbc.gbcSet(0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.BASELINE_LEADING, 1.0, 1.0)); |
68 | |
|
69 | 0 | if (mode == ViewMode.VIEW) { |
70 | 0 | addViewModeButtons(); |
71 | |
} else { |
72 | 0 | addOtherModesButtons(); |
73 | |
} |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
private void addViewModeButtons() { |
80 | 0 | add(buttonAdd, gbc.gbcSet(1, 0)); |
81 | 0 | add(buttonEdit, gbc.gbcSet(2, 0)); |
82 | 0 | add(buttonDelete, gbc.gbcSet(3, 0)); |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
private void addOtherModesButtons() { |
89 | 0 | add(buttonSave, gbc.gbcSet(1, 0)); |
90 | 0 | add(buttonCancel, gbc.gbcSet(2, 0)); |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
void setMode(ViewMode mode) { |
99 | 0 | if (this.mode != mode) { |
100 | 0 | this.mode = mode; |
101 | |
|
102 | 0 | remove(buttonSave); |
103 | 0 | remove(buttonCancel); |
104 | 0 | remove(buttonAdd); |
105 | 0 | remove(buttonEdit); |
106 | 0 | remove(buttonDelete); |
107 | |
|
108 | 0 | switch (mode) { |
109 | |
case VIEW: |
110 | 0 | addViewModeButtons(); |
111 | |
|
112 | 0 | break; |
113 | |
case NEW: |
114 | |
case EDIT: |
115 | |
case AUTO: |
116 | 0 | addOtherModesButtons(); |
117 | |
|
118 | |
break; |
119 | |
} |
120 | |
|
121 | 0 | Managers.getManager(IViewManager.class).refresh(this); |
122 | |
} |
123 | 0 | } |
124 | |
|
125 | |
@Override |
126 | |
public void setDisplayMode(ViewMode mode) { |
127 | 0 | setMode(mode); |
128 | 0 | } |
129 | |
} |