Changeset 7141


Ignore:
Timestamp:
2004-03-29T15:25:59+12:00 (20 years ago)
Author:
kjdon
Message:

added in a left click on a folder handler: if the folder is closed, then move the focus to the parent folder. Note that this was a bit trickier than expected because there is another mysterious handler that does left and right clicks to close and open folders. I needed to test for left click on a closed folder on the key pressed, but actually action it on the key release other wise the other handler comes into play and you get two actions happening on a single click.

File:
1 edited

Legend:

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

    r7123 r7141  
    10371037    private class KeyListenerImpl
    10381038    extends KeyAdapter {
     1039    private boolean vk_left_pressed = false;
    10391040    /** Called whenever a key that was pressed is released, it is this action that will cause the desired effects (this allows for the key event itself to be processed prior to this listener dealing with it). */
    10401041    public void keyReleased(KeyEvent event) {
     
    10641065        if(path != null) {
    10651066            File file = ((FileNode)path.getLastPathComponent()).getFile();
    1066             if(file != null && file.isFile()) {
    1067             TreePath parent_path = path.getParentPath();
    1068             if (parent_path != null && parent_path.getParentPath() != null) {
    1069                 // if this file is in the top level folder, don't move the focus
    1070                 tree.setImmediate(true);
    1071                 tree.clearSelection();
    1072                 tree.setSelectionPath(parent_path);
    1073                 tree.setImmediate(false);
     1067            if(file != null) {
     1068            if (file.isFile() || vk_left_pressed) {
     1069                vk_left_pressed = false;
     1070                TreePath parent_path = path.getParentPath();
     1071                if (parent_path != null && parent_path.getParentPath() != null) {
     1072                // if this file is in the top level folder, don't move the focus
     1073                tree.setImmediate(true);
     1074                tree.clearSelection();
     1075                tree.setSelectionPath(parent_path);
     1076                tree.setImmediate(false);
     1077                }
    10741078            }
    10751079            }
    10761080        }
     1081        }       
     1082    }
     1083
     1084    // we need to watch for left clicks on an unopened folder - should shift the focus to teh parent folder. But because there is some other mysterious key listener that does opening and closing folders on right and left clicks, we must detect the situation before the other handler has done its job, and process it after.
     1085    public void keyPressed(KeyEvent event) {
     1086        if (event.getKeyCode() == KeyEvent.VK_LEFT) {
     1087        // left key on  closed directory shifts the selection to the parent folder
     1088        DragTree tree = (DragTree)event.getSource();
     1089        TreePath path = tree.getLeadSelectionPath();
     1090        if(path == null) return;
     1091        File file = ((FileNode)path.getLastPathComponent()).getFile();
     1092        if(file == null) return;
     1093       
     1094        if (file.isDirectory() && tree.isCollapsed(path)) {
     1095            vk_left_pressed = true;
     1096        }       
    10771097        }
    10781098    }
Note: See TracChangeset for help on using the changeset viewer.