1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.custom;
16 import org.eclipse.swt.*;
19 * Instances of this class represent bullets in the <code>StyledText</code>.
21 * The hashCode() method in this class uses the values of the public
22 * fields to compute the hash value. When storing instances of the
23 * class in hashed collections, do not modify these fields after the
24 * object has been inserted.
27 * Application code does <em>not</em> need to explicitly release the
28 * resources managed by each instance when those instances are no longer
29 * required, and thus no <code>dispose()</code> method is provided.
32 * @see StyledText#setLineBullet(int, int, Bullet)
33 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
39 * The bullet type. Possible values are:
41 * <li><code>ST.BULLET_DOT</code></li>
42 * <li><code>ST.BULLET_NUMBER</code></li>
43 * <li><code>ST.BULLET_LETTER_LOWER</code></li>
44 * <li><code>ST.BULLET_LETTER_UPPER</code></li>
45 * <li><code>ST.BULLET_TEXT</code></li>
46 * <li><code>ST.BULLET_CUSTOM</code></li>
54 public StyleRange style;
65 * Create a new bullet with the specified style, and type <code>ST.BULLET_DOT</code>.
66 * The style must have a glyph metrics set.
68 * @param style the style
70 * @exception IllegalArgumentException <ul>
71 * <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li>
74 public Bullet(StyleRange style) {
75 this(ST.BULLET_DOT, style);
78 * Create a new bullet the specified style and type.
79 * The style must have a glyph metrics set.
81 * @param type the bullet type
82 * @param style the style
84 * @exception IllegalArgumentException <ul>
85 * <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li>
88 public Bullet(int type, StyleRange style) {
89 if (style == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
90 if (style.metrics == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
94 void addIndices (int startLine, int lineCount) {
95 if (linesIndices == null) {
96 linesIndices = new int[lineCount];
98 for (int i = 0; i < lineCount; i++) linesIndices[i] = startLine + i;
101 while (modifyStart < count) {
102 if (startLine <= linesIndices[modifyStart]) break;
105 int modifyEnd = modifyStart;
106 while (modifyEnd < count) {
107 if (startLine + lineCount <= linesIndices[modifyEnd]) break;
110 int newSize = modifyStart + lineCount + count - modifyEnd;
111 if (newSize > linesIndices.length) {
112 int[] newLinesIndices = new int[newSize];
113 System.arraycopy(linesIndices, 0, newLinesIndices, 0, count);
114 linesIndices = newLinesIndices;
116 System.arraycopy(linesIndices, modifyEnd, linesIndices, modifyStart + lineCount, count - modifyEnd);
117 for (int i = 0; i < lineCount; i++) linesIndices[modifyStart + i] = startLine + i;
121 int indexOf (int lineIndex) {
122 for (int i = 0; i < count; i++) {
123 if (linesIndices[i] == lineIndex) return i;
128 public int hashCode() {
129 return style.hashCode() ^ type;
131 int[] removeIndices (int startLine, int replaceLineCount, int newLineCount, boolean update) {
132 if (count == 0) return null;
133 if (startLine > linesIndices[count - 1]) return null;
134 int endLine = startLine + replaceLineCount;
135 int delta = newLineCount - replaceLineCount;
136 for (int i = 0; i < count; i++) {
137 int index = linesIndices[i];
138 if (startLine <= index) {
141 if (linesIndices[j] >= endLine) break;
145 for (int k = j; k < count; k++) linesIndices[k] += delta;
147 int[] redrawLines = new int[count - j];
148 System.arraycopy(linesIndices, j, redrawLines, 0, count - j);
149 System.arraycopy(linesIndices, j, linesIndices, i, count - j);
154 for (int i = 0; i < count; i++) linesIndices[i] += delta;