1 11 package org.eclipse.swt.graphics; 12 13 import org.eclipse.swt.*; 14 15 36 public class TextStyle { 37 38 41 public Font font; 42 43 46 public Color foreground; 47 48 51 public Color background; 52 53 58 public boolean underline; 59 60 65 public boolean strikeout; 66 67 72 public GlyphMetrics metrics; 73 74 79 public int rise; 80 81 89 public TextStyle (Font font, Color foreground, Color background) { 90 if (font != null && font.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); 91 if (foreground != null && foreground.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); 92 if (background != null && background.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); 93 this.font = font; 94 this.foreground = foreground; 95 this.background = background; 96 } 97 98 108 public boolean equals(Object object) { 109 if (object == this) return true; 110 if (object == null) return false; 111 if (!(object instanceof TextStyle)) return false; 112 TextStyle style = (TextStyle)object; 113 if (foreground != null) { 114 if (!foreground.equals(style.foreground)) return false; 115 } else if (style.foreground != null) return false; 116 if (background != null) { 117 if (!background.equals(style.background)) return false; 118 } else if (style.background != null) return false; 119 if (font != null) { 120 if (!font.equals(style.font)) return false; 121 } else if (style.font != null) return false; 122 if (metrics != null || style.metrics != null) return false; 123 if (underline != style.underline) return false; 124 if (strikeout != style.strikeout) return false; 125 if (rise != style.rise) return false; 126 return true; 127 } 128 129 139 public int hashCode() { 140 int hash = 0; 141 if (foreground != null) hash ^= foreground.hashCode(); 142 if (background != null) hash ^= background.hashCode(); 143 if (font != null) hash ^= font.hashCode(); 144 if (metrics != null) hash ^= metrics.hashCode(); 145 if (underline) hash ^= hash; 146 if (strikeout) hash ^= hash; 147 hash ^= rise; 148 return hash; 149 } 150 151 157 public String toString () { 158 StringBuffer buffer = new StringBuffer ("TextStyle {"); 159 int startLength = buffer.length(); 160 if (font != null) { 161 if (buffer.length() > startLength) buffer.append(", "); 162 buffer.append("font="); 163 buffer.append(font); 164 } 165 if (foreground != null) { 166 if (buffer.length() > startLength) buffer.append(", "); 167 buffer.append("foreground="); 168 buffer.append(foreground); 169 } 170 if (background != null) { 171 if (buffer.length() > startLength) buffer.append(", "); 172 buffer.append("background="); 173 buffer.append(background); 174 } 175 if (underline) { 176 if (buffer.length() > startLength) buffer.append(", "); 177 buffer.append("underlined"); 178 } 179 if (strikeout) { 180 if (buffer.length() > startLength) buffer.append(", "); 181 buffer.append("striked out"); 182 } 183 if (rise != 0) { 184 if (buffer.length() > startLength) buffer.append(", "); 185 buffer.append("rise="); 186 buffer.append(rise); 187 } 188 if (metrics != null) { 189 if (buffer.length() > startLength) buffer.append(", "); 190 buffer.append("metrics="); 191 buffer.append(metrics); 192 } 193 buffer.append("}"); 194 return buffer.toString(); 195 } 196 197 } 198 | Popular Tags |