Source code: com/virtuosotechnologies/lib/basiccommand/builder/SimpleLabelBuilderNode.java
1 /*
2 ================================================================================
3
4 FILE: SimpleLabelBuilderNode.java
5
6 PROJECT:
7
8 Virtuoso Utilities
9
10 CONTENTS:
11
12 A builder that creates a label
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.builder;
43
44
45 import javax.swing.JLabel;
46 import javax.swing.Icon;
47
48 import com.virtuosotechnologies.lib.command.CommandNode;
49 import com.virtuosotechnologies.lib.basiccommand.BasicCommandNode;
50 import com.virtuosotechnologies.lib.propertyset.PropertySet;
51 import com.virtuosotechnologies.lib.propertyset.PropertySetEvent;
52
53
54 /**
55 * A builder that creates a label
56 */
57 public class SimpleLabelBuilderNode
58 extends AbstractElementBuilderNode
59 {
60 /**
61 * Constructor
62 */
63 public SimpleLabelBuilderNode(
64 CommandNode commandNode)
65 {
66 this(commandNode, null, END_POSITION, null);
67 }
68
69
70 /**
71 * Constructor
72 */
73 public SimpleLabelBuilderNode(
74 CommandNode commandNode,
75 JLabel label)
76 {
77 this(commandNode, null, END_POSITION, label);
78 }
79
80
81 /**
82 * Constructor
83 */
84 protected SimpleLabelBuilderNode(
85 CommandNode commandNode,
86 AbstractBranchBuilderNode parent,
87 int index,
88 JLabel label)
89 {
90 super(commandNode, parent, index, label);
91 label = (JLabel)getElement();
92 Integer i = (Integer)commandNode.getValue(BasicCommandNode.MNEMONIC_CODE_PROPERTY);
93 if (i != null)
94 {
95 label.setDisplayedMnemonic(i.intValue());
96 }
97 label.setText((String)
98 commandNode.getValue(BasicCommandNode.NAME_PROPERTY));
99 label.setIcon((Icon)
100 commandNode.getValue(BasicCommandNode.SMALL_ICON_PROPERTY));
101 label.setToolTipText((String)
102 commandNode.getValue(BasicCommandNode.SHORT_DESCRIPTION_PROPERTY));
103 }
104
105
106 /**
107 * Model changed
108 */
109 public void propertySetChanged(
110 PropertySetEvent ev)
111 {
112 PropertySet properties = ev.getPropertySet();
113 JLabel label = (JLabel)getElement();
114 if (ev.getKey().equals(BasicCommandNode.MNEMONIC_CODE_PROPERTY))
115 {
116 if (ev.getNewValue() != null)
117 {
118 label.setDisplayedMnemonic(((Integer)ev.getNewValue()).intValue());
119 }
120 }
121 else if (ev.getKey().equals(BasicCommandNode.NAME_PROPERTY))
122 {
123 label.setText((String)ev.getNewValue());
124 }
125 else if (ev.getKey().equals(BasicCommandNode.SMALL_ICON_PROPERTY))
126 {
127 label.setIcon((Icon)ev.getNewValue());
128 }
129 else if (ev.getKey().equals(BasicCommandNode.SHORT_DESCRIPTION_PROPERTY))
130 {
131 label.setToolTipText((String)ev.getNewValue());
132 }
133 super.propertySetChanged(ev);
134 }
135
136
137 /**
138 * Override this method to create the initial element object.
139 */
140 protected Object createInitialElement()
141 {
142 return new JLabel();
143 }
144 }