jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
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-2003 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
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.SwingUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.SwingConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class XButtonPeer extends XComponentPeer implements ButtonPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    boolean pressed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    boolean armed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private Insets focusInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private Insets borderInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private Insets contentAreaInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private final static String propertyPrefix = "Button" + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    protected Color focusColor =  SystemColor.windowText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private boolean disposed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    String label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        return propertyPrefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        borderInsets = new Insets(2,2,2,2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        focusInsets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        contentAreaInsets = new Insets(3,3,3,3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public  XButtonPeer(Button target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        label = target.getLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        updateMotifColors(getPeerBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public  void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        synchronized (target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            disposed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public void  setLabel(java.lang.String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        paint(g,target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        updateMotifColors(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    void handleJavaMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super.handleJavaMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
              if (XToolkit.isLeftMouseButton(e) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                  Button b = (Button) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                  if(b.contains(e.getX(), e.getY())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                      if (!isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                          // Disabled buttons ignore all input...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                          return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                      pressed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                      armed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                      repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
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
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
              if (XToolkit.isLeftMouseButton(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                  if (armed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                      action(e.getWhen(),e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                  pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                  armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
          case  MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
              if (pressed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                  armed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
//                 repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
              armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
//                 repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void action(final long when, final int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                  ((Button)target).getActionCommand(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                  when, modifiers));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    void handleJavaKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
              if (e.getKeyCode() == KeyEvent.VK_SPACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
              {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                  pressed=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                  armed=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                  action(e.getWhen(),e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
              if (e.getKeyCode() == KeyEvent.VK_SPACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
              {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                  pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                  armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        FontMetrics fm = getFontMetrics(getPeerFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if ( label == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            label = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return new Dimension(fm.stringWidth(label) + 14,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                             fm.getHeight() + 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
       This method is called from Toolkit Thread and so it should not call any client code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public void paint(Graphics g, Component c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (!disposed && (g != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            Dimension size = getPeerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            g.setColor( getPeerBackground() );   /* erase the existing button remains */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            g.fillRect(0,0, size.width , size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            paintBorder(g,borderInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                        borderInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                        size.width-(borderInsets.left+borderInsets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        size.height-(borderInsets.top+borderInsets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            Rectangle textRect,iconRect,viewRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            viewRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            viewRect.x = contentAreaInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            viewRect.y = contentAreaInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            String llabel = (label != null) ? label : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            // layout the text and icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            String text = SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                                             fm, llabel, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                                             SwingConstants.CENTER, SwingConstants.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                                             SwingConstants.CENTER, SwingConstants.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                                             viewRect, iconRect, textRect, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            Font f = getPeerFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            // perform UI specific press action, e.g. Windows L&F shifts text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (pressed && armed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                paintButtonPressed(g,target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            paintText(g, target, textRect, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                // paint UI specific focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                paintFocus(g,focusInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                           focusInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                           size.width-(focusInsets.left+focusInsets.right)-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                           size.height-(focusInsets.top+focusInsets.bottom)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public void paintBorder(Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        drawMotif3DRect(g, x, y, w-1, h-1, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        super.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        target.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    protected void paintFocus(Graphics g, int x, int y, int w, int h){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        g.setColor(focusColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        g.drawRect(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    protected void paintButtonPressed(Graphics g, Component b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        Dimension size = getPeerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        g.setColor(selectColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        g.fillRect(contentAreaInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                   contentAreaInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                   size.width-(contentAreaInsets.left+contentAreaInsets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                   size.height-(contentAreaInsets.top+contentAreaInsets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    protected void paintText(Graphics g, Component c, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        int mnemonicIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        /* Draw the Text */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if(isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            /*** paint the text normally */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            g.setColor(getPeerForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            /*** paint the text disabled ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            g.setColor(getPeerBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                                         textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            g.setColor(c.getBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                                         textRect.x - 1, textRect.y + fm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
}