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

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

added a default build type - MG, for pre 2.71 collections. post 2.71 we have build type set in config file

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