annotate dwt/custom/Bullet.d @ 212:ab60f3309436

reverted the char[] to String and use the an alias.
author Frank Benoit <benoit@tionex.de>
date Mon, 05 May 2008 00:12:38 +0200
parents a5afe31f5cdd
children fd9c62a2998e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 155
diff changeset
1 /*******************************************************************************
155
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module dwt.custom.Bullet;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 import dwt.DWT;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16 import dwt.custom.StyleRange;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17 import dwt.custom.ST;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 import dwt.dwthelper.System;
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 155
diff changeset
19 import dwt.dwthelper.utils;
155
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 /**
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 * Instances of this class represent bullets in the <code>StyledText</code>.
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 * <p>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 * The hashCode() method in this class uses the values of the public
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 * fields to compute the hash value. When storing instances of the
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 * class in hashed collections, do not modify these fields after the
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 * object has been inserted.
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 * </p>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 * <p>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 * Application code does <em>not</em> need to explicitly release the
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 * resources managed by each instance when those instances are no longer
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 * required, and thus no <code>dispose()</code> method is provided.
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 * </p>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 *
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35 * @see StyledText#setLineBullet(int, int, Bullet)
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 *
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 * @since 3.2
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 */
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 public class Bullet {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 public int type;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 public StyleRange style;
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 155
diff changeset
42 public String text;
155
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 int[] linesIndices;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 int count;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 /**
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47 * Create a new bullet the specified style, the type is set to ST.BULLET_DOT.
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 * The style must have a glyph metrics set.
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 *
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 * @param style the style
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 *
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 * @exception IllegalArgumentException <ul>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 * <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 * </ul>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 */
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 public this(StyleRange style) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 this(ST.BULLET_DOT, style);
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 /**
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 * Create a new bullet the specified style and type.
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 * The style must have a glyph metrics set.
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 *
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 * @param style the style
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 *
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 * @exception IllegalArgumentException <ul>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 * <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 * </ul>
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 */
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 public this(int type, StyleRange style) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 if (style is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 if (style.metrics is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 this.type = type;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 this.style = style;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 void addIndices (int startLine, int lineCount) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 if (linesIndices is null) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 linesIndices = new int[lineCount];
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 count = lineCount;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 for (int i = 0; i < lineCount; i++) linesIndices[i] = startLine + i;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 } else {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 int modifyStart = 0;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 while (modifyStart < count) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83 if (startLine <= linesIndices[modifyStart]) break;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 modifyStart++;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86 int modifyEnd = modifyStart;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 while (modifyEnd < count) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88 if (startLine + lineCount <= linesIndices[modifyEnd]) break;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89 modifyEnd++;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 int newSize = modifyStart + lineCount + count - modifyEnd;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 if (newSize > linesIndices.length) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93 int[] newLinesIndices = new int[newSize];
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 System.arraycopy(linesIndices, 0, newLinesIndices, 0, count);
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95 linesIndices = newLinesIndices;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 System.arraycopy(linesIndices, modifyEnd, linesIndices, modifyStart + lineCount, count - modifyEnd);
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98 for (int i = 0; i < lineCount; i++) linesIndices[modifyStart + i] = startLine + i;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
99 count = newSize;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
100 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
101 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102 int indexOf (int lineIndex) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 for (int i = 0; i < count; i++) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104 if (linesIndices[i] is lineIndex) return i;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
105 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
106 return -1;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
107 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
108 public override hash_t toHash() {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
109 return style.toHash() ^ type;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
110 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
111 int[] removeIndices (int startLine, int replaceLineCount, int newLineCount, bool update) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
112 if (count is 0) return null;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
113 if (startLine > linesIndices[count - 1]) return null;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
114 int endLine = startLine + replaceLineCount;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
115 int delta = newLineCount - replaceLineCount;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
116 for (int i = 0; i < count; i++) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
117 int index = linesIndices[i];
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
118 if (startLine <= index) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
119 int j = i;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
120 while (j < count) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
121 if (linesIndices[j] >= endLine) break;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
122 j++;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
123 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
124 if (update) {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
125 for (int k = j; k < count; k++) linesIndices[k] += delta;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
126 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
127 int[] redrawLines = new int[count - j];
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
128 System.arraycopy(linesIndices, j, redrawLines, 0, count - j);
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
129 System.arraycopy(linesIndices, j, linesIndices, i, count - j);
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
130 count -= (j - i);
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
131 return redrawLines;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
132 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
133 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
134 for (int i = 0; i < count; i++) linesIndices[i] += delta;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
135 return null;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
136 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
137 int size() {
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
138 return count;
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
139 }
a5afe31f5cdd Added custom controls
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 }