01: package japa.dev;
02:
03: import tide.editor.UIConstants;
04: import japa.parser.ast.body.ModifierSet;
05: import japa.parser.ast.Node;
06: import java.awt.Color;
07: import javax.swing.tree.*;
08:
09: public final class TNode extends DefaultMutableTreeNode implements
10: Comparable<TNode> {
11: Node ref; // some japa ast Node (FieldDeclaration, ...)
12:
13: String fatName;
14: int fatWidth = 30;
15: String displayName;
16: Color color = Color.black; // use UIConstants.brown ...
17: final int accessModifiers;
18: final int secondSortKey;
19:
20: public TNode(final String descr, final Node ref,
21: final int accessModifiers, final String fatName,
22: final String displayName, final int secondSortKey) {
23: super (descr); // user object;
24: this .ref = ref;
25: this .secondSortKey = secondSortKey;
26: this .fatName = fatName;
27: this .displayName = displayName;
28: this .accessModifiers = accessModifiers;
29: if (accessModifiers != 0) {
30: this .color = getColorForVisibilityMod(accessModifiers);
31: }
32: }
33:
34: public int compareTo(TNode n2) {
35: // 1) key access mods
36: int c1 = -Integer.valueOf(getFirstSortKey(accessModifiers))
37: .compareTo(getFirstSortKey(n2.accessModifiers));
38: if (c1 != 0)
39: return c1;
40:
41: // 2): first constructors, second
42: int c2 = Integer.valueOf(secondSortKey).compareTo(
43: n2.secondSortKey);
44: if (c2 != 0)
45: return c2;
46:
47: // 3): name
48: return -displayName.compareTo(n2.displayName);
49: }
50:
51: /* public, ...
52: static TNode createForMainModifier(final String name, final Color c)
53: {
54: TNode tn = new TNode(name, null, 0, name, "", 0);
55: tn.fatWidth = 95; // "package scope"
56: tn.color = c;
57: return tn;
58: }*/
59:
60: /** public, ... type = "C" for class, A, I E */
61: static TNode createForClass(final String type, final String cname,
62: final Node ref, final int mods) {
63: TNode tn = new TNode("", ref, mods, type, cname, 0);
64: tn.fatWidth = 25;
65: //tn.color = getColorForVisibilityMod(mods);
66: return tn;
67: }
68:
69: private static Color getColorForVisibilityMod(final int mods) {
70: if (ModifierSet.isPublic(mods))
71: return UIConstants.blue;
72: if (ModifierSet.isPrivate(mods))
73: return UIConstants.red;
74: if (ModifierSet.isProtected(mods))
75: return UIConstants.brown;
76: // package scope
77: return Color.black;
78: }
79:
80: private static int getFirstSortKey(final int mods) {
81: if (ModifierSet.isPublic(mods))
82: return 0;
83: if (ModifierSet.isProtected(mods))
84: return 1;
85: if (ModifierSet.isPrivate(mods))
86: return 3;
87:
88: // package scope
89: return 2;
90: }
91:
92: }
|