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 | */
|
---|
27 | package org.greenstone.gatherer.gui;
|
---|
28 |
|
---|
29 | import java.awt.*;
|
---|
30 | import java.awt.event.*;
|
---|
31 | import java.io.*;
|
---|
32 | import java.util.*;
|
---|
33 | import javax.swing.*;
|
---|
34 | import javax.swing.event.*;
|
---|
35 | import org.greenstone.gatherer.Configuration;
|
---|
36 | import org.greenstone.gatherer.Dictionary;
|
---|
37 | import org.greenstone.gatherer.Gatherer;
|
---|
38 | import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
|
---|
39 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
40 | import org.greenstone.gatherer.util.Utility;
|
---|
41 |
|
---|
42 | /** A dialog which provides a straight-forward access to the currently installed collections. It also will contain the ability to continue through to the original OpenCollectionDialog if your source collection is located somewhere other than the gsdl collect folder. */
|
---|
43 | public class SimpleOpenCollectionDialog
|
---|
44 | extends ModalDialog {
|
---|
45 |
|
---|
46 | static final public int OK_OPTION = 0;
|
---|
47 | static final public int CANCEL_OPTION = 1;
|
---|
48 | static final public int BROWSE_OPTION = 2;
|
---|
49 |
|
---|
50 | static final private Dimension SIZE = new Dimension(640,480);
|
---|
51 | static final private String BLANK = "b";
|
---|
52 | static final private String DESCRIPTION = "d";
|
---|
53 |
|
---|
54 | private CardLayout card_layout;
|
---|
55 | private int result;
|
---|
56 | private JButton advanced_button;
|
---|
57 | private JButton cancel_button;
|
---|
58 | private JButton open_button;
|
---|
59 | private JList collection_list;
|
---|
60 | private JTextArea description_textarea;
|
---|
61 | private JPanel description_pane;
|
---|
62 | private String filename;
|
---|
63 |
|
---|
64 | public SimpleOpenCollectionDialog() {
|
---|
65 | super(Gatherer.g_man, "", true);
|
---|
66 | setSize(SIZE);
|
---|
67 | Dictionary.setText(this, "OpenCollectionDialog.Title");
|
---|
68 |
|
---|
69 | // Creation
|
---|
70 | JPanel content_pane = (JPanel) getContentPane();
|
---|
71 |
|
---|
72 | JPanel center_pane = new JPanel();
|
---|
73 |
|
---|
74 | JPanel collection_list_pane = new JPanel();
|
---|
75 | JLabel collection_list_label = new JLabel();
|
---|
76 | Dictionary.setText(collection_list_label, "OpenCollectionDialog.Available_Collections");
|
---|
77 | collection_list = new JList(new CollectionListModel());
|
---|
78 | description_pane = new JPanel();
|
---|
79 | card_layout = new CardLayout();
|
---|
80 |
|
---|
81 | JPanel blank_pane = new JPanel();
|
---|
82 |
|
---|
83 | JPanel description_textarea_pane = new JPanel();
|
---|
84 | JLabel description_textarea_label = new JLabel();
|
---|
85 | Dictionary.setText(description_textarea_label, "OpenCollectionDialog.Description");
|
---|
86 | description_textarea = new JTextArea();
|
---|
87 |
|
---|
88 | JPanel button_pane = new JPanel();
|
---|
89 | open_button = new GLIButton();
|
---|
90 | open_button.setEnabled(false);
|
---|
91 | open_button.setMnemonic(KeyEvent.VK_O);
|
---|
92 | Dictionary.setBoth(open_button, "OpenCollectionDialog.Open", "OpenCollectionDialog.Open_Tooltip");
|
---|
93 | advanced_button = new GLIButton();
|
---|
94 | advanced_button.setMnemonic(KeyEvent.VK_B);
|
---|
95 | Dictionary.setBoth(advanced_button, "OpenCollectionDialog.Browse", "OpenCollectionDialog.Browse_Tooltip");
|
---|
96 | cancel_button = new GLIButton();
|
---|
97 | cancel_button.setMnemonic(KeyEvent.VK_C);
|
---|
98 | Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
|
---|
99 |
|
---|
100 | // Connection
|
---|
101 | advanced_button.addActionListener(new AdvancedListener());
|
---|
102 | cancel_button.addActionListener(new CancelListener());
|
---|
103 | open_button.addActionListener(new OpenListener());
|
---|
104 | CollectionListSelectionListener clsl = new CollectionListSelectionListener();
|
---|
105 | collection_list.addListSelectionListener(clsl);
|
---|
106 | collection_list.addMouseListener(clsl);
|
---|
107 | clsl = null;
|
---|
108 |
|
---|
109 | // Layout
|
---|
110 | collection_list_pane.setLayout(new BorderLayout());
|
---|
111 | collection_list_pane.add(collection_list_label, BorderLayout.NORTH);
|
---|
112 | collection_list_pane.add(new JScrollPane(collection_list), BorderLayout.CENTER);
|
---|
113 |
|
---|
114 | description_textarea_pane.setLayout(new BorderLayout());
|
---|
115 | description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH);
|
---|
116 | description_textarea_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
|
---|
117 |
|
---|
118 | description_pane.setLayout(card_layout);
|
---|
119 | description_pane.add(description_textarea_pane, DESCRIPTION);
|
---|
120 | description_pane.add(blank_pane, BLANK);
|
---|
121 |
|
---|
122 | center_pane.setLayout(new GridLayout(2,1,0,5));
|
---|
123 | center_pane.add(collection_list_pane);
|
---|
124 | center_pane.add(description_pane);
|
---|
125 |
|
---|
126 | button_pane.setLayout(new GridLayout(1,4));
|
---|
127 | button_pane.add(new JPanel());
|
---|
128 | button_pane.add(open_button);
|
---|
129 | if (!Gatherer.GS3) { // Temporarily disable Browse for GS3
|
---|
130 | button_pane.add(advanced_button);
|
---|
131 | }
|
---|
132 | button_pane.add(cancel_button);
|
---|
133 |
|
---|
134 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
135 | content_pane.setLayout(new BorderLayout());
|
---|
136 | content_pane.add(center_pane, BorderLayout.CENTER);
|
---|
137 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
138 |
|
---|
139 | Dimension screen_size = Configuration.screen_size;
|
---|
140 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
141 | screen_size = null;
|
---|
142 | }
|
---|
143 |
|
---|
144 | public void destroy() {
|
---|
145 | }
|
---|
146 |
|
---|
147 | public int display() {
|
---|
148 | setVisible(true);
|
---|
149 | return result;
|
---|
150 | }
|
---|
151 |
|
---|
152 | public String getFileName() {
|
---|
153 | return this.filename;
|
---|
154 | }
|
---|
155 | private class AdvancedListener
|
---|
156 | implements ActionListener {
|
---|
157 |
|
---|
158 | public void actionPerformed(ActionEvent event) {
|
---|
159 | result = BROWSE_OPTION;
|
---|
160 | SimpleOpenCollectionDialog.this.dispose();
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | private class CancelListener
|
---|
165 | implements ActionListener {
|
---|
166 |
|
---|
167 | public void actionPerformed(ActionEvent event) {
|
---|
168 | result = CANCEL_OPTION;
|
---|
169 | SimpleOpenCollectionDialog.this.dispose();
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | private class CollectionListSelectionListener
|
---|
174 | extends MouseAdapter
|
---|
175 | implements ListSelectionListener {
|
---|
176 |
|
---|
177 | public void mouseClicked(MouseEvent event) {
|
---|
178 | ///ystem.err.println("Mouse clicked");
|
---|
179 | if(event.getClickCount() >= 2) {
|
---|
180 | Point location = event.getPoint();
|
---|
181 | int index = collection_list.locationToIndex(location);
|
---|
182 | collection_list.setSelectedIndex(index);
|
---|
183 | location = null;
|
---|
184 | open_button.doClick();
|
---|
185 | }
|
---|
186 | }
|
---|
187 |
|
---|
188 | public void valueChanged(ListSelectionEvent event) {
|
---|
189 | if(collection_list.isSelectionEmpty()) {
|
---|
190 | card_layout.show(description_pane, BLANK);
|
---|
191 | open_button.setEnabled(false);
|
---|
192 | }
|
---|
193 | else {
|
---|
194 | BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue();
|
---|
195 | description_textarea.setText(collection_configuration.getDescription());
|
---|
196 | description_textarea.setCaretPosition(0);
|
---|
197 | card_layout.show(description_pane, DESCRIPTION);
|
---|
198 | open_button.setEnabled(true);
|
---|
199 | }
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | // use this if we ever go back to viewing all colls at once
|
---|
204 | /* private class GS3CollectionListModel
|
---|
205 | extends AbstractListModel {
|
---|
206 |
|
---|
207 | private TreeSet data;
|
---|
208 |
|
---|
209 | public GS3CollectionListModel() {
|
---|
210 | data = new TreeSet();
|
---|
211 | File sites_folder = new File(Utility.getSitesDir(Configuration.gsdl3_path));
|
---|
212 | File sites[] = sites_folder.listFiles();
|
---|
213 | for (int s=0; s<sites.length; s++) {
|
---|
214 | String site_name = sites[s].getName();
|
---|
215 | System.err.println("found site "+site_name);
|
---|
216 | File collect_folder = new File(Utility.getCollectDir(Configuration.gsdl3_path, site_name) );
|
---|
217 | if (!collect_folder.exists()) {
|
---|
218 | continue;
|
---|
219 | }
|
---|
220 | File[] collection_folders = collect_folder.listFiles();
|
---|
221 | for(int i = 0; i < collection_folders.length; i++) {
|
---|
222 | File collection_folder = collection_folders[i];
|
---|
223 | String collection_foldername = collection_folder.getName();
|
---|
224 | if(!collection_folder.isFile() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
|
---|
225 | BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(new File(collection_folder, Utility.CONFIG_FILE), site_name);
|
---|
226 | if(!collection_configuration.getName().equals(StaticStrings.ERROR_STR)) {
|
---|
227 | data.add(collection_configuration);
|
---|
228 | }
|
---|
229 | }
|
---|
230 | collection_foldername = null;
|
---|
231 | collection_folder = null;
|
---|
232 | } // for each collection
|
---|
233 | collection_folders = null;
|
---|
234 | collect_folder = null;
|
---|
235 | } // for each site
|
---|
236 | sites_folder = null;
|
---|
237 | sites = null;
|
---|
238 | }
|
---|
239 |
|
---|
240 | public Object getElementAt(int index) {
|
---|
241 | Iterator iterator = data.iterator();
|
---|
242 | for(int i = 0; iterator.hasNext(); i++) {
|
---|
243 | Object object = iterator.next();
|
---|
244 | if(i == index) {
|
---|
245 | iterator = null;
|
---|
246 | return object;
|
---|
247 | }
|
---|
248 | object = null;
|
---|
249 | }
|
---|
250 | iterator = null;
|
---|
251 | return null;
|
---|
252 | }
|
---|
253 |
|
---|
254 | public int getSize() {
|
---|
255 | return data.size();
|
---|
256 | }
|
---|
257 | }
|
---|
258 | */
|
---|
259 | private class CollectionListModel
|
---|
260 | extends AbstractListModel {
|
---|
261 |
|
---|
262 | private TreeSet data;
|
---|
263 |
|
---|
264 | public CollectionListModel() {
|
---|
265 | data = new TreeSet();
|
---|
266 | File collect_directory = new File(Gatherer.getCollectDirectoryPath());
|
---|
267 | if (!collect_directory.exists()) {
|
---|
268 | collect_directory = null;
|
---|
269 | return;
|
---|
270 | }
|
---|
271 | File[] collection_folders = collect_directory.listFiles();
|
---|
272 | for(int i = 0; i < collection_folders.length; i++) {
|
---|
273 | File collection_folder = collection_folders[i];
|
---|
274 | String collection_foldername = collection_folder.getName();
|
---|
275 | if(collection_folder.isDirectory() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
|
---|
276 | File config_file = new File(collection_folder, Utility.CONFIG_FILE);
|
---|
277 | if (config_file.exists()) {
|
---|
278 | BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(config_file);
|
---|
279 | data.add(collection_configuration);
|
---|
280 | }
|
---|
281 | config_file = null;
|
---|
282 | }
|
---|
283 | collection_foldername = null;
|
---|
284 | collection_folder = null;
|
---|
285 | }
|
---|
286 | collection_folders = null;
|
---|
287 | collect_directory = null;
|
---|
288 | }
|
---|
289 |
|
---|
290 | public Object getElementAt(int index) {
|
---|
291 | Iterator iterator = data.iterator();
|
---|
292 | for(int i = 0; iterator.hasNext(); i++) {
|
---|
293 | Object object = iterator.next();
|
---|
294 | if(i == index) {
|
---|
295 | iterator = null;
|
---|
296 | return object;
|
---|
297 | }
|
---|
298 | object = null;
|
---|
299 | }
|
---|
300 | iterator = null;
|
---|
301 | return null;
|
---|
302 | }
|
---|
303 |
|
---|
304 | public int getSize() {
|
---|
305 | return data.size();
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | private class OpenListener
|
---|
310 | implements ActionListener {
|
---|
311 |
|
---|
312 | public void actionPerformed(ActionEvent event) {
|
---|
313 | result = OK_OPTION;
|
---|
314 | Object selected_object = collection_list.getSelectedValue();
|
---|
315 | if (selected_object instanceof BasicCollectionConfiguration) {
|
---|
316 | BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration)selected_object; //(BasicCollectionConfiguration) collection_list.getSelectedValue();
|
---|
317 | //*************888
|
---|
318 | File collect_cfg_file = collection_configuration.getFile(); // returns the collect.cfg file
|
---|
319 | File etc_folder = collect_cfg_file.getParentFile();
|
---|
320 | File collection_folder = etc_folder.getParentFile();
|
---|
321 | filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + Utility.GLI_EXTENSION;
|
---|
322 | collection_folder = null;
|
---|
323 | etc_folder = null;
|
---|
324 | collect_cfg_file = null;
|
---|
325 | collection_configuration = null;
|
---|
326 | SimpleOpenCollectionDialog.this.dispose();
|
---|
327 | }
|
---|
328 | }
|
---|
329 | }
|
---|
330 | }
|
---|