jdk/src/solaris/classes/sun/awt/X11/XCheckboxPeer.java
author dav
Mon, 07 Apr 2008 16:52:51 +0400
changeset 439 3488710b02f8
parent 2 90ce3da70b43
child 3938 ef327bd847c0
permissions -rw-r--r--
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern Summary: Access to interface's fiels via their name rather then implementation Reviewed-by: volk, son
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.basic.BasicGraphicsUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
class XCheckboxPeer extends XComponentPeer implements CheckboxPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static final Logger log = Logger.getLogger("sun.awt.X11.XCheckboxPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final Insets focusInsets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final Insets borderInsets = new Insets(2,2,2,2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static final int checkBoxInsetFromText = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    //The check mark is less common than a plain "depressed" button,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    //so don't use the checkmark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // The checkmark shape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final double MASTER_SIZE = 128.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final Polygon MASTER_CHECKMARK = new Polygon(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        new int[] {1, 25,56,124,124,85, 64},  // X-coords
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        new int[] {59,35,67,  0, 12,66,123},  // Y-coords
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
      7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private Shape myCheckMark;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private Color focusColor = SystemColor.windowText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private boolean pressed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private boolean armed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private boolean selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Rectangle textRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private Rectangle focusRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private int checkBoxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private int cbX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private int cbY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    String label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    CheckboxGroup checkBoxGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    XCheckboxPeer(Checkbox target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        selected = target.getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        label = target.getLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if ( label == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            label = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        checkBoxGroup = target.getCheckboxGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        updateMotifColors(getPeerBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // Put this here so it is executed before layout() is called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // setFont() in XComponent.postInit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        focusRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public boolean isFocusable() { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // TODO: only need to paint the focus bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // TODO: only need to paint the focus bit?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    void handleJavaKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        int i = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        switch (i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
              keyPressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
              keyReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
          case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
              keyTyped(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void keyTyped(KeyEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (e.getKeyCode() == KeyEvent.VK_SPACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            //pressed=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            //armed=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            //selected=!selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            action(!selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            //repaint();  // Gets the repaint from action()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public void keyReleased(KeyEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void  setLabel(java.lang.String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if ( label == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            this.label = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    void handleJavaMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        super.handleJavaMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int i = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        switch (i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
              mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
              mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
          case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
              mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
              mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
          case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
              mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (XToolkit.isLeftMouseButton(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            Checkbox cb = (Checkbox) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (cb.contains(e.getX(), e.getY())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                if (log.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    log.finer("mousePressed() on " + target.getName() + " : armed = " + armed + ", pressed = " + pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                              + ", selected = " + selected + ", enabled = " + isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                if (!isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    // Disabled buttons ignore all input...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                if (!armed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    armed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                pressed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (log.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            log.finer("mouseReleased() on " + target.getName() + ": armed = " + armed + ", pressed = " + pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                      + ", selected = " + selected + ", enabled = " + isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        boolean sendEvent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (XToolkit.isLeftMouseButton(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            // TODO: Multiclick Threshold? - see BasicButtonListener.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (armed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                //selected = !selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                // send action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                //action(e.getWhen(),e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                sendEvent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if (sendEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                action(!selected);  // Also gets repaint in action()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (log.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            log.finer("mouseEntered() on " + target.getName() + ": armed = " + armed + ", pressed = " + pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                      + ", selected = " + selected + ", enabled = " + isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            armed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (log.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            log.finer("mouseExited() on " + target.getName() + ": armed = " + armed + ", pressed = " + pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                      + ", selected = " + selected + ", enabled = " + isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (armed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public void mouseClicked(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
         * Spacing (number of pixels between check mark and label text) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
         * currently set to 0, but in case it ever changes we have to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         * it. 8 is a heuristic number. Indicator size depends on font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         * height, so we don't need to include it in checkbox's height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         * calculation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        FontMetrics fm = getFontMetrics(getPeerFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        int wdth = fm.stringWidth(label) + getCheckboxSize(fm) + (2 * checkBoxInsetFromText) + 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        int hght = Math.max(fm.getHeight() + 8, 15);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return new Dimension(wdth, hght);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    private int getCheckboxSize(FontMetrics fm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        // the motif way of sizing is a bit inscutible, but this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // is a fair approximation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return (fm.getHeight() * 76 / 100) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        updateMotifColors(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Layout the checkbox/radio button and text label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public void layout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        Dimension size = getPeerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        Font f = getPeerFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        FontMetrics fm = getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        String text = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        checkBoxSize = getCheckboxSize(fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // Note - Motif appears to use an left inset that is slightly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // scaled to the checkbox/font size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        cbX = borderInsets.left + checkBoxInsetFromText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        cbY = size.height / 2 - checkBoxSize / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        int minTextX = borderInsets.left + 2 * checkBoxInsetFromText + checkBoxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // FIXME: will need to account for alignment?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // FIXME: call layout() on alignment changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        //textRect.width = fm.stringWidth(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        textRect.width = fm.stringWidth(text == null ? "" : text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        textRect.height = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        textRect.x = Math.max(minTextX, size.width / 2 - textRect.width / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        textRect.y = (size.height - textRect.height) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        focusRect.x = focusInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        focusRect.y = focusInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        focusRect.width = size.width-(focusInsets.left+focusInsets.right)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        focusRect.height = size.height-(focusInsets.top+focusInsets.bottom)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        double fsize = (double) checkBoxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        myCheckMark = AffineTransform.getScaleInstance(fsize / MASTER_SIZE, fsize / MASTER_SIZE).createTransformedShape(MASTER_CHECKMARK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (g != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            //layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            Dimension size = getPeerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            Font f = getPeerFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            g.setColor(getPeerBackground());   // erase the existing button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            g.fillRect(0,0, size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (label != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                paintText(g, textRect, label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            if (hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                paintFocus(g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                           focusRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                           focusRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                           focusRect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                           focusRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            // Paint the checkbox or radio button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (checkBoxGroup == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                paintCheckbox(g, cbX, cbY, checkBoxSize, checkBoxSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                paintRadioButton(g, cbX, cbY, checkBoxSize, checkBoxSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    // You'll note this looks suspiciously like paintBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public void paintCheckbox(Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                              int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        boolean useBufferedImage = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        BufferedImage buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        Graphics2D g2 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        int rx = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        int ry = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (!(g instanceof Graphics2D)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            // Fix for 5045936. While printing, g is an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            //   sun.print.ProxyPrintGraphics which extends Graphics. So
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            //   we use a separate buffered image and its graphics is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            //   always Graphics2D instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            buffer = graphicsConfig.createCompatibleImage(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            g2 = buffer.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            useBufferedImage = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            rx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            ry = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            g2 = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            drawMotif3DRect(g2, rx, ry, w-1, h-1, armed | selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            // then paint the check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            g2.setColor((armed | selected) ? selectColor : getPeerBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            g2.fillRect(rx+1, ry+1, w-2, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if (armed | selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                //Paint the check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                // FIXME: is this the right color?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                g2.setColor(getPeerForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                AffineTransform af = g2.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                g2.setTransform(AffineTransform.getTranslateInstance(rx,ry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                g2.fill(myCheckMark);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                g2.setTransform(af);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            if (useBufferedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                g2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (useBufferedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            g.drawImage(buffer, x, y, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        super.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        target.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public void paintRadioButton(Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        g.setColor((armed | selected) ? darkShadow : lightShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        g.drawArc(x-1, y-1, w+2, h+2, 45, 180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        g.setColor((armed | selected) ? lightShadow : darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        g.drawArc(x-1, y-1, w+2, h+2, 45, -180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (armed | selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            g.setColor(selectColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            g.fillArc(x+1, y+1, w-1, h-1, 0, 360);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    protected void paintText(Graphics g, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        int mnemonicIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if(isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            /*** paint the text normally */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            g.setColor(getPeerForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            /*** paint the text disabled ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            g.setColor(getPeerBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                                                         textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            g.setColor(getPeerBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                                         textRect.x - 1, textRect.y + fm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    // TODO: copied directly from XButtonPeer.  Should probabaly be shared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    protected void paintFocus(Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        g.setColor(focusColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        g.drawRect(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public void setState(boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (selected != state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            selected = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public void setCheckboxGroup(CheckboxGroup g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        // If changed from grouped/ungrouped, need to repaint()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        checkBoxGroup = g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    // From MCheckboxPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    void action(boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        final Checkbox cb = (Checkbox)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        final boolean newState = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        XToolkit.executeOnEventHandlerThread(cb, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    CheckboxGroup cbg = checkBoxGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    // Bugid 4039594. If this is the current Checkbox in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    // a CheckboxGroup, then return to prevent deselection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    // Otherwise, it's logical state will be turned off,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    // but it will appear on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    if ((cbg != null) && (cbg.getSelectedCheckbox() == cb) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        cb.getState()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                        //inUpCall = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        cb.setState(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    // All clear - set the new state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    cb.setState(newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    notifyStateChanged(newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    void notifyStateChanged(boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        Checkbox cb = (Checkbox) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        ItemEvent e = new ItemEvent(cb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                                    ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                    cb.getLabel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                    state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
}