jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java
author serb
Thu, 24 Oct 2013 14:32:07 +0400
changeset 21270 8a0fc12b81a2
parent 10096 f9ac9a52952d
permissions -rw-r--r--
7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError Reviewed-by: anthony, art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
21270
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
     2
 * Copyright (c) 2002, 2013, 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
21270
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    82
    @Override
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    83
    public void setLabel(String label) {
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    84
        if (label == null) {
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    85
            label = "";
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    86
        }
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    87
        if (!label.equals(this.label)) {
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    88
            this.label = label;
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    89
            repaint();
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    90
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
21270
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 10096
diff changeset
    92
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        updateMotifColors(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    void handleJavaMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        super.handleJavaMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
              if (XToolkit.isLeftMouseButton(e) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                  Button b = (Button) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                  if(b.contains(e.getX(), e.getY())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                      if (!isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                          // Disabled buttons ignore all input...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                          return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                      pressed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                      armed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                      repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
              if (XToolkit.isLeftMouseButton(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                  if (armed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                      action(e.getWhen(),e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                  pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                  armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
          case  MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
              if (pressed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                  armed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
              armed = false;
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public void action(final long when, final int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                  ((Button)target).getActionCommand(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                  when, modifiers));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    void handleJavaKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
              if (e.getKeyCode() == KeyEvent.VK_SPACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
              {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                  pressed=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                  armed=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                  action(e.getWhen(),e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
              if (e.getKeyCode() == KeyEvent.VK_SPACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
              {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                  pressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                  armed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        FontMetrics fm = getFontMetrics(getPeerFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if ( label == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            label = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return new Dimension(fm.stringWidth(label) + 14,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                             fm.getHeight() + 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   205
    /**
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   206
     * 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
   207
     * client code.
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   208
     */
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   209
    @Override
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   210
    void paintPeer(final Graphics g) {
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   211
        if (!disposed) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            Dimension size = getPeerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            g.setColor( getPeerBackground() );   /* erase the existing button remains */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            g.fillRect(0,0, size.width , size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            paintBorder(g,borderInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        borderInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        size.width-(borderInsets.left+borderInsets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        size.height-(borderInsets.top+borderInsets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            Rectangle textRect,iconRect,viewRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            viewRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            viewRect.x = contentAreaInsets.left;
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   232
            viewRect.y = contentAreaInsets.top;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            String llabel = (label != null) ? label : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // layout the text and icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            String text = SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                                             fm, llabel, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                                             SwingConstants.CENTER, SwingConstants.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                                             SwingConstants.CENTER, SwingConstants.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                                             viewRect, iconRect, textRect, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            Font f = getPeerFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            // perform UI specific press action, e.g. Windows L&F shifts text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (pressed && armed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                paintButtonPressed(g,target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            paintText(g, target, textRect, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                // paint UI specific focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                paintFocus(g,focusInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                           focusInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                           size.width-(focusInsets.left+focusInsets.right)-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                           size.height-(focusInsets.top+focusInsets.bottom)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        flush();
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 paintBorder(Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        drawMotif3DRect(g, x, y, w-1, h-1, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    protected void paintFocus(Graphics g, int x, int y, int w, int h){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        g.setColor(focusColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        g.drawRect(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    protected void paintButtonPressed(Graphics g, Component b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        Dimension size = getPeerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        g.setColor(selectColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        g.fillRect(contentAreaInsets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                   contentAreaInsets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                   size.width-(contentAreaInsets.left+contentAreaInsets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                   size.height-(contentAreaInsets.top+contentAreaInsets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    protected void paintText(Graphics g, Component c, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        int mnemonicIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        /* Draw the Text */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if(isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            /*** paint the text normally */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            g.setColor(getPeerForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            /*** paint the text disabled ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            g.setColor(getPeerBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                                         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
   297
            g.setColor(getPeerBackground().darker());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                                         textRect.x - 1, textRect.y + fm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
}