source: trunk/gli/src/org/greenstone/gatherer/cdm/BuildTypeManager.java@ 12123

Last change on this file since 12123 was 12123, checked in by kjdon, 18 years ago

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1package org.greenstone.gatherer.cdm;
2
3import java.awt.*;
4import java.awt.event.*;
5import javax.swing.*;
6import java.util.EventListener;
7import javax.swing.event.EventListenerList;
8
9import org.greenstone.gatherer.Configuration;
10import org.greenstone.gatherer.Dictionary;
11import org.greenstone.gatherer.Gatherer;
12import org.greenstone.gatherer.gui.GLIButton;
13import org.greenstone.gatherer.gui.ModalDialog;
14
15public 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 listeners = new EventListenerList();
39 manager = this;
40 }
41
42 public void addBuildTypeListener(BuildTypeListener listener) {
43 listeners.add(BuildTypeListener.class, listener);
44 }
45
46 protected void notifyListeners(String new_build_type) {
47 Object[] concerned = listeners.getListenerList();
48 for(int i = 0; i < concerned.length ; i++) {
49 if(concerned[i] == BuildTypeListener.class) {
50 ((BuildTypeListener)concerned[i+1]).buildTypeChanged(new_build_type);
51 }
52 }
53 concerned = null;
54 }
55
56
57 public void promptForNewBuildType() {
58
59 BuildTypePrompt btp = new BuildTypePrompt(build_type_meta.getValue(CollectionMeta.TEXT));
60 }
61
62 public boolean isMGPP () {
63
64 return getBuildType().equals(BUILD_TYPE_MGPP);
65 }
66 public boolean isMG () {
67
68 return getBuildType().equals(BUILD_TYPE_MG);
69 }
70 public boolean isLucene () {
71
72 return getBuildType().equals(BUILD_TYPE_LUCENE);
73 }
74
75
76 public String getBuildType() {
77 return build_type_meta.getValue(CollectionMeta.TEXT);
78 }
79
80 public Control getControls() {
81 if (controls == null) {
82 controls = new BuildTypeControl();
83 }
84 return controls;
85 }
86
87 public interface BuildTypeListener
88 extends EventListener {
89 public void buildTypeChanged(String new_build_type);
90 }
91
92 private class BuildTypeControl
93 extends JPanel
94 implements Control, BuildTypeListener {
95
96 JLabel label = null;
97 JButton change_button = null;
98
99 public BuildTypeControl() {
100 super();
101
102 JPanel spacer_panel = new JPanel();
103
104 JPanel main_panel = new JPanel();
105 label = new JLabel(Dictionary.get("CDM.BuildTypeManager.Current_Type", getBuildTypeString(getBuildType())));
106 change_button = new GLIButton(Dictionary.get("CDM.BuildTypeManager.Change"), Dictionary.get("CDM.BuildTypeManager.Change_Tooltip"));
107
108 change_button.addActionListener(new ActionListener() {
109 public void actionPerformed(ActionEvent event) {
110 promptForNewBuildType();
111 }
112 });
113
114 main_panel.setLayout(new BorderLayout(10,10));
115 main_panel.add(label, BorderLayout.CENTER);
116 main_panel.add(change_button, BorderLayout.EAST);
117
118 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
119 setLayout(new BorderLayout());
120 add(spacer_panel, BorderLayout.CENTER);
121 add(main_panel, BorderLayout.EAST);
122
123 manager.addBuildTypeListener(this);
124 }
125
126 public void loseFocus() {}
127 public void gainFocus() {}
128 public void destroy() {}
129
130 private String getBuildTypeString(String build_type) {
131 if (build_type.equals(BUILD_TYPE_MG)) {
132 return BUILD_TYPE_MG_STR;
133 }
134 if (build_type.equals(BUILD_TYPE_MGPP)) {
135 return BUILD_TYPE_MGPP_STR;
136 }
137 if (build_type.equals(BUILD_TYPE_LUCENE)) {
138 return BUILD_TYPE_LUCENE_STR;
139 }
140 return "";
141 }
142
143
144 public void buildTypeChanged(String new_build_type) {
145 label.setText(Dictionary.get("CDM.BuildTypeManager.Current_Type", getBuildTypeString(new_build_type)));
146 }
147 }
148
149 private class BuildTypePrompt
150 extends ModalDialog {
151
152 private JDialog self;
153
154 private JRadioButton mg_button = null;
155 private JRadioButton mgpp_button = null;
156 private JRadioButton lucene_button = null;
157
158 private JTextArea description_textarea = null;
159
160 JButton ok_button = null;
161 JButton cancel_button = null;
162
163 public BuildTypePrompt(String current_build_type) {
164 super(Gatherer.g_man, true);
165 this.self = this;
166 setSize(DIALOG_SIZE);
167 setTitle(Dictionary.get("CDM.BuildTypeManager.Title"));
168
169 mg_button = new JRadioButton(BUILD_TYPE_MG_STR);
170 mg_button.setActionCommand(BUILD_TYPE_MG);
171 mgpp_button = new JRadioButton(BUILD_TYPE_MGPP_STR);
172 mgpp_button.setActionCommand(BUILD_TYPE_MGPP);
173 lucene_button = new JRadioButton(BUILD_TYPE_LUCENE_STR);
174 lucene_button.setActionCommand(BUILD_TYPE_LUCENE);
175
176 BuildTypeButtonListener btbl = new BuildTypeButtonListener();
177 mg_button.addActionListener(btbl);
178 mgpp_button.addActionListener(btbl);
179 lucene_button.addActionListener(btbl);
180
181 ButtonGroup build_type_group = new ButtonGroup();
182 build_type_group.add(mgpp_button);
183 build_type_group.add(mg_button);
184 build_type_group.add(lucene_button);
185
186 if (current_build_type != null) {
187 if (current_build_type.equals(BUILD_TYPE_MGPP)) {
188 mgpp_button.setSelected(true);
189 } else if (current_build_type.equals(BUILD_TYPE_MG)) {
190 mg_button.setSelected(true);
191 } else if (current_build_type.equals(BUILD_TYPE_LUCENE)) {
192 lucene_button.setSelected(true);
193 }
194 }
195
196 JPanel radio_pane = new JPanel();
197 radio_pane.setLayout(new GridLayout(3,1));
198 radio_pane.add(mgpp_button);
199 radio_pane.add(mg_button);
200 radio_pane.add(lucene_button);
201
202 description_textarea = new JTextArea();
203 description_textarea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
204 description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+current_build_type+"_Description"));
205 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
206
207 cancel_button.addActionListener(new ActionListener() {
208 public void actionPerformed(ActionEvent event) {
209 self.dispose();
210 }
211 });
212
213 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
214
215 ok_button.addActionListener(new ActionListener() {
216 public void actionPerformed(ActionEvent event) {
217 String new_build_type = BUILD_TYPE_MGPP;
218 if (mgpp_button.isSelected()) {
219 new_build_type = BUILD_TYPE_MGPP;
220 } else if (mg_button.isSelected()) {
221 new_build_type = BUILD_TYPE_MG;
222 } else if (lucene_button.isSelected()) {
223 new_build_type = BUILD_TYPE_LUCENE;
224 }
225 if (!build_type_meta.getValue(CollectionMeta.TEXT).equals(new_build_type)) {
226 build_type_meta.setValue(new_build_type);
227 manager.notifyListeners(new_build_type);
228 }
229 self.dispose();
230 }
231 });
232
233 JPanel button_pane = new JPanel();
234 button_pane.setLayout(new GridLayout(1,2));
235 button_pane.add(ok_button);
236 button_pane.add(cancel_button);
237
238 JPanel content_pane = (JPanel) getContentPane();
239 content_pane.setOpaque(true);
240 content_pane.setLayout(new BorderLayout());
241 content_pane.add(radio_pane, BorderLayout.NORTH);
242 content_pane.add(description_textarea, BorderLayout.CENTER);
243 content_pane.add(button_pane, BorderLayout.SOUTH);
244
245 // Center and display.
246 Dimension screen_size = Configuration.screen_size;
247 this.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
248 this.setVisible(true); // blocks until the dialog is killed
249
250 }
251
252 public void loseFocus() {
253
254 }
255 public void gainFocus() {
256
257 }
258 public void destroy() {
259
260 }
261
262 private class BuildTypeButtonListener
263 implements ActionListener {
264
265 public void actionPerformed(ActionEvent event) {
266 description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+event.getActionCommand()+"_Description"));
267 }
268 }
269 }
270}
Note: See TracBrowser for help on using the repository browser.