Ignore:
Timestamp:
2004-03-29T15:36:55+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/GatherPane.java

    r7123 r7143  
    666666    private class KeyListenerImpl
    667667    extends KeyAdapter {
     668    private boolean vk_left_pressed = false;
    668669    /** 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). */
    669670    public void keyReleased(KeyEvent event) {
     
    728729        if(path != null) {
    729730            File file = ((FileNode)path.getLastPathComponent()).getFile();
    730             if(file != null && file.isFile()) {
    731             TreePath parent_path = path.getParentPath();
    732             if (parent_path != null && parent_path.getParentPath() != null) {
    733                 // if this file is in the top level folder, don't move the focus
    734                 tree.setImmediate(true);
    735                 tree.clearSelection();
    736                 tree.setSelectionPath(parent_path);
    737                 tree.setImmediate(false);
     731            if(file != null) {
     732            if (file.isFile() || vk_left_pressed) {
     733                vk_left_pressed = false;
     734                TreePath parent_path = path.getParentPath();
     735                if (parent_path != null && parent_path.getParentPath() != null) {
     736                // if this file is in the top level folder, don't move the focus
     737                tree.setImmediate(true);
     738                tree.clearSelection();
     739                tree.setSelectionPath(parent_path);
     740                tree.setImmediate(false);
     741                }
    738742            }
    739743            }
     
    741745        }
    742746    }
    743 
    744     }
    745 
     747   
     748    // 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.
     749    public void keyPressed(KeyEvent event) {
     750        if (event.getKeyCode() == KeyEvent.VK_LEFT) {
     751        // left key on  closed directory shifts the selection to the parent folder
     752        DragTree tree = (DragTree)event.getSource();
     753        TreePath path = tree.getLeadSelectionPath();
     754        if(path == null) return;
     755        File file = ((FileNode)path.getLastPathComponent()).getFile();
     756        if(file == null) return;
     757       
     758        if (file.isDirectory() && tree.isCollapsed(path)) {
     759            vk_left_pressed = true;
     760        }
     761        }
     762    }   
     763    }
     764   
    746765    /** This provides a small prompt for gathering addition details about a special directory mapping such as its symbolic name. */
    747766    private class MappingPrompt
Note: See TracChangeset for help on using the changeset viewer.