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

Last change on this file since 10610 was 10610, checked in by kjdon, 19 years ago

removed a comment

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