aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/text/PlainView.java
diff options
context:
space:
mode:
authorMark Wielaard <mark@gcc.gnu.org>2006-05-18 17:29:21 +0000
committerMark Wielaard <mark@gcc.gnu.org>2006-05-18 17:29:21 +0000
commit4f9533c7722fa07511a94d005227961f4a4dec23 (patch)
tree9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/javax/swing/text/PlainView.java
parenteaec4980e139903ae9b274d1abcf3a13946603a8 (diff)
downloadgcc-4f9533c7722fa07511a94d005227961f4a4dec23.zip
gcc-4f9533c7722fa07511a94d005227961f4a4dec23.tar.gz
gcc-4f9533c7722fa07511a94d005227961f4a4dec23.tar.bz2
Imported GNU Classpath 0.90
Imported GNU Classpath 0.90 * scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. From-SVN: r113887
Diffstat (limited to 'libjava/classpath/javax/swing/text/PlainView.java')
-rw-r--r--libjava/classpath/javax/swing/text/PlainView.java78
1 files changed, 67 insertions, 11 deletions
diff --git a/libjava/classpath/javax/swing/text/PlainView.java b/libjava/classpath/javax/swing/text/PlainView.java
index 4bb3a8e..18818c0 100644
--- a/libjava/classpath/javax/swing/text/PlainView.java
+++ b/libjava/classpath/javax/swing/text/PlainView.java
@@ -59,6 +59,18 @@ public class PlainView extends View implements TabExpander
* The color that is used to draw disabled text fields.
*/
Color disabledColor;
+
+ /**
+ * While painting this is the textcomponent's current start index
+ * of the selection.
+ */
+ int selectionStart;
+
+ /**
+ * While painting this is the textcomponent's current end index
+ * of the selection.
+ */
+ int selectionEnd;
Font font;
@@ -150,12 +162,47 @@ public class PlainView extends View implements TabExpander
{
try
{
- metrics = g.getFontMetrics();
- // FIXME: Selected text are not drawn yet.
Element line = getElement().getElement(lineIndex);
- drawUnselectedText(g, x, y, line.getStartOffset(),
- line.getEndOffset() - 1);
- //drawSelectedText(g, , , , );
+ int startOffset = line.getStartOffset();
+ int endOffset = line.getEndOffset() - 1;
+
+ if (selectionStart <= startOffset)
+ // Selection starts before the line ...
+ if (selectionEnd <= startOffset)
+ {
+ // end ends before the line: Draw completely unselected text.
+ drawUnselectedText(g, x, y, startOffset, endOffset);
+ }
+ else if (selectionEnd <= endOffset)
+ {
+ // and ends within the line: First part is selected,
+ // second is not.
+ x = drawSelectedText(g, x, y, startOffset, selectionEnd);
+ drawUnselectedText(g, x, y, selectionEnd, endOffset);
+ }
+ else
+ // and ends behind the line: Draw completely selected text.
+ drawSelectedText(g, x, y, startOffset, endOffset);
+ else if (selectionStart < endOffset)
+ // Selection starts within the line ..
+ if (selectionEnd < endOffset)
+ {
+ // and ends within it: First part unselected, second part
+ // selected, third part unselected.
+ x = drawUnselectedText(g, x, y, startOffset, selectionStart);
+ x = drawSelectedText(g, x, y, selectionStart, selectionEnd);
+ drawUnselectedText(g, x, y, selectionEnd, endOffset);
+ }
+ else
+ {
+ // and ends behind the line: First part unselected, second
+ // part selected.
+ x = drawUnselectedText(g, x, y, startOffset, selectionStart);
+ drawSelectedText(g, x, y, selectionStart, endOffset);
+ }
+ else
+ // Selection is behind this line: Draw completely unselected text.
+ drawUnselectedText(g, x, y, startOffset, endOffset);
}
catch (BadLocationException e)
{
@@ -171,7 +218,7 @@ public class PlainView extends View implements TabExpander
g.setColor(selectedColor);
Segment segment = getLineBuffer();
getDocument().getText(p0, p1 - p0, segment);
- return Utilities.drawTabbedText(segment, x, y, g, this, 0);
+ return Utilities.drawTabbedText(segment, x, y, g, this, segment.offset);
}
/**
@@ -212,6 +259,8 @@ public class PlainView extends View implements TabExpander
selectedColor = textComponent.getSelectedTextColor();
unselectedColor = textComponent.getForeground();
disabledColor = textComponent.getDisabledTextColor();
+ selectionStart = textComponent.getSelectionStart();
+ selectionEnd = textComponent.getSelectionEnd();
Rectangle rect = s.getBounds();
@@ -219,11 +268,13 @@ public class PlainView extends View implements TabExpander
Document document = textComponent.getDocument();
Element root = document.getDefaultRootElement();
int y = rect.y + metrics.getAscent();
+ int height = metrics.getHeight();
- for (int i = 0; i < root.getElementCount(); i++)
+ int count = root.getElementCount();
+ for (int i = 0; i < count; i++)
{
drawLine(i, g, rect.x, y);
- y += metrics.getHeight();
+ y += height;
}
}
@@ -274,7 +325,7 @@ public class PlainView extends View implements TabExpander
{
Element child = el.getElement(i);
int start = child.getStartOffset();
- int end = child.getEndOffset();
+ int end = child.getEndOffset() - 1;
try
{
el.getDocument().getText(start, end - start, seg);
@@ -386,6 +437,11 @@ public class PlainView extends View implements TabExpander
*/
protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f)
{
+ // Return early and do no updates if the allocation area is null
+ // (like the RI).
+ if (a == null)
+ return;
+
float oldMaxLineLength = maxLineLength;
Rectangle alloc = a.getBounds();
Element el = getElement();
@@ -467,7 +523,7 @@ public class PlainView extends View implements TabExpander
{
Element child = newElements[i];
int start = child.getStartOffset();
- int end = child.getEndOffset();
+ int end = child.getEndOffset() - 1;
try
{
el.getDocument().getText(start, end - start, seg);
@@ -586,7 +642,7 @@ public class PlainView extends View implements TabExpander
* @returna {@link Segment} object, that can be used to fetch text from
* the document
*/
- protected Segment getLineBuffer()
+ protected final Segment getLineBuffer()
{
if (lineBuffer == null)
lineBuffer = new Segment();