jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthTableUI.java
author alexsch
Fri, 15 Apr 2016 19:15:12 +0400
changeset 37698 4d798c873df0
parent 25859 3317bb8137f4
permissions -rw-r--r--
8132791: No access to SynthContext.getContext() Reviewed-by: serb, ssadetsky
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2002, 2014, 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: 4967
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: 4967
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: 4967
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4967
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4967
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.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    30
import java.awt.Dimension;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.text.DateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.text.Format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.text.NumberFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.Icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.ImageIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.JCheckBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.JComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.JLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.swing.JTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.swing.LookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.swing.border.Border;
4967
da853cd502c8 6913768: With default SynthLookAndFeel instance installed new JTable creation leads to throwing NPE
rupashka
parents: 4848
diff changeset
    48
import javax.swing.plaf.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.swing.plaf.basic.BasicTableUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.swing.table.DefaultTableCellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.swing.table.JTableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.swing.table.TableCellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.swing.table.TableColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.swing.table.TableColumnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 8989
diff changeset
    57
 * Provides the Synth L&F UI delegate for
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    58
 * {@link javax.swing.JTable}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author Philip Milne
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    61
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    63
public class SynthTableUI extends BasicTableUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    64
                          implements SynthUI, PropertyChangeListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
// Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private boolean useTableColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private boolean useUIBorder;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    73
    private Color alternateColor; //the background color to use for cells for alternate cells
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    // TableCellRenderer installed on the JTable at the time we're installed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // cached so that we can reinstall them at uninstallUI time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private TableCellRenderer dateRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private TableCellRenderer numberRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private TableCellRenderer doubleRender;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private TableCellRenderer floatRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private TableCellRenderer iconRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private TableCellRenderer imageIconRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private TableCellRenderer booleanRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private TableCellRenderer objectRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
//  The installation/uninstall procedures and support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    90
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    91
     * Creates a new UI object for the given component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    92
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    93
     * @param c component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    94
     * @return the UI object
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
    95
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return new SynthTableUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   101
     * Initializes JTable properties, such as font, foreground, and background.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * The font, foreground, and background properties are only set if their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * current value is either null or a UIResource, other properties are set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * if the current value is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   108
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        dateRenderer = installRendererIfPossible(Date.class, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        numberRenderer = installRendererIfPossible(Number.class, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        doubleRender = installRendererIfPossible(Double.class, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        floatRenderer = installRendererIfPossible(Float.class, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        iconRenderer = installRendererIfPossible(Icon.class, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        imageIconRenderer = installRendererIfPossible(ImageIcon.class, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        booleanRenderer = installRendererIfPossible(Boolean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                 new SynthBooleanTableCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        objectRenderer = installRendererIfPossible(Object.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                        new SynthTableCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        updateStyle(table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25100
diff changeset
   123
    private TableCellRenderer installRendererIfPossible(Class<?> objectClass,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                     TableCellRenderer renderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        TableCellRenderer currentRenderer = table.getDefaultRenderer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                 objectClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (currentRenderer instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            table.setDefaultRenderer(objectClass, renderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return currentRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private void updateStyle(JTable c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            context.setComponentState(ENABLED | SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            Color sbg = table.getSelectionBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            if (sbg == null || sbg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                table.setSelectionBackground(style.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                        context, ColorType.TEXT_BACKGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            Color sfg = table.getSelectionForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (sfg == null || sfg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                table.setSelectionForeground(style.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                  context, ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            context.setComponentState(ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            Color gridColor = table.getGridColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (gridColor == null || gridColor instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                gridColor = (Color)style.get(context, "Table.gridColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                if (gridColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    gridColor = style.getColor(context, ColorType.FOREGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                }
4967
da853cd502c8 6913768: With default SynthLookAndFeel instance installed new JTable creation leads to throwing NPE
rupashka
parents: 4848
diff changeset
   160
                table.setGridColor(gridColor == null ? new ColorUIResource(Color.GRAY) : gridColor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            useTableColors = style.getBoolean(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                  "Table.rendererUseTableColors", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            useUIBorder = style.getBoolean(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                  "Table.rendererUseUIBorder", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            Object rowHeight = style.get(context, "Table.rowHeight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            if (rowHeight != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                LookAndFeel.installProperty(table, "rowHeight", rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   172
            boolean showGrid = style.getBoolean(context, "Table.showGrid", true);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   173
            if (!showGrid) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   174
                table.setShowGrid(false);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   175
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   176
            Dimension d = table.getIntercellSpacing();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   177
//            if (d == null || d instanceof UIResource) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   178
            if (d != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   179
                d = (Dimension)style.get(context, "Table.intercellSpacing");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   180
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   181
            alternateColor = (Color)style.get(context, "Table.alternateRowColor");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   182
            if (d != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   183
                table.setIntercellSpacing(d);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   184
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   185
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   186
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Attaches listeners to the JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   197
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        table.addPropertyChangeListener(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: 4283
diff changeset
   203
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 8989
diff changeset
   204
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   205
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   206
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        table.setDefaultRenderer(Date.class, dateRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        table.setDefaultRenderer(Number.class, numberRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        table.setDefaultRenderer(Double.class, doubleRender);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        table.setDefaultRenderer(Float.class, floatRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        table.setDefaultRenderer(Icon.class, iconRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        table.setDefaultRenderer(ImageIcon.class, imageIconRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        table.setDefaultRenderer(Boolean.class, booleanRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        table.setDefaultRenderer(Object.class, objectRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (table.getTransferHandler() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            table.setTransferHandler(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        SynthContext context = getContext(table, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   225
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 8989
diff changeset
   226
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   227
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   228
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        table.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    // SynthUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    //
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   237
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   238
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 8989
diff changeset
   239
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   240
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   241
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   243
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    private SynthContext getContext(JComponent c, int state) {
25100
d527cc827d7d 8043627: NPE in SynthContext in plugin mode
malenkov
parents: 23697
diff changeset
   247
        return SynthContext.getContext(c, style, state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
//  Paint methods and support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   254
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   255
     * 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
   256
     * 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
   257
     * 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
   258
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   259
     * <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
   260
     * 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
   261
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   262
     * @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
   263
     * @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
   264
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   265
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   266
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        context.getPainter().paintTableBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                          g, 0, 0, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   276
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 8989
diff changeset
   277
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   278
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   279
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        context.getPainter().paintTableBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   285
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   286
     * 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
   287
     * <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
   288
     * 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
   289
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   290
     * @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
   291
     * @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
   292
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   293
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   294
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   301
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   302
     * Paints the specified component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   303
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   304
     * @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
   305
     * @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
   306
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   307
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        Rectangle clip = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        Rectangle bounds = table.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // account for the fact that the graphics has already been translated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // into the table's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        bounds.x = bounds.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                // this check prevents us from painting the entire table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                // when the clip doesn't intersect our bounds at all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                !bounds.intersects(clip)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            paintDropLines(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        boolean ltr = table.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        Point upperLeft = clip.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        Point lowerRight = new Point(clip.x + clip.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                     clip.y + clip.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        int rMin = table.rowAtPoint(upperLeft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        int rMax = table.rowAtPoint(lowerRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // This should never happen (as long as our bounds intersect the clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        // which is why we bail above if that is the case).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (rMin == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            rMin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        // If the table does not have enough rows to fill the view we'll get -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // (We could also get -1 if our bounds don't intersect the clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        // which is why we bail above if that is the case).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // Replace this with the index of the last row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (rMax == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            rMax = table.getRowCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        // This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (cMin == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            cMin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        // If the table does not have enough columns to fill the view we'll get -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        // Replace this with the index of the last column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (cMax == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            cMax = table.getColumnCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        // Paint the cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        paintCells(context, g, rMin, rMax, cMin, cMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
5588
57eca0aa621e 6937798: Nimbus: Issues with JTable grid
alexp
parents: 4967
diff changeset
   362
        // Paint the grid.
57eca0aa621e 6937798: Nimbus: Issues with JTable grid
alexp
parents: 4967
diff changeset
   363
        // it is important to paint the grid after the cells, otherwise the grid will be overpainted
57eca0aa621e 6937798: Nimbus: Issues with JTable grid
alexp
parents: 4967
diff changeset
   364
        // because in Synth cell renderers are likely to be opaque
57eca0aa621e 6937798: Nimbus: Issues with JTable grid
alexp
parents: 4967
diff changeset
   365
        paintGrid(context, g, rMin, rMax, cMin, cMax);
57eca0aa621e 6937798: Nimbus: Issues with JTable grid
alexp
parents: 4967
diff changeset
   366
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        paintDropLines(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    private void paintDropLines(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        JTable.DropLocation loc = table.getDropLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (loc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        Color color = (Color)style.get(context, "Table.dropLineColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        Color shortColor = (Color)style.get(context, "Table.dropLineShortColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (color == null && shortColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        Rectangle rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        rect = getHDropLineRect(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (rect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            int x = rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            int w = rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (color != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                extendRect(rect, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                g.fillRect(rect.x, rect.y, rect.width, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            if (!loc.isInsertColumn() && shortColor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                g.setColor(shortColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                g.fillRect(x, rect.y, w, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        rect = getVDropLineRect(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (rect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            int y = rect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            int h = rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            if (color != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                extendRect(rect, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                g.fillRect(rect.x, rect.y, rect.width, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            if (!loc.isInsertRow() && shortColor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                g.setColor(shortColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                g.fillRect(rect.x, y, rect.width, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    private Rectangle getHDropLineRect(JTable.DropLocation loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (!loc.isInsertRow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        int row = loc.getRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        int col = loc.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (col >= table.getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            col--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        Rectangle rect = table.getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (row >= table.getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            row--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            Rectangle prevRect = table.getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            rect.y = prevRect.y + prevRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (rect.y == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            rect.y = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            rect.y -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        rect.height = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    private Rectangle getVDropLineRect(JTable.DropLocation loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        if (!loc.isInsertColumn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        boolean ltr = table.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        int col = loc.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        Rectangle rect = table.getCellRect(loc.getRow(), col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (col >= table.getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            col--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            rect = table.getCellRect(loc.getRow(), col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                rect.x = rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        } else if (!ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            rect.x = rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (rect.x == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            rect.x = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            rect.x -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        rect.width = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    private Rectangle extendRect(Rectangle rect, boolean horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (rect == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            rect.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            rect.width = table.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            rect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            if (table.getRowCount() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                Rectangle lastRect = table.getCellRect(table.getRowCount() - 1, 0, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                rect.height = lastRect.y + lastRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                rect.height = table.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Paints the grid lines within <I>aRect</I>, using the grid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * color set with <I>setGridColor</I>. Paints vertical lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * if <code>getShowVerticalLines()</code> returns true and paints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * horizontal lines if <code>getShowHorizontalLines()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    private void paintGrid(SynthContext context, Graphics g, int rMin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                           int rMax, int cMin, int cMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        g.setColor(table.getGridColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        Rectangle minCell = table.getCellRect(rMin, cMin, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        Rectangle maxCell = table.getCellRect(rMax, cMax, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        Rectangle damagedArea = minCell.union( maxCell );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                     context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (table.getShowHorizontalLines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            int tableWidth = damagedArea.x + damagedArea.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            int y = damagedArea.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            for (int row = rMin; row <= rMax; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                y += table.getRowHeight(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                synthG.drawLine(context, "Table.grid",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                g, damagedArea.x, y - 1, tableWidth - 1,y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if (table.getShowVerticalLines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            TableColumnModel cm = table.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            int tableHeight = damagedArea.y + damagedArea.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            if (table.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                x = damagedArea.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                for (int column = cMin; column <= cMax; column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    int w = cm.getColumn(column).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    x += w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    synthG.drawLine(context, "Table.grid", g, x - 1, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                                    x - 1, tableHeight - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                x = damagedArea.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                for (int column = cMax; column >= cMin; column--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    int w = cm.getColumn(column).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    x += w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                    tableHeight - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    private int viewIndexForColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        TableColumnModel cm = table.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        for (int column = 0; column < cm.getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (cm.getColumn(column) == aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    private void paintCells(SynthContext context, Graphics g, int rMin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                            int rMax, int cMin, int cMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        JTableHeader header = table.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        TableColumnModel cm = table.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        int columnMargin = cm.getColumnMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        Rectangle cellRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        TableColumn aColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        int columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (table.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            for(int row = rMin; row <= rMax; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                cellRect = table.getCellRect(row, cMin, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                for(int column = cMin; column <= cMax; column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    aColumn = cm.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    columnWidth = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    cellRect.width = columnWidth - columnMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    if (aColumn != draggedColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                        paintCell(context, g, cellRect, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                    cellRect.x += columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            for(int row = rMin; row <= rMax; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                cellRect = table.getCellRect(row, cMin, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                aColumn = cm.getColumn(cMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                if (aColumn != draggedColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    columnWidth = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    cellRect.width = columnWidth - columnMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    paintCell(context, g, cellRect, row, cMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                for(int column = cMin+1; column <= cMax; column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    aColumn = cm.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    columnWidth = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    cellRect.width = columnWidth - columnMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                    cellRect.x -= columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    if (aColumn != draggedColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                        paintCell(context, g, cellRect, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        // Paint the dragged column if we are dragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (draggedColumn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        // Remove any renderers that may be left in the rendererPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        rendererPane.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    private void paintDraggedArea(SynthContext context, Graphics g, int rMin, int rMax, TableColumn draggedColumn, int distance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        int draggedColumnIndex = viewIndexForColumn(draggedColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        Rectangle vacatedColumnRect = minCell.union(maxCell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        // Paint a gray well in place of the moving column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        g.setColor(table.getParent().getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                   vacatedColumnRect.width, vacatedColumnRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        // Move to the where the cell has been dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        vacatedColumnRect.x += distance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // Fill the background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        g.setColor(context.getStyle().getColor(context, ColorType.BACKGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                   vacatedColumnRect.width, vacatedColumnRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                            context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // Paint the vertical grid lines if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        if (table.getShowVerticalLines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            g.setColor(table.getGridColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            int x1 = vacatedColumnRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            int y1 = vacatedColumnRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            int x2 = x1 + vacatedColumnRect.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            int y2 = y1 + vacatedColumnRect.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            // Left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            synthG.drawLine(context, "Table.grid", g, x1-1, y1, x1-1, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            // Right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            synthG.drawLine(context, "Table.grid", g, x2, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        for(int row = rMin; row <= rMax; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            // Render the cell value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            Rectangle r = table.getCellRect(row, draggedColumnIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            r.x += distance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            paintCell(context, g, r, row, draggedColumnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            // Paint the (lower) horizontal grid line if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            if (table.getShowHorizontalLines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                g.setColor(table.getGridColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                rcr.x += distance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                int x1 = rcr.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                int y1 = rcr.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                int x2 = x1 + rcr.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                int y2 = y1 + rcr.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                synthG.drawLine(context, "Table.grid", g, x1, y2, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    private void paintCell(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            Rectangle cellRect, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        if (table.isEditing() && table.getEditingRow()==row &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                                 table.getEditingColumn()==column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            Component component = table.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            component.setBounds(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            component.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            TableCellRenderer renderer = table.getCellRenderer(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            Component component = table.prepareRenderer(renderer, row, column);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   680
            Color b = component.getBackground();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   681
            if ((b == null || b instanceof UIResource
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   682
                    || component instanceof SynthBooleanTableCellRenderer)
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   683
                    && !table.isCellSelected(row, column)) {
4283
06d5378aaff3 6882917: Nimbus and DefaultTableCellRenderer: must start with normal background
peterz
parents: 2658
diff changeset
   684
                if (alternateColor != null && row % 2 != 0) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   685
                    component.setBackground(alternateColor);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   686
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   687
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            rendererPane.paintComponent(g, component, table, cellRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    cellRect.y, cellRect.width, cellRect.height, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   693
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 8989
diff changeset
   694
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   695
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4283
diff changeset
   696
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        if (SynthLookAndFeel.shouldUpdateStyle(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            updateStyle((JTable)event.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   703
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    private class SynthBooleanTableCellRenderer extends JCheckBox implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                      TableCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        private boolean isRowSelected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        public SynthBooleanTableCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            setHorizontalAlignment(JLabel.CENTER);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   710
            setName("Table.cellRenderer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        public Component getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                            JTable table, Object value, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                            boolean hasFocus, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            isRowSelected = isSelected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            if (isSelected) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   719
                setForeground(unwrap(table.getSelectionForeground()));
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   720
                setBackground(unwrap(table.getSelectionBackground()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            } else {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   722
                setForeground(unwrap(table.getForeground()));
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   723
                setBackground(unwrap(table.getBackground()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            setSelected((value != null && ((Boolean)value).booleanValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   730
        private Color unwrap(Color c) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   731
            if (c instanceof UIResource) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   732
                return new Color(c.getRGB());
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   733
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   734
            return c;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   735
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   736
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        public boolean isOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            return isRowSelected ? true : super.isOpaque();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   742
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    private class SynthTableCellRenderer extends DefaultTableCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        private Object numberFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        private Object dateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        private boolean opaque;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        public void setOpaque(boolean isOpaque) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            opaque = isOpaque;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        public boolean isOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            return opaque;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            String name = super.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                return "Table.cellRenderer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        public void setBorder(Border b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            if (useUIBorder || b instanceof SynthBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                super.setBorder(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        public Component getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                  JTable table, Object value, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                  boolean hasFocus, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            if (!useTableColors && (isSelected || hasFocus)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                             getUIOfType(getUI(), SynthLabelUI.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                                   isSelected, hasFocus, table.isEnabled(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                SynthLookAndFeel.resetSelectedUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            super.getTableCellRendererComponent(table, value, isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                                                hasFocus, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            setIcon(null);
8989
09e49dac04d8 7032791: TableCellRenderer.getTableCellRendererComponent() doesn't accept null JTable with GTK+ L&F
alexp
parents: 7668
diff changeset
   785
            if (table != null) {
09e49dac04d8 7032791: TableCellRenderer.getTableCellRendererComponent() doesn't accept null JTable with GTK+ L&F
alexp
parents: 7668
diff changeset
   786
                configureValue(value, table.getColumnClass(column));
09e49dac04d8 7032791: TableCellRenderer.getTableCellRendererComponent() doesn't accept null JTable with GTK+ L&F
alexp
parents: 7668
diff changeset
   787
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25100
diff changeset
   791
        private void configureValue(Object value, Class<?> columnClass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            if (columnClass == Object.class || columnClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                setHorizontalAlignment(JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            } else if (columnClass == Float.class || columnClass == Double.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                if (numberFormat == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                    numberFormat = NumberFormat.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                setHorizontalAlignment(JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                setText((value == null) ? "" : ((NumberFormat)numberFormat).format(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            else if (columnClass == Number.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                setHorizontalAlignment(JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                // Super will have set value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            else if (columnClass == Icon.class || columnClass == ImageIcon.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                setHorizontalAlignment(JLabel.CENTER);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   807
                setIcon((value instanceof Icon) ? (Icon)value : null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            else if (columnClass == Date.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                if (dateFormat == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    dateFormat = DateFormat.getDateInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                setHorizontalAlignment(JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                setText((value == null) ? "" : ((Format)dateFormat).format(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                configureValue(value, columnClass.getSuperclass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            SynthLookAndFeel.resetSelectedUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
}