Changeset 4671


Ignore:
Timestamp:
2003-06-16T10:01:27+12:00 (21 years ago)
Author:
jmt12
Message:

Reimplemented dialog with more useful messages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/FileAssociationDialog.java

    r4427 r4671  
    4141import java.util.*;
    4242import javax.swing.*;
     43import javax.swing.event.*;
    4344import org.greenstone.gatherer.Gatherer;
    4445import org.greenstone.gatherer.file.FileAssociationManager;
    4546import org.greenstone.gatherer.gui.GComboBox;
     47import org.greenstone.gatherer.gui.ModalDialog;
     48import org.greenstone.gatherer.gui.SimpleMenuBar;
    4649import org.greenstone.gatherer.util.Utility;
    4750import org.outerj.pollo.util.*;
    48 import org.greenstone.gatherer.gui.SimpleMenuBar;
    49 import org.greenstone.gatherer.gui.ModalDialog;
    5051
    5152/** 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.
     
    8081    static final private Dimension LABEL_SIZE = new Dimension(150, 25);
    8182    /** 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);
    8384    /** Create a new file association dialog.
    8485     * @param manager A reference to the <strong>FileAssociationManager</strong> so we can determine what extensions are already associated.
     
    9899    JPanel content_pane = (JPanel) getContentPane();
    99100    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);
    100107    JPanel extension_pane = new JPanel();
    101108    extension_pane.setOpaque(false);
     
    105112    extension.setEditable(true);
    106113    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));
    109116    }
    110117    JPanel command_pane = new JPanel();
     
    119126    command.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false));
    120127    if(extension.count() > 0) {
    121         command.setText(manager.getCommandImmediately((String)extension.get(0)));
     128        command.setText(manager.getCommandString((String)extension.get(0)));
    122129    }
    123130    browse = new JButton(get("Browse"));
     
    134141    cancel.addActionListener(new CancelListener());
    135142    ok.addActionListener(new OKListener());
    136     extension.addItemListener(new ExtensionListener());
    137     command.addKeyListener(new CommandListener());
     143    extension.addActionListener(new ExtensionListener());
     144    command.getDocument().addDocumentListener(new CommandListener());
    138145    // Layout
     146    extension_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
    139147    extension_pane.setLayout(new BorderLayout());
    140148    extension_pane.add(extension_label, BorderLayout.WEST);
     
    149157    command_pane.add(command_label);
    150158    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);
    151163
    152164    button_pane.setLayout(new GridLayout(1,2,2,2));
     
    156168    content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    157169    content_pane.setLayout(new BorderLayout());
    158     content_pane.add(extension_pane, BorderLayout.NORTH);
    159     content_pane.add(command_pane, BorderLayout.CENTER);
     170    content_pane.add(new JScrollPane(instructions_area), BorderLayout.NORTH);
     171    content_pane.add(control_pane, BorderLayout.CENTER);
    160172    content_pane.add(button_pane, BorderLayout.SOUTH);
    161173
     
    174186    previous_extension = null;
    175187    }
    176     /** Redisplay the dialog, ensuring that the details (or lack thereof) for a certain extension is apparent.
    177       * @param new_extension The extension code as a <strong>String</strong>.
    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     */
    179191    public String display(String new_extension) {
    180192    if(new_extension != null) {
     193        ok.setText(get("Add"));
    181194        int index = extension.add(new_extension);
    182195        extension.setSelectedIndex(index);
     196        extension.setEnabled(false);
    183197    }
    184198    else {
    185 
     199        ok.setText(get("General.OK"));
     200        extension.setEnabled(true);
    186201    }
    187202    setVisible(true);
    188203    if(save_required) {
    189         manager.setCommand((String)extension.getSelectedItem(), (String)command.getText());
     204        setCommand((String)extension.getSelectedItem(), (String)command.getText(), true);
    190205        save_required = false;
    191206    }
    192     if(cancelled) {
     207    if(!cancelled) {
     208        return setCommand((String)extension.getSelectedItem(), (String)command.getText(), false);
     209    }
     210    else {
    193211        return null;
    194212    }
    195     return command.getText();
    196213    }
    197214
     
    206223    return Gatherer.dictionary.get(key, args);
    207224    }   
     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    }
    208235
    209236    /** 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. */
     
    241268    /** 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. */
    242269    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;
    249283    }
    250284    }
    251285    /** 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). */
    252286    private class ExtensionListener
    253     implements ItemListener {
     287    implements ActionListener {
    254288    /** 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.
    255289     * @param event An <strong>ItemEvent</strong> encompassing everything you ever wanted to know about the list selectio, but were afraid to ask.
    256290     * @see org.greenstone.gatherer.file.FileAssociationManager
    257291     */
    258     public void itemStateChanged(ItemEvent event) {
     292    public void actionPerformed(ActionEvent event) {
    259293        String ext = (String) extension.getSelectedItem();
    260294        if(!ignore && ext != null && ext.length() > 0) {
     
    262296        // Save the previous extension if necessary
    263297        if(save_required && previous_extension != null) {
    264             manager.setCommand(previous_extension, command.getText());
     298            setCommand(previous_extension, command.getText(), true);
    265299            save_required = false;
    266300        }
    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;
    274303        ignore = false;
    275304        }
     
    284313    public void actionPerformed(ActionEvent event) {
    285314        if(save_required) {
    286         manager.setCommand(extension.getSelectedItem().toString(), command.getText());
     315        setCommand(extension.getSelectedItem().toString(), command.getText(), true);
    287316        save_required = false;
    288317        }
Note: See TracChangeset for help on using the changeset viewer.