001 /*
002 * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.swing.plaf.synth;
027
028 import java.awt.Color;
029 import java.awt.Component;
030 import java.awt.Graphics;
031 import java.awt.Point;
032 import java.awt.Rectangle;
033 import java.beans.PropertyChangeEvent;
034 import java.beans.PropertyChangeListener;
035 import java.text.DateFormat;
036 import java.text.Format;
037 import java.text.NumberFormat;
038 import java.util.Date;
039 import javax.swing.Icon;
040 import javax.swing.ImageIcon;
041 import javax.swing.JCheckBox;
042 import javax.swing.JComponent;
043 import javax.swing.JLabel;
044 import javax.swing.JTable;
045 import javax.swing.LookAndFeel;
046 import javax.swing.border.Border;
047 import javax.swing.plaf.ComponentUI;
048 import javax.swing.plaf.UIResource;
049 import javax.swing.plaf.basic.BasicTableUI;
050 import javax.swing.table.DefaultTableCellRenderer;
051 import javax.swing.table.JTableHeader;
052 import javax.swing.table.TableCellRenderer;
053 import javax.swing.table.TableColumn;
054 import javax.swing.table.TableColumnModel;
055
056 import sun.swing.plaf.synth.SynthUI;
057
058 /**
059 * SynthTableUI implementation
060 *
061 * @version 1.29, 05/05/07
062 * @author Philip Milne
063 */
064 class SynthTableUI extends BasicTableUI implements SynthUI,
065 PropertyChangeListener {
066 //
067 // Instance Variables
068 //
069
070 private SynthStyle style;
071
072 private boolean useTableColors;
073 private boolean useUIBorder;
074
075 // TableCellRenderer installed on the JTable at the time we're installed,
076 // cached so that we can reinstall them at uninstallUI time.
077 private TableCellRenderer dateRenderer;
078 private TableCellRenderer numberRenderer;
079 private TableCellRenderer doubleRender;
080 private TableCellRenderer floatRenderer;
081 private TableCellRenderer iconRenderer;
082 private TableCellRenderer imageIconRenderer;
083 private TableCellRenderer booleanRenderer;
084 private TableCellRenderer objectRenderer;
085
086 //
087 // The installation/uninstall procedures and support
088 //
089
090 public static ComponentUI createUI(JComponent c) {
091 return new SynthTableUI();
092 }
093
094 /**
095 * Initialize JTable properties, e.g. font, foreground, and background.
096 * The font, foreground, and background properties are only set if their
097 * current value is either null or a UIResource, other properties are set
098 * if the current value is null.
099 *
100 * @see #installUI
101 */
102 protected void installDefaults() {
103 dateRenderer = installRendererIfPossible(Date.class, null);
104 numberRenderer = installRendererIfPossible(Number.class, null);
105 doubleRender = installRendererIfPossible(Double.class, null);
106 floatRenderer = installRendererIfPossible(Float.class, null);
107 iconRenderer = installRendererIfPossible(Icon.class, null);
108 imageIconRenderer = installRendererIfPossible(ImageIcon.class,
109 null);
110 booleanRenderer = installRendererIfPossible(Boolean.class,
111 new SynthBooleanTableCellRenderer());
112 objectRenderer = installRendererIfPossible(Object.class,
113 new SynthTableCellRenderer());
114 updateStyle(table);
115 }
116
117 private TableCellRenderer installRendererIfPossible(
118 Class objectClass, TableCellRenderer renderer) {
119 TableCellRenderer currentRenderer = table
120 .getDefaultRenderer(objectClass);
121 if (currentRenderer instanceof UIResource) {
122 table.setDefaultRenderer(objectClass, renderer);
123 }
124 return currentRenderer;
125 }
126
127 private void updateStyle(JTable c) {
128 SynthContext context = getContext(c, ENABLED);
129 SynthStyle oldStyle = style;
130 style = SynthLookAndFeel.updateStyle(context, this );
131 if (style != oldStyle) {
132 context.setComponentState(ENABLED | SELECTED);
133
134 Color sbg = table.getSelectionBackground();
135 if (sbg == null || sbg instanceof UIResource) {
136 table.setSelectionBackground(style.getColor(context,
137 ColorType.TEXT_BACKGROUND));
138 }
139
140 Color sfg = table.getSelectionForeground();
141 if (sfg == null || sfg instanceof UIResource) {
142 table.setSelectionForeground(style.getColor(context,
143 ColorType.TEXT_FOREGROUND));
144 }
145
146 context.setComponentState(ENABLED);
147
148 Color gridColor = table.getGridColor();
149 if (gridColor == null || gridColor instanceof UIResource) {
150 gridColor = (Color) style.get(context,
151 "Table.gridColor");
152 if (gridColor == null) {
153 gridColor = style.getColor(context,
154 ColorType.FOREGROUND);
155 }
156 table.setGridColor(gridColor);
157 }
158
159 useTableColors = style.getBoolean(context,
160 "Table.rendererUseTableColors", true);
161 useUIBorder = style.getBoolean(context,
162 "Table.rendererUseUIBorder", true);
163
164 Object rowHeight = style.get(context, "Table.rowHeight");
165 if (rowHeight != null) {
166 LookAndFeel.installProperty(table, "rowHeight",
167 rowHeight);
168 }
169 if (oldStyle != null) {
170 uninstallKeyboardActions();
171 installKeyboardActions();
172 }
173 }
174 context.dispose();
175 }
176
177 /**
178 * Attaches listeners to the JTable.
179 */
180 protected void installListeners() {
181 super .installListeners();
182 table.addPropertyChangeListener(this );
183 }
184
185 protected void uninstallDefaults() {
186 table.setDefaultRenderer(Date.class, dateRenderer);
187 table.setDefaultRenderer(Number.class, numberRenderer);
188 table.setDefaultRenderer(Double.class, doubleRender);
189 table.setDefaultRenderer(Float.class, floatRenderer);
190 table.setDefaultRenderer(Icon.class, iconRenderer);
191 table.setDefaultRenderer(ImageIcon.class, imageIconRenderer);
192 table.setDefaultRenderer(Boolean.class, booleanRenderer);
193 table.setDefaultRenderer(Object.class, objectRenderer);
194
195 if (table.getTransferHandler() instanceof UIResource) {
196 table.setTransferHandler(null);
197 }
198 SynthContext context = getContext(table, ENABLED);
199 style.uninstallDefaults(context);
200 context.dispose();
201 style = null;
202 }
203
204 protected void uninstallListeners() {
205 table.removePropertyChangeListener(this );
206 super .uninstallListeners();
207 }
208
209 //
210 // SynthUI
211 //
212 public SynthContext getContext(JComponent c) {
213 return getContext(c, getComponentState(c));
214 }
215
216 private SynthContext getContext(JComponent c, int state) {
217 return SynthContext.getContext(SynthContext.class, c,
218 SynthLookAndFeel.getRegion(c), style, state);
219 }
220
221 private Region getRegion(JComponent c) {
222 return SynthLookAndFeel.getRegion(c);
223 }
224
225 private int getComponentState(JComponent c) {
226 return SynthLookAndFeel.getComponentState(c);
227 }
228
229 //
230 // Paint methods and support
231 //
232
233 public void update(Graphics g, JComponent c) {
234 SynthContext context = getContext(c);
235
236 SynthLookAndFeel.update(context, g);
237 context.getPainter().paintTableBackground(context, g, 0, 0,
238 c.getWidth(), c.getHeight());
239 paint(context, g);
240 context.dispose();
241 }
242
243 public void paintBorder(SynthContext context, Graphics g, int x,
244 int y, int w, int h) {
245 context.getPainter().paintTableBorder(context, g, x, y, w, h);
246 }
247
248 public void paint(Graphics g, JComponent c) {
249 SynthContext context = getContext(c);
250
251 paint(context, g);
252 context.dispose();
253 }
254
255 protected void paint(SynthContext context, Graphics g) {
256 Rectangle clip = g.getClipBounds();
257
258 Rectangle bounds = table.getBounds();
259 // account for the fact that the graphics has already been translated
260 // into the table's bounds
261 bounds.x = bounds.y = 0;
262
263 if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
264 // this check prevents us from painting the entire table
265 // when the clip doesn't intersect our bounds at all
266 !bounds.intersects(clip)) {
267
268 paintDropLines(context, g);
269 return;
270 }
271
272 boolean ltr = table.getComponentOrientation().isLeftToRight();
273
274 Point upperLeft = clip.getLocation();
275
276 Point lowerRight = new Point(clip.x + clip.width - 1, clip.y
277 + clip.height - 1);
278
279 int rMin = table.rowAtPoint(upperLeft);
280 int rMax = table.rowAtPoint(lowerRight);
281 // This should never happen (as long as our bounds intersect the clip,
282 // which is why we bail above if that is the case).
283 if (rMin == -1) {
284 rMin = 0;
285 }
286 // If the table does not have enough rows to fill the view we'll get -1.
287 // (We could also get -1 if our bounds don't intersect the clip,
288 // which is why we bail above if that is the case).
289 // Replace this with the index of the last row.
290 if (rMax == -1) {
291 rMax = table.getRowCount() - 1;
292 }
293
294 int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
295 int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
296 // This should never happen.
297 if (cMin == -1) {
298 cMin = 0;
299 }
300 // If the table does not have enough columns to fill the view we'll get -1.
301 // Replace this with the index of the last column.
302 if (cMax == -1) {
303 cMax = table.getColumnCount() - 1;
304 }
305
306 // Paint the grid.
307 paintGrid(context, g, rMin, rMax, cMin, cMax);
308
309 // Paint the cells.
310 paintCells(context, g, rMin, rMax, cMin, cMax);
311
312 paintDropLines(context, g);
313 }
314
315 private void paintDropLines(SynthContext context, Graphics g) {
316 JTable.DropLocation loc = table.getDropLocation();
317 if (loc == null) {
318 return;
319 }
320
321 Color color = (Color) style.get(context, "Table.dropLineColor");
322 Color shortColor = (Color) style.get(context,
323 "Table.dropLineShortColor");
324 if (color == null && shortColor == null) {
325 return;
326 }
327
328 Rectangle rect;
329
330 rect = getHDropLineRect(loc);
331 if (rect != null) {
332 int x = rect.x;
333 int w = rect.width;
334 if (color != null) {
335 extendRect(rect, true);
336 g.setColor(color);
337 g.fillRect(rect.x, rect.y, rect.width, rect.height);
338 }
339 if (!loc.isInsertColumn() && shortColor != null) {
340 g.setColor(shortColor);
341 g.fillRect(x, rect.y, w, rect.height);
342 }
343 }
344
345 rect = getVDropLineRect(loc);
346 if (rect != null) {
347 int y = rect.y;
348 int h = rect.height;
349 if (color != null) {
350 extendRect(rect, false);
351 g.setColor(color);
352 g.fillRect(rect.x, rect.y, rect.width, rect.height);
353 }
354 if (!loc.isInsertRow() && shortColor != null) {
355 g.setColor(shortColor);
356 g.fillRect(rect.x, y, rect.width, h);
357 }
358 }
359 }
360
361 private Rectangle getHDropLineRect(JTable.DropLocation loc) {
362 if (!loc.isInsertRow()) {
363 return null;
364 }
365
366 int row = loc.getRow();
367 int col = loc.getColumn();
368 if (col >= table.getColumnCount()) {
369 col--;
370 }
371
372 Rectangle rect = table.getCellRect(row, col, true);
373
374 if (row >= table.getRowCount()) {
375 row--;
376 Rectangle prevRect = table.getCellRect(row, col, true);
377 rect.y = prevRect.y + prevRect.height;
378 }
379
380 if (rect.y == 0) {
381 rect.y = -1;
382 } else {
383 rect.y -= 2;
384 }
385
386 rect.height = 3;
387
388 return rect;
389 }
390
391 private Rectangle getVDropLineRect(JTable.DropLocation loc) {
392 if (!loc.isInsertColumn()) {
393 return null;
394 }
395
396 boolean ltr = table.getComponentOrientation().isLeftToRight();
397 int col = loc.getColumn();
398 Rectangle rect = table.getCellRect(loc.getRow(), col, true);
399
400 if (col >= table.getColumnCount()) {
401 col--;
402 rect = table.getCellRect(loc.getRow(), col, true);
403 if (ltr) {
404 rect.x = rect.x + rect.width;
405 }
406 } else if (!ltr) {
407 rect.x = rect.x + rect.width;
408 }
409
410 if (rect.x == 0) {
411 rect.x = -1;
412 } else {
413 rect.x -= 2;
414 }
415
416 rect.width = 3;
417
418 return rect;
419 }
420
421 private Rectangle extendRect(Rectangle rect, boolean horizontal) {
422 if (rect == null) {
423 return rect;
424 }
425
426 if (horizontal) {
427 rect.x = 0;
428 rect.width = table.getWidth();
429 } else {
430 rect.y = 0;
431
432 if (table.getRowCount() != 0) {
433 Rectangle lastRect = table.getCellRect(table
434 .getRowCount() - 1, 0, true);
435 rect.height = lastRect.y + lastRect.height;
436 } else {
437 rect.height = table.getHeight();
438 }
439 }
440
441 return rect;
442 }
443
444 /*
445 * Paints the grid lines within <I>aRect</I>, using the grid
446 * color set with <I>setGridColor</I>. Paints vertical lines
447 * if <code>getShowVerticalLines()</code> returns true and paints
448 * horizontal lines if <code>getShowHorizontalLines()</code>
449 * returns true.
450 */
451 private void paintGrid(SynthContext context, Graphics g, int rMin,
452 int rMax, int cMin, int cMax) {
453 g.setColor(table.getGridColor());
454
455 Rectangle minCell = table.getCellRect(rMin, cMin, true);
456 Rectangle maxCell = table.getCellRect(rMax, cMax, true);
457 Rectangle damagedArea = minCell.union(maxCell);
458 SynthGraphicsUtils synthG = context.getStyle()
459 .getGraphicsUtils(context);
460
461 if (table.getShowHorizontalLines()) {
462 int tableWidth = damagedArea.x + damagedArea.width;
463 int y = damagedArea.y;
464 for (int row = rMin; row <= rMax; row++) {
465 y += table.getRowHeight(row);
466 synthG.drawLine(context, "Table.grid", g,
467 damagedArea.x, y - 1, tableWidth - 1, y - 1);
468 }
469 }
470 if (table.getShowVerticalLines()) {
471 TableColumnModel cm = table.getColumnModel();
472 int tableHeight = damagedArea.y + damagedArea.height;
473 int x;
474 if (table.getComponentOrientation().isLeftToRight()) {
475 x = damagedArea.x;
476 for (int column = cMin; column <= cMax; column++) {
477 int w = cm.getColumn(column).getWidth();
478 x += w;
479 synthG.drawLine(context, "Table.grid", g, x - 1, 0,
480 x - 1, tableHeight - 1);
481 }
482 } else {
483 x = damagedArea.x;
484 for (int column = cMax; column >= cMin; column--) {
485 int w = cm.getColumn(column).getWidth();
486 x += w;
487 synthG.drawLine(context, "Table.grid", g, x - 1, 0,
488 x - 1, tableHeight - 1);
489 }
490 }
491 }
492 }
493
494 private int viewIndexForColumn(TableColumn aColumn) {
495 TableColumnModel cm = table.getColumnModel();
496 for (int column = 0; column < cm.getColumnCount(); column++) {
497 if (cm.getColumn(column) == aColumn) {
498 return column;
499 }
500 }
501 return -1;
502 }
503
504 private void paintCells(SynthContext context, Graphics g, int rMin,
505 int rMax, int cMin, int cMax) {
506 JTableHeader header = table.getTableHeader();
507 TableColumn draggedColumn = (header == null) ? null : header
508 .getDraggedColumn();
509
510 TableColumnModel cm = table.getColumnModel();
511 int columnMargin = cm.getColumnMargin();
512
513 Rectangle cellRect;
514 TableColumn aColumn;
515 int columnWidth;
516 if (table.getComponentOrientation().isLeftToRight()) {
517 for (int row = rMin; row <= rMax; row++) {
518 cellRect = table.getCellRect(row, cMin, false);
519 for (int column = cMin; column <= cMax; column++) {
520 aColumn = cm.getColumn(column);
521 columnWidth = aColumn.getWidth();
522 cellRect.width = columnWidth - columnMargin;
523 if (aColumn != draggedColumn) {
524 paintCell(context, g, cellRect, row, column);
525 }
526 cellRect.x += columnWidth;
527 }
528 }
529 } else {
530 for (int row = rMin; row <= rMax; row++) {
531 cellRect = table.getCellRect(row, cMin, false);
532 aColumn = cm.getColumn(cMin);
533 if (aColumn != draggedColumn) {
534 columnWidth = aColumn.getWidth();
535 cellRect.width = columnWidth - columnMargin;
536 paintCell(context, g, cellRect, row, cMin);
537 }
538 for (int column = cMin + 1; column <= cMax; column++) {
539 aColumn = cm.getColumn(column);
540 columnWidth = aColumn.getWidth();
541 cellRect.width = columnWidth - columnMargin;
542 cellRect.x -= columnWidth;
543 if (aColumn != draggedColumn) {
544 paintCell(context, g, cellRect, row, column);
545 }
546 }
547 }
548 }
549
550 // Paint the dragged column if we are dragging.
551 if (draggedColumn != null) {
552 paintDraggedArea(context, g, rMin, rMax, draggedColumn,
553 header.getDraggedDistance());
554 }
555
556 // Remove any renderers that may be left in the rendererPane.
557 rendererPane.removeAll();
558 }
559
560 private void paintDraggedArea(SynthContext context, Graphics g,
561 int rMin, int rMax, TableColumn draggedColumn, int distance) {
562 int draggedColumnIndex = viewIndexForColumn(draggedColumn);
563
564 Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex,
565 true);
566 Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex,
567 true);
568
569 Rectangle vacatedColumnRect = minCell.union(maxCell);
570
571 // Paint a gray well in place of the moving column.
572 g.setColor(table.getParent().getBackground());
573 g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
574 vacatedColumnRect.width, vacatedColumnRect.height);
575
576 // Move to the where the cell has been dragged.
577 vacatedColumnRect.x += distance;
578
579 // Fill the background.
580 g.setColor(context.getStyle().getColor(context,
581 ColorType.BACKGROUND));
582 g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
583 vacatedColumnRect.width, vacatedColumnRect.height);
584
585 SynthGraphicsUtils synthG = context.getStyle()
586 .getGraphicsUtils(context);
587
588 // Paint the vertical grid lines if necessary.
589 if (table.getShowVerticalLines()) {
590 g.setColor(table.getGridColor());
591 int x1 = vacatedColumnRect.x;
592 int y1 = vacatedColumnRect.y;
593 int x2 = x1 + vacatedColumnRect.width - 1;
594 int y2 = y1 + vacatedColumnRect.height - 1;
595 // Left
596 synthG.drawLine(context, "Table.grid", g, x1 - 1, y1,
597 x1 - 1, y2);
598 // Right
599 synthG.drawLine(context, "Table.grid", g, x2, y1, x2, y2);
600 }
601
602 for (int row = rMin; row <= rMax; row++) {
603 // Render the cell value
604 Rectangle r = table.getCellRect(row, draggedColumnIndex,
605 false);
606 r.x += distance;
607 paintCell(context, g, r, row, draggedColumnIndex);
608
609 // Paint the (lower) horizontal grid line if necessary.
610 if (table.getShowHorizontalLines()) {
611 g.setColor(table.getGridColor());
612 Rectangle rcr = table.getCellRect(row,
613 draggedColumnIndex, true);
614 rcr.x += distance;
615 int x1 = rcr.x;
616 int y1 = rcr.y;
617 int x2 = x1 + rcr.width - 1;
618 int y2 = y1 + rcr.height - 1;
619 synthG.drawLine(context, "Table.grid", g, x1, y2, x2,
620 y2);
621 }
622 }
623 }
624
625 private void paintCell(SynthContext context, Graphics g,
626 Rectangle cellRect, int row, int column) {
627 if (table.isEditing() && table.getEditingRow() == row
628 && table.getEditingColumn() == column) {
629 Component component = table.getEditorComponent();
630 component.setBounds(cellRect);
631 component.validate();
632 } else {
633 TableCellRenderer renderer = table.getCellRenderer(row,
634 column);
635 Component component = table.prepareRenderer(renderer, row,
636 column);
637 rendererPane.paintComponent(g, component, table,
638 cellRect.x, cellRect.y, cellRect.width,
639 cellRect.height, true);
640 }
641 }
642
643 public void propertyChange(PropertyChangeEvent event) {
644 if (SynthLookAndFeel.shouldUpdateStyle(event)) {
645 updateStyle((JTable) event.getSource());
646 }
647 }
648
649 private class SynthBooleanTableCellRenderer extends JCheckBox
650 implements TableCellRenderer {
651 private boolean isRowSelected;
652
653 public SynthBooleanTableCellRenderer() {
654 super ();
655 setHorizontalAlignment(JLabel.CENTER);
656 }
657
658 public String getName() {
659 String name = super .getName();
660 if (name == null) {
661 return "Table.cellRenderer";
662 }
663 return name;
664 }
665
666 public Component getTableCellRendererComponent(JTable table,
667 Object value, boolean isSelected, boolean hasFocus,
668 int row, int column) {
669 isRowSelected = isSelected;
670
671 if (isSelected) {
672 setForeground(table.getSelectionForeground());
673 setBackground(table.getSelectionBackground());
674 } else {
675 setForeground(table.getForeground());
676 setBackground(table.getBackground());
677 }
678
679 setSelected((value != null && ((Boolean) value)
680 .booleanValue()));
681 return this ;
682 }
683
684 public boolean isOpaque() {
685 return isRowSelected ? true : super .isOpaque();
686 }
687 }
688
689 private class SynthTableCellRenderer extends
690 DefaultTableCellRenderer {
691 private Object numberFormat;
692 private Object dateFormat;
693 private boolean opaque;
694
695 public void setOpaque(boolean isOpaque) {
696 opaque = isOpaque;
697 }
698
699 public boolean isOpaque() {
700 return opaque;
701 }
702
703 public String getName() {
704 String name = super .getName();
705 if (name == null) {
706 return "Table.cellRenderer";
707 }
708 return name;
709 }
710
711 public void setBorder(Border b) {
712 if (useUIBorder || b instanceof SynthBorder) {
713 super .setBorder(b);
714 }
715 }
716
717 public Component getTableCellRendererComponent(JTable table,
718 Object value, boolean isSelected, boolean hasFocus,
719 int row, int column) {
720 if (!useTableColors && (isSelected || hasFocus)) {
721 SynthLookAndFeel.setSelectedUI(
722 (SynthLabelUI) SynthLookAndFeel.getUIOfType(
723 getUI(), SynthLabelUI.class),
724 isSelected, hasFocus, table.isEnabled(), false);
725 } else {
726 SynthLookAndFeel.resetSelectedUI();
727 }
728 super .getTableCellRendererComponent(table, value,
729 isSelected, hasFocus, row, column);
730
731 setIcon(null);
732 Class columnClass = table.getColumnClass(column);
733 configureValue(value, columnClass);
734
735 return this ;
736 }
737
738 private void configureValue(Object value, Class columnClass) {
739 if (columnClass == Object.class || columnClass == null) {
740 setHorizontalAlignment(JLabel.LEADING);
741 } else if (columnClass == Float.class
742 || columnClass == Double.class) {
743 if (numberFormat == null) {
744 numberFormat = NumberFormat.getInstance();
745 }
746 setHorizontalAlignment(JLabel.TRAILING);
747 setText((value == null) ? ""
748 : ((NumberFormat) numberFormat).format(value));
749 } else if (columnClass == Number.class) {
750 setHorizontalAlignment(JLabel.TRAILING);
751 // Super will have set value.
752 } else if (columnClass == Icon.class
753 || columnClass == ImageIcon.class) {
754 setHorizontalAlignment(JLabel.CENTER);
755 setIcon((Icon) value);
756 setText("");
757 } else if (columnClass == Date.class) {
758 if (dateFormat == null) {
759 dateFormat = DateFormat.getDateInstance();
760 }
761 setHorizontalAlignment(JLabel.LEADING);
762 setText((value == null) ? "" : ((Format) dateFormat)
763 .format(value));
764 } else {
765 configureValue(value, columnClass.getSuperclass());
766 }
767 }
768
769 public void paint(Graphics g) {
770 super.paint(g);
771 SynthLookAndFeel.resetSelectedUI();
772 }
773 }
774 }
|