comparison org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/LineBreakingReader.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
25 25
26 import java.lang.all; 26 import java.lang.all;
27 import java.io.Reader; 27 import java.io.Reader;
28 import java.util.Set; 28 import java.util.Set;
29 import java.io.BufferedReader; 29 import java.io.BufferedReader;
30 import java.mangoicu.UBreakIterator;
31 30
32 import org.eclipse.swt.graphics.GC; 31 import org.eclipse.swt.graphics.GC;
32
33 import com.ibm.icu.text.BreakIterator;
33 34
34 /* 35 /*
35 * Not a real reader. Could change if requested 36 * Not a real reader. Could change if requested
36 */ 37 */
37 public class LineBreakingReader { 38 public class LineBreakingReader {
41 private int fMaxWidth; 42 private int fMaxWidth;
42 43
43 private String fLine; 44 private String fLine;
44 private int fOffset; 45 private int fOffset;
45 46
46 private UBreakIterator fLineBreakIterator; 47 private BreakIterator fLineBreakIterator;
47 private bool fBreakWords; 48 private bool fBreakWords;
48 49
49 /** 50 /**
50 * Creates a reader that breaks an input text to fit in a given width. 51 * Creates a reader that breaks an input text to fit in a given width.
51 * 52 *
57 fReader= new BufferedReader(reader); 58 fReader= new BufferedReader(reader);
58 fGC= gc; 59 fGC= gc;
59 fMaxWidth= maxLineWidth; 60 fMaxWidth= maxLineWidth;
60 fOffset= 0; 61 fOffset= 0;
61 fLine= null; 62 fLine= null;
62 fLineBreakIterator= UBreakIterator.openLineIterator( ULocale.Default); 63 fLineBreakIterator= BreakIterator.getLineInstance();
63 fBreakWords= true; 64 fBreakWords= true;
64 } 65 }
65 66
66 public bool isFormattedLine() { 67 public bool isFormattedLine() {
67 return fLine !is null; 68 return fLine !is null;
88 fLineBreakIterator.setText(line); 89 fLineBreakIterator.setText(line);
89 fOffset= 0; 90 fOffset= 0;
90 } 91 }
91 int breakOffset= findNextBreakOffset(fOffset); 92 int breakOffset= findNextBreakOffset(fOffset);
92 String res; 93 String res;
93 if (breakOffset !is UBreakIterator.DONE) { 94 if (breakOffset !is BreakIterator.DONE) {
94 res= fLine.substring(fOffset, breakOffset); 95 res= fLine.substring(fOffset, breakOffset);
95 fOffset= findWordBegin(breakOffset); 96 fOffset= findWordBegin(breakOffset);
96 if (fOffset is fLine.length()) { 97 if (fOffset is fLine.length()) {
97 fLine= null; 98 fLine= null;
98 } 99 }
104 } 105 }
105 106
106 private int findNextBreakOffset(int currOffset) { 107 private int findNextBreakOffset(int currOffset) {
107 int currWidth= 0; 108 int currWidth= 0;
108 int nextOffset= fLineBreakIterator.following(currOffset); 109 int nextOffset= fLineBreakIterator.following(currOffset);
109 while (nextOffset !is UBreakIterator.DONE) { 110 while (nextOffset !is BreakIterator.DONE) {
110 String word= fLine.substring(currOffset, nextOffset); 111 String word= fLine.substring(currOffset, nextOffset);
111 int wordWidth= fGC.textExtent(word).x; 112 int wordWidth= fGC.textExtent(word).x;
112 int nextWidth= wordWidth + currWidth; 113 int nextWidth= wordWidth + currWidth;
113 if (nextWidth > fMaxWidth) { 114 if (nextWidth > fMaxWidth) {
114 if (currWidth > 0) 115 if (currWidth > 0)