1
2
3
4
5
6
7
8
9
10 package nl.tudelft.dsol.introspection;
11
12 import java.awt.BorderLayout;
13
14 import javax.swing.JFrame;
15 import javax.swing.JScrollPane;
16 import javax.swing.JTable;
17 import javax.swing.ScrollPaneConstants;
18 import javax.swing.table.DefaultTableModel;
19 import javax.swing.table.JTableHeader;
20 import javax.swing.table.TableModel;
21
22 import nl.tudelft.simulation.introspection.gui.SortingObjectTableModel;
23 import nl.tudelft.simulation.introspection.sortable.SortDefinition;
24 import nl.tudelft.simulation.introspection.sortable.Sortable;
25 import nl.tudelft.simulation.introspection.sortable.SortingTableHeader;
26
27 /***
28 * A test program for the sortable table model.
29 * <p>
30 * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
31 * University of Technology </a>, the Netherlands. <br>
32 * See for project information <a
33 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
34 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
35 * License (GPL) </a>, no warranty <br>
36 *
37 * @author <a
38 * href="http://web.eur.nl/fbk/dep/dep1/Introduction/Staff/People/Lang">Niels
39 * Lang </a><a
40 * href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
41 * Jacobs </a>
42 * @version 1.1 Apr 15, 2004
43 * @since 1.4
44 */
45 public final class PTestSorter
46 {
47 /***
48 * constructs a new PTestSorter
49 */
50 private PTestSorter()
51 {
52 super();
53
54 }
55
56 /***
57 * executes the PTestSorter
58 *
59 * @param args the command-line arguments
60 */
61 public static void main(final String[] args)
62 {
63 TableModel unsorted = new DefaultTableModel(new Object[][]{
64 {"fruit", "apple", new Integer(200), "1"},
65 {"car", "BMW 3", new Integer(1980), "2"},
66 {"nation", "America", new Integer(1776), "3"},
67 {"nation", "Germany", new Integer(1024), "4"},
68 {"nation", "England", new Integer(500), "5"},
69 {"nation", "Scotland", new Integer(1666), "6"},
70 {"nation", "Russia", new Integer(200), "7"},
71 {"nation", "France", new Integer(1789), "8"},
72 {"nation", "Belgium", new Integer(1820), "9"},
73 {"nation", "Pakistan", new Integer(1960), "10"},
74 {"nation", "Israel", new Integer(1945), "11"},
75 {"nation", "Palestina", new Integer(2004), "12"},
76 {"nation", "Iraq", new Integer(1300), "13"},
77 {"nation", "China", new Integer(-2000), "14"},
78 {"nation", "Peru", new Integer(-3000), "15"},
79 {"nation", "Nigeria", new Integer(-2000), "16"}}, new String[]{
80 "category", "instance", "date", "entry"});
81 TableModel sorted = new SortingObjectTableModel(unsorted);
82
83 ((Sortable) sorted).setDefinitions(new SortDefinition[]{
84 new SortDefinition(0, true), new SortDefinition(2, false),
85 new SortDefinition(1, false)});
86 ((Sortable) sorted).sort();
87
88 JFrame test = new JFrame("Test sorter");
89 test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
90 test.getContentPane().setLayout(new BorderLayout());
91
92 JTable table = new JTable(sorted);
93 JTableHeader header = new SortingTableHeader(
94 new SortDefinition[]{new SortDefinition(0, true)});
95 header.setColumnModel(table.getColumnModel());
96 table.setTableHeader(header);
97 JScrollPane scroller = new JScrollPane(table,
98 ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
99 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
100 test.getContentPane().add(scroller, BorderLayout.CENTER);
101 test.pack();
102 test.setVisible(true);
103 }
104 }