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

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

New code for "incremental" building, by Matthew Whyte.

I've only had time to look at this briefly; I've fixed a few obvious problems but I imagine this will be pretty flaky for a while.

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