1
2 package hep.wired.heprep.interaction;
3
4 import java.util.*;
5 import javax.swing.*;
6 import javax.swing.table.*;
7
8 import hep.graphics.heprep.HepRep;
9 import hep.graphics.heprep.HepRepAttDef;
10 import hep.graphics.heprep.HepRepAttValue;
11 import hep.graphics.heprep.HepRepInstance;
12 import hep.graphics.heprep.HepRepType;
13 import hep.graphics.heprep.HepRepTypeTree;
14
15 import hep.wired.util.SortableListTableModel;
16
17 import hep.wired.util.ScientificTable;
18
19 /***
20 * TableModel for HepRep Instances.
21 *
22 * @author Mark Donszelmann
23 * @version $Id: InstanceTableModel.java 1935 2005-06-21 18:05:29Z duns $
24 */
25 public class InstanceTableModel extends SortableListTableModel {
26
27 private List
28
29 private static final int INSTANCETYPENAME = 0;
30 private static final int INSTANCEPOINTS = 1;
31 private static final int INSTANCEHASH = 2;
32
33 public InstanceTableModel(List
34 super(new String[] { "Type", "Points", "Code" },
35 new Class[] { String.class, Integer.class, Integer.class },
36 values);
37 this.instanceValues = values;
38 }
39
40 public boolean isCellEditable(int row, int col) {
41 return false;
42 }
43
44 public Object getValueAt(int row, int col) {
45 HepRepInstance instance = (HepRepInstance)instanceValues.get(row);
46 switch(col) {
47 case INSTANCETYPENAME:
48 return instance.getType().getName();
49 case INSTANCEPOINTS:
50 return new Integer(instance.getPoints().size());
51 case INSTANCEHASH:
52 return new Integer(instance.hashCode());
53 default:
54 return "";
55 }
56 }
57
58 protected int compareKeys(Object o1, Object o2, int col, boolean ascending) {
59 HepRepInstance i1 = (HepRepInstance)o1;
60 HepRepInstance i2 = (HepRepInstance)o2;
61 switch(col) {
62 default:
63 case INSTANCETYPENAME:
64 return (ascending ? 1 : -1) *
65 (i1.getType().getName().compareTo(i2.getType().getName()));
66 case INSTANCEPOINTS:
67 int n1 = i1.getPoints().size();
68 int n2 = i2.getPoints().size();
69 return (ascending ? 1 : -1) *
70 (n1 < n2 ? -1 : n1 == n2 ? 0 : 1);
71 case INSTANCEHASH:
72 int h1 = i1.hashCode();
73 int h2 = i2.hashCode();
74 return (ascending ? 1 : -1) *
75 (h1 < h2 ? -1 : h1 == h2 ? 0 : 1);
76 }
77 }
78 }