001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.table;
006:
007: import java.util.*;
008: import java.sql.*;
009: import java.awt.*;
010:
011: import javax.swing.table.*;
012:
013: import com.javelin.swinglets.*;
014:
015: /**
016: * A SQLTableRenderer
017: *
018: * @author Dino Fancellu
019: */
020:
021: public class SQLTableRenderer implements STableCellRenderer {
022: SLabel label = new SLabel();
023: SCheckBox checkbox = new SCheckBox();
024: Vector linkColumns = new Vector();
025:
026: class Target {
027: public int targetColumn;
028: public String targetWindow;
029:
030: public Target(int targetColumn, String targetWindow) {
031: this .targetColumn = targetColumn;
032: this .targetWindow = targetWindow;
033: }
034: }
035:
036: public void setLink(int column) {
037: setLink(column, column, "");
038: }
039:
040: public void setLink(int column, String targetWindow) {
041: setLink(column, column, targetWindow);
042: }
043:
044: public void setLink(int column, int target) {
045: setLink(column, target, "");
046: }
047:
048: public void setLink(int column, int target, String targetWindow) {
049: linkColumns.setSize(column + 1);
050: linkColumns.setElementAt(new Target(target, targetWindow),
051: column);
052: }
053:
054: public void removeAllLinks() {
055: linkColumns.removeAllElements();
056: }
057:
058: public void getLinks(STable table, Object value, int row, int column) {
059: if (column >= linkColumns.size()) {
060: label.setLink(null);
061: return;
062: }
063:
064: Target t = (Target) linkColumns.elementAt(column);
065:
066: if (t != null) {
067: String url = table.getValueAt(row, t.targetColumn)
068: .toString();
069: label.setLink(new SLink(url, t.targetWindow));
070: } else {
071: label.setLink(null);
072: }
073: }
074:
075: public SComponent getTableCellRendererComponent(STable table,
076: Object value, int row, int column) {
077: if (value == null)
078: return null;
079:
080: getLinks(table, value, row, column);
081:
082: if (value instanceof Boolean) {
083: checkbox.setSelected(((Boolean) value).booleanValue());
084: table.setHorizontalAlignmentAt(SConstants.CENTER, row,
085: column);
086: return checkbox;
087: }
088:
089: if (value instanceof Number) {
090: label.setHorizontalAlignment(SConstants.RIGHT);
091: } else {
092: label.setHorizontalAlignment(SConstants.LEFT);
093: }
094:
095: if (value instanceof SComponent) {
096: return (SComponent) value;
097: }
098:
099: if (value instanceof SColor) {
100: label.setForeground(((SColor) value));
101: } else {
102: label.setForeground(null);
103: }
104:
105: label.setText(value.toString());
106:
107: return label;
108: }
109: }
|