source: gli/branches/rtl-gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java@ 18297

Last change on this file since 18297 was 18297, checked in by kjdon, 15 years ago

interface updated to display right to left for rtl languages. This code is thanks to Amin Hejazi. It seems to be only partially complete. Amin was working with Greenstone 3 so might have missed some panels

  • Property svn:keywords set to Author Date Id Revision
File size: 12.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 OpenCollectionDialog
44 extends ModalDialog {
45
46 static final public int OK_OPTION = 0;
47 static final public int CANCEL_OPTION = 1;
48
49 static final private Dimension SIZE = new Dimension(640,480);
50 static final private String BLANK = "b";
51 static final private String DESCRIPTION = "d";
52
53 private CardLayout card_layout;
54 private int result;
55 private JButton cancel_button;
56 private JButton open_button;
57 private JList collection_list;
58 private JTextArea description_textarea;
59 private JPanel description_pane;
60 private String filename;
61
62 public OpenCollectionDialog() {
63 super(Gatherer.g_man, "", true);
64 setJMenuBar(new SimpleMenuBar("openingacollection"));
65 this.setComponentOrientation(Dictionary.getOrientation());
66 setSize(SIZE);
67 setTitle(Dictionary.get("OpenCollectionDialog.Title"));
68
69 // Creation
70 JPanel content_pane = (JPanel) getContentPane();
71 content_pane.setComponentOrientation(Dictionary.getOrientation());
72
73 JPanel center_pane = new JPanel();
74 center_pane.setComponentOrientation(Dictionary.getOrientation());
75
76 JPanel collection_list_pane = new JPanel();
77 collection_list_pane.setComponentOrientation(Dictionary.getOrientation());
78 JLabel collection_list_label = new JLabel(Dictionary.get("OpenCollectionDialog.Available_Collections"));
79 collection_list_label.setComponentOrientation(Dictionary.getOrientation());
80 collection_list = new JList(new CollectionListModel());
81 collection_list.setComponentOrientation(Dictionary.getOrientation());
82
83 description_pane = new JPanel();
84 description_pane.setComponentOrientation(Dictionary.getOrientation());
85 card_layout = new CardLayout();
86
87 JPanel blank_pane = new JPanel();
88 blank_pane.setComponentOrientation(Dictionary.getOrientation());
89
90 JPanel description_textarea_pane = new JPanel();
91 description_textarea_pane.setComponentOrientation(Dictionary.getOrientation());
92 JLabel description_textarea_label = new JLabel(Dictionary.get("OpenCollectionDialog.Description"));
93 description_textarea_label.setComponentOrientation(Dictionary.getOrientation());
94 description_textarea = new JTextArea();
95 description_textarea.setComponentOrientation(Dictionary.getOrientation());
96
97 JPanel button_pane = new JPanel();
98 button_pane.setComponentOrientation(Dictionary.getOrientation());
99 open_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Open"), Dictionary.get("OpenCollectionDialog.Open_Tooltip"));
100 open_button.setEnabled(false);
101
102 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
103
104 // Connection
105 cancel_button.addActionListener(new CancelListener());
106 open_button.addActionListener(new OpenListener());
107 CollectionListSelectionListener clsl = new CollectionListSelectionListener();
108 collection_list.addListSelectionListener(clsl);
109 collection_list.addMouseListener(clsl);
110 clsl = null;
111
112 // Layout
113 JScrollPane scrol_tmp;
114
115 collection_list_pane.setLayout(new BorderLayout());
116 collection_list_pane.add(collection_list_label, BorderLayout.NORTH);
117 scrol_tmp = new JScrollPane(collection_list);
118 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
119 collection_list_pane.add(scrol_tmp, BorderLayout.CENTER);
120
121 description_textarea_pane.setLayout(new BorderLayout());
122 description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH);
123 scrol_tmp =new JScrollPane(description_textarea);
124 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
125 description_textarea_pane.add(scrol_tmp, BorderLayout.CENTER);
126
127 description_pane.setLayout(card_layout);
128 description_pane.add(description_textarea_pane, DESCRIPTION);
129 description_pane.add(blank_pane, BLANK);
130
131 center_pane.setLayout(new GridLayout(2,1,0,5));
132 center_pane.add(collection_list_pane);
133 center_pane.add(description_pane);
134
135 button_pane.setLayout(new GridLayout(1,4));
136 JPanel tmp =new JPanel();
137 tmp.setComponentOrientation(Dictionary.getOrientation());
138 button_pane.add(tmp);
139 button_pane.add(open_button);
140 button_pane.add(cancel_button);
141
142 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
143 content_pane.setLayout(new BorderLayout());
144 content_pane.add(center_pane, BorderLayout.CENTER);
145 content_pane.add(button_pane, BorderLayout.SOUTH);
146
147 Dimension screen_size = Configuration.screen_size;
148 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
149 screen_size = null;
150 }
151
152 public void destroy() {
153 }
154
155 public int display() {
156 setVisible(true);
157 return result;
158 }
159
160 public String getFileName() {
161 return this.filename;
162 }
163
164 private class CancelListener
165 implements ActionListener {
166
167 public void actionPerformed(ActionEvent event) {
168 result = CANCEL_OPTION;
169 OpenCollectionDialog.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 // this 'file_name' has already been prefixed by 'etc'
277 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
278 File config_file = new File(collection_folder, file_name);
279 File collection_metadata_directory = new File(collection_folder, "metadata");
280 if (collection_metadata_directory.exists() && config_file.exists()) {
281 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(config_file);
282 data.add(collection_configuration);
283 }
284 config_file = null;
285 }
286 collection_foldername = null;
287 collection_folder = null;
288 }
289 collection_folders = null;
290 collect_directory = null;
291 }
292
293 public Object getElementAt(int index) {
294 Iterator iterator = data.iterator();
295 for(int i = 0; iterator.hasNext(); i++) {
296 Object object = iterator.next();
297 if(i == index) {
298 iterator = null;
299 return object;
300 }
301 object = null;
302 }
303 iterator = null;
304 return null;
305 }
306
307 public int getSize() {
308 return data.size();
309 }
310 }
311
312 private class OpenListener
313 implements ActionListener {
314
315 public void actionPerformed(ActionEvent event) {
316 result = OK_OPTION;
317 Object selected_object = collection_list.getSelectedValue();
318 if (selected_object instanceof BasicCollectionConfiguration) {
319 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration)selected_object; //(BasicCollectionConfiguration) collection_list.getSelectedValue();
320 //*************888
321 File collect_cfg_file = collection_configuration.getFile(); // returns the collect.cfg file
322 File etc_folder = collect_cfg_file.getParentFile();
323 File collection_folder = etc_folder.getParentFile();
324 filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + ".col";
325 collection_folder = null;
326 etc_folder = null;
327 collect_cfg_file = null;
328 collection_configuration = null;
329 OpenCollectionDialog.this.dispose();
330 }
331 }
332 }
333}
Note: See TracBrowser for help on using the repository browser.