Changeset 8503


Ignore:
Timestamp:
2004-11-10T11:06:50+13:00 (19 years ago)
Author:
mdewsnip
Message:

Can now double-click on a leaf node in the value tree to assign it immediately.

File:
1 edited

Legend:

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

    r8501 r8503  
    951951    private class MetadataValueTree
    952952    extends JPanel
    953     implements TreeSelectionListener
    954953    {
    955954    private boolean ignore_tree_selection_event = false;
     
    984983        metadata_value_text_field.setPreferredSize(new Dimension(413, 24));
    985984        metadata_value_text_field.getDocument().addDocumentListener(new DocumentListenerImpl());
    986         metadata_value_text_field.addKeyListener(new MetadataFieldListener());
     985        metadata_value_text_field.addKeyListener(new MetadataValueTextFieldKeyListener());
    987986        metadata_value_text_field.setFocusTraversalKeysEnabled(false);
    988987        Dictionary.setTooltip(metadata_value_text_field, "MetaEdit.Value_Field_Tooltip");
     
    995994
    996995        tree = new JTree();
    997         tree.addTreeSelectionListener(this);
     996        tree.addMouseListener(new MetadataValueTreeMouseListener());
     997        tree.addTreeSelectionListener(new MetadataValueTreeSelectionListener());
    998998        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    999999        tree.setRootVisible(false);
     
    12171217
    12181218
    1219     /** Handles TreeSelectionEvents. */
    1220     public void valueChanged(TreeSelectionEvent event)
    1221     {
    1222         if (tree.getSelectionCount() != 0 && !ignore_tree_selection_event) {
    1223         TreePath path = tree.getSelectionPath();
    1224         MetadataValueTreeNode node = (MetadataValueTreeNode) path.getLastPathComponent();
    1225         setSelectedValue(node.getFullValue());
    1226         }
    1227     }
    1228 
    1229 
    1230     private class MetadataFieldListener
    1231         implements KeyListener {
    1232 
     1219    private class MetadataValueTextFieldKeyListener
     1220        extends KeyAdapter
     1221    {
    12331222        /** Gives notification of key events on the text field */
    12341223        public void keyPressed(KeyEvent e)
     
    12601249        }
    12611250        }
    1262 
    1263         public void keyReleased(KeyEvent e) { }
    1264 
    1265         public void keyTyped(KeyEvent e) { }
     1251    }
     1252
     1253
     1254    private class MetadataValueTreeMouseListener
     1255        extends MouseAdapter
     1256    {
     1257        public void mouseClicked(MouseEvent e)
     1258        {
     1259        // Double click: assign the selected value tree node immediately (if possible)
     1260        if (e.getClickCount() == 2 && tree.getSelectionCount() != 0) {
     1261            TreePath path = tree.getSelectionPath();
     1262            MetadataValueTreeNode node = (MetadataValueTreeNode) path.getLastPathComponent();
     1263
     1264            // Leaf nodes only (folder nodes will expand/contract)
     1265            if (node.getChildCount() == 0 && add.isEnabled()) {
     1266            add.doClick();
     1267            }
     1268        }
     1269        }
     1270    }
     1271
     1272
     1273    private class MetadataValueTreeSelectionListener
     1274        implements TreeSelectionListener
     1275    {
     1276        public void valueChanged(TreeSelectionEvent event)
     1277        {
     1278        // Select a node in the tree: fill the metadata value text field with the selected node's value
     1279        if (tree.getSelectionCount() != 0 && !ignore_tree_selection_event) {
     1280            TreePath path = tree.getSelectionPath();
     1281            MetadataValueTreeNode node = (MetadataValueTreeNode) path.getLastPathComponent();
     1282            setSelectedValue(node.getFullValue());
     1283        }
     1284        }
    12661285    }
    12671286
     
    13441363        }
    13451364        tree.setImmediate(false);
    1346         } else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
     1365        }
     1366        else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
    13471367        // left key on a file shifts the selection to the parent folder
    13481368        DragTree tree = (DragTree)event.getSource();
Note: See TracChangeset for help on using the changeset viewer.