jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java
author serb
Fri, 15 Jul 2011 19:23:03 +0400
changeset 10096 f9ac9a52952d
parent 5506 202f599c92aa
child 21270 8a0fc12b81a2
permissions -rw-r--r--
6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails Reviewed-by: art, dcherepanov, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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
public class XButtonPeer extends XComponentPeer implements ButtonPeer {
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    37
    private boolean pressed;
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    38
    private boolean armed;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private Insets focusInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private Insets borderInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private Insets contentAreaInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final static String propertyPrefix = "Button" + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    protected Color focusColor =  SystemColor.windowText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private boolean disposed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    String label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        return propertyPrefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        borderInsets = new Insets(2,2,2,2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        focusInsets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        contentAreaInsets = new Insets(3,3,3,3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public  XButtonPeer(Button target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        label = target.getLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        updateMotifColors(getPeerBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public  void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        synchronized (target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            disposed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public void  setLabel(java.lang.String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        updateMotifColors(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    void handleJavaMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        super.handleJavaMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
              if (XToolkit.isLeftMouseButton(e) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                  Button b = (Button) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                  if(b.contains(e.getX(), e.getY())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                      if (!isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                          // Disabled buttons ignore all input...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                          return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                      pressed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                      armed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                      repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
              if (XToolkit.isLeftMouseButton(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                  if (armed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                      action(e.getWhen(),e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                  pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                  armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
          case  MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
              if (pressed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                  armed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
              armed = false;
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void action(final long when, final int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                  ((Button)target).getActionCommand(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                  when, modifiers));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    void handleJavaKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
              if (e.getKeyCode() == KeyEvent.VK_SPACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
              {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                  pressed=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                  armed=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                  action(e.getWhen(),e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
              if (e.getKeyCode() == KeyEvent.VK_SPACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
              {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                  pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                  armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        FontMetrics fm = getFontMetrics(getPeerFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if ( label == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            label = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return new Dimension(fm.stringWidth(label) + 14,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                             fm.getHeight() + 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   198
    /**
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   199
     * This method is called from Toolkit Thread and so it should not call any
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   200
     * client code.
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   201
     */
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   202
    @Override
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   203
    void paintPeer(final Graphics g) {
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   204
        if (!disposed) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            Dimension size = getPeerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            g.setColor( getPeerBackground() );   /* erase the existing button remains */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            g.fillRect(0,0, size.width , size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            paintBorder(g,borderInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        borderInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                        size.width-(borderInsets.left+borderInsets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        size.height-(borderInsets.top+borderInsets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            Rectangle textRect,iconRect,viewRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            viewRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            viewRect.x = contentAreaInsets.left;
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   225
            viewRect.y = contentAreaInsets.top;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            String llabel = (label != null) ? label : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            // layout the text and icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            String text = SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                                             fm, llabel, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                                             SwingConstants.CENTER, SwingConstants.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                                             SwingConstants.CENTER, SwingConstants.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                                             viewRect, iconRect, textRect, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            Font f = getPeerFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            // perform UI specific press action, e.g. Windows L&F shifts text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (pressed && armed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                paintButtonPressed(g,target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            paintText(g, target, textRect, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                // paint UI specific focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                paintFocus(g,focusInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                           focusInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                           size.width-(focusInsets.left+focusInsets.right)-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                           size.height-(focusInsets.top+focusInsets.bottom)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public void paintBorder(Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        drawMotif3DRect(g, x, y, w-1, h-1, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        super.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        target.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    protected void paintFocus(Graphics g, int x, int y, int w, int h){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        g.setColor(focusColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        g.drawRect(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    protected void paintButtonPressed(Graphics g, Component b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        Dimension size = getPeerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        g.setColor(selectColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        g.fillRect(contentAreaInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                   contentAreaInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                   size.width-(contentAreaInsets.left+contentAreaInsets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                   size.height-(contentAreaInsets.top+contentAreaInsets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    protected void paintText(Graphics g, Component c, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        int mnemonicIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        /* Draw the Text */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if(isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            /*** paint the text normally */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            g.setColor(getPeerForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            /*** paint the text disabled ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            g.setColor(getPeerBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                                         textRect.x, textRect.y + fm.getAscent());
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   294
            g.setColor(getPeerBackground().darker());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                                         textRect.x - 1, textRect.y + fm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
}