Changeset 8496
- Timestamp:
- 2004-11-09T13:54:52+13:00 (19 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java
r8381 r8496 576 576 JLabel source_label = new JLabel(); 577 577 Dictionary.registerText(source_label, "CDM.IndexManager.Source"); 578 source_list = new CheckList(new_data, false); 578 source_list = new CheckList(false); 579 source_list.setListData(new_data); 579 580 Dictionary.registerTooltip(source_list, "CDM.IndexManager.Source_Tooltip"); 580 581 … … 696 697 new_data.addAll(MetadataSetManager.getEveryMetadataSetElement()); 697 698 // reset the model in the list and combobox 698 source_list.setListData(new_data .toArray());699 source_list.setListData(new_data); 699 700 new_data = null; 700 701 // refresh the indexList … … 742 743 } 743 744 // Can't add a new index if no sources are selected 744 else if (source_list.isSelectionEmpty()) {745 else if (source_list.getSelected().size() == 0) { 745 746 add_enabled = false; 746 747 } … … 795 796 public void actionPerformed(ActionEvent event) { 796 797 String name = name_textfield.getText(); 797 if (!source_list.isSelectionEmpty()&& name.length() != 0) {798 if (source_list.getSelected().size() > 0 && name.length() != 0) { 798 799 ArrayList sources = source_list.getSelected(); 799 800 Index index = new Index(level_combobox.getSelectedIndex(), sources); -
trunk/gli/src/org/greenstone/gatherer/cdm/SuperCollectionManager.java
r8243 r8496 117 117 super(); 118 118 119 buildModel();120 119 // Creation 121 120 JPanel header_panel = new JPanel(); … … 135 134 Dictionary.registerText(instructions, "CDM.SuperCollectionManager.Instructions"); 136 135 137 collection_checklist = new CheckList(collection_checklist_model, false); 136 collection_checklist = new CheckList(false); 137 buildModel(); 138 collection_checklist.setListData(collection_checklist_model); 138 139 139 140 // Layout … … 189 190 } 190 191 191 private void buildModel() { 192 // We start by building a model of the installed collections. 192 193 private void buildModel() 194 { 193 195 collection_checklist_model = new ArrayList(); 196 current_coll_name = Gatherer.c_man.getCollection().getName(); 197 194 198 File gsdl_collection_directory; 195 199 if (Gatherer.GS3) { 196 200 gsdl_collection_directory = new File(Utility.getCollectDir(Configuration.gsdl3_path, Configuration.site_name)); 197 } else { 201 } 202 else { 198 203 gsdl_collection_directory = new File(Utility.getCollectDir(Configuration.gsdl_path)); 199 204 } 200 current_coll_name = Gatherer.c_man.getCollection().getName(); 205 201 206 File[] possible_collections = gsdl_collection_directory.listFiles(); 202 207 for(int i = 0; possible_collections != null && i < possible_collections.length; i++) { 203 // The simpliest case is if the directory etc/collect.cfg file and a metadata/ in it. Thus it can easily be built upon.204 208 File collect_cfg_file = new File(possible_collections[i], Utility.CONFIG_FILE); 205 if (collect_cfg_file.exists()) {209 if (collect_cfg_file.exists()) { 206 210 BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(collect_cfg_file); 207 211 StringBuffer title_buffer = new StringBuffer(collect_cfg.getName()); … … 213 217 title_buffer = null; 214 218 String collection_name = possible_collections[i].getName(); 215 // We do have to block the model collection. 216 if(!collect_cfg.getName().equals("**title**")) { 217 Entry entry = new Entry(collection_title); 218 entry.setProperty(collection_name); 219 // Check if a collection with this name exists. The current collection is always selected. 220 entry.setSelected(getSuperCollection(collection_name) != null || collection_name.equals(current_coll_name)); 221 entry.setFixed(collection_name.equals(current_coll_name)); 222 collection_checklist_model.add(entry); 223 entry = null; 224 219 220 // We have to block the model collection. 221 if (collect_cfg.getName().equals("**title**")) { 222 continue; 225 223 } 226 collection_name = null; 227 collection_title = null; 228 collect_cfg = null; 224 225 // The current collection is always selected. 226 Entry entry = new Entry(collection_title); 227 entry.setProperty(collection_name); 228 entry.setSelected(getSuperCollection(collection_name) != null || collection_name.equals(current_coll_name)); 229 entry.setFixed(collection_name.equals(current_coll_name)); 230 collection_checklist_model.add(entry); 229 231 } 230 collect_cfg_file = null; 231 } 232 possible_collections = null; 233 gsdl_collection_directory = null; 234 // Sort the result. 235 Collections.sort(collection_checklist_model); 232 } 236 233 } 237 234 } -
trunk/gli/src/org/greenstone/gatherer/checklist/CheckList.java
r8379 r8496 37 37 package org.greenstone.gatherer.checklist; 38 38 39 /**************************************************************************************40 * Title: Gatherer41 * Description: The Gatherer: a tool for gathering and enriching a digital collection.42 * Company: The University of Waikato43 * Written: 14/08/0244 * Revised:45 **************************************************************************************/46 39 import java.awt.*; 47 40 import java.awt.event.*; … … 50 43 import javax.swing.border.*; 51 44 45 52 46 /** This class provides a visual component that has the form of a list, as provided by JList but uses JCheckBox for data selection. Thus several elements can be 'ticked' in the list, and this selection returned using the method getSelected().<BR>Parts of this code modified from Trevor Harmon's posting on www.dejanews.com. 53 47 * @author John Thompson 54 48 * @version 2.3 55 49 */ 56 // ####################################################################################57 // Optimization Saving58 // ####################################################################################59 // Vector -> ArrayList + Processor60 // ####################################################################################61 50 public class CheckList 62 extends JList { 51 extends JList 52 { 63 53 /** The border used when a list row is not in focus. */ 64 protected staticBorder noFocusBorder = new EmptyBorder(1, 1, 1, 1);65 54 static private Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); 55 66 56 private boolean show_selected_row = true; 57 58 67 59 /** Constructor. */ 68 public CheckList(boolean show_selected_row) { 60 public CheckList(boolean show_selected_row) 61 { 69 62 super(); 70 63 this.show_selected_row = show_selected_row; 64 71 65 setCellRenderer(new CellRenderer()); 72 66 setModel(new DefaultListModel()); … … 74 68 addMouseListener(new CheckListListener()); 75 69 } 76 /** Constructor. 77 * @param list_data An ArrayList of entries for this checklist. 78 * @see org.greenstone.gatherer.checklist.Entry 79 */ 80 public CheckList(ArrayList list_data, boolean show_selected_row) { 81 super(); 82 this.show_selected_row = show_selected_row; 83 // Create a new model. 84 DefaultListModel model = new DefaultListModel(); 85 for(int i = 0; i < list_data.size(); i++) { 86 Entry entry = null; 87 Object temp = list_data.get(i); 88 if(temp instanceof Entry) { 89 entry = (Entry) temp; 90 } 91 else { 92 entry = new Entry(list_data.get(i)); 93 } 94 temp = null; 95 String name = entry.toString(); 96 int index = 0; 97 boolean found = false; 98 while(index < model.size() && !found) { 99 Object sibling = model.getElementAt(index); 100 if(name.compareTo(sibling.toString()) <= 0) { 101 model.add(index, entry); 102 found = true; 103 } 104 index++; 105 } 106 if(!found) { 107 model.addElement(entry); 108 } 109 } 110 setModel(model); 111 setCellRenderer(new CellRenderer()); 112 addMouseListener(new CheckListListener()); 113 setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 114 } 115 116 /** Constructor. */ 117 public CheckList(ListModel data_model, boolean show_selected_row) { 118 super(data_model); 119 this.show_selected_row = show_selected_row; 120 setCellRenderer(new CellRenderer()); 121 addMouseListener(new CheckListListener()); 122 setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 123 } 124 125 public void addEntry(Entry entry) { 126 DefaultListModel model = (DefaultListModel) getModel(); 70 71 72 public void addEntry(Entry entry) 73 { 74 DefaultListModel model = (DefaultListModel) getModel(); 75 76 // Add the entry in alpabetical order 127 77 String name = entry.toString(); 128 int index = 0; 129 boolean found = false; 130 while(index < model.size() && !found) { 131 Object sibling = model.getElementAt(index); 132 if(name.compareTo(sibling.toString()) <= 0) { 133 model.add(index, entry); 134 found = true; 135 } 136 index++; 137 sibling = null; 138 } 139 if(!found) { 140 model.addElement(entry); 141 } 142 name = null; 143 model = null; 144 } 145 146 public void clearSelection() { 147 DefaultListModel model = (DefaultListModel) getModel(); 148 int size = model.size(); 149 for(int i = 0; i < size; i++) { 150 Entry entry = (Entry) model.get(i); 151 entry.setSelected(false); 78 for (int i = 0; i < model.size(); i++) { 79 Object sibling = model.getElementAt(i); 80 if (name.compareTo(sibling.toString()) <= 0) { 81 model.add(i, entry); 82 return; 83 } 84 } 85 86 model.addElement(entry); 87 } 88 89 90 public void clearSelection() 91 { 92 DefaultListModel model = (DefaultListModel) getModel(); 93 for (int i = 0; i < model.size(); i++) { 94 ((Entry) model.get(i)).setSelected(false); 152 95 } 153 96 updateUI(); 154 97 } 155 98 156 public Entry get(int index) {157 DefaultListModel model = (DefaultListModel) getModel();158 return (Entry) model.get(index);159 }160 99 161 100 /** Retrieve the currently ticked entries from this list. … … 163 102 * @see org.greenstone.gatherer.checklist.Entry 164 103 */ 165 public ArrayList getSelected() { 104 public ArrayList getSelected() 105 { 166 106 ArrayList result = new ArrayList(); 167 107 DefaultListModel model = (DefaultListModel) getModel(); 168 int size = model.size(); 169 for(int i = 0; i < size; i++) { 108 for (int i = 0; i < model.size(); i++) { 170 109 Entry entry = (Entry) model.get(i); 171 if (entry.isSelected()) {110 if (entry.isSelected()) { 172 111 result.add(entry.getObject()); 173 112 } … … 176 115 } 177 116 178 public boolean isSelected(int index) { 179 DefaultListModel model = (DefaultListModel) getModel(); 180 Entry entry = (Entry) model.get(index); 181 return entry.isSelected(); 182 } 183 184 public boolean isSelectionEmpty() { 185 DefaultListModel model = (DefaultListModel) getModel(); 186 int size = model.size(); 187 for(int i = 0; i < size; i++) { 117 118 // public boolean isSelectionEmpty() 119 // { 120 // System.err.println("In CheckList.isSelectionEmpty()..."); 121 // DefaultListModel model = (DefaultListModel) getModel(); 122 // for (int i = 0; i < model.size(); i++) { 123 // Entry entry = (Entry) model.get(i); 124 // if (entry.isSelected()) { 125 // return false; 126 // } 127 // } 128 129 // return true; 130 // } 131 132 133 public void setListData(ArrayList list_data) 134 { 135 // Create a new model. 136 setModel(new DefaultListModel()); 137 138 // Add the items from the list to the model 139 for (int i = 0; i < list_data.size(); i++) { 140 Object list_object = list_data.get(i); 141 if (list_object instanceof Entry) { 142 addEntry((Entry) list_object); 143 } 144 else { 145 addEntry(new Entry(list_object)); 146 } 147 } 148 } 149 150 151 public void setSelectedObjects(Object objects[]) 152 { 153 if (objects == null) { 154 return; 155 } 156 157 DefaultListModel model = (DefaultListModel) getModel(); 158 for (int i = 0; i < model.size(); i++) { 188 159 Entry entry = (Entry) model.get(i); 189 if(entry.isSelected()) { 190 entry = null; 191 model = null; 192 return false; 193 } 194 entry = null; 195 } 196 model = null; 197 return true; 198 } 199 200 public int getEntryCount() { 201 return getModel().getSize(); 202 } 203 204 public void setListData(Object[] list_data) { 205 // Create a new model. 206 DefaultListModel model = new DefaultListModel(); 207 for(int i = 0; i < list_data.length; i++) { 208 Entry entry = null; 209 Object temp = list_data[i]; 210 if(temp instanceof Entry) { 211 entry = (Entry) temp; 212 } 213 else { 214 entry = new Entry(temp); 215 } 216 temp = null; 217 String name = entry.toString(); 218 int index = 0; 219 boolean found = false; 220 while(index < model.size() && !found) { 221 Object sibling = model.getElementAt(index); 222 if(name.compareTo(sibling.toString()) <= 0) { 223 model.add(index, entry); 224 found = true; 225 } 226 index++; 227 } 228 if(!found) { 229 model.addElement(entry); 230 } 231 } 232 setModel(model); 233 } 234 235 /** Checks the entries in the list whose name appear in the given array. 236 * @param names The name of entries to be checked as a <strong>String[]</strong>. 237 * @see org.greenstone.gatherer.checklist.Entry 238 */ 239 public void setSelected(String names[]) { 240 DefaultListModel model = (DefaultListModel) getModel(); 241 int size = model.size(); 242 for(int i = 0; i < size; i++) { 243 Entry entry = (Entry) model.get(i); 244 for(int j = 0; names != null && j < names.length; j++) { 245 if(entry.toString().equals(names[j])) { 246 entry.setSelected(true); 247 248 } 249 } 250 } 251 } 252 253 public void setSelectedObjects(Object objects[]) { 254 DefaultListModel model = (DefaultListModel) getModel(); 255 int size = model.size(); 256 for(int i = 0; i < size; i++) { 257 Entry entry = (Entry) model.get(i); 258 for(int j = 0; objects != null && j < objects.length; j++) { 259 if(entry.getObject().equals(objects[j])) { 160 for (int j = 0; j < objects.length; j++) { 161 if (entry.getObject().equals(objects[j])) { 260 162 entry.setSelected(true); 261 163 } … … 263 165 } 264 166 updateUI(); 265 266 267 } 167 } 168 169 268 170 private void selectionChanged(int index) { 269 171 fireSelectionValueChanged(index, index, false); 270 172 } 173 271 174 272 175 /** A custom list cell renderer for producing rows which contain clickable check boxes. */ 273 176 protected class CellRenderer 274 177 implements ListCellRenderer { 178 275 179 /** Return a component that has been configured to display the specified value. That component's paint method is then called to "render" the cell. If it is necessary to compute the dimensions of a list because the list cells do not have a fixed size, this method is called to generate a component on which getPreferredSize can be invoked. 276 180 * @param list The </strong>JList</strong> we're painting. … … 300 204 } 301 205 } 206 207 302 208 /** Listens for clicks apon the checks within the list, and updates as necessary. */ 303 209 private class CheckListListener 304 210 extends MouseAdapter { 305 211 306 //private Entry previous_checkbox = null;307 212 /** Called whenever the mouse is clicked over our list. We find the nearest checkbox and change its state. 308 213 * @param e A <strong>MouseEvent</strong> containing everything you ever wanted to know about the mouse event but were afraid to ask. -
trunk/gli/src/org/greenstone/gatherer/collection/ExportCollectionPrompt.java
r8243 r8496 76 76 /** The currently selected collection for deletion. */ 77 77 private BasicCollectionConfiguration collection = null; 78 /** The model behind the list. */79 private DefaultListModel list_model = null;80 78 /** A reference to ourself so any inner-classes can dispose of us. */ 81 79 private ExportCollectionPrompt prompt = null; … … 88 86 /** The label above the list. */ 89 87 private JLabel list_label = null; 90 /** The list of available collections. */91 //private JList list = null;92 88 /** The text area used to display details about the collection selected. */ 93 89 private JTextArea details_textarea = null; … … 133 129 Dictionary.registerText(instructions_textarea, "ExportCollectionPrompt.Instructions"); 134 130 135 //list = new JList();136 //list_model = new DefaultListModel();137 131 all_collections = new ArrayList(); 138 132 list = new CheckList(true); … … 148 142 Dictionary.setText(title_label, "ExportCollectionPrompt.CD_Name"); 149 143 scanForCollections(); 150 list.setListData(all_collections .toArray());144 list.setListData(all_collections); 151 145 152 146 prompt = this; -
trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java
r8243 r8496 734 734 Gatherer.g_man.modeChanged(new_mode); 735 735 } 736 736 737 // Warning preferences 737 for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) { 738 Entry entry = warning_preferences_check_list.get(i); 738 ListModel warning_preferences_check_list_model = warning_preferences_check_list.getModel(); 739 for (int i = 0; i < warning_preferences_check_list_model.getSize(); i++) { 740 Entry entry = (Entry) warning_preferences_check_list_model.getElementAt(i); 739 741 Configuration.set(entry.getProperty(), true, entry.isSelected()); 740 742 } 741 743 742 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection() !=null) {744 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection() != null) { 743 745 // shut down the collection 744 746 System.err.println("shutting down teh collection");
Note:
See TracChangeset
for help on using the changeset viewer.