Changeset 6003


Ignore:
Timestamp:
2003-11-25T16:29:27+13:00 (20 years ago)
Author:
jmt12
Message:

Added functionality (even though I wasn't meant to - shhh) by providing buttons for the user to click on and browse for about page and home icons. Once an image is selected, GLI copies it to the images folder as necessary, then constructs the _httpcollection_ relative path to the icon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/GeneralManager.java

    r5649 r6003  
    2929import java.awt.*;
    3030import java.awt.event.*;
     31import java.io.*;
     32import java.util.regex.*;
    3133import javax.swing.*;
     34import javax.swing.filechooser.*;
    3235import javax.swing.event.*;
    3336import javax.swing.tree.*;
     
    3942import org.greenstone.gatherer.cdm.Control;
    4043import org.greenstone.gatherer.gui.EmailField;
     44import org.greenstone.gatherer.gui.OpenCollectionDialog;
     45import org.greenstone.gatherer.util.StaticStrings;
    4146import org.greenstone.gatherer.util.Utility;
    4247
     
    5863    private Control controls;
    5964    /** The panel apon which is rendered the currently selected section screen. */
    60    private Control view = null;
     65    private Control view = null;
    6166    /** 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. */
    6267    private DesignTree tree;
     
    143148    /** The maintainers email. */
    144149    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;
    145154    /** The checkbox controlling the state of the collection. */
    146155    private JCheckBox beta_checkbox;
     
    217226        icon_textfield = new JTextField("CDM.General.Icon_Collection");
    218227        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");
    219230        JPanel small_icon_panel = new JPanel();
    220231        small_icon_label = new JLabel("CDM.General.Icon_Collection_Small");
     
    223234        small_icon_textfield = new JTextField("CDM.General.Icon_Collection_Small");
    224235        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");
    225238        JPanel description_panel = new JPanel();
    226239        description_label = new JLabel();
     
    232245        // Connection
    233246        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;
    234251        public_checkbox.addActionListener(CollectionDesignManager.change_listener);
    235252        creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
     
    261278        icon_panel.add(icon_label, BorderLayout.WEST);
    262279        icon_panel.add(icon_textfield, BorderLayout.CENTER);
     280        icon_panel.add(browse_about_icon_button, BorderLayout.EAST);
    263281
    264282        small_icon_panel.setLayout(new BorderLayout());
    265283        small_icon_panel.add(small_icon_label, BorderLayout.WEST);
    266284        small_icon_panel.add(small_icon_textfield, BorderLayout.CENTER);
     285        small_icon_panel.add(browse_home_icon_button, BorderLayout.EAST);
    267286
    268287        details_panel.setLayout(new GridLayout(7,1,5,0));
     
    334353    }
    335354
    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
    337433    /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
    338434    private class DesignTree
Note: See TracChangeset for help on using the changeset viewer.