jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifScrollBarUI.java
author serb
Mon, 07 Apr 2014 15:34:27 +0400
changeset 24163 d56df89854c4
parent 5506 202f599c92aa
permissions -rw-r--r--
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F Reviewed-by: pchelko, flar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2014, 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 com.sun.java.swing.plaf.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    27
import java.awt.Dimension;
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    28
import java.awt.Graphics;
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    29
import java.awt.Insets;
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    30
import java.awt.Rectangle;
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    31
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    32
import javax.swing.JButton;
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    33
import javax.swing.JComponent;
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    34
import javax.swing.JScrollBar;
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    35
import javax.swing.plaf.ComponentUI;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.basic.BasicScrollBarUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    38
import static sun.swing.SwingUtilities2.drawHLine;
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    39
import static sun.swing.SwingUtilities2.drawVLine;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Implementation of ScrollBarUI for the Motif Look and Feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author Rich Schiavi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class MotifScrollBarUI extends BasicScrollBarUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return new MotifScrollBarUI();
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 Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        int dx = insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        int dy = insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            ? new Dimension(dx + 11, dy + 33)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            : new Dimension(dx + 33, dy + 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected JButton createDecreaseButton(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return new MotifScrollBarButton(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected JButton createIncreaseButton(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return new MotifScrollBarButton(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        g.setColor(trackColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    84
    public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    85
        if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        int w = thumbBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int h = thumbBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        g.translate(thumbBounds.x, thumbBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        g.setColor(thumbColor);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    94
        g.fillRect(0, 0, w - 1, h - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        g.setColor(thumbHighlightColor);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    97
        drawVLine(g, 0, 0, h - 1);
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
    98
        drawHLine(g, 1, w - 1, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        g.setColor(thumbLightShadowColor);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
   101
        drawHLine(g, 1, w - 1, h - 1);
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 5506
diff changeset
   102
        drawVLine(g, w - 1, 1, h - 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        g.translate(-thumbBounds.x, -thumbBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
}