Changeset 13393
- Timestamp:
- 2006-12-01T12:21:13+13:00 (17 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/gui
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java
r13391 r13393 709 709 private String showOpenCollectionDialog() 710 710 { 711 // We first try the simple open collection dialog 712 SimpleOpenCollectionDialog dialog = new SimpleOpenCollectionDialog(); 713 int user_choice = dialog.display(); 714 715 // Used simple collection list 716 if (user_choice == SimpleOpenCollectionDialog.OK_OPTION) { 711 OpenCollectionDialog dialog = new OpenCollectionDialog(); 712 if (dialog.display() == OpenCollectionDialog.OK_OPTION) { 717 713 return dialog.getFileName(); 718 }719 720 // Chosen to use the advanced 'browse' dialog721 File collect_directory = null;722 if (user_choice == SimpleOpenCollectionDialog.BROWSE_OPTION) {723 if (Gatherer.GS3) {724 collect_directory = new File(Utility.getSitesDir(Configuration.gsdl3_path));725 }726 else {727 collect_directory = new File(Gatherer.getCollectDirectoryPath());728 }729 OpenCollectionDialog chooser = new OpenCollectionDialog(collect_directory);730 return chooser.getFileName();731 714 } 732 715 -
trunk/gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java
r12119 r13393 6 6 * University of Waikato, New Zealand. 7 7 * 8 * <BR><BR>9 *10 8 * Author: John Thompson, Greenstone Digital Library, University of Waikato 11 9 * 12 * <BR><BR>13 *14 10 * Copyright (C) 1999 New Zealand Digital Library Project 15 *16 * <BR><BR>17 11 * 18 12 * This program is free software; you can redistribute it and/or modify … … 21 15 * (at your option) any later version. 22 16 * 23 * <BR><BR>24 *25 17 * This program is distributed in the hope that it will be useful, 26 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 27 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 20 * GNU General Public License for more details. 29 *30 * <BR><BR>31 21 * 32 22 * You should have received a copy of the GNU General Public License … … 39 29 import java.awt.*; 40 30 import java.awt.event.*; 41 import java.beans.*; 42 import java.io.File; 43 import java.io.IOException; 44 import java.text.*; 31 import java.io.*; 45 32 import java.util.*; 46 33 import javax.swing.*; 47 import javax.swing.filechooser.*; 34 import javax.swing.event.*; 35 import org.greenstone.gatherer.Configuration; 48 36 import org.greenstone.gatherer.Dictionary; 37 import org.greenstone.gatherer.Gatherer; 49 38 import org.greenstone.gatherer.collection.BasicCollectionConfiguration; 50 import org.greenstone.gatherer.collection.CollectionManager;51 import org.greenstone.gatherer.util.JarTools;52 39 import org.greenstone.gatherer.util.StaticStrings; 53 40 import org.greenstone.gatherer.util.Utility; 54 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. */ 55 43 public class OpenCollectionDialog 56 extends JFileChooser { 57 static final private ImageIcon LOCKED_COLLECTION_ICON = JarTools.getImage("lcolicn.gif"); 58 static final private ImageIcon NORMAL_COLLECTION_ICON = JarTools.getImage("ncolicn.gif"); 59 60 /** Constructor */ 61 public OpenCollectionDialog(File file) { 62 super(file); 63 ///ystem.err.println("Size = " + getSize()); 64 // Other initialization 65 setAcceptAllFileFilterUsed(false); 66 setDialogTitle(Dictionary.get("OpenCollectionDialog.Title")); 67 setFileFilter(new GathererFilter()); 68 setFileSystemView(new GathererFileSystemView()); 69 setFileView(new GathererFileView()); 70 setSize(400,300); 71 // Stop the annoying renaming 72 GUIUtils.disableRename(this); 73 // Description accessory 74 DescriptionPreview accessory = new DescriptionPreview(this); 75 setAccessory(accessory); 76 // Move accessory 77 JPanel accessory_pane = (JPanel) accessory.getParent(); 78 JPanel center_pane = (JPanel) accessory_pane.getParent(); 79 center_pane.add(accessory_pane, BorderLayout.SOUTH); 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 setSize(SIZE); 66 setTitle(Dictionary.get("OpenCollectionDialog.Title")); 67 68 // Creation 69 JPanel content_pane = (JPanel) getContentPane(); 70 71 JPanel center_pane = new JPanel(); 72 73 JPanel collection_list_pane = new JPanel(); 74 JLabel collection_list_label = new JLabel(Dictionary.get("OpenCollectionDialog.Available_Collections")); 75 collection_list = new JList(new CollectionListModel()); 76 description_pane = new JPanel(); 77 card_layout = new CardLayout(); 78 79 JPanel blank_pane = new JPanel(); 80 81 JPanel description_textarea_pane = new JPanel(); 82 JLabel description_textarea_label = new JLabel(Dictionary.get("OpenCollectionDialog.Description")); 83 description_textarea = new JTextArea(); 84 85 JPanel button_pane = new JPanel(); 86 open_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Open"), Dictionary.get("OpenCollectionDialog.Open_Tooltip")); 87 open_button.setEnabled(false); 88 89 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip")); 90 91 // Connection 92 cancel_button.addActionListener(new CancelListener()); 93 open_button.addActionListener(new OpenListener()); 94 CollectionListSelectionListener clsl = new CollectionListSelectionListener(); 95 collection_list.addListSelectionListener(clsl); 96 collection_list.addMouseListener(clsl); 97 clsl = null; 98 99 // Layout 100 collection_list_pane.setLayout(new BorderLayout()); 101 collection_list_pane.add(collection_list_label, BorderLayout.NORTH); 102 collection_list_pane.add(new JScrollPane(collection_list), BorderLayout.CENTER); 103 104 description_textarea_pane.setLayout(new BorderLayout()); 105 description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH); 106 description_textarea_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER); 107 108 description_pane.setLayout(card_layout); 109 description_pane.add(description_textarea_pane, DESCRIPTION); 110 description_pane.add(blank_pane, BLANK); 111 112 center_pane.setLayout(new GridLayout(2,1,0,5)); 113 center_pane.add(collection_list_pane); 114 center_pane.add(description_pane); 115 116 button_pane.setLayout(new GridLayout(1,4)); 117 button_pane.add(new JPanel()); 118 button_pane.add(open_button); 119 button_pane.add(cancel_button); 120 121 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 122 content_pane.setLayout(new BorderLayout()); 123 content_pane.add(center_pane, BorderLayout.CENTER); 124 content_pane.add(button_pane, BorderLayout.SOUTH); 125 126 Dimension screen_size = Configuration.screen_size; 127 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 128 screen_size = null; 80 129 } 81 130 … … 83 132 } 84 133 134 public int display() { 135 setVisible(true); 136 return result; 137 } 138 85 139 public String getFileName() { 86 // Continually loop until the use chooses an appropriate file or cancels. 87 while(true) { 88 int return_val = showOpenDialog(null); 89 if(return_val == JFileChooser.APPROVE_OPTION) { 90 File file = getSelectedFile(); 91 if(file != null && file.getName().endsWith(".col")) { 92 return file.getAbsolutePath(); 140 return this.filename; 141 } 142 143 private class CancelListener 144 implements ActionListener { 145 146 public void actionPerformed(ActionEvent event) { 147 result = CANCEL_OPTION; 148 OpenCollectionDialog.this.dispose(); 149 } 150 } 151 152 private class CollectionListSelectionListener 153 extends MouseAdapter 154 implements ListSelectionListener { 155 156 public void mouseClicked(MouseEvent event) { 157 ///ystem.err.println("Mouse clicked"); 158 if(event.getClickCount() >= 2) { 159 Point location = event.getPoint(); 160 int index = collection_list.locationToIndex(location); 161 collection_list.setSelectedIndex(index); 162 location = null; 163 open_button.doClick(); 164 } 165 } 166 167 public void valueChanged(ListSelectionEvent event) { 168 if(collection_list.isSelectionEmpty()) { 169 card_layout.show(description_pane, BLANK); 170 open_button.setEnabled(false); 171 } 172 else { 173 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue(); 174 description_textarea.setText(collection_configuration.getDescription()); 175 description_textarea.setCaretPosition(0); 176 card_layout.show(description_pane, DESCRIPTION); 177 open_button.setEnabled(true); 178 } 179 } 180 } 181 182 // use this if we ever go back to viewing all colls at once 183 /* private class GS3CollectionListModel 184 extends AbstractListModel { 185 186 private TreeSet data; 187 188 public GS3CollectionListModel() { 189 data = new TreeSet(); 190 File sites_folder = new File(Utility.getSitesDir(Configuration.gsdl3_path)); 191 File sites[] = sites_folder.listFiles(); 192 for (int s=0; s<sites.length; s++) { 193 String site_name = sites[s].getName(); 194 System.err.println("found site "+site_name); 195 File collect_folder = new File(Utility.getCollectDir(Configuration.gsdl3_path, site_name) ); 196 if (!collect_folder.exists()) { 197 continue; 93 198 } 94 } 95 else { 96 return null; 97 } 98 } 99 } 100 101 102 103 /* The DescriptionPreview accessory is adapted from the ImagePreview.java (an example used by FileChooserDemo2.java). */ 104 private class DescriptionPreview 105 extends JPanel 106 implements PropertyChangeListener { 107 private File file = null; 108 private JTextArea text; 109 110 public DescriptionPreview(JFileChooser fc) { 111 setName("Description Preview"); 112 setPreferredSize(new Dimension(100, 75)); // About three rows. 113 114 text = new JTextArea(Dictionary.get("OpenCollectionDialog.No_Description")); 115 116 setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 117 setLayout(new BorderLayout()); 118 add(new JScrollPane(text), BorderLayout.CENTER); 119 120 fc.addPropertyChangeListener(this); 121 } 122 123 /** Whenever a new file or folder is selected we determine what description should be displayed. */ 124 public void propertyChange(PropertyChangeEvent e) { 125 boolean update = false; 126 String prop = e.getPropertyName(); 127 // If the directory changed, don't show an image. 128 if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) { 129 file = null; 130 update = true; 131 } 132 // If a file became selected, find out which one. 133 else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) { 134 file = (File) e.getNewValue(); 135 update = true; 136 } 137 138 // Update the description accordingly. 139 if (update) { 140 if(file == null) { 141 text.setText(Dictionary.get("OpenCollectionDialog.No_Description")); 199 File[] collection_folders = collect_folder.listFiles(); 200 for(int i = 0; i < collection_folders.length; i++) { 201 File collection_folder = collection_folders[i]; 202 String collection_foldername = collection_folder.getName(); 203 if(!collection_folder.isFile() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) { 204 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(new File(collection_folder, Utility.CONFIG_FILE), site_name); 205 if(!collection_configuration.getName().equals(StaticStrings.ERROR_STR)) { 206 data.add(collection_configuration); 207 } 208 } 209 collection_foldername = null; 210 collection_folder = null; 211 } // for each collection 212 collection_folders = null; 213 collect_folder = null; 214 } // for each site 215 sites_folder = null; 216 sites = null; 217 } 218 219 public Object getElementAt(int index) { 220 Iterator iterator = data.iterator(); 221 for(int i = 0; iterator.hasNext(); i++) { 222 Object object = iterator.next(); 223 if(i == index) { 224 iterator = null; 225 return object; 142 226 } 143 else { 144 // Build a wrapper around the collection configuration file. 145 File config_file = new File(file.getParentFile(), Utility.CONFIG_FILE); 146 if(config_file.exists()) { 147 BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(config_file); 148 text.setText(StaticStrings.SPEECH_CHARACTER + collect_cfg.getName() + StaticStrings.SPEECH_CHARACTER + StaticStrings.NEW_LINE_CHAR); 149 text.setText(collect_cfg.getDescription()); 150 text.setCaretPosition(0); 227 object = null; 228 } 229 iterator = null; 230 return null; 231 } 232 233 public int getSize() { 234 return data.size(); 235 } 236 } 237 */ 238 private class CollectionListModel 239 extends AbstractListModel { 240 241 private TreeSet data; 242 243 public CollectionListModel() { 244 data = new TreeSet(); 245 File collect_directory = new File(Gatherer.getCollectDirectoryPath()); 246 if (!collect_directory.exists()) { 247 collect_directory = null; 248 return; 249 } 250 File[] collection_folders = collect_directory.listFiles(); 251 for(int i = 0; i < collection_folders.length; i++) { 252 File collection_folder = collection_folders[i]; 253 String collection_foldername = collection_folder.getName(); 254 if(collection_folder.isDirectory() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) { 255 File config_file = new File(collection_folder, Utility.CONFIG_FILE); 256 if (config_file.exists()) { 257 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(config_file); 258 data.add(collection_configuration); 151 259 } 260 config_file = null; 152 261 } 153 } 154 } 155 } 156 157 /** ImageFilter.java is a 1.4 example used by FileChooserDemo2.java. */ 158 private class GathererFilter 159 extends FileFilter { 160 161 // Accept all directories and all .col files 162 public boolean accept(File f) { 163 return (f.isDirectory() || f.getName().toLowerCase().endsWith(".col")); 164 } 165 166 // The description of this filter 167 public String getDescription() { 168 return Dictionary.get("OpenCollectionDialog.Collection"); 169 } 170 } 171 172 private class GathererFileSystemView 173 extends FileSystemView { 174 175 private FileSystemView default_system_view = FileSystemView.getFileSystemView(); 176 177 /** Creates a new folder with a default folder name. */ 178 public File createNewFolder(File containingDir) 179 throws IOException { 180 return default_system_view.createNewFolder(containingDir); 181 } 182 183 /** Gets the list of shown (i.e. */ 184 public File[] getFiles(File dir, boolean useFileHiding) { 185 // Retrieve the files usually returned by the platform specific file system view. 186 File[] files = default_system_view.getFiles(dir, useFileHiding); 187 // Determine if the current dir actually contains a valid greenstone collection. To do this we check for the presence of the file <dir>/etc/collect.cfg and a directory named import. 188 File collect_cfg_file = new File(dir, Utility.CONFIG_FILE); 189 File import_dir_file = new File(dir, "import"); 190 if(collect_cfg_file.exists() && import_dir_file.exists()) { 191 // Create a new dummy collection file. 192 String name = dir.getName(); 193 File collection_file = new File(dir, name + ".col"); 194 // If this file doesn't already exist. 195 if(!collection_file.exists()) { 196 File[] temp = new File[files.length + 1]; 197 System.arraycopy(files, 0, temp, 0, files.length); 198 temp[files.length] = collection_file; 199 files = temp; 200 temp = null; 262 collection_foldername = null; 263 collection_folder = null; 264 } 265 collection_folders = null; 266 collect_directory = null; 267 } 268 269 public Object getElementAt(int index) { 270 Iterator iterator = data.iterator(); 271 for(int i = 0; iterator.hasNext(); i++) { 272 Object object = iterator.next(); 273 if(i == index) { 274 iterator = null; 275 return object; 201 276 } 202 collection_file = null; 203 name = null; 204 } 205 import_dir_file = null; 206 collect_cfg_file = null; 207 return files; 208 } 209 } 210 211 /** A FileView which returns differing icons depending on whether a lock file is present within the collection folder. */ 212 private class GathererFileView 213 extends FileView { 214 215 public String getDescription(File file) { 216 String description = null; 217 if (file.getName().endsWith(".col")) { 218 if (!lockExists(file)) { 219 description = Dictionary.get("OpenCollectionDialog.Normal_Collection"); 220 } 221 else { 222 description = Dictionary.get("OpenCollectionDialog.Locked_Collection"); 223 } 224 } 225 return description; 226 } 227 228 public Icon getIcon(File file) { 229 Icon icon = null; 230 if (file.getName().endsWith(".col")) { 231 if (!lockExists(file)) { 232 icon = NORMAL_COLLECTION_ICON; 233 } 234 else { 235 icon = LOCKED_COLLECTION_ICON; 236 } 237 } 238 return icon; 239 } 240 241 /** Determine if a lock file exists. */ 242 private boolean lockExists(File file) { 243 File lock_file = new File(file.getParentFile(), CollectionManager.LOCK_FILE); 244 return lock_file.exists(); 277 object = null; 278 } 279 iterator = null; 280 return null; 281 } 282 283 public int getSize() { 284 return data.size(); 285 } 286 } 287 288 private class OpenListener 289 implements ActionListener { 290 291 public void actionPerformed(ActionEvent event) { 292 result = OK_OPTION; 293 Object selected_object = collection_list.getSelectedValue(); 294 if (selected_object instanceof BasicCollectionConfiguration) { 295 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration)selected_object; //(BasicCollectionConfiguration) collection_list.getSelectedValue(); 296 //*************888 297 File collect_cfg_file = collection_configuration.getFile(); // returns the collect.cfg file 298 File etc_folder = collect_cfg_file.getParentFile(); 299 File collection_folder = etc_folder.getParentFile(); 300 filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + ".col"; 301 collection_folder = null; 302 etc_folder = null; 303 collect_cfg_file = null; 304 collection_configuration = null; 305 OpenCollectionDialog.this.dispose(); 306 } 245 307 } 246 308 }
Note:
See TracChangeset
for help on using the changeset viewer.