KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > nbprefuse > NbFocusControl


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  * NbFocusControl.java
21  *
22  * Created on March 26, 2006, 7:15 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.xml.nbprefuse;
29
30 import java.awt.event.MouseEvent JavaDoc;
31 import prefuse.Visualization;
32 import prefuse.controls.FocusControl;
33 import prefuse.data.tuple.TupleSet;
34 import prefuse.util.ui.UILib;
35 import prefuse.visual.NodeItem;
36 import prefuse.visual.VisualItem;
37
38 /**
39  *
40  * @author Jeri Lockhart
41  */

42 public class NbFocusControl extends FocusControl{
43     
44     private String JavaDoc group = Visualization.FOCUS_ITEMS;
45     protected SelectionMode selectionMode = SelectionMode.MULTIPLE;
46     
47     public enum SelectionMode {SINGLE, MULTIPLE};
48     
49     /**
50      * Creates a new FocusControl that changes the focus to another item
51      * when that item is clicked once.
52      */

53     public NbFocusControl() {
54         super();
55         
56     }
57     
58     /**
59      * Creates a new FocusControl that changes the focus to another item
60      * when that item is clicked once.
61      * @param focusGroup the name of the focus group to use
62      */

63     public NbFocusControl(String JavaDoc focusGroup) {
64         super(focusGroup);
65     }
66     
67     /**
68      * Creates a new FocusControl that changes the focus when an item is
69      * clicked the specified number of times. A click value of zero indicates
70      * that the focus should be changed in response to mouse-over events.
71      * @param clicks the number of clicks needed to switch the focus.
72      */

73     public NbFocusControl(int clicks) {
74         super(clicks);
75     }
76     
77     /**
78      * Creates a new FocusControl that changes the focus when an item is
79      * clicked the specified number of times. A click value of zero indicates
80      * that the focus should be changed in response to mouse-over events.
81      * @param focusGroup the name of the focus group to use
82      * @param clicks the number of clicks needed to switch the focus.
83      */

84     public NbFocusControl(String JavaDoc focusGroup, int clicks) {
85         super(focusGroup, clicks);
86     }
87     
88     /**
89      * Creates a new FocusControl that changes the focus when an item is
90      * clicked the specified number of times. A click value of zero indicates
91      * that the focus should be changed in response to mouse-over events.
92      * @param clicks the number of clicks needed to switch the focus.
93      * @param act an action run to upon focus change
94      */

95     public NbFocusControl(int clicks, String JavaDoc act) {
96         super(clicks, act);
97     }
98     
99     /**
100      * Creates a new FocusControl that changes the focus when an item is
101      * clicked the specified number of times. A click value of zero indicates
102      * that the focus should be changed in response to mouse-over events.
103      * @param focusGroup the name of the focus group to use
104      * @param clicks the number of clicks needed to switch the focus.
105      * @param act an action run to upon focus change
106      */

107     public NbFocusControl(String JavaDoc focusGroup, int clicks, String JavaDoc act) {
108         super(focusGroup, clicks, act);
109     }
110     
111     
112     /**
113      * @see prefuse.controls.Control#itemClicked(prefuse.visual.VisualItem, java.awt.event.MouseEvent)
114      */

115     public void itemClicked(VisualItem item, MouseEvent JavaDoc e) {
116         if ( UILib.isButtonPressed(e, button) &&
117                 e.getClickCount() == ccount ) {
118 // if ( item != curFocus ) {
119
Visualization vis = item.getVisualization();
120                 TupleSet ts = vis.getFocusGroup(group);
121                 
122                 boolean ctrl = e.isControlDown();
123                 if ( !ctrl) {
124                     curFocus = item;
125                     ts.setTuple(item);
126                 } else if ( ts.containsTuple(item) ) {
127                     ts.removeTuple(item);
128                     // MouseoverActionControl sets MOUSEOVER to true
129
// Set MOUSEOVER to false so the node is
130
// rendered without MOUSEOVER color
131
// This mimics Windows selection behaviour for trees and
132
// lists.
133
if (item instanceof NodeItem &&
134                             item.canSetBoolean(AnalysisConstants.MOUSEOVER)){
135                         item.setBoolean(AnalysisConstants.MOUSEOVER, false);
136                     }
137                 } else {
138                     if (selectionMode == SelectionMode.MULTIPLE){
139                         ts.addTuple(item);
140                     } else {
141                         curFocus = item;
142                         ts.setTuple(item);
143                     }
144                 }
145                 runActivity(vis);
146 // }
147
}
148     }
149     
150     
151     
152     
153     protected void runActivity(Visualization vis) {
154         if ( activity != null ) {
155             vis.run(activity);
156         }
157     }
158     
159     public void setSelectionMode(SelectionMode mode){
160         this.selectionMode = mode;
161     }
162     
163     
164     
165     public SelectionMode getSelectionMode(){
166         return this.selectionMode;
167     }
168     
169 }
170
Popular Tags