source: trunk/gli/src/org/greenstone/gatherer/gui/SimpleOpenCollectionDialog.java@ 12119

Last change on this file since 12119 was 12119, checked in by kjdon, 18 years ago

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages

  • Property svn:keywords set to Author Date Id Revision
File size: 11.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.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.Configuration;
36import org.greenstone.gatherer.Dictionary;
37import org.greenstone.gatherer.Gatherer;
38import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
39import org.greenstone.gatherer.util.StaticStrings;
40import 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. */
43public 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 setTitle(Dictionary.get("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(Dictionary.get("OpenCollectionDialog.Available_Collections"));
76 collection_list = new JList(new CollectionListModel());
77 description_pane = new JPanel();
78 card_layout = new CardLayout();
79
80 JPanel blank_pane = new JPanel();
81
82 JPanel description_textarea_pane = new JPanel();
83 JLabel description_textarea_label = new JLabel(Dictionary.get("OpenCollectionDialog.Description"));
84 description_textarea = new JTextArea();
85
86 JPanel button_pane = new JPanel();
87 open_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Open"), Dictionary.get("OpenCollectionDialog.Open_Tooltip"));
88 open_button.setEnabled(false);
89
90 advanced_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Browse"), Dictionary.get("OpenCollectionDialog.Browse_Tooltip"));
91
92 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
93
94 // Connection
95 advanced_button.addActionListener(new AdvancedListener());
96 cancel_button.addActionListener(new CancelListener());
97 open_button.addActionListener(new OpenListener());
98 CollectionListSelectionListener clsl = new CollectionListSelectionListener();
99 collection_list.addListSelectionListener(clsl);
100 collection_list.addMouseListener(clsl);
101 clsl = null;
102
103 // Layout
104 collection_list_pane.setLayout(new BorderLayout());
105 collection_list_pane.add(collection_list_label, BorderLayout.NORTH);
106 collection_list_pane.add(new JScrollPane(collection_list), BorderLayout.CENTER);
107
108 description_textarea_pane.setLayout(new BorderLayout());
109 description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH);
110 description_textarea_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
111
112 description_pane.setLayout(card_layout);
113 description_pane.add(description_textarea_pane, DESCRIPTION);
114 description_pane.add(blank_pane, BLANK);
115
116 center_pane.setLayout(new GridLayout(2,1,0,5));
117 center_pane.add(collection_list_pane);
118 center_pane.add(description_pane);
119
120 button_pane.setLayout(new GridLayout(1,4));
121 button_pane.add(new JPanel());
122 button_pane.add(open_button);
123 if (!Gatherer.GS3) { // Temporarily disable Browse for GS3
124 button_pane.add(advanced_button);
125 }
126 button_pane.add(cancel_button);
127
128 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
129 content_pane.setLayout(new BorderLayout());
130 content_pane.add(center_pane, BorderLayout.CENTER);
131 content_pane.add(button_pane, BorderLayout.SOUTH);
132
133 Dimension screen_size = Configuration.screen_size;
134 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
135 screen_size = null;
136 }
137
138 public void destroy() {
139 }
140
141 public int display() {
142 setVisible(true);
143 return result;
144 }
145
146 public String getFileName() {
147 return this.filename;
148 }
149 private class AdvancedListener
150 implements ActionListener {
151
152 public void actionPerformed(ActionEvent event) {
153 result = BROWSE_OPTION;
154 SimpleOpenCollectionDialog.this.dispose();
155 }
156 }
157
158 private class CancelListener
159 implements ActionListener {
160
161 public void actionPerformed(ActionEvent event) {
162 result = CANCEL_OPTION;
163 SimpleOpenCollectionDialog.this.dispose();
164 }
165 }
166
167 private class CollectionListSelectionListener
168 extends MouseAdapter
169 implements ListSelectionListener {
170
171 public void mouseClicked(MouseEvent event) {
172 ///ystem.err.println("Mouse clicked");
173 if(event.getClickCount() >= 2) {
174 Point location = event.getPoint();
175 int index = collection_list.locationToIndex(location);
176 collection_list.setSelectedIndex(index);
177 location = null;
178 open_button.doClick();
179 }
180 }
181
182 public void valueChanged(ListSelectionEvent event) {
183 if(collection_list.isSelectionEmpty()) {
184 card_layout.show(description_pane, BLANK);
185 open_button.setEnabled(false);
186 }
187 else {
188 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue();
189 description_textarea.setText(collection_configuration.getDescription());
190 description_textarea.setCaretPosition(0);
191 card_layout.show(description_pane, DESCRIPTION);
192 open_button.setEnabled(true);
193 }
194 }
195 }
196
197 // use this if we ever go back to viewing all colls at once
198 /* private class GS3CollectionListModel
199 extends AbstractListModel {
200
201 private TreeSet data;
202
203 public GS3CollectionListModel() {
204 data = new TreeSet();
205 File sites_folder = new File(Utility.getSitesDir(Configuration.gsdl3_path));
206 File sites[] = sites_folder.listFiles();
207 for (int s=0; s<sites.length; s++) {
208 String site_name = sites[s].getName();
209 System.err.println("found site "+site_name);
210 File collect_folder = new File(Utility.getCollectDir(Configuration.gsdl3_path, site_name) );
211 if (!collect_folder.exists()) {
212 continue;
213 }
214 File[] collection_folders = collect_folder.listFiles();
215 for(int i = 0; i < collection_folders.length; i++) {
216 File collection_folder = collection_folders[i];
217 String collection_foldername = collection_folder.getName();
218 if(!collection_folder.isFile() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
219 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(new File(collection_folder, Utility.CONFIG_FILE), site_name);
220 if(!collection_configuration.getName().equals(StaticStrings.ERROR_STR)) {
221 data.add(collection_configuration);
222 }
223 }
224 collection_foldername = null;
225 collection_folder = null;
226 } // for each collection
227 collection_folders = null;
228 collect_folder = null;
229 } // for each site
230 sites_folder = null;
231 sites = null;
232 }
233
234 public Object getElementAt(int index) {
235 Iterator iterator = data.iterator();
236 for(int i = 0; iterator.hasNext(); i++) {
237 Object object = iterator.next();
238 if(i == index) {
239 iterator = null;
240 return object;
241 }
242 object = null;
243 }
244 iterator = null;
245 return null;
246 }
247
248 public int getSize() {
249 return data.size();
250 }
251 }
252 */
253 private class CollectionListModel
254 extends AbstractListModel {
255
256 private TreeSet data;
257
258 public CollectionListModel() {
259 data = new TreeSet();
260 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
261 if (!collect_directory.exists()) {
262 collect_directory = null;
263 return;
264 }
265 File[] collection_folders = collect_directory.listFiles();
266 for(int i = 0; i < collection_folders.length; i++) {
267 File collection_folder = collection_folders[i];
268 String collection_foldername = collection_folder.getName();
269 if(collection_folder.isDirectory() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
270 File config_file = new File(collection_folder, Utility.CONFIG_FILE);
271 if (config_file.exists()) {
272 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(config_file);
273 data.add(collection_configuration);
274 }
275 config_file = null;
276 }
277 collection_foldername = null;
278 collection_folder = null;
279 }
280 collection_folders = null;
281 collect_directory = null;
282 }
283
284 public Object getElementAt(int index) {
285 Iterator iterator = data.iterator();
286 for(int i = 0; iterator.hasNext(); i++) {
287 Object object = iterator.next();
288 if(i == index) {
289 iterator = null;
290 return object;
291 }
292 object = null;
293 }
294 iterator = null;
295 return null;
296 }
297
298 public int getSize() {
299 return data.size();
300 }
301 }
302
303 private class OpenListener
304 implements ActionListener {
305
306 public void actionPerformed(ActionEvent event) {
307 result = OK_OPTION;
308 Object selected_object = collection_list.getSelectedValue();
309 if (selected_object instanceof BasicCollectionConfiguration) {
310 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration)selected_object; //(BasicCollectionConfiguration) collection_list.getSelectedValue();
311 //*************888
312 File collect_cfg_file = collection_configuration.getFile(); // returns the collect.cfg file
313 File etc_folder = collect_cfg_file.getParentFile();
314 File collection_folder = etc_folder.getParentFile();
315 filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + ".col";
316 collection_folder = null;
317 etc_folder = null;
318 collect_cfg_file = null;
319 collection_configuration = null;
320 SimpleOpenCollectionDialog.this.dispose();
321 }
322 }
323 }
324}
Note: See TracBrowser for help on using the repository browser.