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

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

changed the button name

  • 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();
106 label.setText(Dictionary.get("CDM.BuildTypeManager.Current_Type", getBuildTypeString(getBuildType())));
107 change_button = new GLIButton();
108 Dictionary.registerBoth(change_button, "CDM.BuildTypeManager.Change", "CDM.BuildTypeManager.Change_Tooltip");
109
110 change_button.addActionListener(new ActionListener() {
111 public void actionPerformed(ActionEvent event) {
112 promptForNewBuildType();
113 }
114 });
115
116 main_panel.setLayout(new BorderLayout(10,10));
117 main_panel.add(label, BorderLayout.CENTER);
118 main_panel.add(change_button, BorderLayout.EAST);
119
120 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
121 setLayout(new BorderLayout());
122 add(spacer_panel, BorderLayout.CENTER);
123 add(main_panel, BorderLayout.EAST);
124
125 manager.addBuildTypeListener(this);
126 }
127
128 public void loseFocus() {}
129 public void gainFocus() {}
130 public void destroy() {}
131
132 private String getBuildTypeString(String build_type) {
133 if (build_type.equals(BUILD_TYPE_MG)) {
134 return BUILD_TYPE_MG_STR;
135 }
136 if (build_type.equals(BUILD_TYPE_MGPP)) {
137 return BUILD_TYPE_MGPP_STR;
138 }
139 if (build_type.equals(BUILD_TYPE_LUCENE)) {
140 return BUILD_TYPE_LUCENE_STR;
141 }
142 return "";
143 }
144
145
146 public void buildTypeChanged(String new_build_type) {
147 label.setText(Dictionary.get("CDM.BuildTypeManager.Current_Type", getBuildTypeString(new_build_type)));
148 }
149 }
150
151 private class BuildTypePrompt
152 extends ModalDialog {
153
154 private JDialog self;
155
156 private JRadioButton mg_button = null;
157 private JRadioButton mgpp_button = null;
158 private JRadioButton lucene_button = null;
159
160 private JTextArea description_textarea = null;
161
162 JButton ok_button = null;
163 JButton cancel_button = null;
164
165 public BuildTypePrompt(String current_build_type) {
166 super(Gatherer.g_man, true);
167 this.self = this;
168 setSize(DIALOG_SIZE);
169 Dictionary.setText(this, "CDM.BuildTypeManager.Title");
170
171 mg_button = new JRadioButton(BUILD_TYPE_MG_STR);
172 mg_button.setActionCommand(BUILD_TYPE_MG);
173 mgpp_button = new JRadioButton(BUILD_TYPE_MGPP_STR);
174 mgpp_button.setActionCommand(BUILD_TYPE_MGPP);
175 lucene_button = new JRadioButton(BUILD_TYPE_LUCENE_STR);
176 lucene_button.setActionCommand(BUILD_TYPE_LUCENE);
177
178 BuildTypeButtonListener btbl = new BuildTypeButtonListener();
179 mg_button.addActionListener(btbl);
180 mgpp_button.addActionListener(btbl);
181 lucene_button.addActionListener(btbl);
182
183 ButtonGroup build_type_group = new ButtonGroup();
184 build_type_group.add(mgpp_button);
185 build_type_group.add(mg_button);
186 build_type_group.add(lucene_button);
187
188 if (current_build_type != null) {
189 if (current_build_type.equals(BUILD_TYPE_MGPP)) {
190 mgpp_button.setSelected(true);
191 } else if (current_build_type.equals(BUILD_TYPE_MG)) {
192 mg_button.setSelected(true);
193 } else if (current_build_type.equals(BUILD_TYPE_LUCENE)) {
194 lucene_button.setSelected(true);
195 }
196 }
197
198 JPanel radio_pane = new JPanel();
199 radio_pane.setLayout(new GridLayout(3,1));
200 radio_pane.add(mgpp_button);
201 radio_pane.add(mg_button);
202 radio_pane.add(lucene_button);
203
204 description_textarea = new JTextArea();
205 description_textarea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
206 description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+current_build_type+"_Description"));
207 cancel_button = new GLIButton();
208 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip");
209 cancel_button.addActionListener(new ActionListener() {
210 public void actionPerformed(ActionEvent event) {
211 self.dispose();
212 }
213 });
214
215 ok_button = new GLIButton();
216 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
217 ok_button.addActionListener(new ActionListener() {
218 public void actionPerformed(ActionEvent event) {
219 String new_build_type = BUILD_TYPE_MGPP;
220 if (mgpp_button.isSelected()) {
221 new_build_type = BUILD_TYPE_MGPP;
222 } else if (mg_button.isSelected()) {
223 new_build_type = BUILD_TYPE_MG;
224 } else if (lucene_button.isSelected()) {
225 new_build_type = BUILD_TYPE_LUCENE;
226 }
227 if (!build_type_meta.getValue(CollectionMeta.TEXT).equals(new_build_type)) {
228 build_type_meta.setValue(new_build_type);
229 manager.notifyListeners(new_build_type);
230 }
231 self.dispose();
232 }
233 });
234
235 JPanel button_pane = new JPanel();
236 button_pane.setLayout(new GridLayout(1,2));
237 button_pane.add(ok_button);
238 button_pane.add(cancel_button);
239
240 JPanel content_pane = (JPanel) getContentPane();
241 content_pane.setOpaque(true);
242 content_pane.setLayout(new BorderLayout());
243 content_pane.add(radio_pane, BorderLayout.NORTH);
244 content_pane.add(description_textarea, BorderLayout.CENTER);
245 content_pane.add(button_pane, BorderLayout.SOUTH);
246
247 // Center and display.
248 Dimension screen_size = Configuration.screen_size;
249 this.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
250 this.setVisible(true); // blocks until the dialog is killed
251
252 }
253
254 public void loseFocus() {
255
256 }
257 public void gainFocus() {
258
259 }
260 public void destroy() {
261
262 }
263
264 private class BuildTypeButtonListener
265 implements ActionListener {
266
267 public void actionPerformed(ActionEvent event) {
268 description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+event.getActionCommand()+"_Description"));
269 }
270 }
271 }
272}
Note: See TracBrowser for help on using the repository browser.