source: trunk/gli/src/org/greenstone/gatherer/cdm/GeneralManager.java@ 11031

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

removed instructions, changed title to be the same string as in the contents, and use a new class DesignPaneHeader to create teh header which has title and help button

  • Property svn:keywords set to Author Date Id Revision
File size: 29.2 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.*;
32import java.util.regex.*;
33import javax.swing.*;
34import javax.swing.filechooser.*;
35import javax.swing.event.*;
36import javax.swing.tree.*;
37import org.greenstone.gatherer.Configuration;
38import org.greenstone.gatherer.DebugStream;
39import org.greenstone.gatherer.Dictionary;
40import org.greenstone.gatherer.Gatherer;
41import org.greenstone.gatherer.gui.DesignPaneHeader;
42import org.greenstone.gatherer.gui.EmailField;
43import org.greenstone.gatherer.gui.GLIButton;
44import org.greenstone.gatherer.gui.NewCollectionDetailsPrompt;
45import org.greenstone.gatherer.gui.OpenCollectionDialog;
46import org.greenstone.gatherer.gui.WarningDialog;
47import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
48import org.greenstone.gatherer.util.StaticStrings;
49
50/** This class is responsible for generating the necessary GUI components. It does this by calling the getEditControls() method of the appropriate class (i.e. IndexManager for index related edits). It also is in charge of correctly adding (and removing) listeners, using phrases from the <strong>Dictionary</strong> rather than the text keys inserted in the component classes, and several other aspects of the design page, including the config file section tree.
51* @author John Thompson, Greenstone Digital Library, University of Waikato
52* @version 2.3d
53*/
54public class GeneralManager
55 extends JPanel {
56 /** The available subscreens. */
57 static final private String CONTENTS[] = { "CDM.GUI.General", "CDM.GUI.Plugins", "CDM.GUI.SearchTypes", "CDM.GUI.Indexes", "CDM.GUI.Subcollections", "CDM.GUI.SuperCollection", "CDM.GUI.Classifiers", "CDM.GUI.Formats", "CDM.GUI.Translation", "CDM.GUI.MetadataSets" };
58 /** The preferred size of the contents tree. */
59 static final private Dimension TREE_SIZE = new Dimension(200, 500);
60 /** The controls used to modify the general options. */
61 private Control controls;
62 /** The panel apon which is rendered the currently selected section screen. */
63 private Control view = null;
64 /** A tree to serve as a 'table of contents' for this design tool. We decided on a tree rather than a list, as it allows us to break sections into subsections if they become to complicated. */
65 private DesignTree tree;
66 /** Constructor. */
67 public GeneralManager() {
68 super();
69 DebugStream.println("GeneralManager: Main GUI components created.");
70 // Assignments
71 this.controls = new GeneralControl();
72
73 // Creation
74 JPanel tree_pane = new JPanel();
75 //JLabel title = new JLabel();
76 //Dictionary.registerText(title, "CDM.GUI.Design_Topics");
77 tree = new DesignTree();
78 view = controls;
79
80 // Connect
81 tree.addTreeSelectionListener(new TreeListener());
82
83 // Layout
84 tree_pane.setLayout(new BorderLayout());
85 tree_pane.setPreferredSize(TREE_SIZE);
86 //tree_pane.add(title, BorderLayout.NORTH);
87 tree_pane.add(new JScrollPane(tree), BorderLayout.CENTER);
88
89 setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
90 setLayout(new BorderLayout());
91 add(tree_pane, BorderLayout.WEST);
92 add((JPanel)view, BorderLayout.CENTER);
93 }
94
95 public boolean canSave() {
96 return (controls == null || ((GeneralControl)controls).canSave());
97 }
98
99 /** Destructor. */
100 public void destroy() {
101 controls.destroy();
102 controls = null;
103 tree = null;
104 view = null;
105 }
106
107 /** Called whenever the detail mode changes to ensure the contents tree is at an appropriate level (ie with Partitions disabled in lower levels)
108 * Written 1543-07-01-2004, and made obsolete by a new list of requirements 1611-07-01-2004. *sigh*
109 * @param mode the mode level as an int
110 */
111 /* public void modeChanged(int mode) {
112 tree.resetModel(mode);
113 } */
114
115 /** Force the display to show a certain pane of controls.
116 * @param type a String giving the name of the information manager or view we wish to display
117 */
118 public void setSelectedView(String type) {
119 tree.setSelectedView(type);
120 }
121
122 /** Refresh the values on our controls that could be stale due to changes in other components. */
123 public void gainFocus() {
124 if (view != null) {
125 view.gainFocus();
126 }
127 }
128
129 /** Saves the state of the controls in the current view. */
130 public void loseFocus() {
131 if (view != null) {
132 view.loseFocus();
133 }
134 }
135
136 /** This class is resposible for generating the controls for the editing of general options.
137 * @return the Control for editing the general options
138 */
139 private Control getControls() {
140 return controls;
141 }
142
143 /** This class represents the visual component of the general options stored in the CollectionDesignManager. */
144 private class GeneralControl
145 extends JPanel
146 implements Control {
147
148 private boolean has_been_warned = false;
149 private boolean ready = false;
150 private CollectionMeta collection_extra_collectionmeta;
151 private CollectionMeta collection_name_collectionmeta;
152 private CollectionMeta creator_collectionmeta;
153 private CollectionMeta icon_collection_collectionmeta;
154 private CollectionMeta icon_collection_small_collectionmeta;
155 private CollectionMeta maintainer_collectionmeta;
156 private CollectionMeta public_collectionmeta;
157 /** The creators email. */
158 private EmailField creator_emailfield;
159 /** The maintainers email. */
160 private EmailField maintainer_emailfield;
161 /** Button to browse for the collection about page icon. */
162 private JButton browse_about_icon_button;
163 /** Button to browse for the collection home page icon. */
164 private JButton browse_home_icon_button;
165 /** The checkbox controlling public access to the collection. */
166 private JCheckBox public_checkbox;
167 private JLabel creator_label;
168 private JLabel description_label;
169 private JLabel icon_label;
170 private JLabel maintainer_label;
171 private JLabel name_label;
172 private JLabel small_icon_label;
173 /** The text field used to edit the file name of the collections icon. */
174 private JTextField icon_textfield;
175 /** The text field used to edit the collections title. */
176 private JTextField name_textfield;
177 /** The text field used to edit the file name of the collections small icon. */
178 private JTextField small_icon_textfield;
179 /** A text area used to modify the collection description. */
180 private JTextArea description_textarea;
181 /** Constructor. */
182 public GeneralControl() {
183 super();
184 // Retrieve some of the model elements, those we know aren't language dependant
185 public_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getPublic());
186
187 // Creation
188 JPanel header_panel = new DesignPaneHeader("CDM.GUI.General", "generalsettings");
189
190 JPanel all_details_panel = new JPanel();
191 JPanel details_panel = new JPanel();
192 JPanel fields_panel = new JPanel();
193
194 creator_label = new JLabel();
195 Dictionary.registerText(creator_label, "CDM.General.Email.Creator");
196
197 creator_emailfield = new EmailField(Configuration.getColor("coloring.error_background", false));
198 Dictionary.registerTooltip(creator_emailfield, "CDM.General.Email.Creator_Tooltip");
199
200 maintainer_label = new JLabel();
201 Dictionary.registerText(maintainer_label, "CDM.General.Email.Maintainer");
202
203 maintainer_emailfield = new EmailField(Configuration.getColor("coloring.error_background", false));
204 Dictionary.registerTooltip(maintainer_emailfield, "CDM.General.Email.Maintainer_Tooltip");
205
206 name_label = new JLabel();
207 Dictionary.registerText(name_label, "CDM.General.Collection_Name");
208 name_textfield = new JTextField("CDM.General.Collection_Name");
209 Dictionary.registerTooltip(name_textfield, "CDM.General.Collection_Name_Tooltip");
210 JLabel short_name_label = new JLabel();
211 Dictionary.registerText(short_name_label, "NewCollectionPrompt.Collection_Name");
212 JTextField short_name_textfield = new JTextField(Gatherer.c_man.getCollection().getName());
213 short_name_textfield.setEditable(false);
214 short_name_textfield.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
215 JPanel icon_panel = new JPanel();
216 icon_label = new JLabel();
217 Dictionary.registerText(icon_label, "CDM.General.Icon_Collection");
218 icon_textfield = new JTextField("CDM.General.Icon_Collection");
219 Dictionary.registerTooltip(icon_textfield, "CDM.General.Icon_Collection_Tooltip");
220 browse_about_icon_button = new GLIButton();
221 browse_about_icon_button.setMnemonic(KeyEvent.VK_A);
222 Dictionary.registerText(browse_about_icon_button, "General.Browse");
223 JPanel small_icon_panel = new JPanel();
224 small_icon_label = new JLabel("CDM.General.Icon_Collection_Small");
225 Dictionary.registerText(small_icon_label, "CDM.General.Icon_Collection_Small");
226 small_icon_textfield = new JTextField("CDM.General.Icon_Collection_Small");
227 Dictionary.registerTooltip(small_icon_textfield, "CDM.General.Icon_Collection_Small_Tooltip");
228 browse_home_icon_button = new GLIButton();
229 browse_home_icon_button.setMnemonic(KeyEvent.VK_A);
230 Dictionary.registerText(browse_home_icon_button, "General.Browse");
231
232 // public
233 JPanel box_panel = new JPanel();
234 public_checkbox = new JCheckBox("", public_collectionmeta.getValue(CollectionMeta.TEXT).equals(CollectionConfiguration.TRUE_STR));
235 Dictionary.registerText(public_checkbox, "CDM.General.Access");
236
237 JPanel description_panel = new JPanel();
238 description_label = new JLabel();
239 Dictionary.registerText(description_label, "CDM.General.Collection_Extra");
240 description_textarea = new JTextArea();
241 description_textarea.setBackground(Configuration.getColor("coloring.editable_background", false));
242 Dictionary.registerTooltip(description_textarea, "CDM.General.Collection_Extra_Tooltip");
243 // Connection
244 BrowseListener browse_listener = new BrowseListener(StaticStrings.IMAGES_PATH_RELATIVE_TO_GSDL_PREFIX);
245 browse_about_icon_button.addActionListener(browse_listener);
246 browse_home_icon_button.addActionListener(browse_listener);
247 browse_listener = null;
248 public_checkbox.addActionListener(CollectionDesignManager.change_listener);
249 public_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
250 creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
251 creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
252 description_textarea.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
253 description_textarea.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
254 icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
255 icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
256 maintainer_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
257 maintainer_emailfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
258 name_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
259 name_textfield.getDocument().addDocumentListener(new CollectionTitleUpdater());
260 name_textfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
261 small_icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
262 small_icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
263 //Note: unfortunately just loading the General Design panel fires the buildcol_change_listener (even if nothing is changed).
264
265 // Layout
266 fields_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
267 fields_panel.setLayout(new BorderLayout(5,2));
268
269 JPanel fields_label_panel = new JPanel();
270 fields_label_panel.setLayout(new GridLayout(6,1));
271
272 JPanel fields_box_panel = new JPanel();
273 fields_box_panel.setLayout(new GridLayout(6,1));
274
275 // creator
276 fields_label_panel.add(creator_label);
277 fields_box_panel.add(creator_emailfield);
278
279 // maintainer
280 fields_label_panel.add(maintainer_label);
281 fields_box_panel.add(maintainer_emailfield);
282
283 // title
284 fields_label_panel.add(name_label);
285 fields_box_panel.add(name_textfield);
286
287 // collection short name
288 fields_label_panel.add(short_name_label);
289 fields_box_panel.add(short_name_textfield);
290
291 // icon
292 fields_label_panel.add(icon_label);
293 fields_box_panel.add(icon_panel);
294
295 // small icon
296 fields_label_panel.add(small_icon_label);
297 fields_box_panel.add(small_icon_panel);
298
299 fields_panel.add(fields_label_panel, BorderLayout.WEST);
300 fields_panel.add(fields_box_panel, BorderLayout.CENTER);
301
302 icon_panel.setLayout(new BorderLayout());
303 icon_panel.add(icon_textfield, BorderLayout.CENTER);
304 icon_panel.add(browse_about_icon_button, BorderLayout.EAST);
305
306 small_icon_panel.setLayout(new BorderLayout());
307 small_icon_panel.add(small_icon_textfield, BorderLayout.CENTER);
308 small_icon_panel.add(browse_home_icon_button, BorderLayout.EAST);
309
310 box_panel.setLayout(new GridLayout(1,1,5,2));
311 box_panel.add(public_checkbox);
312
313 description_panel.setLayout(new BorderLayout());
314 description_panel.add(description_label, BorderLayout.NORTH);
315 description_panel.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
316
317 details_panel.setLayout(new BorderLayout());
318 details_panel.add(fields_panel, BorderLayout.NORTH);
319 details_panel.add(box_panel, BorderLayout.CENTER);
320
321 all_details_panel.setLayout(new BorderLayout());
322 all_details_panel.add(details_panel, BorderLayout.NORTH);
323 all_details_panel.add(description_panel, BorderLayout.CENTER);
324
325 setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
326 setLayout(new BorderLayout());
327 add(header_panel, BorderLayout.NORTH);
328 add(all_details_panel, BorderLayout.CENTER);
329 }
330
331 /** Destructor. */
332 public void destroy() {
333 }
334
335 /** Called to refresh the components. */
336 public void gainFocus() {
337 // Retrieve all of the elements that are dependant on default language.
338 collection_extra_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
339 collection_name_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_COLLECTIONNAME_STR);
340
341 creator_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getCreator());
342 icon_collection_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
343 icon_collection_small_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
344 maintainer_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getMaintainer());
345 // Make sure the components are up to date
346 creator_emailfield.setText(creator_collectionmeta.getValue(CollectionMeta.TEXT));
347 creator_emailfield.setCaretPosition(0);
348 description_textarea.setText(collection_extra_collectionmeta.getValue(CollectionMeta.TEXT));
349 description_textarea.setCaretPosition(0);
350 icon_textfield.setText(icon_collection_collectionmeta.getValue(CollectionMeta.TEXT));
351 icon_textfield.setCaretPosition(0);
352 maintainer_emailfield.setText(maintainer_collectionmeta.getValue(CollectionMeta.TEXT));
353 maintainer_emailfield.setCaretPosition(0);
354 name_textfield.setText(collection_name_collectionmeta.getValue(CollectionMeta.TEXT));
355 name_textfield.setCaretPosition(0);
356 small_icon_textfield.setText(icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT));
357 small_icon_textfield.setCaretPosition(0);
358 public_checkbox.setSelected(public_collectionmeta.getValue(CollectionMeta.TEXT).equals(CollectionConfiguration.TRUE_STR));
359 ready = true;
360 }
361
362 public boolean canSave() {
363 boolean title_clash_warning = true;
364 // Oh, and if the collection title is already in use warn them about it
365 String title = name_textfield.getText();
366 // I just happen to have a handy method in the new details prompt to detect this very thing
367 if(NewCollectionDetailsPrompt.titleClashes(title, CollectionDesignManager.collect_config.getFile())) {
368 // Determine if the user wants to be warned about this
369 WarningDialog dialog = new WarningDialog("warning.TitleClashes", "TitleClashes.Title", Dictionary.get("TitleClashes.Message"), null, true);
370 if(dialog.display() == JOptionPane.OK_OPTION) {
371 // If they have said yes, then carry on with the assignement
372 collection_name_collectionmeta.setValue(title);
373 has_been_warned = true;
374 }
375 // Otherwise we don't assign anything. In fact we have to restore the frame title back to its original value
376 else {
377 title_clash_warning = false;
378 String collection_title = collection_name_collectionmeta.getValue(CollectionMeta.TEXT);
379 String collection_name = Gatherer.c_man.getCollection().getName();
380 Gatherer.g_man.setTitle(collection_title, collection_name);
381 collection_name = null;
382 collection_title = null;
383 }
384 dialog.dispose();
385 dialog = null;
386 }
387 // No clash, no worries.
388 else if(collection_name_collectionmeta != null) {
389 collection_name_collectionmeta.setValue(title);
390 }
391 return title_clash_warning;
392 }
393
394 /** Called to store the current value of the components. */
395 public void loseFocus() {
396 // String values. Have to test if this component has actually ever recieved focus anyway.
397 if(ready) {
398 // Boolean values
399 public_collectionmeta.setValue((public_checkbox.isSelected() ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
400 String creator_email_str = creator_emailfield.getText();
401 creator_collectionmeta.setValue(creator_email_str);
402 // If the email is currently empty, store this email
403 if(Configuration.getEmail() == null) {
404 Configuration.setEmail(creator_email_str); // Store the email address in the configuration
405 }
406 collection_extra_collectionmeta.setValue(description_textarea.getText());
407 icon_collection_collectionmeta.setValue(icon_textfield.getText());
408 maintainer_collectionmeta.setValue(maintainer_emailfield.getText());
409 icon_collection_small_collectionmeta.setValue(small_icon_textfield.getText());
410
411 // Oh, and if the collection title is already in use warn them about it
412 String title = name_textfield.getText();
413 // I just happen to have a handy method in the new details prompt to detect this very thing
414 if(!has_been_warned && NewCollectionDetailsPrompt.titleClashes(title, CollectionDesignManager.collect_config.getFile())) {
415 // Determine if the user wants to be warned about this
416 WarningDialog dialog = new WarningDialog("warning.TitleClashes", "TitleClashes.Title", Dictionary.get("TitleClashes.Message"), null, true);
417 if(dialog.display() == JOptionPane.OK_OPTION) {
418 // If they have said yes, then carry on with the assignement
419 collection_name_collectionmeta.setValue(title);
420 }
421 // Otherwise we don't assign anything. In fact we have to restore the frame title back to its original value
422 else {
423 String collection_title = collection_name_collectionmeta.getValue(CollectionMeta.TEXT);
424 String collection_name = Gatherer.c_man.getCollection().getName();
425 Gatherer.g_man.setTitle(collection_title, collection_name);
426 collection_name = null;
427 collection_title = null;
428 }
429 dialog.dispose();
430 dialog = null;
431 }
432 // No clash, no worries.
433 else {
434 collection_name_collectionmeta.setValue(title);
435 }
436 title = null;
437
438 ready = false;
439 has_been_warned = false;
440 }
441 }
442
443 /** Listens for a click on either browse button, and when detected opens a file browser window initially pointed at the images folder of the collection. Once a user has selected a path, does it's best to construct the best address to the resource, such as _httpcollection_/images/about.gif */
444 private class BrowseListener
445 implements ActionListener {
446
447 private String prefix;
448
449 public BrowseListener(String prefix_raw) {
450 this.prefix = prefix_raw.replaceAll(StaticStrings.COLNAME_PATTERN, Gatherer.c_man.getCollection().getName());
451 }
452
453 public void actionPerformed(ActionEvent event) {
454 // Open an almost standard file browser to the images folder of the current collection
455 File images_folder = new File(Gatherer.c_man.getCollectionImagesDirectoryPath());
456 // If images isn't already there, create it
457 if(!images_folder.exists()) {
458 images_folder.mkdirs();
459 }
460 JFileChooser file_chooser = new JFileChooser(images_folder);
461 file_chooser.setAcceptAllFileFilterUsed(false);
462 file_chooser.setDialogTitle(Dictionary.get("CDM.General.Browser_Title"));
463 file_chooser.setFileFilter(new ImageFilter());
464 file_chooser.setSize(400,300);
465 OpenCollectionDialog.disableRename(file_chooser);
466 int value = file_chooser.showOpenDialog(Gatherer.g_man);
467 // If the user hasn't cancelled, retrieve the file path selected
468 if(value == JFileChooser.APPROVE_OPTION) {
469 // If the file isn't in the images folder, then ask the user if they want to copy it there
470 File file = file_chooser.getSelectedFile();
471 if(!file.getParentFile().equals(images_folder)) {
472 if(true) { //JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("CDM.General.Copy_Image"), Dictionary.get("General.Warning"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
473 // Copy the file
474 try {
475 File collection_image_file = new File(images_folder, file.getName());
476 Gatherer.f_man.getQueue().copyFile(file, collection_image_file, null);
477
478 // If we're using a remote Greenstone server, upload the image
479 if (Gatherer.isGsdlRemote) {
480 RemoteGreenstoneServer.uploadCollectionFile(Gatherer.c_man.getCollection().getName(), collection_image_file);
481 }
482 }
483 catch(Exception exception) {
484 DebugStream.printStackTrace(exception);
485 // Show warning
486 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.General.Image_Copy_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
487 // Nothing else we can do.
488 return;
489 }
490 }
491 else {
492 // Nothing we can safely do
493 return;
494 }
495 }
496 // Create the path starting _httpcollection_/images/<filename>
497 String path = prefix + file.getName();
498 if(event.getSource() == browse_about_icon_button) {
499 icon_textfield.setText(path);
500 }
501 else {
502 small_icon_textfield.setText(path);
503 }
504 path = null;
505 }
506 }
507
508 /** ImageFilter.java is a 1.4 example used by FileChooserDemo2.java. */
509 private class ImageFilter
510 extends javax.swing.filechooser.FileFilter {
511
512 private Pattern pattern = null;
513
514 public ImageFilter() {
515 pattern = Pattern.compile(".*\\.(gif|png|jpe?g)");
516 }
517
518 // Accept all directories and all .col files
519 public boolean accept(File f) {
520 String filename = f.getName().toLowerCase();
521 Matcher matcher = pattern.matcher(filename);
522 return f.isDirectory() || matcher.matches();
523 }
524
525 // The description of this filter
526 public String getDescription() {
527 return Dictionary.get("CDM.General.Image_Filter");
528 }
529 }
530 }
531
532 private class CollectionTitleUpdater
533 implements DocumentListener {
534 /** Gives notification that an attribute or set of attributes changed. */
535 public void changedUpdate(DocumentEvent e) {
536 setTitle();
537 }
538 /** Gives notification that there was an insert into the document. */
539 public void insertUpdate(DocumentEvent e) {
540 setTitle();
541 }
542 /** Gives notification that a portion of the document has been removed. */
543 public void removeUpdate(DocumentEvent e) {
544 setTitle();
545 }
546
547 private void setTitle() {
548 // Set the title
549 String collection_title = name_textfield.getText();
550 String collection_name = Gatherer.c_man.getCollection().getName();
551 Gatherer.g_man.setTitle(collection_title, collection_name);
552 collection_title = null;
553 collection_name = null;
554 }
555 }
556 }
557
558 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
559 private class DesignTree
560 extends JTree {
561 private DesignNode root = null;
562 /** Constructor. Automatically generates all of the nodes, in the order of CONTENTS. */
563 public DesignTree() {
564 super();
565 resetModel(Configuration.getMode());
566 expandRow(0);
567 setRootVisible(false);
568 setSelectionRow(0);
569 }
570
571 /** Reset the model used by the design page contents tree. This is necessary to hide the partitions entry when in lower detail modes
572 * @param mode the current detail mode as an int
573 */
574 public void resetModel(int mode) {
575 root = new DesignNode("CDM.GUI.Root");
576 // Now add the design categories.
577 for(int i = 0; i < CONTENTS.length; i++) {
578 root.add(new DesignNode(CONTENTS[i]));
579 }
580 this.setModel(new DefaultTreeModel(root));
581 updateUI();
582 }
583 /** Set the current view to the one specified.
584 * @param type the name of the desired view as a String
585 */
586 public void setSelectedView(String type) {
587 type = Dictionary.get(type);
588 for(int i = 0; i < root.getChildCount(); i++) {
589 DesignNode child = (DesignNode) root.getChildAt(i);
590 if(child.toString().equals(type)) {
591 TreePath path = new TreePath(child.getPath());
592 setSelectionPath(path);
593 }
594 }
595 }
596 }
597 /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */
598 private class DesignNode
599 extends DefaultMutableTreeNode {
600 /** Constructor.
601 * @param object The <strong>Object</strong> assigned to this node.
602 */
603 public DesignNode(String object) {
604 super(object);
605 }
606 /** Retrieve a textual representation of the object.
607 * @return a String
608 */
609 public String toString() {
610 // return Dictionary.get("CDM.GUI." + (String)getUserObject());
611 return Dictionary.get((String) getUserObject());
612 }
613 }
614 /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */
615 private class TreeListener
616 implements TreeSelectionListener {
617 /** Called whenever the selection changes, we must update the view so it matches the node selected.
618 * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.
619 * @see org.greenstone.gatherer.cdm.ClassifierManager
620 * @see org.greenstone.gatherer.cdm.CollectionDesignManager
621 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
622 * @see org.greenstone.gatherer.cdm.FormatManager
623 * @see org.greenstone.gatherer.cdm.LanguageManager
624 * @see org.greenstone.gatherer.cdm.MetadataSetView
625 * @see org.greenstone.gatherer.cdm.SubcollectionManager
626 * @see org.greenstone.gatherer.cdm.TranslationView
627 * @see org.greenstone.gatherer.cdm.PlugInManager
628 */
629 public void valueChanged(TreeSelectionEvent event) {
630 if(!tree.isSelectionEmpty()) {
631 TreePath path = tree.getSelectionPath();
632 DesignNode node = (DesignNode)path.getLastPathComponent();
633 String type = (String)node.getUserObject();
634 // Wait begins
635 Gatherer.g_man.wait(true);
636 // Save information in current view
637 view.loseFocus();
638 remove((JPanel)view);
639 // Change panes.
640 if(type == CONTENTS[0]) {
641 view = getControls();
642 }
643 else if(type == CONTENTS[1]) {
644 view = CollectionDesignManager.plugin_manager.getControls();
645 }
646 else if(type == CONTENTS[2]) {
647 view = CollectionDesignManager.searchtype_manager.getControls();
648 }
649 else if(type == CONTENTS[3]) {
650 view = CollectionDesignManager.index_manager.getControls();
651 }
652 else if(type == CONTENTS[4]) {
653 view = CollectionDesignManager.subcollection_manager.getControls();
654 }
655 else if(type == CONTENTS[5]) {
656 view = CollectionDesignManager.supercollection_manager.getControls();
657 }
658 else if(type == CONTENTS[6]) {
659 view = CollectionDesignManager.classifier_manager.getControls();
660 }
661 else if(type == CONTENTS[7]) {
662 view = CollectionDesignManager.format_manager.getControls();
663 }
664 else if(type == CONTENTS[8]) {
665 view = CollectionDesignManager.translation_view.getControls();
666 }
667 else if(type == CONTENTS[9]) {
668 view = CollectionDesignManager.metadataset_view.getControls();
669 }
670 add((JPanel)view, BorderLayout.CENTER);
671 // Update information on visible pane
672 view.gainFocus();
673 repaint();
674 // Wait ends
675 Gatherer.g_man.wait(false);
676 }
677 }
678 }
679}
Note: See TracBrowser for help on using the repository browser.