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