Changeset 6003
- Timestamp:
- 2003-11-25T16:29:27+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/GeneralManager.java
r5649 r6003 29 29 import java.awt.*; 30 30 import java.awt.event.*; 31 import java.io.*; 32 import java.util.regex.*; 31 33 import javax.swing.*; 34 import javax.swing.filechooser.*; 32 35 import javax.swing.event.*; 33 36 import javax.swing.tree.*; … … 39 42 import org.greenstone.gatherer.cdm.Control; 40 43 import org.greenstone.gatherer.gui.EmailField; 44 import org.greenstone.gatherer.gui.OpenCollectionDialog; 45 import org.greenstone.gatherer.util.StaticStrings; 41 46 import org.greenstone.gatherer.util.Utility; 42 47 … … 58 63 private Control controls; 59 64 /** The panel apon which is rendered the currently selected section screen. */ 60 private Control view = null;65 private Control view = null; 61 66 /** A tree to serve as a 'table of contents' for this design tool. We decided on a tree rather than a list, as it allows us to break sections into subsections if they become to complicated. */ 62 67 private DesignTree tree; … … 143 148 /** The maintainers email. */ 144 149 private EmailField maintainer_emailfield; 150 /** Button to browse for the collection about page icon. */ 151 private JButton browse_about_icon_button; 152 /** Button to browse for the collection home page icon. */ 153 private JButton browse_home_icon_button; 145 154 /** The checkbox controlling the state of the collection. */ 146 155 private JCheckBox beta_checkbox; … … 217 226 icon_textfield = new JTextField("CDM.General.Icon_Collection"); 218 227 Dictionary.registerTooltip(icon_textfield, "CDM.General.Icon_Collection_Tooltip"); 228 browse_about_icon_button = new JButton(); 229 Dictionary.registerText(browse_about_icon_button, "General.Browse"); 219 230 JPanel small_icon_panel = new JPanel(); 220 231 small_icon_label = new JLabel("CDM.General.Icon_Collection_Small"); … … 223 234 small_icon_textfield = new JTextField("CDM.General.Icon_Collection_Small"); 224 235 Dictionary.registerTooltip(small_icon_textfield, "CDM.General.Icon_Collection_Small_Tooltip"); 236 browse_home_icon_button = new JButton(); 237 Dictionary.registerText(browse_home_icon_button, "General.Browse"); 225 238 JPanel description_panel = new JPanel(); 226 239 description_label = new JLabel(); … … 232 245 // Connection 233 246 beta_checkbox.addActionListener(CollectionDesignManager.change_listener); 247 ActionListener browse_listener = new BrowseListener(); 248 browse_about_icon_button.addActionListener(browse_listener); 249 browse_home_icon_button.addActionListener(browse_listener); 250 browse_listener = null; 234 251 public_checkbox.addActionListener(CollectionDesignManager.change_listener); 235 252 creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener); … … 261 278 icon_panel.add(icon_label, BorderLayout.WEST); 262 279 icon_panel.add(icon_textfield, BorderLayout.CENTER); 280 icon_panel.add(browse_about_icon_button, BorderLayout.EAST); 263 281 264 282 small_icon_panel.setLayout(new BorderLayout()); 265 283 small_icon_panel.add(small_icon_label, BorderLayout.WEST); 266 284 small_icon_panel.add(small_icon_textfield, BorderLayout.CENTER); 285 small_icon_panel.add(browse_home_icon_button, BorderLayout.EAST); 267 286 268 287 details_panel.setLayout(new GridLayout(7,1,5,0)); … … 334 353 } 335 354 336 } 355 /** Listens for a click on either browse button, and when detected opens a file browser window initially pointed at the images folder of the collection. Once a user has selected a path, does it's best to construct the best address to the resource, such as _httpcollection_/images/about.gif */ 356 private class BrowseListener 357 implements ActionListener { 358 359 public void actionPerformed(ActionEvent event) { 360 // Open an almost standard file browser to the images folder of the current collection 361 File images_folder = new File(Gatherer.c_man.getCollectionImages()); 362 // If images isn't already there, create it 363 if(!images_folder.exists()) { 364 images_folder.mkdirs(); 365 } 366 JFileChooser file_chooser = new JFileChooser(images_folder); 367 file_chooser.setAcceptAllFileFilterUsed(false); 368 file_chooser.setDialogTitle(Dictionary.get("CDM.General.Browser_Title")); 369 file_chooser.setFileFilter(new ImageFilter()); 370 file_chooser.setSize(400,300); 371 OpenCollectionDialog.disableRename(file_chooser); 372 int value = file_chooser.showOpenDialog(Gatherer.g_man); 373 // If the user hasn't cancelled, retrieve the file path selected 374 if(value == JFileChooser.APPROVE_OPTION) { 375 // If the file isn't in the images folder, then ask the user if they want to copy it there 376 File file = file_chooser.getSelectedFile(); 377 if(!file.getParentFile().equals(images_folder)) { 378 if(JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("CDM.General.Copy_Image"), Dictionary.get("General.Warning"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { 379 // Copy the file 380 try { 381 Gatherer.f_man.getQueue().copyFile(file, new File(images_folder, file.getName()), null); 382 } 383 catch(Exception exception) { 384 Gatherer.printStackTrace(exception); 385 // Show warning 386 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.General.Image_Copy_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 387 // Nothing else we can do. 388 return; 389 } 390 } 391 else { 392 // Nothing we can safely do 393 return; 394 } 395 } 396 // Create the path starting _httpcollection_/images/<filename> 397 String path = StaticStrings.IMAGES_PATH_PREFIX + file.getName(); 398 if(event.getSource() == browse_about_icon_button) { 399 icon_textfield.setText(path); 400 } 401 else { 402 small_icon_textfield.setText(path); 403 } 404 path = null; 405 } 406 } 407 408 /** ImageFilter.java is a 1.4 example used by FileChooserDemo2.java. */ 409 private class ImageFilter 410 extends javax.swing.filechooser.FileFilter { 411 412 private Pattern pattern = null; 413 414 public ImageFilter() { 415 pattern = Pattern.compile(".*\\.(gif|png|jpe?g)"); 416 } 417 418 // Accept all directories and all .col files 419 public boolean accept(File f) { 420 String filename = f.getName().toLowerCase(); 421 Matcher matcher = pattern.matcher(filename); 422 return f.isDirectory() || matcher.matches(); 423 } 424 425 // The description of this filter 426 public String getDescription() { 427 return Dictionary.get("CDM.General.Image_Filter"); 428 } 429 } 430 } 431 } 432 337 433 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */ 338 434 private class DesignTree
Note:
See TracChangeset
for help on using the changeset viewer.