diff options
author | Mikhail Khodjaiants | 2004-04-27 23:19:26 +0000 |
---|---|---|
committer | Mikhail Khodjaiants | 2004-04-27 23:19:26 +0000 |
commit | 970cec46b626ef241d54a10352168aba8c80b3ea (patch) | |
tree | 8e5e90b736c288345ecfd083673c4f0eea43c20b /debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/LineBreakingReader.java | |
parent | 06ad0291255a08746bc2e271a6626cb91afdd25b (diff) | |
download | org.eclipse.cdt-970cec46b626ef241d54a10352168aba8c80b3ea.tar.gz org.eclipse.cdt-970cec46b626ef241d54a10352168aba8c80b3ea.tar.xz org.eclipse.cdt-970cec46b626ef241d54a10352168aba8c80b3ea.zip |
Breakpoints presentation in the Disassembly view.
Diffstat (limited to 'debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/LineBreakingReader.java')
-rw-r--r-- | debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/LineBreakingReader.java | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/LineBreakingReader.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/LineBreakingReader.java new file mode 100644 index 00000000000..de54602107c --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/LineBreakingReader.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.internal.ui; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; + +import java.text.BreakIterator; +import org.eclipse.swt.graphics.GC; + +/* + * Not a real reader. Could change if requested + */ +public class LineBreakingReader { + + private BufferedReader fReader; + private GC fGC; + private int fMaxWidth; + + private String fLine; + private int fOffset; + + private BreakIterator fLineBreakIterator; + + /** + * Creates a reader that breaks an input text to fit in a given width. + * @param reader Reader of the input text + * @param gc The graphic context that defines the currently used font sizes + * @param maxLineWidth The max width (pixes) where the text has to fit in + */ + public LineBreakingReader(Reader reader, GC gc, int maxLineWidth) { + fReader= new BufferedReader(reader); + fGC= gc; + fMaxWidth= maxLineWidth; + fOffset= 0; + fLine= null; + fLineBreakIterator= BreakIterator.getLineInstance(); + } + + public boolean isFormattedLine() { + return fLine != null; + } + + /** + * Reads the next line. The lengths of the line will not exceed the gived maximum + * width. + */ + public String readLine() throws IOException { + if (fLine == null) { + String line= fReader.readLine(); + if (line == null) + return null; + + int lineLen= fGC.textExtent(line).x; + if (lineLen < fMaxWidth) { + return line; + } + fLine= line; + fLineBreakIterator.setText(line); + fOffset= 0; + } + int breakOffset= findNextBreakOffset(fOffset); + String res; + if (breakOffset != BreakIterator.DONE) { + res= fLine.substring(fOffset, breakOffset); + fOffset= findWordBegin(breakOffset); + if (fOffset == fLine.length()) { + fLine= null; + } + } else { + res= fLine.substring(fOffset); + fLine= null; + } + return res; + } + + private int findNextBreakOffset(int currOffset) { + int currWidth= 0; + int nextOffset= fLineBreakIterator.following(currOffset); + while (nextOffset != BreakIterator.DONE) { + String word= fLine.substring(currOffset, nextOffset); + int wordWidth= fGC.textExtent(word).x; + int nextWidth= wordWidth + currWidth; + if (nextWidth > fMaxWidth) { + if (currWidth > 0) { + return currOffset; + } else { + return nextOffset; + } + } + currWidth= nextWidth; + currOffset= nextOffset; + nextOffset= fLineBreakIterator.next(); + } + return nextOffset; + } + + private int findWordBegin(int idx) { + while (idx < fLine.length() && Character.isWhitespace(fLine.charAt(idx))) { + idx++; + } + return idx; + } +} |