KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > FocusTraversalManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * FocusTreversalManager.java
22  *
23  * Created on August 30, 2006, 6:26 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe;
30
31 import java.awt.AWTKeyStroke JavaDoc;
32 import java.awt.Component JavaDoc;
33 import java.awt.Container JavaDoc;
34 import java.awt.FocusTraversalPolicy JavaDoc;
35 import java.awt.KeyboardFocusManager JavaDoc;
36 import java.awt.event.KeyEvent JavaDoc;
37 import java.util.Collections JavaDoc;
38 import java.util.HashSet JavaDoc;
39 import java.util.Set JavaDoc;
40 import org.netbeans.modules.xml.schema.abe.visitors.TraversalVisitor;
41 import org.netbeans.modules.xml.schema.abe.visitors.UpTraversalVisitor;
42 import org.netbeans.modules.xml.schema.abe.visitors.BackTraversalVisitor;
43 import org.netbeans.modules.xml.schema.abe.visitors.FrontTraversalVisitor;
44 import org.netbeans.modules.xml.schema.abe.visitors.DownTraversalVisitor;
45
46 /**
47  *
48  * @author girix
49  */

50 public class FocusTraversalManager{
51     
52     public enum NavigationType{
53         FRONT,
54         BACK,
55         UP,
56         DOWN,
57         NONE
58     }
59     boolean metaKeyDown;
60     /** Creates a new instance of FocusTreversalManager */
61     InstanceUIContext context;
62     KeyEvent JavaDoc currentEvent;
63     ABEBaseDropPanel currentComp;
64     
65     public FocusTraversalManager(InstanceUIContext context) {
66         this.context = context;
67     }
68     
69     public void handleEvent(KeyEvent JavaDoc e, ABEBaseDropPanel panel) {
70         this.currentEvent = e;
71         this.currentComp = panel;
72         
73         NavigationType navType = getNavigationType(e);
74         ABEBaseDropPanel nextFocuComp = null;
75         TraversalVisitor tv = null;
76         switch(navType){
77             case FRONT:
78                 tv = new FrontTraversalVisitor(panel);
79                 break;
80             case BACK:
81                 tv = new BackTraversalVisitor(panel);
82                 break;
83             case UP:
84                 tv = new UpTraversalVisitor(panel);
85                 break;
86             case DOWN:
87                 tv = new DownTraversalVisitor(panel);
88                 break;
89             case NONE:
90                 return;
91         }
92         panel.accept(tv);
93         nextFocuComp = tv.getResult();
94         if(nextFocuComp != null){
95             if(e.isControlDown()){
96                 //multiple select
97
context.getComponentSelectionManager().addToSelectedComponents(nextFocuComp);
98             }else{
99                 //single select
100
context.getComponentSelectionManager().setSelectedComponent(nextFocuComp);
101             }
102             UIUtilities.scrollViewTo(nextFocuComp, context);
103         }
104         //dont let the scroll pane scroll around
105
e.consume();
106         
107     }
108     
109     public static NavigationType getNavigationType(KeyEvent JavaDoc e){
110         int keyCode = e.getKeyCode();
111         
112         if(keyCode == KeyEvent.VK_RIGHT)
113             return NavigationType.FRONT;
114         
115         /*if(keyCode == KeyEvent.VK_LEFT)
116             return NavigationType.BACK;
117         
118         if(keyCode == KeyEvent.VK_UP)
119             return NavigationType.UP;
120         
121         if(keyCode == KeyEvent.VK_DOWN)
122             return NavigationType.DOWN;*/

123         
124         return NavigationType.NONE;
125     }
126     
127     public boolean isFocusChangeEvent(KeyEvent JavaDoc e) {
128         if(getNavigationType(e) == NavigationType.NONE)
129             return false;
130         return true;
131     }
132     
133     
134     
135     
136 }
137
Popular Tags