Changeset 4671
- Timestamp:
- 2003-06-16T10:01:27+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/FileAssociationDialog.java
r4427 r4671 41 41 import java.util.*; 42 42 import javax.swing.*; 43 import javax.swing.event.*; 43 44 import org.greenstone.gatherer.Gatherer; 44 45 import org.greenstone.gatherer.file.FileAssociationManager; 45 46 import org.greenstone.gatherer.gui.GComboBox; 47 import org.greenstone.gatherer.gui.ModalDialog; 48 import org.greenstone.gatherer.gui.SimpleMenuBar; 46 49 import org.greenstone.gatherer.util.Utility; 47 50 import org.outerj.pollo.util.*; 48 import org.greenstone.gatherer.gui.SimpleMenuBar;49 import org.greenstone.gatherer.gui.ModalDialog;50 51 51 52 /** The file association allows the entry of new file associations and the modification of existing ones. This is done via a list of known extensions, and two fields to fill out relevant details. … … 80 81 static final private Dimension LABEL_SIZE = new Dimension(150, 25); 81 82 /** The default size for the dialog. */ 82 static final private Dimension SIZE = new Dimension(600, 175);83 static final private Dimension SIZE = new Dimension(600, 270); 83 84 /** Create a new file association dialog. 84 85 * @param manager A reference to the <strong>FileAssociationManager</strong> so we can determine what extensions are already associated. … … 98 99 JPanel content_pane = (JPanel) getContentPane(); 99 100 content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false)); 101 JPanel control_pane = new JPanel(); 102 JTextArea instructions_area = new JTextArea(get("Instructions")); 103 instructions_area.setEditable(false); 104 instructions_area.setLineWrap(true); 105 instructions_area.setRows(5); 106 instructions_area.setWrapStyleWord(true); 100 107 JPanel extension_pane = new JPanel(); 101 108 extension_pane.setOpaque(false); … … 105 112 extension.setEditable(true); 106 113 extension.setPreferredSize(LABEL_SIZE); 107 for( Iterator extensions = manager.keySet().iterator(); extensions.hasNext();) {108 extension.add( (String)extensions.next());114 for(int i = 0; i < manager.size(); i++) { 115 extension.add(manager.getExtension(i)); 109 116 } 110 117 JPanel command_pane = new JPanel(); … … 119 126 command.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false)); 120 127 if(extension.count() > 0) { 121 command.setText(manager.getCommand Immediately((String)extension.get(0)));128 command.setText(manager.getCommandString((String)extension.get(0))); 122 129 } 123 130 browse = new JButton(get("Browse")); … … 134 141 cancel.addActionListener(new CancelListener()); 135 142 ok.addActionListener(new OKListener()); 136 extension.add ItemListener(new ExtensionListener());137 command. addKeyListener(new CommandListener());143 extension.addActionListener(new ExtensionListener()); 144 command.getDocument().addDocumentListener(new CommandListener()); 138 145 // Layout 146 extension_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 139 147 extension_pane.setLayout(new BorderLayout()); 140 148 extension_pane.add(extension_label, BorderLayout.WEST); … … 149 157 command_pane.add(command_label); 150 158 command_pane.add(inner_pane); 159 160 control_pane.setLayout(new BorderLayout()); 161 control_pane.add(extension_pane, BorderLayout.NORTH); 162 control_pane.add(command_pane, BorderLayout.CENTER); 151 163 152 164 button_pane.setLayout(new GridLayout(1,2,2,2)); … … 156 168 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 157 169 content_pane.setLayout(new BorderLayout()); 158 content_pane.add( extension_pane, BorderLayout.NORTH);159 content_pane.add(co mmand_pane, BorderLayout.CENTER);170 content_pane.add(new JScrollPane(instructions_area), BorderLayout.NORTH); 171 content_pane.add(control_pane, BorderLayout.CENTER); 160 172 content_pane.add(button_pane, BorderLayout.SOUTH); 161 173 … … 174 186 previous_extension = null; 175 187 } 176 /** Redisplay the dialog, ensuring that the details (or lack thereof) for a certain extension is apparent. 177 178 188 /** Redisplay the dialog, ensuring that the details (or lack thereof) for a certain extension is apparent. In fact if an extension is provided force the user to add it or cancel. 189 * @param new_extension The extension code as a <strong>String</strong>. 190 */ 179 191 public String display(String new_extension) { 180 192 if(new_extension != null) { 193 ok.setText(get("Add")); 181 194 int index = extension.add(new_extension); 182 195 extension.setSelectedIndex(index); 196 extension.setEnabled(false); 183 197 } 184 198 else { 185 199 ok.setText(get("General.OK")); 200 extension.setEnabled(true); 186 201 } 187 202 setVisible(true); 188 203 if(save_required) { 189 manager.setCommand((String)extension.getSelectedItem(), (String)command.getText());204 setCommand((String)extension.getSelectedItem(), (String)command.getText(), true); 190 205 save_required = false; 191 206 } 192 if(cancelled) { 207 if(!cancelled) { 208 return setCommand((String)extension.getSelectedItem(), (String)command.getText(), false); 209 } 210 else { 193 211 return null; 194 212 } 195 return command.getText();196 213 } 197 214 … … 206 223 return Gatherer.dictionary.get(key, args); 207 224 } 225 226 private String setCommand(String extension, String command, boolean process) { 227 if(command.indexOf(FileAssociationManager.FILENAME_ARG) == -1) { 228 command = command + " " + FileAssociationManager.FILENAME_ARG; 229 } 230 if(process) { 231 manager.setCommand(extension, command); 232 } 233 return command; 234 } 208 235 209 236 /** Whenever the user clicks the browse button, we should open up a file browser to allow them to select an executable file from somewhere in the file system. */ … … 241 268 /** If any changes occur to the command field, mark it as needing saving before we can change extensions, or dispose of this dialog (other than cancelling. */ 242 269 private class CommandListener 243 extends KeyAdapter { 244 /** Whenever we detect a new character has been typed, note that we need to update this association in the manager. 245 * @param event A <strong>KeyEvent</strong> containing information about the key typed event. 246 */ 247 public void keyTyped(KeyEvent event) { 248 save_required = true; 270 implements DocumentListener { 271 /** Gives notification that an attribute or set of attributes changed. */ 272 public void changedUpdate(DocumentEvent e) { 273 save_required = !ignore && true; 274 } 275 /** Gives notification that there was an insert into the document. */ 276 public void insertUpdate(DocumentEvent e) { 277 save_required = !ignore && true; 278 } 279 280 /** Gives notification that a portion of the document has been removed. */ 281 public void removeUpdate(DocumentEvent e) { 282 save_required = !ignore && true; 249 283 } 250 284 } 251 285 /** Whenever the user selects an extension, we should fill out the command field with whatever value has been previously entered for the command (if any). */ 252 286 private class ExtensionListener 253 implements ItemListener {287 implements ActionListener { 254 288 /** This method is called whenever the selection in the extension list changes, so that we can save any old details, then load up the information for the new selection. 255 289 * @param event An <strong>ItemEvent</strong> encompassing everything you ever wanted to know about the list selectio, but were afraid to ask. 256 290 * @see org.greenstone.gatherer.file.FileAssociationManager 257 291 */ 258 public void itemStateChanged(ItemEvent event) {292 public void actionPerformed(ActionEvent event) { 259 293 String ext = (String) extension.getSelectedItem(); 260 294 if(!ignore && ext != null && ext.length() > 0) { … … 262 296 // Save the previous extension if necessary 263 297 if(save_required && previous_extension != null) { 264 manager.setCommand(previous_extension, command.getText());298 setCommand(previous_extension, command.getText(), true); 265 299 save_required = false; 266 300 } 267 previous_extension = manager.getCommandImmediately((String)extension.getSelectedItem()); 268 if(previous_extension != null) { 269 command.setText(previous_extension); 270 } 271 else { 272 command.setText(""); 273 } 301 command.setText(manager.getCommandString(ext)); 302 previous_extension = ext; 274 303 ignore = false; 275 304 } … … 284 313 public void actionPerformed(ActionEvent event) { 285 314 if(save_required) { 286 manager.setCommand(extension.getSelectedItem().toString(), command.getText());315 setCommand(extension.getSelectedItem().toString(), command.getText(), true); 287 316 save_required = false; 288 317 }
Note:
See TracChangeset
for help on using the changeset viewer.