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

Last change on this file since 6540 was 6389, checked in by jmt12, 20 years ago

Introduced the idea of detail modes - these have an effect on several parts of the gui, such as disabling or hiding all regular expression based controls, simplifying the output from perl scripts and (having been given yet another new last minute feature to implement) displays a completely different create pane. Mode is stored in the config.xml and is changable via the Preferences controls

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