Changeset 11601


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).

Location:
trunk/gli/src/org/greenstone/gatherer/gui
Files:
3 edited

Legend:

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

    r10604 r11601  
    141141    collection_tree.setRootVisible(false);
    142142
    143     KeyListenerImpl key_listener = new KeyListenerImpl();
    144     collection_tree.addKeyListener(key_listener);
    145143    JScrollPane collection_scroll = new JScrollPane(collection_tree);
    146144
     
    388386        if (selected_metadata_value_tree_node != null) {
    389387        metadata_value_table_pane.setMetadataValueTextFieldValue(selected_metadata_value_tree_node.getFullValue());
    390         }
    391     }
    392     }
    393 
    394 
    395     /** This class listens for certain key presses, such as [Up] or [Down], -copied from Gather Pane */
    396     private class KeyListenerImpl
    397     extends KeyAdapter {
    398     private boolean vk_left_pressed = false;
    399     /** 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). */
    400     public void keyReleased(KeyEvent event) {
    401         ///ystem.err.println("Key Release detected. " + event.getKeyCode());
    402         if (event.getKeyCode() == KeyEvent.VK_UP || event.getKeyCode() == KeyEvent.VK_DOWN) {
    403         DragTree tree = (DragTree)event.getSource();
    404         // we need to manually do the up and down selections
    405         boolean up = (event.getKeyCode() == KeyEvent.VK_UP);
    406         int current_row = tree.getLeadSelectionRow();
    407         tree.setImmediate(true);
    408         if (up) {
    409             if (current_row > 0) {
    410             tree.clearSelection();
    411             tree.setSelectionRow(current_row-1);
    412             }
    413         } else {
    414             if (current_row < tree.getRowCount()-1){
    415             tree.clearSelection();
    416             tree.setSelectionRow(current_row+1);
    417             }
    418         }
    419         tree.setImmediate(false);
    420         }
    421         else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
    422         // left key on a file shifts the selection to the parent folder
    423         DragTree tree = (DragTree)event.getSource();
    424         TreePath path = tree.getLeadSelectionPath();
    425         if(path != null) {
    426             File file = ((CollectionTreeNode) path.getLastPathComponent()).getFile();
    427             if(file != null) {
    428             if (file.isFile() || vk_left_pressed) {
    429                 vk_left_pressed = false;
    430                 TreePath parent_path = path.getParentPath();
    431                 if (parent_path != null && parent_path.getParentPath() != null) {
    432                 // if this file is in the top level folder, don't move the focus
    433                 tree.setImmediate(true);
    434                 tree.clearSelection();
    435                 tree.setSelectionPath(parent_path);
    436                 tree.setImmediate(false);
    437                 }
    438             }
    439             }
    440         }
    441         }       
    442     }
    443 
    444     // 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.
    445     public void keyPressed(KeyEvent event) {
    446         if (event.getKeyCode() == KeyEvent.VK_LEFT) {
    447         // left key on  closed directory shifts the selection to the parent folder
    448         DragTree tree = (DragTree)event.getSource();
    449         TreePath path = tree.getLeadSelectionPath();
    450         if(path == null) return;
    451         File file = ((CollectionTreeNode) path.getLastPathComponent()).getFile();
    452         if(file == null) return;
    453        
    454         if (file.isDirectory() && tree.isCollapsed(path)) {
    455             vk_left_pressed = true;
    456         }       
    457388        }
    458389    }
  • 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 */
  • trunk/gli/src/org/greenstone/gatherer/gui/tree/DragTree.java

    r11367 r11601  
    44import java.awt.datatransfer.*;
    55import java.awt.dnd.*;
     6import java.awt.event.*;
    67import java.awt.geom.AffineTransform;
    78import java.awt.image.BufferedImage;
     
    99100
    100101    // Connection
     102    addKeyListener(new DragTreeKeyListener());
    101103    addTreeSelectionListener(this);
    102104
     
    699701    return valid;
    700702    }
     703
     704
     705    /** This class listens for certain key presses, such as [Enter] or [Delete], and responds appropriately. */
     706    private class DragTreeKeyListener
     707    extends KeyAdapter
     708    {
     709    private boolean vk_left_pressed = false;
     710    /** 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). */
     711    public void keyReleased(KeyEvent event) {
     712        ///ystem.err.println("Key Release detected. " + event.getKeyCode());
     713        if(event.getKeyCode() == KeyEvent.VK_DELETE) {
     714        // Get the selected files from the tree and removal them using the default dnd removal method.
     715        // Find the active tree (you've made selections in).
     716        DragTree tree = (DragTree) group.getActive();
     717        // Fudge things a bit
     718        group.setSource(tree);
     719        // Determine the selection.
     720        TreePath paths[] = tree.getSelectionPaths();
     721        if(paths != null) {
     722            FileNode[] source_nodes = new FileNode[paths.length];
     723            for(int i = 0; i < source_nodes.length; i++) {
     724            source_nodes[i] = (FileNode) paths[i].getLastPathComponent();
     725            }
     726            Gatherer.f_man.action(tree, source_nodes, Gatherer.recycle_bin, null);
     727            source_nodes = null;
     728        }
     729        }
     730        else if(event.getKeyCode() == KeyEvent.VK_ENTER) {
     731        // Get the first selected file.
     732        DragTree tree = (DragTree)event.getSource();
     733        TreePath path = tree.getSelectionPath();
     734        if(path != null) {
     735            File file = ((FileNode)path.getLastPathComponent()).getFile();
     736            if (file != null && file.isFile()) {
     737            Gatherer.f_man.openFileInExternalApplication(file);
     738            }
     739            else {
     740            if(!tree.isExpanded(path)) {
     741                tree.expandPath(path);
     742            }
     743            else {
     744                tree.collapsePath(path);
     745            }
     746            }
     747        }
     748        } else if (event.getKeyCode() == KeyEvent.VK_UP || event.getKeyCode() == KeyEvent.VK_DOWN) {
     749        DragTree tree = (DragTree)event.getSource();
     750        // we need to manually do the up and down selections
     751        boolean up = (event.getKeyCode() == KeyEvent.VK_UP);
     752        int current_row = tree.getLeadSelectionRow();
     753        tree.setImmediate(true);
     754        if (up) {
     755            if (current_row > 0) {
     756            tree.clearSelection();
     757            tree.setSelectionRow(current_row-1);
     758            }
     759        } else {
     760            if (current_row < tree.getRowCount()-1){
     761            tree.clearSelection();
     762            tree.setSelectionRow(current_row+1);
     763            }
     764        }
     765        tree.setImmediate(false);
     766        } else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
     767        // left key on a file shifts the selection to the parent folder
     768        DragTree tree = (DragTree)event.getSource();
     769        TreePath path = tree.getLeadSelectionPath();
     770        if(path != null) {
     771            File file = ((FileNode)path.getLastPathComponent()).getFile();
     772            if(file != null) {
     773            if (file.isFile() || vk_left_pressed) {
     774                vk_left_pressed = false;
     775                TreePath parent_path = path.getParentPath();
     776                if (parent_path != null && parent_path.getParentPath() != null) {
     777                // if this file is in the top level folder, don't move the focus
     778                tree.setImmediate(true);
     779                tree.clearSelection();
     780                tree.setSelectionPath(parent_path);
     781                tree.setImmediate(false);
     782                }
     783            }
     784            }
     785        }
     786        }
     787    }
     788   
     789    // 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.
     790    public void keyPressed(KeyEvent event) {
     791        if (event.getKeyCode() == KeyEvent.VK_LEFT) {
     792        // left key on  closed directory shifts the selection to the parent folder
     793        DragTree tree = (DragTree)event.getSource();
     794        TreePath path = tree.getLeadSelectionPath();
     795        if(path == null) return;
     796        File file = ((FileNode)path.getLastPathComponent()).getFile();
     797        if(file == null) return;
     798       
     799        if (file.isDirectory() && tree.isCollapsed(path)) {
     800            vk_left_pressed = true;
     801        }
     802        }
     803    }
     804    }
    701805}
Note: See TracChangeset for help on using the changeset viewer.