0N/A/*
3261N/A * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing.plaf.synth;
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Component;
1173N/Aimport java.awt.Dimension;
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.Point;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.beans.PropertyChangeEvent;
0N/Aimport java.beans.PropertyChangeListener;
0N/Aimport java.text.DateFormat;
0N/Aimport java.text.Format;
0N/Aimport java.text.NumberFormat;
0N/Aimport java.util.Date;
0N/Aimport javax.swing.Icon;
0N/Aimport javax.swing.ImageIcon;
0N/Aimport javax.swing.JCheckBox;
0N/Aimport javax.swing.JComponent;
0N/Aimport javax.swing.JLabel;
0N/Aimport javax.swing.JTable;
0N/Aimport javax.swing.LookAndFeel;
0N/Aimport javax.swing.border.Border;
2179N/Aimport javax.swing.plaf.*;
0N/Aimport javax.swing.plaf.basic.BasicTableUI;
0N/Aimport javax.swing.table.DefaultTableCellRenderer;
0N/Aimport javax.swing.table.JTableHeader;
0N/Aimport javax.swing.table.TableCellRenderer;
0N/Aimport javax.swing.table.TableColumn;
0N/Aimport javax.swing.table.TableColumnModel;
0N/A
0N/A/**
1999N/A * Provides the Synth L&F UI delegate for
1999N/A * {@link javax.swing.JTable}.
0N/A *
0N/A * @author Philip Milne
1999N/A * @since 1.7
0N/A */
1999N/Apublic class SynthTableUI extends BasicTableUI
1999N/A implements SynthUI, PropertyChangeListener {
0N/A//
0N/A// Instance Variables
0N/A//
0N/A
0N/A private SynthStyle style;
0N/A
0N/A private boolean useTableColors;
0N/A private boolean useUIBorder;
1173N/A private Color alternateColor; //the background color to use for cells for alternate cells
0N/A
0N/A // TableCellRenderer installed on the JTable at the time we're installed,
0N/A // cached so that we can reinstall them at uninstallUI time.
0N/A private TableCellRenderer dateRenderer;
0N/A private TableCellRenderer numberRenderer;
0N/A private TableCellRenderer doubleRender;
0N/A private TableCellRenderer floatRenderer;
0N/A private TableCellRenderer iconRenderer;
0N/A private TableCellRenderer imageIconRenderer;
0N/A private TableCellRenderer booleanRenderer;
0N/A private TableCellRenderer objectRenderer;
0N/A
0N/A//
0N/A// The installation/uninstall procedures and support
0N/A//
0N/A
1999N/A /**
1999N/A * Creates a new UI object for the given component.
1999N/A *
1999N/A * @param c component to create UI object for
1999N/A * @return the UI object
1999N/A */
0N/A public static ComponentUI createUI(JComponent c) {
0N/A return new SynthTableUI();
0N/A }
0N/A
0N/A /**
1999N/A * Initializes JTable properties, such as font, foreground, and background.
0N/A * The font, foreground, and background properties are only set if their
0N/A * current value is either null or a UIResource, other properties are set
0N/A * if the current value is null.
0N/A *
0N/A * @see #installUI
0N/A */
1999N/A @Override
0N/A protected void installDefaults() {
0N/A dateRenderer = installRendererIfPossible(Date.class, null);
0N/A numberRenderer = installRendererIfPossible(Number.class, null);
0N/A doubleRender = installRendererIfPossible(Double.class, null);
0N/A floatRenderer = installRendererIfPossible(Float.class, null);
0N/A iconRenderer = installRendererIfPossible(Icon.class, null);
0N/A imageIconRenderer = installRendererIfPossible(ImageIcon.class, null);
0N/A booleanRenderer = installRendererIfPossible(Boolean.class,
0N/A new SynthBooleanTableCellRenderer());
0N/A objectRenderer = installRendererIfPossible(Object.class,
0N/A new SynthTableCellRenderer());
0N/A updateStyle(table);
0N/A }
0N/A
0N/A private TableCellRenderer installRendererIfPossible(Class objectClass,
0N/A TableCellRenderer renderer) {
0N/A TableCellRenderer currentRenderer = table.getDefaultRenderer(
0N/A objectClass);
0N/A if (currentRenderer instanceof UIResource) {
0N/A table.setDefaultRenderer(objectClass, renderer);
0N/A }
0N/A return currentRenderer;
0N/A }
0N/A
0N/A private void updateStyle(JTable c) {
0N/A SynthContext context = getContext(c, ENABLED);
0N/A SynthStyle oldStyle = style;
0N/A style = SynthLookAndFeel.updateStyle(context, this);
0N/A if (style != oldStyle) {
0N/A context.setComponentState(ENABLED | SELECTED);
0N/A
0N/A Color sbg = table.getSelectionBackground();
0N/A if (sbg == null || sbg instanceof UIResource) {
0N/A table.setSelectionBackground(style.getColor(
0N/A context, ColorType.TEXT_BACKGROUND));
0N/A }
0N/A
0N/A Color sfg = table.getSelectionForeground();
0N/A if (sfg == null || sfg instanceof UIResource) {
0N/A table.setSelectionForeground(style.getColor(
0N/A context, ColorType.TEXT_FOREGROUND));
0N/A }
0N/A
0N/A context.setComponentState(ENABLED);
0N/A
0N/A Color gridColor = table.getGridColor();
0N/A if (gridColor == null || gridColor instanceof UIResource) {
0N/A gridColor = (Color)style.get(context, "Table.gridColor");
0N/A if (gridColor == null) {
0N/A gridColor = style.getColor(context, ColorType.FOREGROUND);
0N/A }
2179N/A table.setGridColor(gridColor == null ? new ColorUIResource(Color.GRAY) : gridColor);
0N/A }
0N/A
0N/A useTableColors = style.getBoolean(context,
0N/A "Table.rendererUseTableColors", true);
0N/A useUIBorder = style.getBoolean(context,
0N/A "Table.rendererUseUIBorder", true);
0N/A
0N/A Object rowHeight = style.get(context, "Table.rowHeight");
0N/A if (rowHeight != null) {
0N/A LookAndFeel.installProperty(table, "rowHeight", rowHeight);
0N/A }
1173N/A boolean showGrid = style.getBoolean(context, "Table.showGrid", true);
1173N/A if (!showGrid) {
1173N/A table.setShowGrid(false);
1173N/A }
1173N/A Dimension d = table.getIntercellSpacing();
1173N/A// if (d == null || d instanceof UIResource) {
1173N/A if (d != null) {
1173N/A d = (Dimension)style.get(context, "Table.intercellSpacing");
1173N/A }
1173N/A alternateColor = (Color)style.get(context, "Table.alternateRowColor");
1173N/A if (d != null) {
1173N/A table.setIntercellSpacing(d);
1173N/A }
1173N/A
1173N/A
0N/A if (oldStyle != null) {
0N/A uninstallKeyboardActions();
0N/A installKeyboardActions();
0N/A }
0N/A }
0N/A context.dispose();
0N/A }
0N/A
0N/A /**
0N/A * Attaches listeners to the JTable.
0N/A */
1999N/A @Override
0N/A protected void installListeners() {
0N/A super.installListeners();
0N/A table.addPropertyChangeListener(this);
0N/A }
0N/A
1999N/A /**
1999N/A * @inheritDoc
1999N/A */
1999N/A @Override
0N/A protected void uninstallDefaults() {
0N/A table.setDefaultRenderer(Date.class, dateRenderer);
0N/A table.setDefaultRenderer(Number.class, numberRenderer);
0N/A table.setDefaultRenderer(Double.class, doubleRender);
0N/A table.setDefaultRenderer(Float.class, floatRenderer);
0N/A table.setDefaultRenderer(Icon.class, iconRenderer);
0N/A table.setDefaultRenderer(ImageIcon.class, imageIconRenderer);
0N/A table.setDefaultRenderer(Boolean.class, booleanRenderer);
0N/A table.setDefaultRenderer(Object.class, objectRenderer);
0N/A
0N/A if (table.getTransferHandler() instanceof UIResource) {
0N/A table.setTransferHandler(null);
0N/A }
0N/A SynthContext context = getContext(table, ENABLED);
0N/A style.uninstallDefaults(context);
0N/A context.dispose();
0N/A style = null;
0N/A }
0N/A
1999N/A /**
1999N/A * @inheritDoc
1999N/A */
1999N/A @Override
0N/A protected void uninstallListeners() {
0N/A table.removePropertyChangeListener(this);
0N/A super.uninstallListeners();
0N/A }
0N/A
0N/A //
0N/A // SynthUI
0N/A //
1999N/A
1999N/A /**
1999N/A * @inheritDoc
1999N/A */
1999N/A @Override
0N/A public SynthContext getContext(JComponent c) {
1999N/A return getContext(c, SynthLookAndFeel.getComponentState(c));
0N/A }
0N/A
0N/A private SynthContext getContext(JComponent c, int state) {
0N/A return SynthContext.getContext(SynthContext.class, c,
0N/A SynthLookAndFeel.getRegion(c), style, state);
0N/A }
0N/A
0N/A//
0N/A// Paint methods and support
0N/A//
0N/A
1999N/A /**
2146N/A * Notifies this UI delegate to repaint the specified component.
2146N/A * This method paints the component background, then calls
2146N/A * the {@link #paint(SynthContext,Graphics)} method.
2146N/A *
2146N/A * <p>In general, this method does not need to be overridden by subclasses.
2146N/A * All Look and Feel rendering code should reside in the {@code paint} method.
2146N/A *
2146N/A * @param g the {@code Graphics} object used for painting
2146N/A * @param c the component being painted
2146N/A * @see #paint(SynthContext,Graphics)
1999N/A */
1999N/A @Override
0N/A public void update(Graphics g, JComponent c) {
0N/A SynthContext context = getContext(c);
0N/A
0N/A SynthLookAndFeel.update(context, g);
0N/A context.getPainter().paintTableBackground(context,
0N/A g, 0, 0, c.getWidth(), c.getHeight());
0N/A paint(context, g);
0N/A context.dispose();
0N/A }
0N/A
1999N/A /**
1999N/A * @inheritDoc
1999N/A */
1999N/A @Override
0N/A public void paintBorder(SynthContext context, Graphics g, int x,
0N/A int y, int w, int h) {
0N/A context.getPainter().paintTableBorder(context, g, x, y, w, h);
0N/A }
0N/A
1999N/A /**
2146N/A * Paints the specified component according to the Look and Feel.
2146N/A * <p>This method is not used by Synth Look and Feel.
2146N/A * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
2146N/A *
2146N/A * @param g the {@code Graphics} object used for painting
2146N/A * @param c the component being painted
2146N/A * @see #paint(SynthContext,Graphics)
1999N/A */
1999N/A @Override
0N/A public void paint(Graphics g, JComponent c) {
0N/A SynthContext context = getContext(c);
0N/A
0N/A paint(context, g);
0N/A context.dispose();
0N/A }
0N/A
1999N/A /**
1999N/A * Paints the specified component.
1999N/A *
1999N/A * @param context context for the component being painted
2146N/A * @param g the {@code Graphics} object used for painting
2146N/A * @see #update(Graphics,JComponent)
1999N/A */
0N/A protected void paint(SynthContext context, Graphics g) {
0N/A Rectangle clip = g.getClipBounds();
0N/A
0N/A Rectangle bounds = table.getBounds();
0N/A // account for the fact that the graphics has already been translated
0N/A // into the table's bounds
0N/A bounds.x = bounds.y = 0;
0N/A
0N/A if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
0N/A // this check prevents us from painting the entire table
0N/A // when the clip doesn't intersect our bounds at all
0N/A !bounds.intersects(clip)) {
0N/A
0N/A paintDropLines(context, g);
0N/A return;
0N/A }
0N/A
0N/A boolean ltr = table.getComponentOrientation().isLeftToRight();
0N/A
0N/A Point upperLeft = clip.getLocation();
0N/A
0N/A Point lowerRight = new Point(clip.x + clip.width - 1,
0N/A clip.y + clip.height - 1);
0N/A
0N/A int rMin = table.rowAtPoint(upperLeft);
0N/A int rMax = table.rowAtPoint(lowerRight);
0N/A // This should never happen (as long as our bounds intersect the clip,
0N/A // which is why we bail above if that is the case).
0N/A if (rMin == -1) {
0N/A rMin = 0;
0N/A }
0N/A // If the table does not have enough rows to fill the view we'll get -1.
0N/A // (We could also get -1 if our bounds don't intersect the clip,
0N/A // which is why we bail above if that is the case).
0N/A // Replace this with the index of the last row.
0N/A if (rMax == -1) {
0N/A rMax = table.getRowCount()-1;
0N/A }
0N/A
0N/A int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
0N/A int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
0N/A // This should never happen.
0N/A if (cMin == -1) {
0N/A cMin = 0;
0N/A }
0N/A // If the table does not have enough columns to fill the view we'll get -1.
0N/A // Replace this with the index of the last column.
0N/A if (cMax == -1) {
0N/A cMax = table.getColumnCount()-1;
0N/A }
0N/A
0N/A // Paint the cells.
0N/A paintCells(context, g, rMin, rMax, cMin, cMax);
0N/A
2379N/A // Paint the grid.
2379N/A // it is important to paint the grid after the cells, otherwise the grid will be overpainted
2379N/A // because in Synth cell renderers are likely to be opaque
2379N/A paintGrid(context, g, rMin, rMax, cMin, cMax);
2379N/A
0N/A paintDropLines(context, g);
0N/A }
0N/A
0N/A private void paintDropLines(SynthContext context, Graphics g) {
0N/A JTable.DropLocation loc = table.getDropLocation();
0N/A if (loc == null) {
0N/A return;
0N/A }
0N/A
0N/A Color color = (Color)style.get(context, "Table.dropLineColor");
0N/A Color shortColor = (Color)style.get(context, "Table.dropLineShortColor");
0N/A if (color == null && shortColor == null) {
0N/A return;
0N/A }
0N/A
0N/A Rectangle rect;
0N/A
0N/A rect = getHDropLineRect(loc);
0N/A if (rect != null) {
0N/A int x = rect.x;
0N/A int w = rect.width;
0N/A if (color != null) {
0N/A extendRect(rect, true);
0N/A g.setColor(color);
0N/A g.fillRect(rect.x, rect.y, rect.width, rect.height);
0N/A }
0N/A if (!loc.isInsertColumn() && shortColor != null) {
0N/A g.setColor(shortColor);
0N/A g.fillRect(x, rect.y, w, rect.height);
0N/A }
0N/A }
0N/A
0N/A rect = getVDropLineRect(loc);
0N/A if (rect != null) {
0N/A int y = rect.y;
0N/A int h = rect.height;
0N/A if (color != null) {
0N/A extendRect(rect, false);
0N/A g.setColor(color);
0N/A g.fillRect(rect.x, rect.y, rect.width, rect.height);
0N/A }
0N/A if (!loc.isInsertRow() && shortColor != null) {
0N/A g.setColor(shortColor);
0N/A g.fillRect(rect.x, y, rect.width, h);
0N/A }
0N/A }
0N/A }
0N/A
0N/A private Rectangle getHDropLineRect(JTable.DropLocation loc) {
0N/A if (!loc.isInsertRow()) {
0N/A return null;
0N/A }
0N/A
0N/A int row = loc.getRow();
0N/A int col = loc.getColumn();
0N/A if (col >= table.getColumnCount()) {
0N/A col--;
0N/A }
0N/A
0N/A Rectangle rect = table.getCellRect(row, col, true);
0N/A
0N/A if (row >= table.getRowCount()) {
0N/A row--;
0N/A Rectangle prevRect = table.getCellRect(row, col, true);
0N/A rect.y = prevRect.y + prevRect.height;
0N/A }
0N/A
0N/A if (rect.y == 0) {
0N/A rect.y = -1;
0N/A } else {
0N/A rect.y -= 2;
0N/A }
0N/A
0N/A rect.height = 3;
0N/A
0N/A return rect;
0N/A }
0N/A
0N/A private Rectangle getVDropLineRect(JTable.DropLocation loc) {
0N/A if (!loc.isInsertColumn()) {
0N/A return null;
0N/A }
0N/A
0N/A boolean ltr = table.getComponentOrientation().isLeftToRight();
0N/A int col = loc.getColumn();
0N/A Rectangle rect = table.getCellRect(loc.getRow(), col, true);
0N/A
0N/A if (col >= table.getColumnCount()) {
0N/A col--;
0N/A rect = table.getCellRect(loc.getRow(), col, true);
0N/A if (ltr) {
0N/A rect.x = rect.x + rect.width;
0N/A }
0N/A } else if (!ltr) {
0N/A rect.x = rect.x + rect.width;
0N/A }
0N/A
0N/A if (rect.x == 0) {
0N/A rect.x = -1;
0N/A } else {
0N/A rect.x -= 2;
0N/A }
0N/A
0N/A rect.width = 3;
0N/A
0N/A return rect;
0N/A }
0N/A
0N/A private Rectangle extendRect(Rectangle rect, boolean horizontal) {
0N/A if (rect == null) {
0N/A return rect;
0N/A }
0N/A
0N/A if (horizontal) {
0N/A rect.x = 0;
0N/A rect.width = table.getWidth();
0N/A } else {
0N/A rect.y = 0;
0N/A
0N/A if (table.getRowCount() != 0) {
0N/A Rectangle lastRect = table.getCellRect(table.getRowCount() - 1, 0, true);
0N/A rect.height = lastRect.y + lastRect.height;
0N/A } else {
0N/A rect.height = table.getHeight();
0N/A }
0N/A }
0N/A
0N/A return rect;
0N/A }
0N/A
0N/A /*
0N/A * Paints the grid lines within <I>aRect</I>, using the grid
0N/A * color set with <I>setGridColor</I>. Paints vertical lines
0N/A * if <code>getShowVerticalLines()</code> returns true and paints
0N/A * horizontal lines if <code>getShowHorizontalLines()</code>
0N/A * returns true.
0N/A */
0N/A private void paintGrid(SynthContext context, Graphics g, int rMin,
0N/A int rMax, int cMin, int cMax) {
0N/A g.setColor(table.getGridColor());
0N/A
0N/A Rectangle minCell = table.getCellRect(rMin, cMin, true);
0N/A Rectangle maxCell = table.getCellRect(rMax, cMax, true);
0N/A Rectangle damagedArea = minCell.union( maxCell );
0N/A SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(
0N/A context);
0N/A
0N/A if (table.getShowHorizontalLines()) {
0N/A int tableWidth = damagedArea.x + damagedArea.width;
0N/A int y = damagedArea.y;
0N/A for (int row = rMin; row <= rMax; row++) {
0N/A y += table.getRowHeight(row);
0N/A synthG.drawLine(context, "Table.grid",
0N/A g, damagedArea.x, y - 1, tableWidth - 1,y - 1);
0N/A }
0N/A }
0N/A if (table.getShowVerticalLines()) {
0N/A TableColumnModel cm = table.getColumnModel();
0N/A int tableHeight = damagedArea.y + damagedArea.height;
0N/A int x;
0N/A if (table.getComponentOrientation().isLeftToRight()) {
0N/A x = damagedArea.x;
0N/A for (int column = cMin; column <= cMax; column++) {
0N/A int w = cm.getColumn(column).getWidth();
0N/A x += w;
0N/A synthG.drawLine(context, "Table.grid", g, x - 1, 0,
0N/A x - 1, tableHeight - 1);
0N/A }
0N/A } else {
0N/A x = damagedArea.x;
0N/A for (int column = cMax; column >= cMin; column--) {
0N/A int w = cm.getColumn(column).getWidth();
0N/A x += w;
0N/A synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1,
0N/A tableHeight - 1);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A private int viewIndexForColumn(TableColumn aColumn) {
0N/A TableColumnModel cm = table.getColumnModel();
0N/A for (int column = 0; column < cm.getColumnCount(); column++) {
0N/A if (cm.getColumn(column) == aColumn) {
0N/A return column;
0N/A }
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A private void paintCells(SynthContext context, Graphics g, int rMin,
0N/A int rMax, int cMin, int cMax) {
0N/A JTableHeader header = table.getTableHeader();
0N/A TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();
0N/A
0N/A TableColumnModel cm = table.getColumnModel();
0N/A int columnMargin = cm.getColumnMargin();
0N/A
0N/A Rectangle cellRect;
0N/A TableColumn aColumn;
0N/A int columnWidth;
0N/A if (table.getComponentOrientation().isLeftToRight()) {
0N/A for(int row = rMin; row <= rMax; row++) {
0N/A cellRect = table.getCellRect(row, cMin, false);
0N/A for(int column = cMin; column <= cMax; column++) {
0N/A aColumn = cm.getColumn(column);
0N/A columnWidth = aColumn.getWidth();
0N/A cellRect.width = columnWidth - columnMargin;
0N/A if (aColumn != draggedColumn) {
0N/A paintCell(context, g, cellRect, row, column);
0N/A }
0N/A cellRect.x += columnWidth;
0N/A }
0N/A }
0N/A } else {
0N/A for(int row = rMin; row <= rMax; row++) {
0N/A cellRect = table.getCellRect(row, cMin, false);
0N/A aColumn = cm.getColumn(cMin);
0N/A if (aColumn != draggedColumn) {
0N/A columnWidth = aColumn.getWidth();
0N/A cellRect.width = columnWidth - columnMargin;
0N/A paintCell(context, g, cellRect, row, cMin);
0N/A }
0N/A for(int column = cMin+1; column <= cMax; column++) {
0N/A aColumn = cm.getColumn(column);
0N/A columnWidth = aColumn.getWidth();
0N/A cellRect.width = columnWidth - columnMargin;
0N/A cellRect.x -= columnWidth;
0N/A if (aColumn != draggedColumn) {
0N/A paintCell(context, g, cellRect, row, column);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Paint the dragged column if we are dragging.
0N/A if (draggedColumn != null) {
0N/A paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
0N/A }
0N/A
0N/A // Remove any renderers that may be left in the rendererPane.
0N/A rendererPane.removeAll();
0N/A }
0N/A
0N/A private void paintDraggedArea(SynthContext context, Graphics g, int rMin, int rMax, TableColumn draggedColumn, int distance) {
0N/A int draggedColumnIndex = viewIndexForColumn(draggedColumn);
0N/A
0N/A Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true);
0N/A Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true);
0N/A
0N/A Rectangle vacatedColumnRect = minCell.union(maxCell);
0N/A
0N/A // Paint a gray well in place of the moving column.
0N/A g.setColor(table.getParent().getBackground());
0N/A g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
0N/A vacatedColumnRect.width, vacatedColumnRect.height);
0N/A
0N/A // Move to the where the cell has been dragged.
0N/A vacatedColumnRect.x += distance;
0N/A
0N/A // Fill the background.
0N/A g.setColor(context.getStyle().getColor(context, ColorType.BACKGROUND));
0N/A g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
0N/A vacatedColumnRect.width, vacatedColumnRect.height);
0N/A
0N/A SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(
0N/A context);
0N/A
0N/A
0N/A // Paint the vertical grid lines if necessary.
0N/A if (table.getShowVerticalLines()) {
0N/A g.setColor(table.getGridColor());
0N/A int x1 = vacatedColumnRect.x;
0N/A int y1 = vacatedColumnRect.y;
0N/A int x2 = x1 + vacatedColumnRect.width - 1;
0N/A int y2 = y1 + vacatedColumnRect.height - 1;
0N/A // Left
0N/A synthG.drawLine(context, "Table.grid", g, x1-1, y1, x1-1, y2);
0N/A // Right
0N/A synthG.drawLine(context, "Table.grid", g, x2, y1, x2, y2);
0N/A }
0N/A
0N/A for(int row = rMin; row <= rMax; row++) {
0N/A // Render the cell value
0N/A Rectangle r = table.getCellRect(row, draggedColumnIndex, false);
0N/A r.x += distance;
0N/A paintCell(context, g, r, row, draggedColumnIndex);
0N/A
0N/A // Paint the (lower) horizontal grid line if necessary.
0N/A if (table.getShowHorizontalLines()) {
0N/A g.setColor(table.getGridColor());
0N/A Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true);
0N/A rcr.x += distance;
0N/A int x1 = rcr.x;
0N/A int y1 = rcr.y;
0N/A int x2 = x1 + rcr.width - 1;
0N/A int y2 = y1 + rcr.height - 1;
0N/A synthG.drawLine(context, "Table.grid", g, x1, y2, x2, y2);
0N/A }
0N/A }
0N/A }
0N/A
0N/A private void paintCell(SynthContext context, Graphics g,
0N/A Rectangle cellRect, int row, int column) {
0N/A if (table.isEditing() && table.getEditingRow()==row &&
0N/A table.getEditingColumn()==column) {
0N/A Component component = table.getEditorComponent();
0N/A component.setBounds(cellRect);
0N/A component.validate();
0N/A }
0N/A else {
0N/A TableCellRenderer renderer = table.getCellRenderer(row, column);
0N/A Component component = table.prepareRenderer(renderer, row, column);
1173N/A Color b = component.getBackground();
1173N/A if ((b == null || b instanceof UIResource
1173N/A || component instanceof SynthBooleanTableCellRenderer)
1173N/A && !table.isCellSelected(row, column)) {
1917N/A if (alternateColor != null && row % 2 != 0) {
1173N/A component.setBackground(alternateColor);
1173N/A }
1173N/A }
0N/A rendererPane.paintComponent(g, component, table, cellRect.x,
0N/A cellRect.y, cellRect.width, cellRect.height, true);
0N/A }
0N/A }
0N/A
1999N/A /**
1999N/A * @inheritDoc
1999N/A */
1999N/A @Override
0N/A public void propertyChange(PropertyChangeEvent event) {
0N/A if (SynthLookAndFeel.shouldUpdateStyle(event)) {
0N/A updateStyle((JTable)event.getSource());
0N/A }
0N/A }
0N/A
0N/A
0N/A private class SynthBooleanTableCellRenderer extends JCheckBox implements
0N/A TableCellRenderer {
0N/A private boolean isRowSelected;
0N/A
0N/A public SynthBooleanTableCellRenderer() {
0N/A setHorizontalAlignment(JLabel.CENTER);
1173N/A setName("Table.cellRenderer");
0N/A }
0N/A
0N/A public Component getTableCellRendererComponent(
0N/A JTable table, Object value, boolean isSelected,
0N/A boolean hasFocus, int row, int column) {
0N/A isRowSelected = isSelected;
0N/A
0N/A if (isSelected) {
1173N/A setForeground(unwrap(table.getSelectionForeground()));
1173N/A setBackground(unwrap(table.getSelectionBackground()));
0N/A } else {
1173N/A setForeground(unwrap(table.getForeground()));
1173N/A setBackground(unwrap(table.getBackground()));
0N/A }
0N/A
0N/A setSelected((value != null && ((Boolean)value).booleanValue()));
0N/A return this;
0N/A }
0N/A
1173N/A private Color unwrap(Color c) {
1173N/A if (c instanceof UIResource) {
1173N/A return new Color(c.getRGB());
1173N/A }
1173N/A return c;
1173N/A }
1173N/A
0N/A public boolean isOpaque() {
0N/A return isRowSelected ? true : super.isOpaque();
0N/A }
0N/A }
0N/A
0N/A private class SynthTableCellRenderer extends DefaultTableCellRenderer {
0N/A private Object numberFormat;
0N/A private Object dateFormat;
0N/A private boolean opaque;
0N/A
0N/A public void setOpaque(boolean isOpaque) {
0N/A opaque = isOpaque;
0N/A }
0N/A
0N/A public boolean isOpaque() {
0N/A return opaque;
0N/A }
0N/A
0N/A public String getName() {
0N/A String name = super.getName();
0N/A if (name == null) {
0N/A return "Table.cellRenderer";
0N/A }
0N/A return name;
0N/A }
0N/A
0N/A public void setBorder(Border b) {
0N/A if (useUIBorder || b instanceof SynthBorder) {
0N/A super.setBorder(b);
0N/A }
0N/A }
0N/A
0N/A public Component getTableCellRendererComponent(
0N/A JTable table, Object value, boolean isSelected,
0N/A boolean hasFocus, int row, int column) {
0N/A if (!useTableColors && (isSelected || hasFocus)) {
0N/A SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
0N/A getUIOfType(getUI(), SynthLabelUI.class),
0N/A isSelected, hasFocus, table.isEnabled(), false);
0N/A }
0N/A else {
0N/A SynthLookAndFeel.resetSelectedUI();
0N/A }
0N/A super.getTableCellRendererComponent(table, value, isSelected,
0N/A hasFocus, row, column);
0N/A
0N/A setIcon(null);
3863N/A if (table != null) {
3863N/A configureValue(value, table.getColumnClass(column));
3863N/A }
0N/A return this;
0N/A }
0N/A
0N/A private void configureValue(Object value, Class columnClass) {
0N/A if (columnClass == Object.class || columnClass == null) {
0N/A setHorizontalAlignment(JLabel.LEADING);
0N/A } else if (columnClass == Float.class || columnClass == Double.class) {
0N/A if (numberFormat == null) {
0N/A numberFormat = NumberFormat.getInstance();
0N/A }
0N/A setHorizontalAlignment(JLabel.TRAILING);
0N/A setText((value == null) ? "" : ((NumberFormat)numberFormat).format(value));
0N/A }
0N/A else if (columnClass == Number.class) {
0N/A setHorizontalAlignment(JLabel.TRAILING);
0N/A // Super will have set value.
0N/A }
0N/A else if (columnClass == Icon.class || columnClass == ImageIcon.class) {
0N/A setHorizontalAlignment(JLabel.CENTER);
1173N/A setIcon((value instanceof Icon) ? (Icon)value : null);
0N/A setText("");
0N/A }
0N/A else if (columnClass == Date.class) {
0N/A if (dateFormat == null) {
0N/A dateFormat = DateFormat.getDateInstance();
0N/A }
0N/A setHorizontalAlignment(JLabel.LEADING);
0N/A setText((value == null) ? "" : ((Format)dateFormat).format(value));
0N/A }
0N/A else {
0N/A configureValue(value, columnClass.getSuperclass());
0N/A }
0N/A }
0N/A
0N/A public void paint(Graphics g) {
0N/A super.paint(g);
0N/A SynthLookAndFeel.resetSelectedUI();
0N/A }
0N/A }
0N/A}