blob: 3f284605053d4c90749eaaaac2576d1761158a7a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package org.openslx.dozmod.gui.changemonitor;
import java.util.Comparator;
import javax.swing.tree.TreePath;
import org.openslx.dozmod.gui.control.JCheckBoxTree;
import org.openslx.dozmod.gui.control.JCheckBoxTree.CheckChangeEvent;
import org.openslx.dozmod.gui.control.JCheckBoxTree.CheckChangeEventListener;
class CheckBoxTreeWrapper extends AbstractControlWrapper<TreePath[]> {
private static final Comparator<TreePath[]> COMPARATOR = new Comparator<TreePath[]>() {
@Override
public int compare(TreePath[] o1, TreePath[] o2) {
if (o1 == null && o2 == null)
return 0;
if (o1 == null)
return o2.length;
if (o2 == null)
return -o1.length;
if (o1.length != o2.length)
return o2.length - o1.length;
for (int i = 0; i < o1.length; ++i) {
TreePath p1 = o1[i];
TreePath p2 = o2[i];
if (p1.getPathCount() != p2.getPathCount())
return p2.getPathCount() - p1.getPathCount();
for (; p1 != null && p2 != null; p1 = p1.getParentPath(), p2 = p2.getParentPath()) {
long diff = p1.getLastPathComponent().hashCode() - p2.getLastPathComponent().hashCode();
if (diff != 0)
return (int)diff;
}
}
return 0;
}
};
private final JCheckBoxTree tree;
public CheckBoxTreeWrapper(DialogChangeMonitor dcm, JCheckBoxTree t) {
super(dcm, COMPARATOR);
tree = t;
tree.addCheckChangeEventListener(new CheckChangeEventListener() {
public void checkStateChanged(CheckChangeEvent event) {
contentChanged();
}
});
}
@Override
TreePath[] getCurrentValue() {
return tree.getCheckedPaths();
}
}
|