jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java
author rupashka
Thu, 16 Feb 2012 17:42:09 +0400
changeset 11975 d3620e28371c
parent 7668 d4a77089c587
child 23632 cd7a34d12e8c
permissions -rw-r--r--
7089914: Focus on image icons are not visible in javaws cache with high contrast mode Reviewed-by: rupashka Contributed-by: Sean Chou <zhouyx@linux.vnet.ibm.com>
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: 5597
diff changeset
     2
 * Copyright (c) 1997, 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: 1639
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: 1639
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: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.windows;
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 javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import static com.sun.java.swing.plaf.windows.TMSchema.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import static com.sun.java.swing.plaf.windows.XPStyle.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.swing.table.*;
5590
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 1639
diff changeset
    38
import sun.swing.SwingUtilities2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class WindowsTableHeaderUI extends BasicTableHeaderUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private TableCellRenderer originalHeaderRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public static ComponentUI createUI(JComponent h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        return new WindowsTableHeaderUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (XPStyle.getXP() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            originalHeaderRenderer = header.getDefaultRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            if (originalHeaderRenderer instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                header.setDefaultRenderer(new XPDefaultRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        if (header.getDefaultRenderer() instanceof XPDefaultRenderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            header.setDefaultRenderer(originalHeaderRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super.uninstallUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected void rolloverColumnUpdated(int oldColumn, int newColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (XPStyle.getXP() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            header.repaint(header.getHeaderRect(oldColumn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            header.repaint(header.getHeaderRect(newColumn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private class XPDefaultRenderer extends DefaultTableCellHeaderRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        Skin skin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        boolean isSelected, hasFocus, hasRollover;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        XPDefaultRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            setHorizontalAlignment(LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        public Component getTableCellRendererComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                                       boolean isSelected, boolean hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                                       int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            super.getTableCellRendererComponent(table, value, isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                                hasFocus, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            this.isSelected = isSelected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            this.hasFocus = hasFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            this.column = column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            this.hasRollover = (column == getRolloverColumn());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (skin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                skin = XPStyle.getXP().getSkin(header, Part.HP_HEADERITEM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            Insets margins = skin.getContentMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            Border border = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            int contentTop = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            int contentLeft = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            int contentBottom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            int contentRight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (margins != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                contentTop = margins.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                contentLeft = margins.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                contentBottom = margins.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                contentRight = margins.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            /* idk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
             * Both on Vista and XP there is some offset to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
             * HP_HEADERITEM content. It does not seem to come from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
             * Prop.CONTENTMARGINS. Do not know where it is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
             * using some hardcoded values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            contentLeft += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            contentBottom += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            contentRight += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            /* On Vista sortIcon is painted above the header's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
             * We use border to paint it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            Icon sortIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (WindowsLookAndFeel.isOnVista()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                && ((sortIcon = getIcon()) instanceof javax.swing.plaf.UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    || sortIcon == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                contentTop += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                setIcon(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                sortIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                SortOrder sortOrder =
1283
bbfc838e2c7d 6668281: NullPointerException in DefaultTableCellHeaderRenderer.getColumnSortOrder()
idk
parents: 2
diff changeset
   128
                    getColumnSortOrder(table, column);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                if (sortOrder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    switch (sortOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    case ASCENDING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                        sortIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                            UIManager.getIcon("Table.ascendingSortIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    case DESCENDING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        sortIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                            UIManager.getIcon("Table.descendingSortIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                if (sortIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    contentBottom = sortIcon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    border = new IconBorder(sortIcon, contentTop, contentLeft,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                            contentBottom, contentRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    sortIcon =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        UIManager.getIcon("Table.ascendingSortIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    int sortIconHeight =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                        (sortIcon != null) ? sortIcon.getIconHeight() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    if (sortIconHeight != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                        contentBottom = sortIconHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    border =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        new EmptyBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                            sortIconHeight + contentTop, contentLeft,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                            contentBottom, contentRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                contentTop += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                border = new EmptyBorder(contentTop, contentLeft,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                         contentBottom, contentRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            setBorder(border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            Dimension size = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            State state = State.NORMAL;
5590
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 1639
diff changeset
   170
            TableColumn draggedColumn = header.getDraggedColumn();
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 1639
diff changeset
   171
            if (draggedColumn != null &&
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 1639
diff changeset
   172
                    column == SwingUtilities2.convertColumnIndexToView(
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 1639
diff changeset
   173
                            header.getColumnModel(), draggedColumn.getModelIndex())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                state = State.PRESSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            } else if (isSelected || hasFocus || hasRollover) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                state = State.HOT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            /* on Vista there are more states for sorted columns */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (WindowsLookAndFeel.isOnVista()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                SortOrder sortOrder = getColumnSortOrder(header.getTable(), column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if (sortOrder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                     switch(sortOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                     case ASCENDING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                         /* falls through */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                     case DESCENDING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                         switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                         case NORMAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                             state = State.SORTEDNORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                         case PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                             state = State.SORTEDPRESSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                         case HOT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                             state = State.SORTEDHOT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                         default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                             /* do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                     default :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                         /* do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            skin.paintSkin(g, 0, 0, size.width-1, size.height-1, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * A border with an Icon at the middle of the top side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Outer insets can be provided for this border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private static class IconBorder implements Border, UIResource{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        private final Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        private final int top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        private final int left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        private final int bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        private final int right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         * Creates this border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         * @param icon - icon to paint for this border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         * @param top, left, bottom, right - outer insets for this border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        public IconBorder(Icon icon, int top, int left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                          int bottom, int right) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            this.icon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            this.top = top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            this.left = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            this.bottom = bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            this.right = right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        public Insets getBorderInsets(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return new Insets(icon.getIconHeight() + top, left, bottom, right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        public boolean isBorderOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            icon.paintIcon(c, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                x + left + (width - left - right - icon.getIconWidth()) / 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                y + top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}