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

Last change on this file since 9045 was 9045, checked in by mdewsnip, 19 years ago

Made major rearrangements to the way path variables are calculated. This is to facilitate being able to specify a "-collectdir" argument to the GLI so one GLI installation can be used in a networked, multi-user situation. Hope I haven't broken anything!

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