01: /*
02: * ActionDisplayRenderer.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.settings;
13:
14: import java.awt.Color;
15: import java.awt.Component;
16: import javax.swing.JTable;
17: import javax.swing.table.DefaultTableCellRenderer;
18: import workbench.gui.renderer.*;
19: import workbench.resource.Settings;
20:
21: /**
22: * @author support@sql-workbench.net
23: */
24: public class ActionDisplayRenderer extends DefaultTableCellRenderer
25: implements WbRenderer {
26: private boolean useAlternateColors = false;
27: private Color alternateBackground = null;
28:
29: public ActionDisplayRenderer() {
30: super ();
31: alternateBackground = Settings.getInstance()
32: .getAlternateRowColor();
33: useAlternateColors = Settings.getInstance()
34: .getUseAlternateRowColor();
35: }
36:
37: public Component getTableCellRendererComponent(JTable table,
38: Object value, boolean isSelected, boolean hasFocus,
39: int row, int column) {
40: try {
41: ActionDisplay d = (ActionDisplay) value;
42: this .setToolTipText(d.tooltip);
43: boolean isAlternatingRow = this .useAlternateColors
44: && ((row % 2) == 1);
45: if (isSelected) {
46: this .setBackground(table.getSelectionBackground());
47: this .setForeground(table.getSelectionForeground());
48: } else {
49: this .setForeground(table.getForeground());
50: if (isAlternatingRow) {
51: this .setBackground(alternateBackground);
52: } else {
53: this .setBackground(table.getBackground());
54: }
55: }
56: return super .getTableCellRendererComponent(table, d.text,
57: isSelected, hasFocus, row, column);
58: } catch (Exception e) {
59: return super .getTableCellRendererComponent(table, value,
60: isSelected, hasFocus, row, column);
61: }
62:
63: }
64:
65: public int getDisplayWidth() {
66: return getText().length();
67: }
68:
69: public String getDisplayValue() {
70: return getText();
71: }
72:
73: public void setUseAlternatingColors(boolean flag) {
74: this.useAlternateColors = flag;
75: }
76:
77: }
|