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

Last change on this file since 12091 was 11491, checked in by mdewsnip, 18 years ago

Now sets the "overwrite" flag when copying the collection images into the images directory, to prevent errors when the file already exists.

  • Property svn:keywords set to Author Date Id Revision
File size: 29.1 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(5,5,5,5));
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,0,0));
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
444 /** 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 */
445 private class BrowseListener
446 implements ActionListener {
447
448 private String prefix;
449
450 public BrowseListener(String prefix_raw) {
451 this.prefix = prefix_raw.replaceAll(StaticStrings.COLNAME_PATTERN, Gatherer.c_man.getCollection().getName());
452 }
453
454 public void actionPerformed(ActionEvent event) {
455 // Open an almost standard file browser to the images folder of the current collection
456 File images_folder = new File(Gatherer.c_man.getCollectionImagesDirectoryPath());
457 // If images isn't already there, create it
458 if(!images_folder.exists()) {
459 images_folder.mkdirs();
460 }
461 JFileChooser file_chooser = new JFileChooser(images_folder);
462 file_chooser.setAcceptAllFileFilterUsed(false);
463 file_chooser.setDialogTitle(Dictionary.get("CDM.General.Browser_Title"));
464 file_chooser.setFileFilter(new ImageFilter());
465 file_chooser.setSize(400,300);
466 OpenCollectionDialog.disableRename(file_chooser);
467 int value = file_chooser.showOpenDialog(Gatherer.g_man);
468 // If the user hasn't cancelled, retrieve the file path selected
469 if(value == JFileChooser.APPROVE_OPTION) {
470 // If the file isn't in the images folder, then ask the user if they want to copy it there
471 File file = file_chooser.getSelectedFile();
472 if (!file.getParentFile().equals(images_folder)) {
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, true);
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 String[] args = new String[] {file.getAbsolutePath(), images_folder.getAbsolutePath()};
487 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.General.Image_Copy_Failed", args), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
488 // Nothing else we can do.
489 return;
490 }
491 }
492
493 // Create the path starting _httpcollection_/images/<filename>
494 String path = prefix + file.getName();
495 if(event.getSource() == browse_about_icon_button) {
496 icon_textfield.setText(path);
497 }
498 else {
499 small_icon_textfield.setText(path);
500 }
501 path = null;
502 }
503 }
504
505 /** ImageFilter.java is a 1.4 example used by FileChooserDemo2.java. */
506 private class ImageFilter
507 extends javax.swing.filechooser.FileFilter {
508
509 private Pattern pattern = null;
510
511 public ImageFilter() {
512 pattern = Pattern.compile(".*\\.(gif|png|jpe?g)");
513 }
514
515 // Accept all directories and all .col files
516 public boolean accept(File f) {
517 String filename = f.getName().toLowerCase();
518 Matcher matcher = pattern.matcher(filename);
519 return f.isDirectory() || matcher.matches();
520 }
521
522 // The description of this filter
523 public String getDescription() {
524 return Dictionary.get("CDM.General.Image_Filter");
525 }
526 }
527 }
528
529 private class CollectionTitleUpdater
530 implements DocumentListener {
531 /** Gives notification that an attribute or set of attributes changed. */
532 public void changedUpdate(DocumentEvent e) {
533 setTitle();
534 }
535 /** Gives notification that there was an insert into the document. */
536 public void insertUpdate(DocumentEvent e) {
537 setTitle();
538 }
539 /** Gives notification that a portion of the document has been removed. */
540 public void removeUpdate(DocumentEvent e) {
541 setTitle();
542 }
543
544 private void setTitle() {
545 // Set the title
546 String collection_title = name_textfield.getText();
547 String collection_name = Gatherer.c_man.getCollection().getName();
548 Gatherer.g_man.setTitle(collection_title, collection_name);
549 collection_title = null;
550 collection_name = null;
551 }
552 }
553 }
554
555 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
556 private class DesignTree
557 extends JTree {
558 private DesignNode root = null;
559 /** Constructor. Automatically generates all of the nodes, in the order of CONTENTS. */
560 public DesignTree() {
561 super();
562 resetModel(Configuration.getMode());
563 expandRow(0);
564 setRootVisible(false);
565 setSelectionRow(0);
566 }
567
568 /** Reset the model used by the design page contents tree. This is necessary to hide the partitions entry when in lower detail modes
569 * @param mode the current detail mode as an int
570 */
571 public void resetModel(int mode) {
572 root = new DesignNode("CDM.GUI.Root");
573 // Now add the design categories.
574 for(int i = 0; i < CONTENTS.length; i++) {
575 root.add(new DesignNode(CONTENTS[i]));
576 }
577 this.setModel(new DefaultTreeModel(root));
578 updateUI();
579 }
580 /** Set the current view to the one specified.
581 * @param type the name of the desired view as a String
582 */
583 public void setSelectedView(String type) {
584 type = Dictionary.get(type);
585 for(int i = 0; i < root.getChildCount(); i++) {
586 DesignNode child = (DesignNode) root.getChildAt(i);
587 if(child.toString().equals(type)) {
588 TreePath path = new TreePath(child.getPath());
589 setSelectionPath(path);
590 }
591 }
592 }
593 }
594 /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */
595 private class DesignNode
596 extends DefaultMutableTreeNode {
597 /** Constructor.
598 * @param object The <strong>Object</strong> assigned to this node.
599 */
600 public DesignNode(String object) {
601 super(object);
602 }
603 /** Retrieve a textual representation of the object.
604 * @return a String
605 */
606 public String toString() {
607 // return Dictionary.get("CDM.GUI." + (String)getUserObject());
608 return Dictionary.get((String) getUserObject());
609 }
610 }
611 /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */
612 private class TreeListener
613 implements TreeSelectionListener {
614 /** Called whenever the selection changes, we must update the view so it matches the node selected.
615 * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.
616 * @see org.greenstone.gatherer.cdm.ClassifierManager
617 * @see org.greenstone.gatherer.cdm.CollectionDesignManager
618 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
619 * @see org.greenstone.gatherer.cdm.FormatManager
620 * @see org.greenstone.gatherer.cdm.LanguageManager
621 * @see org.greenstone.gatherer.cdm.MetadataSetView
622 * @see org.greenstone.gatherer.cdm.SubcollectionManager
623 * @see org.greenstone.gatherer.cdm.TranslationView
624 * @see org.greenstone.gatherer.cdm.PluginManager
625 */
626 public void valueChanged(TreeSelectionEvent event) {
627 if(!tree.isSelectionEmpty()) {
628 TreePath path = tree.getSelectionPath();
629 DesignNode node = (DesignNode)path.getLastPathComponent();
630 String type = (String)node.getUserObject();
631 // Wait begins
632 Gatherer.g_man.wait(true);
633 // Save information in current view
634 view.loseFocus();
635 remove((JPanel)view);
636 // Change panes.
637 if(type == CONTENTS[0]) {
638 view = getControls();
639 }
640 else if(type == CONTENTS[1]) {
641 view = CollectionDesignManager.plugin_manager.getControls();
642 }
643 else if(type == CONTENTS[2]) {
644 view = CollectionDesignManager.searchtype_manager.getControls();
645 }
646 else if(type == CONTENTS[3]) {
647 view = CollectionDesignManager.index_manager.getControls();
648 }
649 else if(type == CONTENTS[4]) {
650 view = CollectionDesignManager.subcollection_manager.getControls();
651 }
652 else if(type == CONTENTS[5]) {
653 view = CollectionDesignManager.supercollection_manager.getControls();
654 }
655 else if(type == CONTENTS[6]) {
656 view = CollectionDesignManager.classifier_manager.getControls();
657 }
658 else if(type == CONTENTS[7]) {
659 view = CollectionDesignManager.format_manager.getControls();
660 }
661 else if(type == CONTENTS[8]) {
662 view = CollectionDesignManager.translation_view.getControls();
663 }
664 else if(type == CONTENTS[9]) {
665 view = CollectionDesignManager.metadataset_view.getControls();
666 }
667 add((JPanel)view, BorderLayout.CENTER);
668 // Update information on visible pane
669 view.gainFocus();
670 repaint();
671 // Wait ends
672 Gatherer.g_man.wait(false);
673 }
674 }
675 }
676}
Note: See TracBrowser for help on using the repository browser.