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

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

changed the layout and unfixed the label sizes so other langs text can fit in

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