diff options
author | Robert Schuster <theBohemian@gmx.net> | 2006-04-28 10:26:31 +0000 |
---|---|---|
committer | Robert Schuster <theBohemian@gmx.net> | 2006-04-28 10:26:31 +0000 |
commit | 96b7e3ae252e7b8cbcdeab29dcd6f3e6e5916952 (patch) | |
tree | bd29df4382fd57a8679c240952070d4d53b396e1 | |
parent | 17a034db5bf794ddb8594f2fb0f73e24364a4ad8 (diff) | |
download | classpath-96b7e3ae252e7b8cbcdeab29dcd6f3e6e5916952.tar.gz |
Partly fixes PR #27220.
2006-04-28 Robert Schuster <robertschuster@fsfe.org>
* javax/swing/text/View.java:
(getNextVisualPositionFrom): Rewritten.
* javax/swing/text/CompositeView.java:
(getNextEastWestVisualPositionFrom): Partly implemented.
(getNextNorthSouthVisualPositionFrom): Partly implemented.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | javax/swing/text/CompositeView.java | 98 | ||||
-rw-r--r-- | javax/swing/text/View.java | 26 |
3 files changed, 121 insertions, 11 deletions
@@ -1,3 +1,11 @@ +2006-04-28 Robert Schuster <robertschuster@fsfe.org> + + * javax/swing/text/View.java: + (getNextVisualPositionFrom): Rewritten. + * javax/swing/text/CompositeView.java: + (getNextEastWestVisualPositionFrom): Partly implemented. + (getNextNorthSouthVisualPositionFrom): Partly implemented. + 2006-04-28 David Gilbert <david.gilbert@object-refinery.com> * javax/swing/JList.java diff --git a/javax/swing/text/CompositeView.java b/javax/swing/text/CompositeView.java index 9195602ce..17f13dbed 100644 --- a/javax/swing/text/CompositeView.java +++ b/javax/swing/text/CompositeView.java @@ -633,8 +633,51 @@ public abstract class CompositeView Position.Bias[] biasRet) throws BadLocationException { - // FIXME: Implement this correctly. - return pos; + // TODO: It is unknown to me how this method has to be implemented and + // there is no specification telling me how to do it properly. Therefore + // the implementation was done for cases that are known. + // + // If this method ever happens to act silly for your particular case then + // it is likely that it is a cause of not knowing about your case when it + // was implemented first. You are free to fix the behavior. + // + // Here are the assumptions that lead to the implementation: + // If direction is NORTH chose the View preceding the one that contains the + // offset 'pos' (imagine the views are stacked on top of each other where + // the top is 0 and the bottom is getViewCount()-1. + // Consecutively when the direction is SOUTH the View following the one + // the offset 'pos' lies in is questioned. + // + // This limitation is described as PR 27345. + int index = getViewIndex(pos, b); + View v = null; + + if (index == -1) + return pos; + + switch (direction) + { + case NORTH: + // If we cannot calculate a proper offset return the one that was + // provided. + if (index <= 0) + return pos; + + v = getView(index - 1); + break; + case SOUTH: + // If we cannot calculate a proper offset return the one that was + // provided. + if (index >= getViewCount() - 1) + return pos; + + v = getView(index + 1); + break; + default: + throw new IllegalArgumentException(); + } + + return v.getNextVisualPositionFrom(pos, b, a, direction, biasRet); } /** @@ -667,8 +710,55 @@ public abstract class CompositeView Position.Bias[] biasRet) throws BadLocationException { - // FIXME: Implement this correctly. - return pos; + // TODO: It is unknown to me how this method has to be implemented and + // there is no specification telling me how to do it properly. Therefore + // the implementation was done for cases that are known. + // + // If this method ever happens to act silly for your particular case then + // it is likely that it is a cause of not knowing about your case when it + // was implemented first. You are free to fix the behavior. + // + // Here are the assumptions that lead to the implementation: + // If direction is EAST increase the offset by one and ask the View to + // which that index belong to calculate the 'next visual position'. + // If the direction is WEST do the same with offset 'pos' being decreased + // by one. + // This behavior will fail in a right-to-left or bidi environment! + // + // This limitation is described as PR 27346. + int index; + + View v = null; + + switch (direction) + { + case EAST: + index = getViewIndex(pos + 1, b); + // If we cannot calculate a proper offset return the one that was + // provided. + if (index == -1) + return pos; + + v = getView(index); + break; + case WEST: + index = getViewIndex(pos - 1, b); + // If we cannot calculate a proper offset return the one that was + // provided. + if (index == -1) + return pos; + + v = getView(index); + break; + default: + throw new IllegalArgumentException(); + } + + return v.getNextVisualPositionFrom(pos, + b, + a, + direction, + biasRet); } /** diff --git a/javax/swing/text/View.java b/javax/swing/text/View.java index 2feaf29a4..80b74f511 100644 --- a/javax/swing/text/View.java +++ b/javax/swing/text/View.java @@ -1,5 +1,5 @@ /* View.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -733,23 +733,35 @@ public abstract class View implements SwingConstants throws BadLocationException { int ret = pos; + Rectangle r; + switch (d) { - case WEST: - ret = pos - 1; - break; case EAST: - ret = pos + 1; + // TODO: take component orientation into account? + // Note: If pos is below zero the implementation will return + // pos + 1 regardless of whether that value is a correct offset + // in the document model. However this is what the RI does. + ret = Math.min(pos + 1, getEndOffset()); + break; + case WEST: + // TODO: take component orientation into account? + ret = Math.max(pos - 1, getStartOffset()); break; case NORTH: - // TODO: Implement this + // Try to find a suitable offset by examining the area above. + r = modelToView(pos, a, b).getBounds(); + ret = viewToModel(r.x, r.y - 1, a, biasRet); break; case SOUTH: - // TODO: Implement this + // Try to find a suitable offset by examining the area below. + r = modelToView(pos, a, b).getBounds(); + ret = viewToModel(r.x + r.width, r.y + r.height, a, biasRet); break; default: throw new IllegalArgumentException("Illegal value for d"); } + return ret; } } |