Changeset 5180


Ignore:
Timestamp:
2003-08-19T11:19:38+12:00 (21 years ago)
Author:
mdewsnip
Message:

The value tree now features tab-completion and enter to append.

File:
1 edited

Legend:

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

    r5176 r5180  
    107107    /** The currently selected metadata determined by listening to every second list selection event from the metadata table. */
    108108    private Metadata selected_metadata;
    109     /** A temporary storage array from Strings passed to the dictionary to be inserted in the phrase returned. */
    110     private String args[];
    111109    /** Provide synchronization between the collection trees in this view and the collection pane view. */
    112110    private TreeSynchronizer tree_sync = null;
     
    161159    expand.setPreferredSize(new Dimension(25, 25));
    162160
    163     tree = new GValueTree(this, CONTROL_SIZE.width, CONTROL_SIZE.height);
     161    tree = new GValueTree(CONTROL_SIZE.width, CONTROL_SIZE.height);
    164162    }
    165163
     
    289287    if(ready) {
    290288        TreeModel collection_model = Gatherer.c_man.getRecordSet();
    291         args = new String[1];
     289        String[] args = new String[1];
    292290        args[0] = Gatherer.c_man.getCollection().getName();
    293291        collection_label.setText(get("Collection.Collection", args));
     
    342340
    343341    ///atherer.println("\tCreating collection_label");
    344     args = new String[1];
    345     args[0] = get("Collection.No_Collection");
    346342    collection_label = new JLabel(get("Collection.Collection"));
    347343    collection_label.setOpaque(true);
     
    394390    main_split_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    395391    main_split_pane.setDividerSize(8);
    396 
    397     // Thumbnail - Currently disabled.
    398     // At least until I figure out how to render thumbnails off screen,
    399     // which possibly may happen with the discovery of CalpaHTML.
    400     /*
    401       thumbnail_pane = new JPanel(new BorderLayout());
    402 
    403       Gatherer.println("\tCreating thumbnail_label");
    404       thumbnail_label = new JLabel(get("Thumbnail"));
    405       thumbnail_label.setHorizontalAlignment(JLabel.CENTER);
    406 
    407       Gatherer.println("\tCreating thumbnail_view_pane");
    408       thumbnail_view_pane = new JPanel(new FlowLayout(FlowLayout.CENTER));
    409       thumbnail_scroll = new JScrollPane(thumbnail_view_pane);
    410 
    411       thumbnail_pane.add(thumbnail_label, BorderLayout.NORTH);
    412       thumbnail_pane.add(thumbnail_scroll, BorderLayout.CENTER);
    413     */
    414392
    415393    // Metadata Table. In order to achieve what Ian envisions I'm going
     
    519497    table_title_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
    520498    table_title_pane.setLayout(new BorderLayout());
    521     //table_title_pane.setLayout(new GridLayout(1,2,5,0));
    522499    table_title_pane.add(table_label, BorderLayout.CENTER);
    523500
     
    645622        }
    646623        else {
    647         // Can append or replace
    648         add.setEnabled(true);
    649         update.setEnabled(true);
     624        // Can append or replace, if something has been entered
     625        add.setEnabled((tree.getSelectedValue().length() > 0));
     626        update.setEnabled((tree.getSelectedValue().length() > 0));
    650627        }
    651628
     
    976953
    977954    /**
    978      * @author John Thompson, Greenstone Digital Library, University of Waikato
    979      * @version 2.2
     955     * This class is a little bit complex, a little bit subtle, and a little bit odd.
     956     * The strange interaction model is due to the fact that it is very tightly
     957     * coupled to the MetaEditPane.
     958     *
     959     * The interaction is complex because there are three separate controls that the
     960     * user may interact with, each of which can affect the other two. The three
     961     * controls are:
     962     *   - The "assigned metadata" table, at the top right of the meta edit pane.
     963     *   - The "metadata value" text field, where users can type in new values.
     964     *   - The "metadata value tree", which shows other values that have been
     965     *     assigned to the selected metadata element.
     966     *
     967     * The interactions are:
     968     *   - The "assigned metadata" table
     969     *     Users may select one (and only one) row in this table. Selecting a row
     970     *     chooses one metadata element. The text field will be set to the current
     971     *     value of the metadata element. This value will also be selected in the
     972     *     metadata value tree.
     973     *
     974     *   - The "metadata value" text field
     975     *     If the value the user has typed in this is a prefix of an entry in the
     976     *     value tree, this value will be selected in the value tree. In this case,
     977     *     pressing "Enter" will complete the value (ie. make the value in the text
     978     *     field the same as the value in the tree). This is to allow users to
     979     *     quickly and easily assign existing metadata values to new documents.
     980     *
     981     *   - The "metadata value tree"
     982     *     Selecting a value in the tree will set the text field to this value.
    980983     */
    981984    private class GValueTree
     
    992995    private JTextField value;
    993996    private JTree tree;
    994     private MetaEditPane metaedit;
    995     private String args[] = new String[1];
    996997    /** Stock standard size for labels. */
    997998    final private Dimension VALUE_LABEL_SIZE = new Dimension(66, 26);
     
    10011002
    10021003
    1003     /**
    1004      * This class is a little bit complex, a little bit subtle, and a little bit odd.
    1005      * The strange interaction model is due to the fact that it is very tightly
    1006      * coupled to the MetaEditPane.
    1007      *
    1008      * The interaction is complex because there are three separate controls that the
    1009      * user may interact with, each of which can affect the other two. The three
    1010      * controls are:
    1011      *   - The "assigned metadata" table, at the top right of the meta edit pane.
    1012      *   - The "metadata value" text field, where users can type in new values.
    1013      *   - The "metadata value tree", which shows other values that have been
    1014      *     assigned to the selected metadata element.
    1015      *
    1016      * The interactions are:
    1017      *   - The "assigned metadata" table
    1018      *     Users may select one (and only one) row in this table. Selecting a row
    1019      *     chooses one metadata element. The text field will be set to the current
    1020      *     value of the metadata element. This value will also be selected in the
    1021      *     metadata value tree.
    1022      *
    1023      *   - The "metadata value" text field
    1024      *     If the value the user has typed in this is a prefix of an entry in the
    1025      *     value tree, this value will be selected in the value tree. In this case,
    1026      *     pressing "Enter" will complete the value (ie. make the value in the text
    1027      *     field the same as the value in the tree). This is to allow users to
    1028      *     quickly and easily assign existing metadata values to new documents.
    1029      *
    1030      *   - The "metadata value tree"
    1031      *     Selecting a value in the tree will set the text field to this value.
    1032      */
    1033     public GValueTree(MetaEditPane metaedit, int width, int height) {
     1004    public GValueTree(int width, int height) {
    10341005        super();
    1035 
    1036         this.metaedit = metaedit;
    10371006
    10381007        setFont(Gatherer.config.getFont("general.font", false));
     
    10511020        value.setPreferredSize(new Dimension(413, 24));
    10521021        value.getDocument().addDocumentListener(new DocumentListenerImpl());
    1053         value.addActionListener(new MetadataFieldListener());
     1022        value.addKeyListener(new MetadataFieldListener());
     1023        value.setFocusTraversalKeysEnabled(false);
    10541024
    10551025        JPanel button_pane = new JPanel();
     
    11581128
    11591129        // Special case the extracted metadata set
    1160         if (selected_metadata_element.getNamespace().equals("")) {
     1130        if (selected_metadata_element.getNamespace().equals(Utility.EXTRACTED_METADATA_NAMESPACE)) {
    11611131        // Display the panel showing the "you cannot edit this metadata" message
     1132        String[] args = new String[1];
    11621133        args[0] = selected_metadata_element.toString();
    11631134        extracted_message.setText(get("AutoMessage", args));
     
    12071178        key = "MetaEdit." + key;
    12081179        }
    1209         return Gatherer.dictionary.get(key,args);
     1180        return Gatherer.dictionary.get(key, args);
    12101181    }
    12111182
     
    12721243
    12731244    private class MetadataFieldListener
    1274         implements ActionListener {
    1275         /** Gives notification of the Enter key being pressed on the text field */
    1276         public void actionPerformed(ActionEvent e) {
    1277         if (tree.getSelectionCount() != 0 && !value.getText().equals("")) {
    1278             TreePath path = tree.getSelectionPath();
    1279             GValueNode node = (GValueNode) path.getLastPathComponent();
    1280             value.setText(Utility.stripNL(node.getFullPath()));
     1245        implements KeyListener {
     1246
     1247        /** Gives notification of key events on the text field */
     1248        public void keyPressed(KeyEvent e) {
     1249        if (e.getKeyCode() == KeyEvent.VK_TAB) {
     1250            // Tab: Auto-complete
     1251            if (tree.getSelectionCount() != 0 && !value.getText().equals("")) {
     1252            TreePath path = tree.getSelectionPath();
     1253            GValueNode node = (GValueNode) path.getLastPathComponent();
     1254            value.setText(Utility.stripNL(node.getFullPath()));
     1255            }
    12811256        }
    1282         }
     1257        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     1258            // Enter: Append the metadata value, if we're allowed to
     1259            if (add.isEnabled()) {
     1260            add.doClick();
     1261            }
     1262        }           
     1263        }
     1264
     1265        public void keyReleased(KeyEvent e) { }
     1266
     1267        public void keyTyped(KeyEvent e) { }
    12831268    }
    12841269
     
    12861271    private class DocumentListenerImpl
    12871272        implements DocumentListener {
    1288         /** Gives notification that an attribute or set of attributes changed. */
     1273        /** Gives notification that an attribute or set of attributes changed */
    12891274        public void changedUpdate(DocumentEvent e) {
    12901275        validate();
    12911276        }
    12921277
    1293         /** Gives notification that there was an insert into the document. */
     1278        /** Gives notification that there was an insert into the document */
    12941279        public void insertUpdate(DocumentEvent e) {
    12951280        validate();
    12961281        }
    12971282
    1298         /** Gives notification that a portion of the document has been removed. */
     1283        /** Gives notification that a portion of the document has been removed */
    12991284        public void removeUpdate(DocumentEvent e) {
    13001285        validate();
     
    13021287
    13031288
    1304         /** Ensures that the value text field and value tree are synchronized. */
     1289        /** Ensures that the value text field and value tree are synchronized */
    13051290        private void validate()
    13061291        {
     
    13291314
    13301315            // Update the status of the buttons
    1331             metaedit.validateControls();
     1316            validateControls();
    13321317        }
    13331318        }
Note: See TracChangeset for help on using the changeset viewer.