1 11 package org.eclipse.jface.text; 12 13 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.graphics.Color; 16 import org.eclipse.swt.graphics.Font; 17 18 19 25 public class TextAttribute { 26 27 32 public static final int STRIKETHROUGH= 1 << 29; 33 34 39 public static final int UNDERLINE= 1 << 30; 40 41 42 43 private Color foreground; 44 45 46 private Color background; 47 48 49 private int style; 50 51 55 private Font font; 56 57 61 private int fHashCode; 62 63 70 public TextAttribute(Color foreground, Color background, int style) { 71 this.foreground= foreground; 72 this.background= background; 73 this.style= style; 74 } 75 76 85 public TextAttribute(Color foreground, Color background, int style, Font font) { 86 this.foreground= foreground; 87 this.background= background; 88 this.style= style; 89 this.font= font; 90 } 91 92 98 public TextAttribute(Color foreground) { 99 this(foreground, null, SWT.NORMAL); 100 } 101 102 105 public boolean equals(Object object) { 106 107 if (object == this) 108 return true; 109 110 if (!(object instanceof TextAttribute)) 111 return false; 112 TextAttribute a= (TextAttribute)object; 113 114 return (a.style == style && equals(a.foreground, foreground) && equals(a.background, background) && equals(a.font, font)); 115 } 116 117 125 private boolean equals(Object o1, Object o2) { 126 if (o1 != null) 127 return o1.equals(o2); 128 return (o2 == null); 129 } 130 131 134 public int hashCode() { 135 if (fHashCode == 0) { 136 int multiplier= 37; fHashCode= 13; fHashCode= multiplier * fHashCode + (font == null ? 0 : font.hashCode()); 139 fHashCode= multiplier * fHashCode + (background == null ? 0 : background.hashCode()); 140 fHashCode= multiplier * fHashCode + (foreground == null ? 0 : foreground.hashCode()); 141 fHashCode= multiplier * fHashCode + style; 142 } 143 return fHashCode; 144 } 145 146 151 public Color getForeground() { 152 return foreground; 153 } 154 155 160 public Color getBackground() { 161 return background; 162 } 163 164 169 public int getStyle() { 170 return style; 171 } 172 173 179 public Font getFont() { 180 return font; 181 } 182 } 183 | Popular Tags |