jdk/src/share/classes/sun/swing/DefaultLayoutStyle.java
author darcy
Thu, 30 Jan 2014 09:15:13 -0800
changeset 22618 927e4fe6cb24
parent 10104 c3cf1968e244
child 23010 6dadb192ad81
permissions -rw-r--r--
8033221: Fix serial lint warnings in sun.swing.* Reviewed-by: alexsch
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) 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
package sun.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.LayoutStyle.ComponentPlacement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * An implementation of <code>LayoutStyle</code> that returns 6 for related
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * components, otherwise 12.  This class also provides helper methods for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class DefaultLayoutStyle extends LayoutStyle {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final DefaultLayoutStyle INSTANCE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
            new DefaultLayoutStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public static LayoutStyle getInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        return INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public int getPreferredGap(JComponent component1, JComponent component2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            ComponentPlacement type, int position, Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (component1 == null || component2 == null || type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
10104
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents: 5506
diff changeset
    54
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents: 5506
diff changeset
    55
        checkPosition(position);
c3cf1968e244 7071166: LayoutStyle.getPreferredGap() - IAE is expected but not thrown
rupashka
parents: 5506
diff changeset
    56
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (type == ComponentPlacement.INDENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                (position == SwingConstants.EAST ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                 position == SwingConstants.WEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            int indent = getIndent(component1, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            if (indent > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                return indent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return (type == ComponentPlacement.UNRELATED) ? 12 : 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public int getContainerGap(JComponent component, int position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                               Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (component == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        checkPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Returns true if the classes identify a JLabel and a non-JLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * along the horizontal axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    protected boolean isLabelAndNonlabel(JComponent c1, JComponent c2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                         int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (position == SwingConstants.EAST ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                position == SwingConstants.WEST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            boolean c1Label = (c1 instanceof JLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            boolean c2Label = (c2 instanceof JLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return ((c1Label || c2Label) && (c1Label != c2Label));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * For some look and feels check boxs and radio buttons typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * don't paint the border, yet they have padding for a border.  Look
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * and feel guidelines generally don't include this space.  Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * this method to subtract this space from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param source First component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param target Second component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param position Position doing layout along.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param offset Ideal offset, not including border/margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @return offset - border/margin around the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    protected int getButtonGap(JComponent source, JComponent target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                               int position, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        offset -= getButtonGap(source, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (offset > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            offset -= getButtonGap(target, flipDirection(position));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (offset < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * For some look and feels check boxs and radio buttons typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * don't paint the border, yet they have padding for a border.  Look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * and feel guidelines generally don't include this space.  Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * this method to subtract this space from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param source Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param position Position doing layout along.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param offset Ideal offset, not including border/margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return offset - border/margin around the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected int getButtonGap(JComponent source, int position, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        offset -= getButtonGap(source, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return Math.max(offset, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * If <code>c</code> is a check box or radio button, and the border is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * not painted this returns the inset along the specified axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public int getButtonGap(JComponent c, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        String classID = c.getUIClassID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if ((classID == "CheckBoxUI" || classID == "RadioButtonUI") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                !((AbstractButton)c).isBorderPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            Border border = c.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if (border instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                return getInset(c, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private void checkPosition(int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (position != SwingConstants.NORTH &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                position != SwingConstants.SOUTH &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                position != SwingConstants.WEST &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                position != SwingConstants.EAST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected int flipDirection(int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        switch(position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        case SwingConstants.NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return SwingConstants.SOUTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        case SwingConstants.SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return SwingConstants.NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        case SwingConstants.EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return SwingConstants.WEST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        case SwingConstants.WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            return SwingConstants.EAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Returns the amount to indent the specified component if it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * a JCheckBox or JRadioButton.  If the component is not a JCheckBox or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * JRadioButton, 0 will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    protected int getIndent(JComponent c, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        String classID = c.getUIClassID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (classID == "CheckBoxUI" || classID == "RadioButtonUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            AbstractButton button = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            Icon icon = getIcon(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            int gap = button.getIconTextGap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (isLeftAligned(button, position)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                return insets.left + icon.getIconWidth() + gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            } else if (isRightAligned(button, position)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                return insets.right + icon.getIconWidth() + gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private Icon getIcon(AbstractButton button) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        Icon icon = button.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        String key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (button instanceof JCheckBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            key = "CheckBox.icon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } else if (button instanceof JRadioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            key = "RadioButton.icon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (key != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            Object oIcon = UIManager.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (oIcon instanceof Icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                return (Icon)oIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return null;
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 boolean isLeftAligned(AbstractButton button, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (position == SwingConstants.WEST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            boolean ltr = button.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            int hAlign = button.getHorizontalAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return ((ltr && (hAlign == SwingConstants.LEFT ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                             hAlign == SwingConstants.LEADING)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    (!ltr && (hAlign == SwingConstants.TRAILING)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private boolean isRightAligned(AbstractButton button, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (position == SwingConstants.EAST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            boolean ltr = button.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            int hAlign = button.getHorizontalAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return ((ltr && (hAlign == SwingConstants.RIGHT ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                             hAlign == SwingConstants.TRAILING)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    (!ltr && (hAlign == SwingConstants.LEADING)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private int getInset(JComponent c, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return getInset(c.getInsets(), position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    private int getInset(Insets insets, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (insets == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        switch(position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        case SwingConstants.NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        case SwingConstants.SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        case SwingConstants.EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        case SwingConstants.WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}