source: trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionMetadataPrompt.java@ 7183

Last change on this file since 7183 was 6318, checked in by jmt12, 20 years ago

Changed JButtons for GLIButtons, which know whether they should paint their background depending on what platform they are run on, and finished keyboard shortcuts

  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 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.gui;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.*;
32import java.util.*;
33import javax.swing.*;
34import javax.swing.event.*;
35import org.greenstone.gatherer.Dictionary;
36import org.greenstone.gatherer.Gatherer;
37import org.greenstone.gatherer.checklist.CheckList;
38import org.greenstone.gatherer.checklist.Entry;
39import org.greenstone.gatherer.gui.GLIButton;
40import org.greenstone.gatherer.gui.SimpleMenuBar;
41import org.greenstone.gatherer.gui.ModalDialog;
42import org.greenstone.gatherer.cdm.ElementWrapper;
43import org.greenstone.gatherer.msm.MetadataSet;
44import org.greenstone.gatherer.util.StaticStrings;
45import org.greenstone.gatherer.util.Utility;
46import org.w3c.dom.*;
47
48public class NewCollectionMetadataPrompt
49 extends ModalDialog {
50
51 private boolean cancelled = true;
52 private CheckList sets_list;
53 private JDialog self;
54 private JList elements_list;
55 static private Dimension size = new Dimension(700, 380);
56
57 public NewCollectionMetadataPrompt() {
58 this(false);
59 }
60 public NewCollectionMetadataPrompt(boolean existing_coll) {
61 super(Gatherer.g_man, true);
62 this.self = this;
63 if (existing_coll) {
64 setJMenuBar(new SimpleMenuBar("openingacollection"));
65 Dictionary.setText(this, "NewCollectionPrompt.Metadata_Title_Existing");
66 } else {
67 setJMenuBar(new SimpleMenuBar("creatingacollection"));
68 Dictionary.setText(this, "NewCollectionPrompt.Title");
69 }
70 setModal(true);
71 setSize(size);
72
73
74 // And the remaining metadata sets.
75 ArrayList sets = new ArrayList();
76 // Determine what collections are available.
77 File metadata_directory = new File(Utility.METADATA_DIR);
78 File[] possible_mdses = metadata_directory.listFiles();
79 for(int i = 0; i < possible_mdses.length; i++) {
80 String name = possible_mdses[i].getName();
81 if(name.endsWith(StaticStrings.METADATA_SET_EXTENSION) && !name.equals(Utility.EXTRACTED_METADATA_NAMESPACE + StaticStrings.METADATA_SET_EXTENSION)) {
82 sets.add(new MetadataSet(possible_mdses[i]));
83 }
84 }
85
86 // Creation
87 JPanel content_pane = (JPanel) getContentPane();
88
89 JPanel instructions_panel = new JPanel();
90 JLabel instructions_label1 = new JLabel();
91 Dictionary.setText(instructions_label1, "NewCollectionPrompt.Metadata_Instructions1");
92 JLabel instructions_label2 = new JLabel();
93 Dictionary.setText(instructions_label2, "NewCollectionPrompt.Metadata_Instructions2");
94
95 JPanel center_pane = new JPanel();
96
97 JPanel sets_list_pane = new JPanel();
98 JLabel sets_list_label = new JLabel();
99 sets_list_label.setOpaque(false);
100 Dictionary.setText(sets_list_label, "NewCollectionPrompt.Select_MDS");
101 sets_list = new CheckList(sets, true);
102
103 JPanel elements_list_pane = new JPanel();
104 JLabel elements_list_label = new JLabel();
105 Dictionary.setText(elements_list_label, "NewCollectionPrompt.Metadata_Elements");
106 elements_list = new JList();
107 elements_list.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
108 elements_list.setForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false));
109 elements_list.setSelectionBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
110 elements_list.setSelectionForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false));
111
112 JPanel button_pane = new JPanel();
113 JButton ok_button = new GLIButton();
114 ok_button.setMnemonic(KeyEvent.VK_O);
115 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
116 JButton cancel_button = new GLIButton();
117 cancel_button.setMnemonic(KeyEvent.VK_C);
118 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
119
120 // Connection
121 ok_button.addActionListener(new OKButtonListener());
122 cancel_button.addActionListener(new CancelButtonListener());
123 sets_list.addListSelectionListener(new MetadataListSelectionListener());
124
125 // Display
126 instructions_panel.setLayout(new GridLayout(2,1));
127 instructions_panel.add(instructions_label1);
128 instructions_panel.add(instructions_label2);
129
130 sets_list_pane.setLayout(new BorderLayout());
131 sets_list_pane.add(sets_list_label, BorderLayout.NORTH);
132 sets_list_pane.add(new JScrollPane(sets_list), BorderLayout.CENTER);
133
134 elements_list_pane.setLayout(new BorderLayout());
135 elements_list_pane.add(elements_list_label, BorderLayout.NORTH);
136 elements_list_pane.add(new JScrollPane(elements_list), BorderLayout.CENTER);
137
138 center_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
139 center_pane.setLayout(new GridLayout(2,1,0,5));
140 center_pane.add(sets_list_pane);
141 center_pane.add(elements_list_pane);
142
143 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
144 button_pane.setLayout(new GridLayout(1,2,5,0));
145 button_pane.add(ok_button);
146 button_pane.add(cancel_button);
147
148 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
149 content_pane.setLayout(new BorderLayout());
150 content_pane.add(instructions_panel, BorderLayout.NORTH);
151 content_pane.add(center_pane, BorderLayout.CENTER);
152 content_pane.add(button_pane, BorderLayout.SOUTH);
153
154 // Show
155 Dimension screen_size = Gatherer.config.screen_size;
156 setLocation((screen_size.width - size.width) / 2, (screen_size.height - size.height) / 2);
157 setVisible(true);
158 }
159
160 public ArrayList getSets() {
161 return sets_list.getSelected();
162 }
163
164 public boolean isCancelled() {
165 return cancelled;
166 }
167
168 private class CancelButtonListener
169 implements ActionListener {
170 public void actionPerformed(ActionEvent event) {
171 cancelled = true;
172 self.dispose();
173 }
174 }
175
176 public class MetadataListSelectionListener
177 implements ListSelectionListener {
178 public void valueChanged(ListSelectionEvent event) {
179 if(!sets_list.isSelectionEmpty()) {
180 // Retrieve the selected set.
181 Entry entry = (Entry) sets_list.getSelectedValue();
182 MetadataSet set = (MetadataSet) entry.getObject();
183 entry = null;
184 // Build a model from its elements.
185 NodeList elements = set.getElements();
186 set = null;
187 Vector elements_model = new Vector();
188 for(int i = 0; i < elements.getLength(); i++) {
189 elements_model.add(new ElementWrapper(elements.item(i)));
190 }
191 elements = null;
192 Collections.sort(elements_model);
193 elements_list.setListData(elements_model);
194 elements_model = null;
195 }
196 else {
197 elements_list.setListData(new String[0]);
198 }
199 }
200 }
201
202 public class OKButtonListener
203 implements ActionListener {
204 public void actionPerformed(ActionEvent event) {
205 // See if the user has selected no metadata sets, and if so confirm thats what they really want.
206 ArrayList selected_sets = sets_list.getSelected();
207 cancelled = false;
208 if(selected_sets.size() == 0) {
209 WarningDialog dialog = new WarningDialog("warning.NoMetadataSetsSelected", true);
210 if(dialog.display() == JOptionPane.OK_OPTION) {
211 // Otherwise we are free to go
212 self.dispose();
213 }
214 dialog.dispose();
215 dialog = null;
216 }
217 else {
218 self.dispose();
219 }
220 }
221 }
222}
Note: See TracBrowser for help on using the repository browser.