2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
43
package org.netbeans.modules.form.fakepeer;
49
* @author Tran Duc Trung
51
class FakeCheckboxPeer extends FakeComponentPeer
53
FakeCheckboxPeer(Checkbox target) {
57
Component createDelegate() {
58
return new Delegate();
61
public void setState(boolean state) {
64
public void setCheckboxGroup(CheckboxGroup g) {
67
public void setLabel(String label) {
74
private class Delegate extends Component
77
// this.setBackground(SystemColor.control);
78
this.setForeground(SystemColor.controlText);
81
public void paint(Graphics g) {
82
Checkbox target = (Checkbox) _target;
83
Dimension sz = target.getSize();
85
int by = (sz.height - BOX_H) / 2;
87
g.setColor(target.getBackground());
88
g.fillRect(0, 0, sz.width, sz.height);
90
String label = target.getLabel();
93
g.setFont(target.getFont());
95
FontMetrics fm = g.getFontMetrics();
96
int h = fm.getHeight() - fm.getDescent(),
98
y = (sz.height - h) / 2 + h - 2;
100
if (target.isEnabled()) {
101
g.setColor(target.getForeground());
104
g.setColor(SystemColor.controlLtHighlight);
105
g.drawString(label, x+1, y+1);
106
g.setColor(SystemColor.controlShadow);
109
g.drawString(label, x, y);
113
// the check-box (Windows like - lowered, white background)
115
if (target.getCheckboxGroup() == null) {
116
g.setColor(SystemColor.window);
117
FakePeerUtils.drawLoweredBox(g,bx,by,BOX_W,BOX_H);
119
if (target.getState()) { // checkbox is checked
120
g.setColor(SystemColor.controlText);
121
for (int i=1; i < drCheckPosX_W.length; i++)
122
g.drawLine(drCheckPosX_W[i-1]+bx,drCheckPosY_W[i-1]+by,
123
drCheckPosX_W[i]+bx,drCheckPosY_W[i]+by);
126
else { // radio button
127
if (radButtIcon1 == null || radButtIcon2 == null)
129
g.drawImage(target.getState() ? radButtIcon2:radButtIcon1, bx+1, by+1, this);
133
public Dimension getMinimumSize() {
134
String label = ((Checkbox)_target).getLabel();
136
FontMetrics fm = this.getFontMetrics(this.getFont());
137
int w = fm.stringWidth(label);
138
int h = fm.getHeight();
140
return new Dimension(w + 6+BOX_W+4, h + 4);
143
void initRBImages() {
144
Toolkit toolkit = Toolkit.getDefaultToolkit();
145
java.net.URL source = this.getClass().getResource("radbutt1.gif");
146
radButtIcon1 = toolkit.getImage(source);
147
source = this.getClass().getResource("radbutt2.gif");
148
radButtIcon2 = toolkit.getImage(source);
150
MediaTracker mt = new MediaTracker(this);
151
mt.addImage(radButtIcon1,0);
152
mt.addImage(radButtIcon2,1);
155
} catch (java.lang.InterruptedException e) {
160
private static final int BOX_W = 16, BOX_H = 16;
161
private static final int[] drCheckPosX_W = { 4,6,10,10,6,4,4,6,10 };
162
private static final int[] drCheckPosY_W = { 6,8,4,5,9,7,8,10,6 };
164
private static Image radButtIcon1 = null;
165
private static Image radButtIcon2 = null;