jdk/src/share/classes/javax/swing/plaf/synth/SynthSplitPaneDivider.java
author alexsch
Wed, 25 Sep 2013 17:08:31 +0400
changeset 20168 137788883a22
parent 5506 202f599c92aa
child 23697 e556a715949f
permissions -rw-r--r--
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth Reviewed-by: serb, alexsch Contributed-by: Alexander Stepanov <alexander.v.stepanov@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2005, 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 javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Synth's SplitPaneDivider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
class SynthSplitPaneDivider extends BasicSplitPaneDivider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public SynthSplitPaneDivider(BasicSplitPaneUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        super(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    protected void setMouseOver(boolean mouseOver) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        if (isMouseOver() != mouseOver) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        super.setMouseOver(mouseOver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        super.propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (e.getSource() == splitPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            if (e.getPropertyName() == JSplitPane.ORIENTATION_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                if (leftButton instanceof SynthArrowButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                    ((SynthArrowButton)leftButton).setDirection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                                       mapDirection(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                if (rightButton instanceof SynthArrowButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                    ((SynthArrowButton)rightButton).setDirection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                                       mapDirection(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        Graphics g2 = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        SynthContext context = ((SynthSplitPaneUI)splitPaneUI).getContext(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                               splitPane, Region.SPLIT_PANE_DIVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        bounds.x = bounds.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        SynthLookAndFeel.updateSubregion(context, g, bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        context.getPainter().paintSplitPaneDividerBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                          g, 0, 0, bounds.width, bounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                          splitPane.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        SynthPainter foreground = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        context.getPainter().paintSplitPaneDividerForeground(context, g, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                getWidth(), getHeight(), splitPane.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // super.paint(g2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        for (int counter = 0; counter < getComponentCount(); counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            Component child = getComponent(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            Rectangle childBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            Graphics childG = g.create(childBounds.x, childBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                       childBounds.width, childBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            child.paint(childG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            childG.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        g2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private int mapDirection(boolean isLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (isLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                return SwingConstants.WEST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            return SwingConstants.NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            return SwingConstants.EAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return SwingConstants.SOUTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Creates and return an instance of JButton that can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * collapse the left component in the split pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected JButton createLeftOneTouchButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        SynthArrowButton b = new SynthArrowButton(SwingConstants.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        int oneTouchSize = lookupOneTouchSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        b.setName("SplitPaneDivider.leftOneTouchButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        b.setFocusPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        b.setBorderPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        b.setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        b.setDirection(mapDirection(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private int lookupOneTouchSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return DefaultLookup.getInt(splitPaneUI.getSplitPane(), splitPaneUI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
              "SplitPaneDivider.oneTouchButtonSize", ONE_TOUCH_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Creates and return an instance of JButton that can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * collapse the right component in the split pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected JButton createRightOneTouchButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        SynthArrowButton b = new SynthArrowButton(SwingConstants.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        int oneTouchSize = lookupOneTouchSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        b.setName("SplitPaneDivider.rightOneTouchButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        b.setFocusPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        b.setBorderPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        b.setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        b.setDirection(mapDirection(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
}