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

Last change on this file since 7275 was 7275, checked in by kjdon, 20 years ago

renamed Utility.CONFIG_DIR to Utility.CONFIG_FILE cos it refers to the file, not the directory. Also getConfigDir renamed to getConfigFile

  • Property svn:keywords set to Author Date Id Revision
File size: 9.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.Dictionary;
36import org.greenstone.gatherer.Gatherer;
37import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
38import org.greenstone.gatherer.gui.GLIButton;
39import org.greenstone.gatherer.gui.ModalDialog;
40import org.greenstone.gatherer.util.StaticStrings;
41import org.greenstone.gatherer.util.Utility;
42
43/** 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. */
44public class SimpleOpenCollectionDialog
45 extends ModalDialog {
46
47 static final public int OK_OPTION = 0;
48 static final public int CANCEL_OPTION = 1;
49 static final public int BROWSE_OPTION = 2;
50
51 static final private Dimension SIZE = new Dimension(640,480);
52 static final private String BLANK = "b";
53 static final private String DESCRIPTION = "d";
54
55 private CardLayout card_layout;
56 private int result;
57 private JButton advanced_button;
58 private JButton cancel_button;
59 private JButton open_button;
60 private JList collection_list;
61 private JTextArea description_textarea;
62 private JPanel description_pane;
63 private String filename;
64
65 public SimpleOpenCollectionDialog() {
66 super(Gatherer.g_man, "", true);
67 setSize(SIZE);
68 Dictionary.setText(this, "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();
77 Dictionary.setText(collection_list_label, "OpenCollectionDialog.Available_Collections");
78 collection_list = new JList(new CollectionListModel());
79
80 description_pane = new JPanel();
81 card_layout = new CardLayout();
82
83 JPanel blank_pane = new JPanel();
84
85 JPanel description_textarea_pane = new JPanel();
86 JLabel description_textarea_label = new JLabel();
87 Dictionary.setText(description_textarea_label, "OpenCollectionDialog.Description");
88 description_textarea = new JTextArea();
89
90 JPanel button_pane = new JPanel();
91 open_button = new GLIButton();
92 open_button.setEnabled(false);
93 open_button.setMnemonic(KeyEvent.VK_O);
94 Dictionary.setBoth(open_button, "OpenCollectionDialog.Open", "OpenCollectionDialog.Open_Tooltip");
95 advanced_button = new GLIButton();
96 advanced_button.setMnemonic(KeyEvent.VK_B);
97 Dictionary.setBoth(advanced_button, "OpenCollectionDialog.Browse", "OpenCollectionDialog.Browse_Tooltip");
98 cancel_button = new GLIButton();
99 cancel_button.setMnemonic(KeyEvent.VK_C);
100 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
101
102 // Connection
103 advanced_button.addActionListener(new AdvancedListener());
104 cancel_button.addActionListener(new CancelListener());
105 open_button.addActionListener(new OpenListener());
106 CollectionListSelectionListener clsl = new CollectionListSelectionListener();
107 collection_list.addListSelectionListener(clsl);
108 collection_list.addMouseListener(clsl);
109 clsl = null;
110
111 // Layout
112 collection_list_pane.setLayout(new BorderLayout());
113 collection_list_pane.add(collection_list_label, BorderLayout.NORTH);
114 collection_list_pane.add(new JScrollPane(collection_list), BorderLayout.CENTER);
115
116 description_textarea_pane.setLayout(new BorderLayout());
117 description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH);
118 description_textarea_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
119
120 description_pane.setLayout(card_layout);
121 description_pane.add(description_textarea_pane, DESCRIPTION);
122 description_pane.add(blank_pane, BLANK);
123
124 center_pane.setLayout(new GridLayout(2,1,0,5));
125 center_pane.add(collection_list_pane);
126 center_pane.add(description_pane);
127
128 button_pane.setLayout(new GridLayout(1,4));
129 button_pane.add(new JPanel());
130 button_pane.add(open_button);
131 button_pane.add(advanced_button);
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 = Gatherer.config.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 filename;
154 }
155
156 private class AdvancedListener
157 implements ActionListener {
158
159 public void actionPerformed(ActionEvent event) {
160 result = BROWSE_OPTION;
161 SimpleOpenCollectionDialog.this.dispose();
162 }
163 }
164
165 private class CancelListener
166 implements ActionListener {
167
168 public void actionPerformed(ActionEvent event) {
169 result = CANCEL_OPTION;
170 SimpleOpenCollectionDialog.this.dispose();
171 }
172 }
173
174 private class CollectionListSelectionListener
175 extends MouseAdapter
176 implements ListSelectionListener {
177
178 public void mouseClicked(MouseEvent event) {
179 ///ystem.err.println("Mouse clicked");
180 if(event.getClickCount() >= 2) {
181 Point location = event.getPoint();
182 int index = collection_list.locationToIndex(location);
183 collection_list.setSelectedIndex(index);
184 location = null;
185 open_button.doClick();
186 }
187 }
188
189 public void valueChanged(ListSelectionEvent event) {
190 if(collection_list.isSelectionEmpty()) {
191 card_layout.show(description_pane, BLANK);
192 open_button.setEnabled(false);
193 }
194 else {
195 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue();
196 description_textarea.setText(collection_configuration.getDescription());
197 description_textarea.setCaretPosition(0);
198 card_layout.show(description_pane, DESCRIPTION);
199 open_button.setEnabled(true);
200 }
201 }
202 }
203
204 private class CollectionListModel
205 extends AbstractListModel {
206
207 private TreeSet data;
208
209 public CollectionListModel() {
210 data = new TreeSet();
211 File collect_folder = new File(Gatherer.config.gsdl_path + Utility.COL_DIR);
212 File[] collection_folders = collect_folder.listFiles();
213 for(int i = 0; i < collection_folders.length; i++) {
214 File collection_folder = collection_folders[i];
215 String collection_foldername = collection_folder.getName();
216 if(!collection_folder.isFile() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
217 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(new File(collection_folder, Utility.CONFIG_FILE));
218 if(!collection_configuration.getName().equals(StaticStrings.ERROR_STR)) {
219 data.add(collection_configuration);
220 }
221 }
222 collection_foldername = null;
223 collection_folder = null;
224 }
225 collection_folders = null;
226 collect_folder = null;
227 }
228
229 public Object getElementAt(int index) {
230 Iterator iterator = data.iterator();
231 for(int i = 0; iterator.hasNext(); i++) {
232 Object object = iterator.next();
233 if(i == index) {
234 iterator = null;
235 return object;
236 }
237 object = null;
238 }
239 iterator = null;
240 return null;
241 }
242
243 public int getSize() {
244 return data.size();
245 }
246 }
247
248 private class OpenListener
249 implements ActionListener {
250
251 public void actionPerformed(ActionEvent event) {
252 result = OK_OPTION;
253 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue();
254 File collect_cfg_file = collection_configuration.getFile();
255 File etc_folder = collect_cfg_file.getParentFile();
256 File collection_folder = etc_folder.getParentFile();
257 filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + Utility.GLI_EXTENSION;
258 collection_folder = null;
259 etc_folder = null;
260 collect_cfg_file = null;
261 collection_configuration = null;
262 SimpleOpenCollectionDialog.this.dispose();
263 }
264 }
265}
Note: See TracBrowser for help on using the repository browser.