1 19 20 package org.netbeans.swing.popupswitcher; 21 22 import javax.swing.Icon ; 23 24 31 public class SwitcherTableItem implements Comparable { 32 33 34 private String name; 35 36 37 private String htmlName; 38 39 40 private String description; 41 42 43 private Icon icon; 44 45 46 private boolean active; 47 48 52 private Activatable activatable; 53 54 55 public SwitcherTableItem(Activatable activatable, String name) { 56 this(activatable, name, null); 57 } 58 59 60 public SwitcherTableItem(Activatable activatable, String name, Icon icon) { 61 this(activatable, name, name, icon, false); 62 } 63 64 65 public SwitcherTableItem(Activatable activatable, String name, String htmlName, 66 Icon icon, boolean active) { 67 this(activatable, name, htmlName, icon, active, null); 68 } 69 70 71 public SwitcherTableItem(Activatable activatable, String name, String htmlName, 72 Icon icon, boolean active, String description) { 73 this.activatable = activatable; 74 this.name = name; 75 this.htmlName = htmlName; 76 this.icon = icon; 77 this.active = active; 78 this.description = description; 79 } 80 81 87 public void activate() { 88 activatable.activate(); 89 } 90 91 92 public String getName() { 93 return name; 94 } 95 96 97 public String getHtmlName() { 98 return htmlName; 99 } 100 101 106 public String getDescription() { 107 return description; 108 } 109 110 111 public Icon getIcon() { 112 return icon; 113 } 114 115 118 public Activatable getActivatable() { 119 return activatable; 120 } 121 122 123 public boolean isActive() { 124 return active; 125 } 126 127 128 public String toString() { 129 return super.toString() + "[name=" + name + ", icon=" + icon + "]"; } 131 132 136 public boolean equals(Object o) { 137 if (o == this) { 138 return true; 139 } 140 if (o instanceof SwitcherTableItem) { 141 SwitcherTableItem item = (SwitcherTableItem) o; 142 boolean result = item.getName().equals(name) && 143 item.getActivatable().equals(activatable); 144 return result; 145 } else { 146 return false; 147 } 148 } 149 150 155 public int hashCode() { 156 return (name == null ? 1 : name.hashCode()) * activatable.hashCode(); 157 } 158 159 163 public int compareTo(Object o) { 164 String name1 = getName(); 165 String name2 = null; 166 if (o instanceof SwitcherTableItem) { 167 name2 = ((SwitcherTableItem) o).getName(); 168 } 169 if (name2 == null) { 170 return (name1 == null ? 0 : -1); 171 } else { 172 return (name1 == null ? 1 : name1.compareToIgnoreCase(name2)); 173 } 174 } 175 176 180 public static interface Activatable { 181 188 void activate(); 189 } 190 } 191 | Popular Tags |