jdk/src/share/classes/javax/swing/plaf/synth/SynthSplitPaneUI.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 20168 137788883a22
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2010, 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
/**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
    39
 * Provides the Synth L&F UI delegate for
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
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
    51
    private static 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
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
    57
    private static 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
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        context = getContext(splitPane, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            Object value = style.get(context, "SplitPane.size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (value == null) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   134
                value = Integer.valueOf(6);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            LookAndFeel.installProperty(splitPane, "dividerSize", value);
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
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Installs the event listeners for the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   168
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        splitPane.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Uninstalls the UI defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   177
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        SynthContext context = getContext(splitPane, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        dividerStyle.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        dividerStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        super.uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   195
     * Uninstalls the event listeners from the UI.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   197
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        splitPane.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   203
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   204
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   205
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   206
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   208
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private SynthContext getContext(JComponent c, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    SynthLookAndFeel.getRegion(c), style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    SynthContext getContext(JComponent c, Region region) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return getContext(c, region, getComponentState(c, region));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    private SynthContext getContext(JComponent c, Region region, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (region == Region.SPLIT_PANE_DIVIDER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return SynthContext.getContext(SynthContext.class, c, region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                           dividerStyle, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return SynthContext.getContext(SynthContext.class, c, region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                       style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    private int getComponentState(JComponent c, Region subregion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        int state = SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (divider.isMouseOver()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            state |= MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   238
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   239
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   240
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   241
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            updateStyle((JSplitPane)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Creates the default divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   251
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public BasicSplitPaneDivider createDefaultDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        SynthSplitPaneDivider divider = new SynthSplitPaneDivider(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        divider.setDividerSize(splitPane.getDividerSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return divider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   259
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   260
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   261
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   262
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    protected Component createDefaultNonContinuousLayoutDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return new Canvas() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                paintDragDivider(g, 0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   271
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   272
     * 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
   273
     * 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
   274
     * 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
   275
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   276
     * <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
   277
     * 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
   278
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   279
     * @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
   280
     * @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
   281
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   282
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   283
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        context.getPainter().paintSplitPaneBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                          g, 0, 0, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   294
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   295
     * 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
   296
     * <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
   297
     * 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
   298
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   299
     * @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
   300
     * @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
   301
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   302
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   303
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   311
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   312
     * Paints the specified component. This implementation does nothing.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   313
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   314
     * @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
   315
     * @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
   316
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   317
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        // This is done to update package private variables in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // BasicSplitPaneUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        super.paint(g, splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   324
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   325
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   326
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   327
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        context.getPainter().paintSplitPaneBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    private void paintDragDivider(Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        SynthContext context = getContext(splitPane,Region.SPLIT_PANE_DIVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                   MOUSE_OVER) | PRESSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        Shape oldClip = g.getClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        g.clipRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        context.getPainter().paintSplitPaneDragDivider(context, g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                           splitPane.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        g.setClip(oldClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   345
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   346
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   347
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1299
diff changeset
   348
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public void finishedPaintingChildren(JSplitPane jc, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if(jc == splitPane && getLastDragLocation() != -1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                              !isContinuousLayout() && !draggingHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            if(jc.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                paintDragDivider(g, getLastDragLocation(), 0, dividerSize - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                 splitPane.getHeight() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                paintDragDivider(g, 0, getLastDragLocation(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                 splitPane.getWidth() - 1, dividerSize - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
}