1 | package org.greenstone.gatherer.cdm;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.event.*;
|
---|
5 | import javax.swing.*;
|
---|
6 | import java.util.EventListener;
|
---|
7 | import javax.swing.event.EventListenerList;
|
---|
8 |
|
---|
9 | import org.greenstone.gatherer.Configuration;
|
---|
10 | import org.greenstone.gatherer.Dictionary;
|
---|
11 | import org.greenstone.gatherer.Gatherer;
|
---|
12 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
13 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
14 |
|
---|
15 | public class BuildTypeManager {
|
---|
16 |
|
---|
17 | /** The size of this new collection dialog box. */
|
---|
18 | static private Dimension DIALOG_SIZE = new Dimension(600, 280);
|
---|
19 |
|
---|
20 | static final public String BUILD_TYPE_MG = "mg";
|
---|
21 | static final public String BUILD_TYPE_MGPP = "mgpp";
|
---|
22 | static final public String BUILD_TYPE_LUCENE = "lucene";
|
---|
23 |
|
---|
24 | static final public String BUILD_TYPE_MG_STR = "MG";
|
---|
25 | static final public String BUILD_TYPE_MGPP_STR = "MGPP";
|
---|
26 | static final public String BUILD_TYPE_LUCENE_STR = "Lucene";
|
---|
27 |
|
---|
28 | static final public String[] BUILD_TYPES = { BUILD_TYPE_MGPP, BUILD_TYPE_MG, BUILD_TYPE_LUCENE };
|
---|
29 |
|
---|
30 | private EventListenerList listeners = null;
|
---|
31 | /** the buildtype element in the config file - uses CollectionMeta */
|
---|
32 | public CollectionMeta build_type_meta = null;
|
---|
33 | private Control controls = null;
|
---|
34 |
|
---|
35 | protected BuildTypeManager manager = null;
|
---|
36 | public BuildTypeManager() {
|
---|
37 | build_type_meta = new CollectionMeta(CollectionDesignManager.collect_config.getBuildType());
|
---|
38 | if (getBuildType().equals("")) {
|
---|
39 | build_type_meta.setValue(BUILD_TYPE_MG);
|
---|
40 | // must have an old collection, assume MG
|
---|
41 | }
|
---|
42 | listeners = new EventListenerList();
|
---|
43 | manager = this;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void addBuildTypeListener(BuildTypeListener listener) {
|
---|
47 | listeners.add(BuildTypeListener.class, listener);
|
---|
48 | }
|
---|
49 |
|
---|
50 | protected void notifyListeners(String new_build_type) {
|
---|
51 | Object[] concerned = listeners.getListenerList();
|
---|
52 | for(int i = 0; i < concerned.length ; i++) {
|
---|
53 | if(concerned[i] == BuildTypeListener.class) {
|
---|
54 | ((BuildTypeListener)concerned[i+1]).buildTypeChanged(new_build_type);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | concerned = null;
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | public void promptForNewBuildType() {
|
---|
62 |
|
---|
63 | BuildTypePrompt btp = new BuildTypePrompt(build_type_meta.getValue(CollectionMeta.TEXT));
|
---|
64 | }
|
---|
65 |
|
---|
66 | public boolean isMGPP () {
|
---|
67 |
|
---|
68 | return getBuildType().equals(BUILD_TYPE_MGPP);
|
---|
69 | }
|
---|
70 | public boolean isMG () {
|
---|
71 |
|
---|
72 | return getBuildType().equals(BUILD_TYPE_MG);
|
---|
73 | }
|
---|
74 | public boolean isLucene () {
|
---|
75 |
|
---|
76 | return getBuildType().equals(BUILD_TYPE_LUCENE);
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | public String getBuildType() {
|
---|
81 | return build_type_meta.getValue(CollectionMeta.TEXT);
|
---|
82 | }
|
---|
83 |
|
---|
84 | public Control getControls() {
|
---|
85 | if (controls == null) {
|
---|
86 | controls = new BuildTypeControl();
|
---|
87 | }
|
---|
88 | return controls;
|
---|
89 | }
|
---|
90 |
|
---|
91 | public interface BuildTypeListener
|
---|
92 | extends EventListener {
|
---|
93 | public void buildTypeChanged(String new_build_type);
|
---|
94 | }
|
---|
95 |
|
---|
96 | private class BuildTypeControl
|
---|
97 | extends JPanel
|
---|
98 | implements Control, BuildTypeListener {
|
---|
99 |
|
---|
100 | JLabel label = null;
|
---|
101 | JButton change_button = null;
|
---|
102 |
|
---|
103 | public BuildTypeControl() {
|
---|
104 | super();
|
---|
105 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
106 |
|
---|
107 | JPanel spacer_panel = new JPanel();
|
---|
108 | spacer_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
109 |
|
---|
110 | JPanel main_panel = new JPanel();
|
---|
111 | main_panel.setComponentOrientation(Dictionary.getOrientation());
|
---|
112 | /* may be CDM.BuildTypeManager.mg, CDM.BuildTYpeManager.mgpp, CDM.BuildTypeManager.lucene */
|
---|
113 | label = new JLabel(Dictionary.get("CDM.BuildTypeManager.Current_Type", getBuildTypeString(getBuildType())));
|
---|
114 | label.setComponentOrientation(Dictionary.getOrientation());
|
---|
115 |
|
---|
116 | change_button = new GLIButton(Dictionary.get("CDM.BuildTypeManager.Change"), Dictionary.get("CDM.BuildTypeManager.Change_Tooltip"));
|
---|
117 |
|
---|
118 | change_button.addActionListener(new ActionListener() {
|
---|
119 | public void actionPerformed(ActionEvent event) {
|
---|
120 | promptForNewBuildType();
|
---|
121 | }
|
---|
122 | });
|
---|
123 |
|
---|
124 | main_panel.setLayout(new BorderLayout(10,10));
|
---|
125 | main_panel.add(label, BorderLayout.CENTER);
|
---|
126 | main_panel.add(change_button, BorderLayout.LINE_END);
|
---|
127 |
|
---|
128 | setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
|
---|
129 | setLayout(new BorderLayout());
|
---|
130 | add(spacer_panel, BorderLayout.CENTER);
|
---|
131 | add(main_panel, BorderLayout.LINE_END);
|
---|
132 |
|
---|
133 | manager.addBuildTypeListener(this);
|
---|
134 | }
|
---|
135 |
|
---|
136 | public void loseFocus() {}
|
---|
137 | public void gainFocus() {}
|
---|
138 | public void destroy() {}
|
---|
139 |
|
---|
140 | private String getBuildTypeString(String build_type) {
|
---|
141 | if (build_type.equals(BUILD_TYPE_MG)) {
|
---|
142 | return BUILD_TYPE_MG_STR;
|
---|
143 | }
|
---|
144 | if (build_type.equals(BUILD_TYPE_MGPP)) {
|
---|
145 | return BUILD_TYPE_MGPP_STR;
|
---|
146 | }
|
---|
147 | if (build_type.equals(BUILD_TYPE_LUCENE)) {
|
---|
148 | return BUILD_TYPE_LUCENE_STR;
|
---|
149 | }
|
---|
150 | return "";
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | public void buildTypeChanged(String new_build_type) {
|
---|
155 | label.setText(Dictionary.get("CDM.BuildTypeManager.Current_Type", getBuildTypeString(new_build_type)));
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | private class BuildTypePrompt
|
---|
160 | extends ModalDialog {
|
---|
161 |
|
---|
162 | private JDialog self;
|
---|
163 |
|
---|
164 | private JRadioButton mg_button = null;
|
---|
165 | private JRadioButton mgpp_button = null;
|
---|
166 | private JRadioButton lucene_button = null;
|
---|
167 |
|
---|
168 | private JTextArea description_textarea = null;
|
---|
169 |
|
---|
170 | JButton ok_button = null;
|
---|
171 | JButton cancel_button = null;
|
---|
172 |
|
---|
173 | public BuildTypePrompt(String current_build_type) {
|
---|
174 | super(Gatherer.g_man, true);
|
---|
175 | this.self = this;
|
---|
176 | setSize(DIALOG_SIZE);
|
---|
177 | setTitle(Dictionary.get("CDM.BuildTypeManager.Title"));
|
---|
178 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
179 | mg_button = new JRadioButton(BUILD_TYPE_MG_STR);
|
---|
180 | mg_button.setComponentOrientation(Dictionary.getOrientation());
|
---|
181 | mg_button.setActionCommand(BUILD_TYPE_MG);
|
---|
182 | mgpp_button = new JRadioButton(BUILD_TYPE_MGPP_STR);
|
---|
183 | mgpp_button.setComponentOrientation(Dictionary.getOrientation());
|
---|
184 | mgpp_button.setActionCommand(BUILD_TYPE_MGPP);
|
---|
185 | lucene_button = new JRadioButton(BUILD_TYPE_LUCENE_STR);
|
---|
186 | lucene_button.setComponentOrientation(Dictionary.getOrientation());
|
---|
187 | lucene_button.setActionCommand(BUILD_TYPE_LUCENE);
|
---|
188 |
|
---|
189 | BuildTypeButtonListener btbl = new BuildTypeButtonListener();
|
---|
190 | mg_button.addActionListener(btbl);
|
---|
191 | mgpp_button.addActionListener(btbl);
|
---|
192 | lucene_button.addActionListener(btbl);
|
---|
193 |
|
---|
194 | ButtonGroup build_type_group = new ButtonGroup();
|
---|
195 | build_type_group.add(mgpp_button);
|
---|
196 | build_type_group.add(mg_button);
|
---|
197 | build_type_group.add(lucene_button);
|
---|
198 |
|
---|
199 | if (current_build_type != null) {
|
---|
200 | if (current_build_type.equals(BUILD_TYPE_MGPP)) {
|
---|
201 | mgpp_button.setSelected(true);
|
---|
202 | } else if (current_build_type.equals(BUILD_TYPE_MG)) {
|
---|
203 | mg_button.setSelected(true);
|
---|
204 | } else if (current_build_type.equals(BUILD_TYPE_LUCENE)) {
|
---|
205 | lucene_button.setSelected(true);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | JPanel radio_pane = new JPanel();
|
---|
210 | radio_pane.setLayout(new GridLayout(3,1));
|
---|
211 | radio_pane.add(mgpp_button);
|
---|
212 | radio_pane.add(mg_button);
|
---|
213 | radio_pane.add(lucene_button);
|
---|
214 | radio_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
215 |
|
---|
216 | description_textarea = new JTextArea();
|
---|
217 | description_textarea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
218 | /* may be CDM.BuildTypeManager.mg_Description, CDM.BuildTYpeManager.mgpp_Description, CDM.BuildTypeManager.lucene_Description */
|
---|
219 | description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+current_build_type+"_Description"));
|
---|
220 | description_textarea.setLineWrap(true);
|
---|
221 | description_textarea.setWrapStyleWord(true);
|
---|
222 | description_textarea.setComponentOrientation(Dictionary.getOrientation());
|
---|
223 |
|
---|
224 | cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
|
---|
225 |
|
---|
226 | cancel_button.addActionListener(new ActionListener() {
|
---|
227 | public void actionPerformed(ActionEvent event) {
|
---|
228 | self.dispose();
|
---|
229 | }
|
---|
230 | });
|
---|
231 |
|
---|
232 | ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
|
---|
233 |
|
---|
234 | ok_button.addActionListener(new ActionListener() {
|
---|
235 | public void actionPerformed(ActionEvent event) {
|
---|
236 | String new_build_type = BUILD_TYPE_MGPP;
|
---|
237 | if (mgpp_button.isSelected()) {
|
---|
238 | new_build_type = BUILD_TYPE_MGPP;
|
---|
239 | } else if (mg_button.isSelected()) {
|
---|
240 | new_build_type = BUILD_TYPE_MG;
|
---|
241 | } else if (lucene_button.isSelected()) {
|
---|
242 | new_build_type = BUILD_TYPE_LUCENE;
|
---|
243 | }
|
---|
244 | if (!build_type_meta.getValue(CollectionMeta.TEXT).equals(new_build_type)) {
|
---|
245 | manager.notifyListeners(new_build_type);
|
---|
246 | build_type_meta.setValue(new_build_type);
|
---|
247 | }
|
---|
248 | self.dispose();
|
---|
249 | }
|
---|
250 | });
|
---|
251 | // tell the CDM that we have (possibly) changed
|
---|
252 | ok_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
253 | JPanel button_pane = new JPanel();
|
---|
254 | button_pane.setLayout(new GridLayout(1,2));
|
---|
255 | button_pane.add(ok_button);
|
---|
256 | button_pane.add(cancel_button);
|
---|
257 | button_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
258 |
|
---|
259 | JPanel content_pane = (JPanel) getContentPane();
|
---|
260 | content_pane.setOpaque(true);
|
---|
261 | content_pane.setLayout(new BorderLayout());
|
---|
262 | content_pane.add(radio_pane, BorderLayout.NORTH);
|
---|
263 | content_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
|
---|
264 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
265 | content_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
266 |
|
---|
267 | // Center and display.
|
---|
268 | Dimension screen_size = Configuration.screen_size;
|
---|
269 | this.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
|
---|
270 | this.setVisible(true); // blocks until the dialog is killed
|
---|
271 |
|
---|
272 | }
|
---|
273 |
|
---|
274 | public void loseFocus() {
|
---|
275 |
|
---|
276 | }
|
---|
277 | public void gainFocus() {
|
---|
278 |
|
---|
279 | }
|
---|
280 | public void destroy() {
|
---|
281 |
|
---|
282 | }
|
---|
283 |
|
---|
284 | private class BuildTypeButtonListener
|
---|
285 | implements ActionListener {
|
---|
286 |
|
---|
287 | public void actionPerformed(ActionEvent event) {
|
---|
288 | description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+event.getActionCommand()+"_Description"));
|
---|
289 | }
|
---|
290 | }
|
---|
291 | }
|
---|
292 | }
|
---|