001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.examples.swinglets;
006:
007: import java.util.*;
008: import java.io.*;
009: import java.awt.*;
010:
011: import javax.servlet.*;
012: import javax.servlet.http.*;
013: import javax.swing.table.*;
014:
015: import com.javelin.swinglets.*;
016: import com.javelin.swinglets.table.*;
017:
018: /**
019: * A Demo STable
020: *
021: * @author Robin Sharp
022: */
023:
024: public class DemoTable extends STable {
025: public DemoTable() {
026: super (new PagedTableModel(getTableModel(), 4));
027: setTableCellRenderer(new DemoSTableCellRenderer());
028:
029: //setTableHeader( new STableHeader( this ) );
030: SortedTableHeader sortedTableHeader = new SortedTableHeader(
031: this );
032: sortedTableHeader.setBackground(SColor.getColor("darkblue"));
033: sortedTableHeader.setForeground(SColor.white);
034: sortedTableHeader.setFont(SFont.getFont("Arial,Helvetica",
035: SFont.BOLD, 10));
036: setTableHeader(sortedTableHeader);
037:
038: PagedTableFooter pagedTableFooter = new PagedTableFooter(this );
039: pagedTableFooter.setBackground(SColor.getColor("darkblue"));
040: pagedTableFooter.setForeground(SColor.white);
041: pagedTableFooter.setFont(SFont.getFont("Arial,Helvetica",
042: SFont.BOLD, 10));
043: pagedTableFooter.setHorizontalAlignment(SConstants.CENTER);
044: setTableFooter(pagedTableFooter);
045:
046: setFont(SFont.getFont("Arial,Helvetica", SFont.PLAIN, 10));
047: setHorizontalAlignmentAt(SConstants.RIGHT, 4);
048:
049: setBackground(SColor.white);
050: }
051:
052: public static TableModel getTableModel() {
053: final String[] names = { "First Name", "Last Name",
054: "Favorite Color", "Favorite Sport", "Favorite Number",
055: "Favorite Food" };
056:
057: // Create the dummy data (a few rows of names)
058: final Object[][] data = {
059: { "Mike", "Albers", SColor.green, "Soccer",
060: new Integer(44),
061: new SIcon("swing/banana.jpg", 40, 40) },
062: { "Mark", "Andrews", SColor.red, "Baseball",
063: new Integer(2),
064: new SIcon("swing/broccoli.jpg", 40, 40) },
065: { "Tom", "Ball", SColor.blue, "Football",
066: new Integer(99),
067: new SIcon("swing/peach.jpg", 40, 40) },
068: { "Alan", "Chung", SColor.green, "Baseball",
069: new Integer(838),
070: new SIcon("swing/cake.jpg", 40, 40) },
071: { "Jeff", "Dinkins", SColor.magenta, "Football",
072: new Integer(8),
073: new SIcon("swing/cherry.jpg", 40, 40) },
074:
075: { "Amy", "Fowler", SColor.yellow, "Hockey",
076: new Integer(3),
077: new SIcon("swing/carrot.jpg", 40, 40) },
078: { "Brian", "Gerhold", SColor.green, "Rugby",
079: new Integer(7),
080: new SIcon("swing/corn.jpg", 40, 40) },
081: { "James", "Gosling", SColor.pink, "Tennis",
082: new Integer(21),
083: new SIcon("swing/garlic.jpg", 40, 40) },
084: { "Earl", "Johnson", SColor.green, "Bicycling",
085: new Integer(8),
086: new SIcon("swing/carrot.jpg", 40, 40) },
087: { "David", "Karlton", SColor.red, "Baseball",
088: new Integer(1),
089: new SIcon("swing/broccoli.jpg", 40, 40) },
090: { "Dave", "Kloba", SColor.yellow, "Football",
091: new Integer(14),
092: new SIcon("swing/orange.jpg", 40, 40) },
093: { "Peter", "Korn", new Color(100, 100, 255),
094: "Scuba Diving", new Integer(12),
095: new SIcon("swing/broccoli.jpg", 40, 40) },
096: { "Dana", "Miller", SColor.blue, "Ice Skating",
097: new Integer(8),
098: new SIcon("swing/banana.jpg", 40, 40) },
099: { "Phil", "Milne", SColor.magenta, "Rugby",
100: new Integer(3),
101: new SIcon("swing/banana.jpg", 40, 40) },
102: { "Dave", "Moore", SColor.green, "Tennis",
103: new Integer(88),
104: new SIcon("swing/peach.jpg", 40, 40) },
105: { "Hans", "Muller", SColor.magenta, "Baseball",
106: new Integer(5),
107: new SIcon("swing/peas.jpg", 40, 40) },
108: { "Rick", "Levenson", SColor.blue, "Football",
109: new Integer(2),
110: new SIcon("swing/pineapple.jpg", 40, 40) },
111: { "Tim", "Prinzing", SColor.blue, "Baseball",
112: new Integer(22),
113: new SIcon("swing/wine.jpg", 40, 40) },
114: { "Chester", "Rose", SColor.black, "Hockey",
115: new Integer(0),
116: new SIcon("swing/radish.jpg", 40, 40) },
117: { "Chris", "Ryan", SColor.black, "None",
118: new Integer(6),
119: new SIcon("swing/cup.jpg", 40, 40) },
120: { "Ray", "Ryan", SColor.gray, "Football",
121: new Integer(77),
122: new SIcon("swing/wine.jpg", 40, 40) },
123: { "Georges", "Saab", SColor.red, "Hockey",
124: new Integer(4),
125: new SIcon("swing/orange.jpg", 40, 40) },
126: { "Tom", "Santos", SColor.blue, "Football",
127: new Integer(3),
128: new SIcon("swing/banana.jpg", 40, 40) },
129: { "Rich", "Schiavi", SColor.blue, "Hockey",
130: new Integer(4),
131: new SIcon("swing/cup.jpg", 40, 40) },
132: { "Nancy", "Schorr", SColor.blue, "Hockey",
133: new Integer(8),
134: new SIcon("swing/corn.jpg", 40, 40) },
135: { "Violet", "Scott", SColor.magenta, "Basketball",
136: new Integer(44),
137: new SIcon("swing/cup.jpg", 40, 40) },
138:
139: { "Joseph", "Scheuhammer", SColor.green, "Hockey",
140: new Integer(66),
141: new SIcon("swing/corn.jpg", 40, 40) },
142: { "Jeff", "Shapiro", SColor.black, "Skiing",
143: new Integer(42),
144: new SIcon("swing/peach.jpg", 40, 40) },
145: { "Willie", "Walker", SColor.blue, "Hockey",
146: new Integer(4),
147: new SIcon("swing/banana.jpg", 40, 40) },
148: { "Kathy", "Walrath", SColor.blue, "Baseball",
149: new Integer(8),
150: new SIcon("swing/banana.jpg", 40, 40) },
151: { "Arnaud", "Weber", SColor.green, "Football",
152: new Integer(993),
153: new SIcon("swing/peach.jpg", 40, 40) },
154:
155: { "Steve", "Wilson", SColor.green, "Baseball",
156: new Integer(7),
157: new SIcon("swing/cup.jpg", 40, 40) } };
158:
159: // Create a model of the data.
160: TableModel dataModel = new AbstractTableModel() {
161: public int getColumnCount() {
162: return names.length;
163: }
164:
165: public int getRowCount() {
166: return data.length;
167: }
168:
169: public Object getValueAt(int row, int col) {
170: return data[row][col];
171: }
172:
173: public String getColumnName(int column) {
174: return names[column];
175: }
176:
177: public Class getColumnClass(int c) {
178: return getValueAt(0, c).getClass();
179: }
180:
181: public boolean isCellEditable(int row, int col) {
182: return getColumnClass(col) == String.class;
183: }
184:
185: public void setValueAt(Object aValue, int row, int column) {
186: data[row][column] = aValue;
187: }
188: };
189:
190: return dataModel;
191: }
192: }
193:
194: class DemoSTableCellRenderer extends SLabel implements
195: STableCellRenderer {
196: public SComponent getTableCellRendererComponent(STable table,
197: Object value, int row, int column) {
198: if (value == null)
199: return null;
200:
201: if (value instanceof SComponent) {
202: return (SComponent) value;
203: }
204:
205: if (value instanceof SColor) {
206: setForeground(((SColor) value));
207: } else {
208: setForeground(null);
209: }
210:
211: setText(value.toString());
212:
213: return this;
214: }
215: }
|