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

Last change on this file since 7151 was 7151, checked in by kjdon, 20 years ago

fixed some more static label sizes and deleted a lot of commented out stuff

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