1 /*
2 * Copyright 2006-2016 The JGUIraffe Team.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jguiraffe.gui.platform.swing.builder.components;
17
18 import javax.swing.JComponent;
19
20 import net.sf.jguiraffe.gui.builder.components.Color;
21 import net.sf.jguiraffe.gui.builder.components.WidgetHandler;
22
23 /**
24 * <p>
25 * A Swing specific implementation of the <code>WidgetHandler</code> interface.
26 * </p>
27 * <p>
28 * This implementation operates on an underlying <code>Component</code> object
29 * and provides access to some of its fundamental properties.
30 * </p>
31 *
32 * @author Oliver Heger
33 * @version $Id: SwingWidgetHandler.java 205 2012-01-29 18:29:57Z oheger $
34 */
35 class SwingWidgetHandler implements WidgetHandler
36 {
37
38 /** Stores the underlying widget. */
39 private final JComponent widget;
40
41 /**
42 * Creates a new instance of <code>SwingWidgetHandler</code> and initializes
43 * it with the wrapped component.
44 *
45 * @param component the underlying component
46 */
47 public SwingWidgetHandler(JComponent component)
48 {
49 widget = component;
50 }
51
52 /**
53 * Returns a reference to the underlying component.
54 *
55 * @return the underlying AWT component
56 */
57 public JComponent getComponent()
58 {
59 return widget;
60 }
61
62 /**
63 * Returns the background color of the underlying widget.
64 *
65 * @return the background color of the underlying widget
66 */
67 public Color getBackgroundColor()
68 {
69 return SwingComponentUtils.getBackgroundColor(getComponent());
70 }
71
72 /**
73 * Returns the foreground color of the underlying widget.
74 *
75 * @return the foreground color of the underlying widget
76 */
77 public Color getForegroundColor()
78 {
79 return SwingComponentUtils.getForegroundColor(getComponent());
80 }
81
82 /**
83 * Returns the underlying widget.
84 *
85 * @return the underlying widget
86 */
87 public Object getWidget()
88 {
89 return getComponent();
90 }
91
92 /**
93 * Returns a flag whether the underlying widget is visible.
94 *
95 * @return the visible flag of the underlying widget
96 */
97 public boolean isVisible()
98 {
99 return getComponent().isVisible();
100 }
101
102 /**
103 * Sets the background color of the underlying widget. The passed in
104 * platform independent <code>Color</code> object will be transformed into
105 * an AWT color object.
106 *
107 * @param c the new background color
108 */
109 public void setBackgroundColor(Color c)
110 {
111 SwingComponentUtils.setBackgroundColor(getComponent(), c);
112 }
113
114 /**
115 * Sets the foreground color of the underlying widget. The passed in
116 * platform independent <code>Color</code> object will be transformed into
117 * an AWT color object.
118 *
119 * @param c the new foreground color
120 */
121 public void setForegroundColor(Color c)
122 {
123 SwingComponentUtils.setForegroundColor(getComponent(), c);
124 }
125
126 /**
127 * Sets the visible flag of the underlying widget.
128 *
129 * @param f the new visible flag
130 */
131 public void setVisible(boolean f)
132 {
133 getComponent().setVisible(f);
134 }
135
136 /**
137 * Returns the tool tip of the associated component.
138 *
139 * @return the tool tip
140 */
141 public String getToolTip()
142 {
143 return SwingComponentUtils.getToolTip(getComponent());
144 }
145
146 /**
147 * Sets the tool tip of the associated component.
148 *
149 * @param tip the new tool tip text
150 */
151 public void setToolTip(String tip)
152 {
153 SwingComponentUtils.setToolTip(getComponent(), tip);
154 }
155
156 /**
157 * Returns the font of this widget. The font is directly obtained from the
158 * underlying Swing component.
159 *
160 * @return the font of this widget
161 */
162 public Object getFont()
163 {
164 return SwingComponentUtils.getFont(getComponent());
165 }
166
167 /**
168 * Sets the font of this widget. The passed in font object is passed to the
169 * underlying Swing component. It must be of type {@code java.awt.Font}.
170 *
171 * @param font the new font
172 */
173 public void setFont(Object font)
174 {
175 SwingComponentUtils.setFont(getComponent(), font);
176 }
177 }