Ignore:
Timestamp:
2006-04-06T15:05:44+12:00 (18 years ago)
Author:
mdewsnip
Message:

Moved the KeyListener from GatherPane into DragTree and removed the KeyListener from EnrichPane so now there is only one (consistent) key listener between the two panes (ie. you can now press "Enter" and "Delete" in the collection tree of the Enrich pane).

File:
1 edited

Legend:

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

    r11599 r11601  
    210210    public void display() {
    211211    // Create Components.
    212     KeyListenerImpl key_listener = new KeyListenerImpl();
    213212    MouseListenerImpl mouse_listener = new MouseListenerImpl();
    214     this.addKeyListener(key_listener);
    215213
    216214    // Workspace Tree
     
    229227    group.add(workspace_tree);
    230228    workspace_tree.addFocusListener(this);
    231     workspace_tree.addKeyListener(key_listener);
    232229    workspace_tree.addMouseListener(mouse_listener);
    233230    workspace_tree.addMouseListener(Gatherer.g_man.foa_listener);
     
    261258    group.add(collection_tree);
    262259    collection_tree.addFocusListener(this);
    263     collection_tree.addKeyListener(key_listener);
    264260    collection_tree.addMouseListener(mouse_listener);
    265261    collection_tree.addMouseListener(Gatherer.g_man.foa_listener);
     
    756752
    757753
    758     /** This class listens for certain key presses, such as [Enter] or [Delete], and responds appropriately. */
    759     private class KeyListenerImpl
    760     extends KeyAdapter {
    761     private boolean vk_left_pressed = false;
    762     /** 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). */
    763     public void keyReleased(KeyEvent event) {
    764         ///ystem.err.println("Key Release detected. " + event.getKeyCode());
    765         if(event.getKeyCode() == KeyEvent.VK_DELETE) {
    766         // Get the selected files from the tree and removal them using the default dnd removal method.
    767         // Find the active tree (you've made selections in).
    768         DragTree tree = (DragTree) group.getActive();
    769         // Fudge things a bit
    770         group.setSource(tree);
    771         // Determine the selection.
    772         TreePath paths[] = tree.getSelectionPaths();
    773         if(paths != null) {
    774             FileNode[] source_nodes = new FileNode[paths.length];
    775             for(int i = 0; i < source_nodes.length; i++) {
    776             source_nodes[i] = (FileNode) paths[i].getLastPathComponent();
    777             }
    778             Gatherer.f_man.action(tree, source_nodes, Gatherer.recycle_bin, null);
    779             source_nodes = null;
    780         }
    781         }
    782         else if(event.getKeyCode() == KeyEvent.VK_ENTER) {
    783         // Get the first selected file.
    784         DragTree tree = (DragTree)event.getSource();
    785         TreePath path = tree.getSelectionPath();
    786         if(path != null) {
    787             File file = ((FileNode)path.getLastPathComponent()).getFile();
    788             if (file != null && file.isFile()) {
    789             Gatherer.f_man.openFileInExternalApplication(file);
    790             }
    791             else {
    792             if(!tree.isExpanded(path)) {
    793                 tree.expandPath(path);
    794             }
    795             else {
    796                 tree.collapsePath(path);
    797             }
    798             }
    799         }
    800         } else if (event.getKeyCode() == KeyEvent.VK_UP || event.getKeyCode() == KeyEvent.VK_DOWN) {
    801         DragTree tree = (DragTree)event.getSource();
    802         // we need to manually do the up and down selections
    803         boolean up = (event.getKeyCode() == KeyEvent.VK_UP);
    804         int current_row = tree.getLeadSelectionRow();
    805         tree.setImmediate(true);
    806         if (up) {
    807             if (current_row > 0) {
    808             tree.clearSelection();
    809             tree.setSelectionRow(current_row-1);
    810             }
    811         } else {
    812             if (current_row < tree.getRowCount()-1){
    813             tree.clearSelection();
    814             tree.setSelectionRow(current_row+1);
    815             }
    816         }
    817         tree.setImmediate(false);
    818         } else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
    819         // left key on a file shifts the selection to the parent folder
    820         DragTree tree = (DragTree)event.getSource();
    821         TreePath path = tree.getLeadSelectionPath();
    822         if(path != null) {
    823             File file = ((FileNode)path.getLastPathComponent()).getFile();
    824             if(file != null) {
    825             if (file.isFile() || vk_left_pressed) {
    826                 vk_left_pressed = false;
    827                 TreePath parent_path = path.getParentPath();
    828                 if (parent_path != null && parent_path.getParentPath() != null) {
    829                 // if this file is in the top level folder, don't move the focus
    830                 tree.setImmediate(true);
    831                 tree.clearSelection();
    832                 tree.setSelectionPath(parent_path);
    833                 tree.setImmediate(false);
    834                 }
    835             }
    836             }
    837         }
    838         }
    839     }
    840    
    841     // 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.
    842     public void keyPressed(KeyEvent event) {
    843         if (event.getKeyCode() == KeyEvent.VK_LEFT) {
    844         // left key on  closed directory shifts the selection to the parent folder
    845         DragTree tree = (DragTree)event.getSource();
    846         TreePath path = tree.getLeadSelectionPath();
    847         if(path == null) return;
    848         File file = ((FileNode)path.getLastPathComponent()).getFile();
    849         if(file == null) return;
    850        
    851         if (file.isDirectory() && tree.isCollapsed(path)) {
    852             vk_left_pressed = true;
    853         }
    854         }
    855     }   
    856     }
    857    
    858754    /** This provides a small prompt for gathering addition details about a special directory mapping such as its symbolic name.
    859755     * Used when creating a new shortcut to a folder */
Note: See TracChangeset for help on using the changeset viewer.