1 11 package org.eclipse.swt.custom; 12 13 import org.eclipse.swt.*; 14 15 33 public class Bullet { 34 public int type; 35 public StyleRange style; 36 public String text; 37 int[] linesIndices; 38 int count; 39 40 50 public Bullet(StyleRange style) { 51 this(ST.BULLET_DOT, style); 52 } 53 63 public Bullet(int type, StyleRange style) { 64 if (style == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 65 if (style.metrics == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 66 this.type = type; 67 this.style = style; 68 } 69 void addIndices (int startLine, int lineCount) { 70 if (linesIndices == null) { 71 linesIndices = new int[lineCount]; 72 count = lineCount; 73 for (int i = 0; i < lineCount; i++) linesIndices[i] = startLine + i; 74 } else { 75 int modifyStart = 0; 76 while (modifyStart < count) { 77 if (startLine <= linesIndices[modifyStart]) break; 78 modifyStart++; 79 } 80 int modifyEnd = modifyStart; 81 while (modifyEnd < count) { 82 if (startLine + lineCount <= linesIndices[modifyEnd]) break; 83 modifyEnd++; 84 } 85 int newSize = modifyStart + lineCount + count - modifyEnd; 86 if (newSize > linesIndices.length) { 87 int[] newLinesIndices = new int[newSize]; 88 System.arraycopy(linesIndices, 0, newLinesIndices, 0, count); 89 linesIndices = newLinesIndices; 90 } 91 System.arraycopy(linesIndices, modifyEnd, linesIndices, modifyStart + lineCount, count - modifyEnd); 92 for (int i = 0; i < lineCount; i++) linesIndices[modifyStart + i] = startLine + i; 93 count = newSize; 94 } 95 } 96 int indexOf (int lineIndex) { 97 for (int i = 0; i < count; i++) { 98 if (linesIndices[i] == lineIndex) return i; 99 } 100 return -1; 101 } 102 public int hashCode() { 103 return style.hashCode() ^ type; 104 } 105 int[] removeIndices (int startLine, int replaceLineCount, int newLineCount, boolean update) { 106 if (count == 0) return null; 107 if (startLine > linesIndices[count - 1]) return null; 108 int endLine = startLine + replaceLineCount; 109 int delta = newLineCount - replaceLineCount; 110 for (int i = 0; i < count; i++) { 111 int index = linesIndices[i]; 112 if (startLine <= index) { 113 int j = i; 114 while (j < count) { 115 if (linesIndices[j] >= endLine) break; 116 j++; 117 } 118 if (update) { 119 for (int k = j; k < count; k++) linesIndices[k] += delta; 120 } 121 int[] redrawLines = new int[count - j]; 122 System.arraycopy(linesIndices, j, redrawLines, 0, count - j); 123 System.arraycopy(linesIndices, j, linesIndices, i, count - j); 124 count -= (j - i); 125 return redrawLines; 126 } 127 } 128 for (int i = 0; i < count; i++) linesIndices[i] += delta; 129 return null; 130 } 131 int size() { 132 return count; 133 } 134 } 135 | Popular Tags |