01: /*
02: * Copyright Javelin Software, All rights reserved.
03: */
04:
05: package com.javelin.swinglets.table;
06:
07: import java.awt.*;
08: import java.awt.event.*;
09: import java.util.*;
10: import java.io.*;
11:
12: import javax.swing.table.*;
13: import com.javelin.swinglets.*;
14: import com.javelin.swinglets.table.*;
15: import com.javelin.swinglets.plaf.*;
16:
17: /**
18: * STableHeader defines a table header.
19: * <p>
20: * If the model in the table is not a SortedTableModel then the model
21: * in the table is embedded inside a SortedTableModel.
22: *
23: * @author Robin Sharp
24: */
25:
26: public class SortedTableHeader extends STableHeader implements
27: ActionListener {
28: /**
29: * Constant for the column index.
30: */
31: public final static String SOURCE_COLUMN = "_SOURCE_COLUMN";
32:
33: /**
34: * Creates a STableHeader.
35: * This defaults to invisible.
36: */
37: public SortedTableHeader(STable table) {
38: super (table);
39:
40: setTableHeaderRenderer(
41: "com.javelin.swinglets.plaf.html.HTMLLookAndFeel",
42: new com.javelin.swinglets.plaf.html.HTMLSortedTableHeaderRenderer());
43:
44: setTableHeaderRenderer(
45: "com.javelin.swinglets.plaf.javascript.JSLookAndFeel",
46: new com.javelin.swinglets.plaf.javascript.JSSortedTableHeaderRenderer());
47:
48: addActionListener(this );
49: }
50:
51: /**
52: * Process an ActionEvent, and sort the appropriate column.
53: */
54: public void actionPerformed(ActionEvent event) {
55: TableModel oldmodel = getTable().getModel();
56: if (oldmodel == null)
57: return;
58:
59: if (!(oldmodel instanceof SortByColumn)) {
60: // this will happen only once, as after this it is a SortedTableModel
61: getTable().setModel(new SortedTableModel(oldmodel));
62: }
63:
64: if (getTable().getModel() instanceof SortByColumn)
65: //Sort the data
66: {
67: ((SortByColumn) getTable().getModel()).sortByColumn(event
68: .getID());
69: }
70:
71: //System.out.println( event );
72: }
73:
74: // PRIVATE //////////////////////////////////////////////////////////////
75:
76: }
|