1 11 package org.eclipse.swt.custom; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.graphics.*; 15 import org.eclipse.swt.internal.CloneableCompatibility; 16 17 public class StyleRange extends TextStyle implements CloneableCompatibility { 18 19 22 public int start; 23 24 27 public int length; 28 29 36 public int fontStyle = SWT.NORMAL; 37 38 43 public StyleRange() { 44 super(null, null, null); 45 } 46 47 55 public StyleRange(int start, int length, Color foreground, Color background) { 56 super(null, foreground, background); 57 this.start = start; 58 this.length = length; 59 } 60 61 70 public StyleRange(int start, int length, Color foreground, Color background, int fontStyle) { 71 this(start, length, foreground, background); 72 this.fontStyle = fontStyle; 73 } 74 75 85 public boolean equals(Object object) { 86 if (object == this) return true; 87 if (object instanceof StyleRange) { 88 StyleRange style = (StyleRange)object; 89 if (start != style.start) return false; 90 if (length != style.length) return false; 91 return similarTo(style); 92 } 93 return false; 94 } 95 96 106 public int hashCode() { 107 return super.hashCode() ^ fontStyle; 108 } 109 boolean isVariableHeight() { 110 return font != null || metrics != null || rise != 0; 111 } 112 118 public boolean isUnstyled() { 119 if (font != null) return false; 120 if (rise != 0) return false; 121 if (metrics != null) return false; 122 if (foreground != null) return false; 123 if (background != null) return false; 124 if (fontStyle != SWT.NORMAL) return false; 125 if (underline) return false; 126 if (strikeout) return false; 127 return true; 128 } 129 130 138 public boolean similarTo(StyleRange style) { 139 if (!super.equals(style)) return false; 140 if (fontStyle != style.fontStyle) return false; 141 return true; 142 } 143 144 149 public Object clone() { 150 try { 151 return super.clone(); 152 } catch (CloneNotSupportedException e) { 153 return null; 154 } 155 } 156 157 163 public String toString() { 164 StringBuffer buffer = new StringBuffer (); 165 buffer.append("StyleRange {"); 166 buffer.append(start); 167 buffer.append(", "); 168 buffer.append(length); 169 buffer.append(", fontStyle="); 170 switch (fontStyle) { 171 case SWT.BOLD: 172 buffer.append("bold"); 173 break; 174 case SWT.ITALIC: 175 buffer.append("italic"); 176 break; 177 case SWT.BOLD | SWT.ITALIC: 178 buffer.append("bold-italic"); 179 break; 180 default: 181 buffer.append("normal"); 182 } 183 String str = super.toString(); 184 int index = str.indexOf('{'); 185 str = str.substring(index + 1); 186 if (str.length() > 1) buffer.append(", "); 187 buffer.append(str); 188 return buffer.toString(); 189 } 190 } 191 | Popular Tags |