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