01: /*
02: * RowStatusRenderer.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.renderer;
13:
14: import java.awt.Component;
15: import java.awt.Dimension;
16:
17: import javax.swing.ImageIcon;
18: import javax.swing.JLabel;
19: import javax.swing.JTable;
20: import javax.swing.table.DefaultTableCellRenderer;
21:
22: import workbench.resource.ResourceMgr;
23: import workbench.storage.DataStore;
24:
25: /**
26: * @author support@sql-workbench.net
27: */
28: public class RowStatusRenderer extends DefaultTableCellRenderer {
29: private static final ImageIcon STATUS_MODIFIED_ICON = ResourceMgr
30: .getPicture("modifiedrow");
31: private static final ImageIcon STATUS_NOT_MODIFIED_ICON = ResourceMgr
32: .getPicture("blank");
33: private static final ImageIcon STATUS_NEW_ICON = ResourceMgr
34: .getPicture("newrow");
35:
36: private final String newTip = ResourceMgr.getString("TxtRowNew");
37: private final String modifiedTip = ResourceMgr
38: .getString("TxtRowModified");
39: private final String notModifiedTip = ResourceMgr
40: .getString("TxtRowNotModified");
41:
42: public RowStatusRenderer() {
43: Dimension dim = new Dimension(18, 18);
44: this .setMaximumSize(dim);
45: this .setMinimumSize(dim);
46: this .setPreferredSize(dim);
47: this .setText(null);
48: this .setIconTextGap(0);
49: this .setHorizontalAlignment(JLabel.LEFT);
50: }
51:
52: public Component getTableCellRendererComponent(JTable table,
53: Object value, boolean isSelected, boolean hasFocus,
54: int row, int column) {
55: try {
56: Integer status = (Integer) value;
57: if (status == DataStore.ROW_NEW) {
58: this .setIcon(STATUS_NEW_ICON);
59: this .setToolTipText(newTip);
60: } else if (status == DataStore.ROW_MODIFIED) {
61: this .setIcon(STATUS_MODIFIED_ICON);
62: this .setToolTipText(modifiedTip);
63: } else {
64: this .setIcon(STATUS_NOT_MODIFIED_ICON);
65: this .setToolTipText(notModifiedTip);
66: }
67: } catch (Exception e) {
68: this.setIcon(STATUS_NOT_MODIFIED_ICON);
69: this.setToolTipText(notModifiedTip);
70: }
71: return this;
72: }
73:
74: }
|