KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > menu > lib > BasicAcceleratorDescription


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.util.explorer.core.menu.lib;
27
28 import org.objectweb.util.explorer.core.common.api.Description;
29 import org.objectweb.util.explorer.core.menu.api.AcceleratorDescription;
30
31 /**
32  * Basic implementation of the <code>AcceleratorDescription</code> interface.
33  *
34  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
35  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
36  *
37  * @version 0.1
38  */

39 public class BasicAcceleratorDescription
40   implements AcceleratorDescription
41 {
42
43     //==================================================================
44
//
45
// Internal States.
46
//
47
// ==================================================================
48

49     protected char char_=0;
50     protected boolean ctrlKey_ = false;
51     protected boolean altKey_ = false;
52     protected boolean shiftKey_ = false;
53     protected boolean metaKey_ = false;
54     
55     // ==================================================================
56
//
57
// Constructors.
58
//
59
// ==================================================================
60

61     // ==================================================================
62
//
63
// Internal methods.
64
//
65
// ==================================================================
66

67     protected boolean equals(BasicAcceleratorDescription accDesc){
68         if(accDesc!=null){
69             return char_==accDesc.char_
70                 && ctrlKey_==accDesc.ctrlKey_
71                 && altKey_==accDesc.altKey_
72                 && shiftKey_==accDesc.shiftKey_
73                 && metaKey_==accDesc.metaKey_;
74         }
75         return false;
76     }
77         
78     protected String JavaDoc getStringRepresentation(){
79         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
80         sb.append(ctrlKey_?"ctrl-":"");
81         sb.append(altKey_?"alt-":"");
82         sb.append(shiftKey_?"shift-":"");
83         sb.append(metaKey_?"meta-":"");
84         sb.append(Character.toUpperCase(char_));
85         return sb.toString();
86     }
87     
88     // ==================================================================
89
//
90
// Public methods for Description interface.
91
//
92
// ==================================================================
93

94     /* (non-Javadoc)
95      * @see org.objectweb.util.explorer.core.common.api.Description#getDescriptionType()
96      */

97     public String JavaDoc getDescriptionType() {
98         return Description.ACCELERATOR_DESCRIPTION;
99     }
100
101     /* (non-Javadoc)
102      * @see boolean#isNull()
103      */

104     public boolean isEmpty() {
105         return char_==0;
106     }
107     
108     // ==================================================================
109
//
110
// Public methods for AcceleratorDescription interface.
111
//
112
// ==================================================================
113

114     
115     /* (non-Javadoc)
116      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#setAcceleratorCharacter(char)
117      */

118     public void setAcceleratorCharacter(char car) {
119         char_ = car;
120     }
121
122     /* (non-Javadoc)
123      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#getAcceleratorCharacter()
124      */

125     public char getAcceleratorCharacter() {
126         return char_;
127     }
128
129     /* (non-Javadoc)
130      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#setCtrlKey(boolean)
131      */

132     public void setCtrlKey(boolean ctrlKey) {
133         ctrlKey_ = ctrlKey;
134     }
135
136     /* (non-Javadoc)
137      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#getCtrlKey()
138      */

139     public boolean getCtrlKey() {
140         return ctrlKey_;
141     }
142
143     /* (non-Javadoc)
144      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#setAltKey(boolean)
145      */

146     public void setAltKey(boolean altKey) {
147         altKey_ = altKey;
148     }
149
150     /* (non-Javadoc)
151      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#getAltKey()
152      */

153     public boolean getAltKey() {
154         return altKey_;
155     }
156
157     /* (non-Javadoc)
158      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#setShiftKey(boolean)
159      */

160     public void setShiftKey(boolean shiftKey) {
161         shiftKey_ = shiftKey;
162     }
163
164     /* (non-Javadoc)
165      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#getShiftKey()
166      */

167     public boolean getShiftKey() {
168         return shiftKey_;
169     }
170
171     /* (non-Javadoc)
172      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#setMetaKey(boolean)
173      */

174     public void setMetaKey(boolean metaKey) {
175         metaKey_ = metaKey;
176     }
177
178     /* (non-Javadoc)
179      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#getMetaKey()
180      */

181     public boolean getMetaKey() {
182         return metaKey_;
183     }
184
185     /* (non-Javadoc)
186      * @see org.objectweb.util.explorer.core.menu.api.AcceleratorDescription#getName()
187      */

188     public String JavaDoc getName() {
189         return getStringRepresentation();
190     }
191
192     // ==================================================================
193
//
194
// Public methods surcharging Object class.
195
//
196
// ==================================================================
197

198     /**
199      * Surcharging the Object.equals method.
200      * @see Object#equals(java.lang.Object)
201      */

202     public boolean equals(Object JavaDoc o){
203         if(o!=null && o instanceof BasicAcceleratorDescription){
204             return equals((BasicAcceleratorDescription)o);
205         }
206         return false;
207     }
208    
209     /**
210      * Return a String representation of a BasicAcceleratorDescription
211      * @see Object#toString()
212      */

213     public String JavaDoc toString(){
214         return "BasicAcceleratorDescription[value=" + getStringRepresentation() + "]";
215     }
216  
217 }
218
219
220
Popular Tags