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

Last change on this file since 5350 was 5286, checked in by jmt12, 21 years ago

A simplfied open collection dialog as per request.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 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.CollectionConfiguration;
39import org.greenstone.gatherer.gui.GUIManager;
40import org.greenstone.gatherer.gui.ModalDialog;
41import org.greenstone.gatherer.util.StaticStrings;
42import org.greenstone.gatherer.util.Utility;
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 setTitle(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(get("OpenCollectionDialog.Available_Collections"));
77 collection_list = new JList(new CollectionListModel());
78
79 description_pane = new JPanel();
80 card_layout = new CardLayout();
81
82 JPanel blank_pane = new JPanel();
83
84 JPanel description_textarea_pane = new JPanel();
85 JLabel description_textarea_label = new JLabel(get("OpenCollectionDialog.Description"));
86 description_textarea = new JTextArea();
87
88 JPanel button_pane = new JPanel();
89 open_button = new JButton(get("OpenCollectionDialog.Open"));
90 open_button.setEnabled(false);
91 open_button.setMnemonic(KeyEvent.VK_O);
92 advanced_button = new JButton(get("OpenCollectionDialog.Advanced"));
93 advanced_button.setMnemonic(KeyEvent.VK_B);
94 cancel_button = new JButton(get("General.Cancel"));
95 cancel_button.setMnemonic(KeyEvent.VK_C);
96 // Connection
97 advanced_button.addActionListener(new AdvancedListener());
98 cancel_button.addActionListener(new CancelListener());
99 open_button.addActionListener(new OpenListener());
100 collection_list.addListSelectionListener(new CollectionListSelectionListener());
101 // Layout
102 collection_list_pane.setLayout(new BorderLayout());
103 collection_list_pane.add(collection_list_label, BorderLayout.NORTH);
104 collection_list_pane.add(new JScrollPane(collection_list), BorderLayout.CENTER);
105
106 description_textarea_pane.setLayout(new BorderLayout());
107 description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH);
108 description_textarea_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
109
110 description_pane.setLayout(card_layout);
111 description_pane.add(description_textarea_pane, DESCRIPTION);
112 description_pane.add(blank_pane, BLANK);
113
114 center_pane.setLayout(new GridLayout(2,1,0,5));
115 center_pane.add(collection_list_pane);
116 center_pane.add(description_pane);
117
118 button_pane.setLayout(new GridLayout(1,4));
119 button_pane.add(new JPanel());
120 button_pane.add(open_button);
121 button_pane.add(advanced_button);
122 button_pane.add(cancel_button);
123
124 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
125 content_pane.setLayout(new BorderLayout());
126 content_pane.add(center_pane, BorderLayout.CENTER);
127 content_pane.add(button_pane, BorderLayout.SOUTH);
128
129 Dimension screen_size = Gatherer.config.screen_size;
130 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
131 screen_size = null;
132 }
133
134 public void destroy() {
135 }
136
137 public int display() {
138 setVisible(true);
139 return result;
140 }
141
142 public String getFileName() {
143 return filename;
144 }
145
146 private String get(String key) {
147 return Gatherer.dictionary.get(key);
148 }
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 implements ListSelectionListener {
170
171 public void valueChanged(ListSelectionEvent event) {
172 if(collection_list.isSelectionEmpty()) {
173 card_layout.show(description_pane, BLANK);
174 open_button.setEnabled(false);
175 }
176 else {
177 CollectionConfiguration collection_configuration = (CollectionConfiguration) collection_list.getSelectedValue();
178 description_textarea.setText(collection_configuration.getDescription());
179 description_textarea.setCaretPosition(0);
180 card_layout.show(description_pane, DESCRIPTION);
181 open_button.setEnabled(true);
182 }
183 }
184 }
185
186 private class CollectionListModel
187 extends AbstractListModel {
188
189 private TreeSet data;
190
191 public CollectionListModel() {
192 data = new TreeSet();
193 File collect_folder = new File(Gatherer.config.gsdl_path + Utility.COL_DIR);
194 File[] collection_folders = collect_folder.listFiles();
195 for(int i = 0; i < collection_folders.length; i++) {
196 File collection_folder = collection_folders[i];
197 String collection_foldername = collection_folder.getName();
198 if(!collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME) && !collection_foldername.equals("CVS")) {
199 data.add(new CollectionConfiguration(new File(collection_folder, Utility.CONFIG_DIR)));
200 }
201 collection_foldername = null;
202 collection_folder = null;
203 }
204 collection_folders = null;
205 collect_folder = null;
206 }
207
208 public Object getElementAt(int index) {
209 Iterator iterator = data.iterator();
210 for(int i = 0; iterator.hasNext(); i++) {
211 Object object = iterator.next();
212 if(i == index) {
213 iterator = null;
214 return object;
215 }
216 object = null;
217 }
218 iterator = null;
219 return null;
220 }
221
222 public int getSize() {
223 return data.size();
224 }
225 }
226
227 private class OpenListener
228 implements ActionListener {
229
230 public void actionPerformed(ActionEvent event) {
231 result = OK_OPTION;
232 CollectionConfiguration collection_configuration = (CollectionConfiguration) collection_list.getSelectedValue();
233 File collect_cfg_file = collection_configuration.getFile();
234 File etc_folder = collect_cfg_file.getParentFile();
235 File collection_folder = etc_folder.getParentFile();
236 filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + Utility.GLI_EXTENSION;
237 collection_folder = null;
238 etc_folder = null;
239 collect_cfg_file = null;
240 collection_configuration = null;
241 SimpleOpenCollectionDialog.this.dispose();
242 }
243 }
244}
Note: See TracBrowser for help on using the repository browser.