1 23 24 package org.netbeans.swing.tabcontrol; 25 26 import javax.swing.*; 27 import java.awt.*; 28 29 44 public final class TabData implements Comparable { 45 Icon icon; 47 String txt; 48 String tip; 49 Object userObject; 50 51 61 public TabData(Object userObject, Icon i, String caption, String tooltip) { 62 this.userObject = userObject; 63 icon = i; 64 txt = caption; 65 tip = tooltip; 66 } 67 68 69 public Object getUserObject() { 70 return userObject; 71 } 72 73 79 public Component getComponent() { 80 if (userObject instanceof Component) { 81 return (Component) userObject; 82 } else { 83 return null; 84 } 85 } 86 87 94 public Icon getIcon() { 95 if (icon == null) { 96 return NO_ICON; 97 } else { 98 return icon; 99 } 100 } 101 102 107 public String getText() { 108 return txt; 109 } 110 111 116 public String getTooltip() { 117 return tip; 118 } 119 120 125 public String toString() { 126 return txt; 127 } 128 129 133 public boolean equals(Object o) { 134 if (o == this) 135 return true; 136 if (o instanceof TabData) { 137 TabData td = (TabData) o; 138 boolean result = td.userObject.equals(userObject) 139 && td.txt.equals(txt); 140 return result; 141 } else { 142 return false; 143 } 144 } 145 146 149 public int hashCode() { 150 return (txt == null ? 0 : txt.hashCode()) 151 ^ (userObject == null ? 0 : userObject.hashCode()); 152 } 153 154 158 public int compareTo(Object o) { 159 String arg1, arg2; 160 arg1 = getText(); 161 if (o instanceof TabData) { 162 arg2 = ((TabData) o).getText(); 163 } else { 164 arg2 = null; 165 } 166 if (arg2 == null) { 167 if (arg1 == null) { 168 return 0; 170 } else { 171 return 1; 173 } 174 } else { 175 if (arg1 == null) { 176 return -1; 178 } else { 179 return arg1.compareTo(arg2); 181 } 182 } 183 } 184 185 189 static final Icon NO_ICON = new Icon() { 190 public int getIconHeight() { 191 return 0; 192 } 193 194 public int getIconWidth() { 195 return 0; 196 } 197 198 public void paintIcon(Component c, Graphics g, int x, int y) { 199 } 200 201 public String toString() { 202 return "empty icon"; 203 }; }; 205 } 206 | Popular Tags |