jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/motif/MotifScrollPaneUI.java
author azvegint
Tue, 09 Sep 2014 16:08:34 +0400
changeset 26737 26e9206d1a6e
parent 25859 3317bb8137f4
child 31164 a61c96d50ddd
permissions -rw-r--r--
8057770: api/javax_swing/JScrollPane/indexTGF.html#UpdateUI failed with MotifLookAndFeel on all platform Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26737
26e9206d1a6e 8057770: api/javax_swing/JScrollPane/indexTGF.html#UpdateUI failed with MotifLookAndFeel on all platform
azvegint
parents: 25859
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.basic.BasicScrollPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A CDE/Motif L&F implementation of ScrollPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class MotifScrollPaneUI extends BasicScrollPaneUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private final static Border vsbMarginBorderR = new EmptyBorder(0, 4, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final static Border vsbMarginBorderL = new EmptyBorder(0, 0, 0, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final static Border hsbMarginBorder = new EmptyBorder(4, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private CompoundBorder vsbBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private CompoundBorder hsbBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private PropertyChangeListener propertyChangeHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
26737
26e9206d1a6e 8057770: api/javax_swing/JScrollPane/indexTGF.html#UpdateUI failed with MotifLookAndFeel on all platform
azvegint
parents: 25859
diff changeset
    59
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected void installListeners(JScrollPane scrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        super.installListeners(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        propertyChangeHandler = createPropertyChangeHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        scrollPane.addPropertyChangeListener(propertyChangeHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
26737
26e9206d1a6e 8057770: api/javax_swing/JScrollPane/indexTGF.html#UpdateUI failed with MotifLookAndFeel on all platform
azvegint
parents: 25859
diff changeset
    66
    @Override
26e9206d1a6e 8057770: api/javax_swing/JScrollPane/indexTGF.html#UpdateUI failed with MotifLookAndFeel on all platform
azvegint
parents: 25859
diff changeset
    67
    protected void uninstallListeners(JComponent scrollPane) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        super.uninstallListeners(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        scrollPane.removePropertyChangeListener(propertyChangeHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private PropertyChangeListener createPropertyChangeHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return new PropertyChangeListener() {
26737
26e9206d1a6e 8057770: api/javax_swing/JScrollPane/indexTGF.html#UpdateUI failed with MotifLookAndFeel on all platform
azvegint
parents: 25859
diff changeset
    74
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                  String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                  if (propertyName.equals("componentOrientation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                        JScrollPane pane = (JScrollPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                        JScrollBar vsb = pane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                        if (vsb != null && vsbBorder != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                            vsb.getBorder() == vsbBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                            // The Border on the verticall scrollbar matches
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                            // what we installed, reset it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                            if (MotifGraphicsUtils.isLeftToRight(pane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                vsbBorder = new CompoundBorder(vsbMarginBorderR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                                vsbBorder.getInsideBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                vsbBorder = new CompoundBorder(vsbMarginBorderL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                                vsbBorder.getInsideBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                            vsb.setBorder(vsbBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
26737
26e9206d1a6e 8057770: api/javax_swing/JScrollPane/indexTGF.html#UpdateUI failed with MotifLookAndFeel on all platform
azvegint
parents: 25859
diff changeset
    98
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected void installDefaults(JScrollPane scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super.installDefaults(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (MotifGraphicsUtils.isLeftToRight(scrollpane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                vsbBorder = new CompoundBorder(vsbMarginBorderR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                               vsb.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                vsbBorder = new CompoundBorder(vsbMarginBorderL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                               vsb.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            vsb.setBorder(vsbBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            hsb.setBorder(hsbBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
26737
26e9206d1a6e 8057770: api/javax_swing/JScrollPane/indexTGF.html#UpdateUI failed with MotifLookAndFeel on all platform
azvegint
parents: 25859
diff changeset
   122
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    protected void uninstallDefaults(JScrollPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        super.uninstallDefaults(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if (vsb.getBorder() == vsbBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                vsb.setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            vsbBorder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            if (hsb.getBorder() == hsbBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                hsb.setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            hsbBorder = null;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return new MotifScrollPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}