jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSplitPaneUI.java
author psadhukhan
Fri, 27 Jan 2017 15:37:47 +0530
changeset 43516 f23912ce3308
parent 37698 4d798c873df0
child 43722 25ba19c20260
permissions -rw-r--r--
7190595: Nimbus: Test6657026 fails Reviewed-by: yan, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43516
f23912ce3308 7190595: Nimbus: Test6657026 fails
psadhukhan
parents: 37698
diff changeset
     2
 * Copyright (c) 2002, 2017, 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: 4848
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: 4848
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: 4848
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
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 javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
    39
 * Provides the Synth L&F UI delegate for
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    40
 * {@link javax.swing.JSplitPane}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Scott Violet
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    43
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    45
public class SynthSplitPaneUI extends BasicSplitPaneUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    46
                              implements PropertyChangeListener, SynthUI {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Keys to use for forward focus traversal when the JComponent is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * managing focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
43516
f23912ce3308 7190595: Nimbus: Test6657026 fails
psadhukhan
parents: 37698
diff changeset
    51
    private Set<KeyStroke> managingFocusForwardTraversalKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Keys to use for backward focus traversal when the JComponent is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * managing focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
43516
f23912ce3308 7190595: Nimbus: Test6657026 fails
psadhukhan
parents: 37698
diff changeset
    57
    private Set<KeyStroke> managingFocusBackwardTraversalKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Style for the JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Style for the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private SynthStyle dividerStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Creates a new SynthSplitPaneUI instance
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    71
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    72
     * @param x component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    73
     * @return the UI object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return new SynthSplitPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Installs the UI defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    82
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        updateStyle(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        setOrientation(splitPane.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        setContinuousLayout(splitPane.isContinuousLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        resetLayoutManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        /* Install the nonContinuousLayoutDivider here to avoid having to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        add/remove everything later. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if(nonContinuousLayoutDivider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            setNonContinuousLayoutDivider(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                createDefaultNonContinuousLayoutDivider(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            setNonContinuousLayoutDivider(nonContinuousLayoutDivider, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // focus forward traversal key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (managingFocusForwardTraversalKeys==null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   103
            managingFocusForwardTraversalKeys = new HashSet<KeyStroke>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            managingFocusForwardTraversalKeys.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                        managingFocusForwardTraversalKeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // focus backward traversal key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (managingFocusBackwardTraversalKeys==null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   111
            managingFocusBackwardTraversalKeys = new HashSet<KeyStroke>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            managingFocusBackwardTraversalKeys.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                        managingFocusBackwardTraversalKeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private void updateStyle(JSplitPane splitPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        SynthContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                          ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        SynthStyle oldDividerStyle = dividerStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        dividerStyle = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        context = getContext(splitPane, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            Object value = style.get(context, "SplitPane.size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            if (value == null) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   133
                value = Integer.valueOf(6);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            LookAndFeel.installProperty(splitPane, "dividerSize", value);
30919
cfa6e12d8951 7190544: Nimbus LaF: regression UnitTest failure
ssadetsky
parents: 25859
diff changeset
   136
            dividerSize = ((Number)value).intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            value = style.get(context, "SplitPane.oneTouchExpandable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                LookAndFeel.installProperty(splitPane, "oneTouchExpandable", value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (divider != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                splitPane.remove(divider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                divider.setDividerSize(splitPane.getDividerSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (style != oldStyle || dividerStyle != oldDividerStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            // Only way to force BasicSplitPaneDivider to reread the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // necessary properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (divider != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                splitPane.remove(divider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            divider = createDefaultDivider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            divider.setBasicSplitPaneUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            splitPane.add(divider, JSplitPane.DIVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Installs the event listeners for the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   167
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        splitPane.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Uninstalls the UI defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   176
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        SynthContext context = getContext(splitPane, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        dividerStyle.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        dividerStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        super.uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   192
     * Uninstalls the event listeners from the UI.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   194
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        splitPane.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   200
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   201
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   202
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   203
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   205
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private SynthContext getContext(JComponent c, int state) {
25100
d527cc827d7d 8043627: NPE in SynthContext in plugin mode
malenkov
parents: 23697
diff changeset
   209
        return SynthContext.getContext(c, style, state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    SynthContext getContext(JComponent c, Region region) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return getContext(c, region, getComponentState(c, region));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private SynthContext getContext(JComponent c, Region region, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (region == Region.SPLIT_PANE_DIVIDER) {
25100
d527cc827d7d 8043627: NPE in SynthContext in plugin mode
malenkov
parents: 23697
diff changeset
   218
            return SynthContext.getContext(c, region, dividerStyle, state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
25100
d527cc827d7d 8043627: NPE in SynthContext in plugin mode
malenkov
parents: 23697
diff changeset
   220
        return SynthContext.getContext(c, region, style, state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    private int getComponentState(JComponent c, Region subregion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        int state = SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (divider.isMouseOver()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            state |= MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   232
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   233
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   234
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   235
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            updateStyle((JSplitPane)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Creates the default divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   245
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public BasicSplitPaneDivider createDefaultDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        SynthSplitPaneDivider divider = new SynthSplitPaneDivider(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        divider.setDividerSize(splitPane.getDividerSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return divider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   253
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   254
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   255
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   256
    @Override
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   257
    @SuppressWarnings("serial") // anonymous class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    protected Component createDefaultNonContinuousLayoutDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return new Canvas() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                paintDragDivider(g, 0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   266
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   267
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   268
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   269
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   270
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   271
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   272
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   273
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   274
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   275
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   276
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   277
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   278
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        context.getPainter().paintSplitPaneBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                          g, 0, 0, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   288
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   289
     * Paints the specified component according to the Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   290
     * <p>This method is not used by Synth Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   291
     * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   292
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   293
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   294
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   295
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   296
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   297
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   304
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   305
     * Paints the specified component. This implementation does nothing.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   306
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   307
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   308
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   309
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   310
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // This is done to update package private variables in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // BasicSplitPaneUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        super.paint(g, splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   317
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   318
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   319
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   320
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        context.getPainter().paintSplitPaneBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private void paintDragDivider(Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        SynthContext context = getContext(splitPane,Region.SPLIT_PANE_DIVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                   MOUSE_OVER) | PRESSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        Shape oldClip = g.getClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        g.clipRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        context.getPainter().paintSplitPaneDragDivider(context, g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                           splitPane.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        g.setClip(oldClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   337
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   338
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   339
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   340
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public void finishedPaintingChildren(JSplitPane jc, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if(jc == splitPane && getLastDragLocation() != -1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                              !isContinuousLayout() && !draggingHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if(jc.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                paintDragDivider(g, getLastDragLocation(), 0, dividerSize - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                 splitPane.getHeight() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                paintDragDivider(g, 0, getLastDragLocation(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                 splitPane.getWidth() - 1, dividerSize - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
}