01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.ui.renderer;
24:
25: import java.awt.Component;
26: import java.text.DateFormat;
27: import java.text.MessageFormat;
28: import java.util.Date;
29:
30: import javax.swing.JTable;
31:
32: import org.isqlviewer.history.HistoricalCommand;
33: import org.isqlviewer.model.HistoryTreeModel;
34: import org.isqlviewer.ui.laf.EnhancedTableCellRenderer;
35:
36: /**
37: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
38: * @version 1.0
39: */
40: public class HistoryTableCellRenderer extends EnhancedTableCellRenderer {
41:
42: private static final long serialVersionUID = -4705227985345615150L;
43: private MessageFormat childCountFormat = new MessageFormat(
44: "({0, number, integer})");
45: private HistoryTreeModel model = null;
46:
47: public HistoryTableCellRenderer(HistoryTreeModel model) {
48:
49: this .model = model;
50: }
51:
52: @Override
53: public Component getTableCellRendererComponent(JTable table,
54: Object value, boolean isSelected, boolean hasFocus,
55: int row, int column) {
56:
57: super .getTableCellRendererComponent(table, value, isSelected,
58: hasFocus, row, column);
59: if (value instanceof HistoricalCommand) {
60: DateFormat timeFormat = DateFormat
61: .getTimeInstance(DateFormat.MEDIUM);
62: Date date = ((HistoricalCommand) value).getQueryTime();
63: setText(timeFormat.format(date));
64: } else if (value instanceof Date) {
65: int count = model.getChildCount(value);
66: setText(childCountFormat.format(new Object[] { new Integer(
67: count) }));
68: }
69: return this;
70: }
71: }
|