Mercurial > projects > dwt2
comparison org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormUtil.d @ 92:ebefa5c2eab4
moving ICU bindings to com.ibm.icu
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 19 Apr 2009 13:49:38 +0200 |
parents | dbfb303e8fb0 |
children |
comparison
equal
deleted
inserted
replaced
91:2755ef2c8ef8 | 92:ebefa5c2eab4 |
---|---|
11 * Port to the D programming language: | 11 * Port to the D programming language: |
12 * Frank Benoit <benoit@tionex.de> | 12 * Frank Benoit <benoit@tionex.de> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module org.eclipse.ui.internal.forms.widgets.FormUtil; | 14 module org.eclipse.ui.internal.forms.widgets.FormUtil; |
15 | 15 |
16 | 16 import java.lang.all; |
17 // import com.ibm.icu.text.BreakIterator; | 17 import java.util.Set; |
18 | 18 |
19 import org.eclipse.swt.SWT; | 19 import org.eclipse.swt.SWT; |
20 import org.eclipse.swt.custom.ScrolledComposite; | 20 import org.eclipse.swt.custom.ScrolledComposite; |
21 import org.eclipse.swt.events.MouseEvent; | 21 import org.eclipse.swt.events.MouseEvent; |
22 import org.eclipse.swt.graphics.Device; | 22 import org.eclipse.swt.graphics.Device; |
38 import org.eclipse.ui.forms.widgets.Form; | 38 import org.eclipse.ui.forms.widgets.Form; |
39 import org.eclipse.ui.forms.widgets.FormText; | 39 import org.eclipse.ui.forms.widgets.FormText; |
40 import org.eclipse.ui.forms.widgets.FormToolkit; | 40 import org.eclipse.ui.forms.widgets.FormToolkit; |
41 import org.eclipse.ui.forms.widgets.ILayoutExtension; | 41 import org.eclipse.ui.forms.widgets.ILayoutExtension; |
42 | 42 |
43 import java.lang.all; | 43 import com.ibm.icu.text.BreakIterator; |
44 import java.util.Set; | |
45 | |
46 import java.mangoicu.UBreakIterator; | |
47 | 44 |
48 public class FormUtil { | 45 public class FormUtil { |
49 | 46 |
50 public static const String PLUGIN_ID = "org.eclipse.ui.forms"; //$NON-NLS-1$ | 47 public static const String PLUGIN_ID = "org.eclipse.ui.forms"; //$NON-NLS-1$ |
51 | 48 |
107 text.setLayoutData(gd); | 104 text.setLayoutData(gd); |
108 return text; | 105 return text; |
109 } | 106 } |
110 | 107 |
111 public static int computeMinimumWidth(GC gc, String text) { | 108 public static int computeMinimumWidth(GC gc, String text) { |
112 auto wb = UBreakIterator.openWordIterator( ULocale.Default, text ); | 109 BreakIterator wb = BreakIterator.getWordInstance(); |
113 scope(exit) wb.close(); | 110 wb.setText(text); |
114 int last = 0; | 111 int last = 0; |
115 int width = 0; | 112 int width = 0; |
116 | 113 |
117 for (int loc = wb.first(); loc !is UBreakIterator.Done; loc = wb.next()) { | 114 for (int loc = wb.first(); loc !is BreakIterator.DONE; loc = wb.next()) { |
118 String word = text.substring(last, loc); | 115 String word = text.substring(last, loc); |
119 Point extent = gc.textExtent(word); | 116 Point extent = gc.textExtent(word); |
120 width = Math.max(width, extent.x); | 117 width = Math.max(width, extent.x); |
121 last = loc; | 118 last = loc; |
122 } | 119 } |
125 width = Math.max(width, extent.x); | 122 width = Math.max(width, extent.x); |
126 return width; | 123 return width; |
127 } | 124 } |
128 | 125 |
129 public static Point computeWrapSize(GC gc, String text, int wHint) { | 126 public static Point computeWrapSize(GC gc, String text, int wHint) { |
130 auto wb = UBreakIterator.openWordIterator( ULocale.Default, text ); | 127 BreakIterator wb = BreakIterator.getWordInstance(); |
131 scope(exit) wb.close(); | 128 wb.setText(text); |
132 FontMetrics fm = gc.getFontMetrics(); | 129 FontMetrics fm = gc.getFontMetrics(); |
133 int lineHeight = fm.getHeight(); | 130 int lineHeight = fm.getHeight(); |
134 | 131 |
135 int saved = 0; | 132 int saved = 0; |
136 int last = 0; | 133 int last = 0; |
137 int height = lineHeight; | 134 int height = lineHeight; |
138 int maxWidth = 0; | 135 int maxWidth = 0; |
139 for (int loc = wb.first(); loc !is UBreakIterator.Done; loc = wb.next()) { | 136 for (int loc = wb.first(); loc !is BreakIterator.DONE; loc = wb.next()) { |
140 String word = text.substring(saved, loc); | 137 String word = text.substring(saved, loc); |
141 Point extent = gc.textExtent(word); | 138 Point extent = gc.textExtent(word); |
142 if (extent.x > wHint) { | 139 if (extent.x > wHint) { |
143 // overflow | 140 // overflow |
144 saved = last; | 141 saved = last; |
164 paintWrapText(gc, text, bounds, false); | 161 paintWrapText(gc, text, bounds, false); |
165 } | 162 } |
166 | 163 |
167 public static void paintWrapText(GC gc, String text, Rectangle bounds, | 164 public static void paintWrapText(GC gc, String text, Rectangle bounds, |
168 bool underline) { | 165 bool underline) { |
169 auto wb = UBreakIterator.openWordIterator( ULocale.Default, text ); | 166 BreakIterator wb = BreakIterator.getWordInstance(); |
170 scope(exit) wb.close(); | 167 wb.setText(text); |
171 FontMetrics fm = gc.getFontMetrics(); | 168 FontMetrics fm = gc.getFontMetrics(); |
172 int lineHeight = fm.getHeight(); | 169 int lineHeight = fm.getHeight(); |
173 int descent = fm.getDescent(); | 170 int descent = fm.getDescent(); |
174 | 171 |
175 int saved = 0; | 172 int saved = 0; |
176 int last = 0; | 173 int last = 0; |
177 int y = bounds.y; | 174 int y = bounds.y; |
178 int width = bounds.width; | 175 int width = bounds.width; |
179 | 176 |
180 for (int loc = wb.first(); loc !is UBreakIterator.Done; loc = wb.next()) { | 177 for (int loc = wb.first(); loc !is BreakIterator.DONE; loc = wb.next()) { |
181 String line = text.substring(saved, loc); | 178 String line = text.substring(saved, loc); |
182 Point extent = gc.textExtent(line); | 179 Point extent = gc.textExtent(line); |
183 | 180 |
184 if (extent.x > width) { | 181 if (extent.x > width) { |
185 // overflow | 182 // overflow |