Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/virtuosotechnologies/lib/basiccommand/BasicCommandNode.java


1   /*
2   ================================================================================
3   
4     FILE:  BasicCommandNode.java
5     
6     PROJECT:
7     
8       Virtuoso Utilities
9     
10    CONTENTS:
11    
12      Base class for CommandNode implementations in basiccommand
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.lib.basiccommand;
43  
44  
45  import javax.swing.KeyStroke;
46  import javax.swing.Icon;
47  
48  import com.virtuosotechnologies.lib.command.CommandNode;
49  import com.virtuosotechnologies.lib.command.AbstractCommandNode;
50  import com.virtuosotechnologies.lib.command.CommandNodeFlavor;
51  import com.virtuosotechnologies.lib.propertyset.PropertySet;
52  import com.virtuosotechnologies.lib.propertyset.BasicPropertySet;
53  import com.virtuosotechnologies.lib.base.ClassConstrainedKey;
54  import com.virtuosotechnologies.lib.base.UniqueClassConstrainedKey;
55  import com.virtuosotechnologies.lib.util.ObjectUtils;
56  
57  
58  /**
59   * Base class for CommandNode implementations in basiccommand
60   */
61  public abstract class BasicCommandNode
62  extends AbstractCommandNode
63  {
64    /**
65     * Property key for the command name property.
66     */
67    public static final ClassConstrainedKey NAME_PROPERTY =
68      new UniqueClassConstrainedKey("Name", String.class);
69    
70    /**
71     * Property key for the short description property.
72     */
73    public static final ClassConstrainedKey SHORT_DESCRIPTION_PROPERTY =
74      new UniqueClassConstrainedKey("ShortDescription", String.class);
75    
76    /**
77     * Property key for the long description property.
78     */
79    public static final ClassConstrainedKey LONG_DESCRIPTION_PROPERTY =
80      new UniqueClassConstrainedKey("LongDescription", String.class);
81    
82    /**
83     * Property key for the keyboard accelerator property.
84     */
85    public static final ClassConstrainedKey ACCELERATOR_KEYSTROKE_PROPERTY =
86      new UniqueClassConstrainedKey("AcceleratorKeystroke", KeyStroke.class);
87    
88    /**
89     * Property key for the keyboard mnemonic property.
90     */
91    public static final ClassConstrainedKey MNEMONIC_CODE_PROPERTY =
92      new UniqueClassConstrainedKey("MnemonicKey", Integer.class);
93    
94    /**
95     * Property key for the icon property.
96     */
97    public static final ClassConstrainedKey SMALL_ICON_PROPERTY =
98      new UniqueClassConstrainedKey("SmallIcon", Icon.class);
99    
100   /**
101    * Property key for the "command disabled" property.
102    */
103   public static final ClassConstrainedKey DISABLED_PROPERTY =
104     new UniqueClassConstrainedKey("Disabled", Boolean.class);
105   
106   /**
107    * Property key for the "command hidden" property.
108    */
109   public static final ClassConstrainedKey HIDDEN_PROPERTY =
110     new UniqueClassConstrainedKey("Hidden", Boolean.class);
111   
112   /**
113    * Property key for the selection state property.
114    */
115   public static final ClassConstrainedKey SELECTION_STATE_PROPERTY =
116     new UniqueClassConstrainedKey("SelectionState", Boolean.class);
117   
118   /**
119    * Property key for the selected child property.
120    */
121   public static final ClassConstrainedKey SELECTED_CHILD_PROPERTY =
122     new UniqueClassConstrainedKey("SelectedChild", CommandNode.class);
123   
124   /**
125    * Property key for the command name when selected property.
126    */
127   public static final ClassConstrainedKey SELECTED_NAME_PROPERTY =
128     new UniqueClassConstrainedKey("SelectedName", String.class);
129   
130   /**
131    * Property key for the icon when selected property.
132    */
133   public static final ClassConstrainedKey SELECTED_SMALL_ICON_PROPERTY =
134     new UniqueClassConstrainedKey("SelectedSmallIcon", Icon.class);
135   
136   /**
137    * Property key for the icon when selected property.
138    */
139   public static final ClassConstrainedKey SELECTED_SHORT_DESCRIPTION_PROPERTY =
140     new UniqueClassConstrainedKey("SelectedShortDescription", String.class);
141   
142   
143   /**
144    * Null flavor. This flavor is defined to be a no-op. Builders must
145    * ignore CommandNodes with this flavor.
146    */
147   public static final CommandNodeFlavor NULL_FLAVOR =
148     new CommandNodeFlavor("null");
149   
150   /**
151    * Separator flavor.
152    */
153   public static final CommandNodeFlavor SEPARATOR_FLAVOR =
154     new CommandNodeFlavor("separator");
155   
156   /**
157    * Action-item flavor.
158    */
159   public static final CommandNodeFlavor ACTIONITEM_FLAVOR =
160     new CommandNodeFlavor("actionitem");
161   
162   /**
163    * Toggle-item flavor.
164    */
165   public static final CommandNodeFlavor TOGGLEITEM_FLAVOR =
166     new CommandNodeFlavor("toggleitem");
167   
168   /**
169    * Special toggle-item flavor used for appearance-changing items. Subflavor
170    * of TOGGLEITEM.
171    */
172   public static final CommandNodeFlavor APPEARANCECHANGING_TOGGLEITEM_FLAVOR =
173     new CommandNodeFlavor("appearancetoggleitem", TOGGLEITEM_FLAVOR);
174   
175   /**
176    * Group flavor.
177    */
178   public static final CommandNodeFlavor GROUP_FLAVOR =
179     new CommandNodeFlavor("group");
180   
181   /**
182    * Container flavor.
183    */
184   public static final CommandNodeFlavor CONTAINER_FLAVOR =
185     new CommandNodeFlavor("container");
186   
187   /**
188    * Radio mutex flavor. An "abstract" flavor never used directly, but it is
189    * a parent of all flavors that indicate radio mutexes.
190    */
191   public static final CommandNodeFlavor RADIOMUTEX_FLAVOR =
192     new CommandNodeFlavor("radiomutex");
193   
194   /**
195    * Radio group flavor. Subflavor of RADIOMUTEX and GROUP.
196    */
197   public static final CommandNodeFlavor RADIOGROUP_FLAVOR =
198     new CommandNodeFlavor("radiogroup", RADIOMUTEX_FLAVOR, GROUP_FLAVOR);
199   
200   /**
201    * Radio container flavor. Subflavor of RADIOMUTEX and CONTAINER.
202    */
203   public static final CommandNodeFlavor RADIOCONTAINER_FLAVOR =
204     new CommandNodeFlavor("radiocontainer", RADIOMUTEX_FLAVOR, CONTAINER_FLAVOR);
205   
206   
207   private static PropertySet defaultProperties_;
208   static
209   {
210     defaultProperties_ = new BasicPropertySet();
211     defaultProperties_.putValue(NAME_PROPERTY, "");
212     defaultProperties_.putValue(DISABLED_PROPERTY, Boolean.FALSE);
213     defaultProperties_.putValue(HIDDEN_PROPERTY, Boolean.FALSE);
214     defaultProperties_.putValue(SELECTION_STATE_PROPERTY, Boolean.FALSE);
215   }
216   
217   
218   /**
219    * Constructor.
220    */
221   protected BasicCommandNode()
222   {
223     super(defaultProperties_);
224   }
225   
226   
227   /**
228    * Constructor.
229    */
230   protected BasicCommandNode(
231     PropertySet defaults)
232   {
233     super(defaults);
234   }
235   
236   
237   /**
238    * Convenience accessor for NAME_PROPERTY
239    */
240   public String getNameProperty()
241   {
242     return (String)getValue(NAME_PROPERTY);
243   }
244   
245   
246   /**
247    * Convenience mutator for NAME_PROPERTY
248    */
249   public void setNameProperty(
250     String value)
251   {
252     putValue(NAME_PROPERTY, value);
253   }
254   
255   
256   /**
257    * Convenience accessor for SHORT_DESCRIPTION_PROPERTY
258    */
259   public String getShortDescriptionProperty()
260   {
261     return (String)getValue(SHORT_DESCRIPTION_PROPERTY);
262   }
263   
264   
265   /**
266    * Convenience mutator for SHORT_DESCRIPTION_PROPERTY
267    */
268   public void setShortDescriptionProperty(
269     String value)
270   {
271     putValue(SHORT_DESCRIPTION_PROPERTY, value);
272   }
273   
274   
275   /**
276    * Convenience accessor for LONG_DESCRIPTION_PROPERTY
277    */
278   public String getLongDescriptionProperty()
279   {
280     return (String)getValue(LONG_DESCRIPTION_PROPERTY);
281   }
282   
283   
284   /**
285    * Convenience mutator for LONG_DESCRIPTION_PROPERTY
286    */
287   public void setLongDescriptionProperty(
288     String value)
289   {
290     putValue(LONG_DESCRIPTION_PROPERTY, value);
291   }
292   
293   
294   /**
295    * Convenience accessor for ACCELERATOR_KEYSTROKE_PROPERTY
296    */
297   public KeyStroke getAcceleratorKeystrokeProperty()
298   {
299     return (KeyStroke)getValue(ACCELERATOR_KEYSTROKE_PROPERTY);
300   }
301   
302   
303   /**
304    * Convenience mutator for ACCELERATOR_KEYSTROKE_PROPERTY
305    */
306   public void setAcceleratorKeystrokeProperty(
307     KeyStroke value)
308   {
309     putValue(ACCELERATOR_KEYSTROKE_PROPERTY, value);
310   }
311   
312   
313   /**
314    * Convenience accessor for MNEMONIC_CODE_PROPERTY
315    */
316   public int getMnemonicCodeProperty()
317   {
318     Integer ival = (Integer)getValue(MNEMONIC_CODE_PROPERTY);
319     return (ival == null ? 0 : ival.intValue());
320   }
321   
322   
323   /**
324    * Convenience mutator for MNEMONIC_CODE_PROPERTY
325    */
326   public void setMnemonicCodeProperty(
327     int value)
328   {
329     putValue(MNEMONIC_CODE_PROPERTY, new Integer(value));
330   }
331   
332   
333   /**
334    * Convenience accessor for SMALL_ICON_PROPERTY
335    */
336   public Icon getSmallIconProperty()
337   {
338     return (Icon)getValue(SMALL_ICON_PROPERTY);
339   }
340   
341   
342   /**
343    * Convenience mutator for SMALL_ICON_PROPERTY
344    */
345   public void setSmallIconProperty(
346     Icon value)
347   {
348     putValue(SMALL_ICON_PROPERTY, value);
349   }
350   
351   
352   /**
353    * Convenience accessor for DISABLED_PROPERTY
354    */
355   public boolean getDisabledProperty()
356   {
357     return Boolean.TRUE.equals(getValue(DISABLED_PROPERTY));
358   }
359   
360   
361   /**
362    * Convenience mutator for DISABLED_PROPERTY
363    */
364   public void setDisabledProperty(
365     boolean value)
366   {
367     putValue(DISABLED_PROPERTY, value ? Boolean.TRUE : Boolean.FALSE);
368   }
369   
370   
371   /**
372    * Convenience accessor for HIDDEN_PROPERTY
373    */
374   public boolean getHiddenProperty()
375   {
376     return Boolean.TRUE.equals(getValue(HIDDEN_PROPERTY));
377   }
378   
379   
380   /**
381    * Convenience mutator for HIDDEN_PROPERTY
382    */
383   public void setHiddenProperty(
384     boolean value)
385   {
386     putValue(HIDDEN_PROPERTY, value ? Boolean.TRUE : Boolean.FALSE);
387   }
388   
389   
390   /**
391    * Convenience accessor for SELECTION_STATE_PROPERTY
392    */
393   public boolean getSelectionStateProperty()
394   {
395     return Boolean.TRUE.equals(getValue(SELECTION_STATE_PROPERTY));
396   }
397   
398   
399   /**
400    * Convenience mutator for SELECTION_STATE_PROPERTY
401    */
402   public void setSelectionStateProperty(
403     boolean value)
404   {
405     putValue(SELECTION_STATE_PROPERTY, value ? Boolean.TRUE : Boolean.FALSE);
406   }
407   
408   
409   /**
410    * Convenience accessor for SELECTED_CHILD_PROPERTY
411    */
412   public CommandNode getSelectedChildProperty()
413   {
414     return (CommandNode)getValue(SELECTED_CHILD_PROPERTY);
415   }
416   
417   
418   /**
419    * Convenience mutator for SELECTED_CHILD_PROPERTY
420    */
421   public void setSelectedChildProperty(
422     CommandNode value)
423   {
424     putValue(SELECTED_CHILD_PROPERTY, value);
425   }
426   
427   
428   /**
429    * Convenience accessor for SELECTED_NAME_PROPERTY
430    */
431   public String getSelectedNameProperty()
432   {
433     return (String)getValue(SELECTED_NAME_PROPERTY);
434   }
435   
436   
437   /**
438    * Convenience mutator for SELECTED_NAME_PROPERTY
439    */
440   public void setSelectedNameProperty(
441     String value)
442   {
443     putValue(SELECTED_NAME_PROPERTY, value);
444   }
445   
446   
447   /**
448    * Convenience accessor for SELECTED_SMALL_ICON_PROPERTY
449    */
450   public Icon getSelectedSmallIconProperty()
451   {
452     return (Icon)getValue(SELECTED_SMALL_ICON_PROPERTY);
453   }
454   
455   
456   /**
457    * Convenience mutator for SELECTED_SMALL_ICON_PROPERTY
458    */
459   public void setSelectedSmallIconProperty(
460     Icon value)
461   {
462     putValue(SELECTED_SMALL_ICON_PROPERTY, value);
463   }
464   
465   
466   /**
467    * Convenience accessor for SELECTED_SHORT_DESCRIPTION_PROPERTY
468    */
469   public String getSelectedShortDescriptionProperty()
470   {
471     return (String)getValue(SELECTED_SHORT_DESCRIPTION_PROPERTY);
472   }
473   
474   
475   /**
476    * Convenience mutator for SELECTED_SHORT_DESCRIPTION_PROPERTY
477    */
478   public void setSelectedShortDescriptionProperty(
479     String value)
480   {
481     putValue(SELECTED_SHORT_DESCRIPTION_PROPERTY, value);
482   }
483   
484   
485   /**
486    * Get the default property set
487    */
488   public static PropertySet getDefaultProperties()
489   {
490     return defaultProperties_;
491   }
492   
493   
494   /**
495    * Dump subgraph to standard error
496    */
497   public static void dump(
498     CommandNode node)
499   {
500     dump(node, "");
501   }
502   
503   
504   /**
505    * Dump subgraph to standard error
506    */
507   private static void dump(
508     CommandNode node,
509     String indent)
510   {
511     System.err.println(indent+ObjectUtils.shortClassName(node)+' '+node.getValue(NAME_PROPERTY));
512     indent += "  ";
513     int numChildren = node.getNumChildren();
514     for (int i=0; i<numChildren; ++i)
515     {
516       dump(node.getNthChild(i), indent);
517     }
518   }
519 }