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

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

added menu bar of changed where help text is opened at

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