This fixes a small offset issue in javax.swing.text.Utilities and
removes some cruft.
2006-08-24 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/text/Utilities.java
(BUF_LENGTH): Removed unused field.
(drawTabbedText): Removed unneeded cast.
(getBreakLocation): Removed unneeded cast.
Fixed offset to account for Segments not starting at 0.
/Roman
Index: javax/swing/text/Utilities.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/Utilities.java,v
retrieving revision 1.36
diff -u -1 -2 -r1.36 Utilities.java
--- javax/swing/text/Utilities.java 14 Aug 2006 13:55:15 -0000 1.36
+++ javax/swing/text/Utilities.java 24 Aug 2006 18:34:09 -0000
@@ -45,28 +45,24 @@
import javax.swing.text.Position.Bias;
/**
* A set of utilities to deal with text. This is used by several other classes
* inside this package.
*
* @author Roman Kennke ([EMAIL PROTECTED])
* @author Robert Schuster ([EMAIL PROTECTED])
*/
public class Utilities
{
- /**
- * The length of the char buffer that holds the characters to be drawn.
- */
- private static final int BUF_LENGTH = 64;
/**
* Creates a new <code>Utilities</code> object.
*/
public Utilities()
{
// Nothing to be done here.
}
/**
* Draws the given text segment. Contained tabs and newline characters
* are taken into account. Tabs are expanded using the
@@ -116,26 +112,26 @@
pixelWidth = 0;
}
pos = offset+1;
len = 0;
}
switch (c)
{
case '\t':
// In case we have a tab, we just 'jump' over the tab.
// When we have no tab expander we just use the width of ' '.
if (e != null)
- pixelX = (int) e.nextTabStop((float) pixelX,
- startOffset + offset - s.offset);
+ pixelX = (int) e.nextTabStop(pixelX,
+ startOffset + offset - s.offset);
else
pixelX += metrics.charWidth(' ');
break;
default:
++len;
pixelWidth += metrics.charWidth(buffer[offset]);
break;
}
}
if (len > 0)
g.drawChars(buffer, pos, len, pixelX, pixelY + ascent);
@@ -167,25 +163,25 @@
// The current maximum width.
int maxWidth = 0;
for (int offset = s.offset; offset < (s.offset + s.count); ++offset)
{
switch (buffer[offset])
{
case '\t':
// In case we have a tab, we just 'jump' over the tab.
// When we have no tab expander we just use the width of 'm'.
if (e != null)
- pixelX = (int) e.nextTabStop((float) pixelX,
+ pixelX = (int) e.nextTabStop(pixelX,
startOffset + offset - s.offset);
else
pixelX += metrics.charWidth(' ');
break;
case '\n':
// In case we have a newline, we must 'draw'
// the buffer and jump on the next line.
pixelX += metrics.charWidth(buffer[offset]);
maxWidth = Math.max(maxWidth, pixelX - x);
pixelX = x;
break;
default:
@@ -542,25 +538,25 @@
breaker.setText(s);
// If startOffset and s.offset differ then we need to use
// that difference two convert the offset between the two metrics.
int shift = startOffset - s.offset;
// If mark is equal to the end of the string, just use that position.
if (mark >= shift + s.count)
return mark;
// Try to find a word boundary previous to the mark at which we
// can break the text.
- int preceding = breaker.preceding(mark + 1 - shift);
+ int preceding = breaker.preceding(mark + 1 + s.offset);
if (preceding != 0)
return preceding + shift;
// If preceding is 0 we couldn't find a suitable word-boundary so
// just break it on the character boundary
return mark;
}
/**
* Returns the paragraph element in the text component <code>c</code> at
* the specified location <code>offset</code>.