]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/custom/Bullet.java
Remove invalid SHA-256-Digests
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / custom / Bullet.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 IBM Corporation and others.
3  *
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/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.custom;
15
16 import org.eclipse.swt.*;
17
18 /**
19  * Instances of this class represent bullets in the <code>StyledText</code>.
20  * <p>
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.
25  * </p>
26  * <p>
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.
30  * </p>
31  *
32  * @see StyledText#setLineBullet(int, int, Bullet)
33  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
34  *
35  * @since 3.2
36  */
37 public class Bullet {
38         /**
39         * The bullet type.  Possible values are:
40         * <ul>
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>
47         * </ul>
48         */
49         public int type;
50
51         /**
52         * The bullet style.
53         */
54         public StyleRange style;
55
56         /**
57         * The bullet text.
58         */
59         public String text;
60
61         int[] linesIndices;
62         int count;
63
64 /**
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.
67  *
68  * @param style the style
69  *
70  * @exception IllegalArgumentException <ul>
71  *    <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li>
72  * </ul>
73  */
74 public Bullet(StyleRange style) {
75         this(ST.BULLET_DOT, style);
76 }
77 /**
78  * Create a new bullet the specified style and type.
79  * The style must have a glyph metrics set.
80  *
81  * @param type the bullet type
82  * @param style the style
83  *
84  * @exception IllegalArgumentException <ul>
85  *    <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li>
86  * </ul>
87  */
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);
91         this.type = type;
92         this.style = style;
93 }
94 void addIndices (int startLine, int lineCount) {
95         if (linesIndices == null) {
96                 linesIndices = new int[lineCount];
97                 count = lineCount;
98                 for (int i = 0; i < lineCount; i++) linesIndices[i] = startLine + i;
99         } else {
100                 int modifyStart = 0;
101                 while (modifyStart < count) {
102                         if (startLine <= linesIndices[modifyStart]) break;
103                         modifyStart++;
104                 }
105                 int modifyEnd = modifyStart;
106                 while (modifyEnd < count) {
107                         if (startLine + lineCount <= linesIndices[modifyEnd]) break;
108                         modifyEnd++;
109                 }
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;
115                 }
116                 System.arraycopy(linesIndices, modifyEnd, linesIndices, modifyStart + lineCount, count - modifyEnd);
117                 for (int i = 0; i < lineCount; i++) linesIndices[modifyStart + i] = startLine + i;
118                 count = newSize;
119         }
120 }
121 int indexOf (int lineIndex) {
122         for (int i = 0; i < count; i++) {
123                 if (linesIndices[i] == lineIndex) return i;
124         }
125         return -1;
126 }
127 @Override
128 public int hashCode() {
129         return style.hashCode() ^ type;
130 }
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) {
139                         int j = i;
140                         while (j < count) {
141                                 if (linesIndices[j] >= endLine) break;
142                                 j++;
143                         }
144                         if (update) {
145                                 for (int k = j; k < count; k++) linesIndices[k] += delta;
146                         }
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);
150                         count -= (j - i);
151                         return redrawLines;
152                 }
153         }
154         for (int i = 0; i < count; i++) linesIndices[i] += delta;
155         return null;
156 }
157 int size() {
158         return count;
159 }
160 }