You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/10/22 22:55:24 UTC
svn commit: r828850 - in /incubator/pivot/trunk:
web/src/org/apache/pivot/web/HexUtils.java
web/src/org/apache/pivot/web/MD5.java
wtk/src/org/apache/pivot/wtk/TextArea.java
wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
Author: gbrown
Date: Thu Oct 22 20:55:23 2009
New Revision: 828850
URL: http://svn.apache.org/viewvc?rev=828850&view=rev
Log:
Redefine TextArea#getCharacterAt() as getInsertionPoint(); remove some redundant casts in HexUtils and MD5.
Modified:
incubator/pivot/trunk/web/src/org/apache/pivot/web/HexUtils.java
incubator/pivot/trunk/web/src/org/apache/pivot/web/MD5.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
Modified: incubator/pivot/trunk/web/src/org/apache/pivot/web/HexUtils.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/org/apache/pivot/web/HexUtils.java?rev=828850&r1=828849&r2=828850&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/org/apache/pivot/web/HexUtils.java (original)
+++ incubator/pivot/trunk/web/src/org/apache/pivot/web/HexUtils.java Thu Oct 22 20:55:23 2009
@@ -111,8 +111,8 @@
public static String convert(byte bytes[]) {
StringBuffer sb = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
- sb.append(convertDigit((int) (bytes[i] >> 4)));
- sb.append(convertDigit((int) (bytes[i] & 0x0f)));
+ sb.append(convertDigit(bytes[i] >> 4));
+ sb.append(convertDigit(bytes[i] & 0x0f));
}
return (sb.toString());
Modified: incubator/pivot/trunk/web/src/org/apache/pivot/web/MD5.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/org/apache/pivot/web/MD5.java?rev=828850&r1=828849&r2=828850&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/org/apache/pivot/web/MD5.java (original)
+++ incubator/pivot/trunk/web/src/org/apache/pivot/web/MD5.java Thu Oct 22 20:55:23 2009
@@ -131,8 +131,8 @@
char[] buffer = new char[MD5_DIGEST_LENTGH_IN_BYTES * 2];
for (int i = 0; i < MD5_DIGEST_LENTGH_IN_BYTES; i++) {
- int low = (int) (binaryData[i] & 0x0f);
- int high = (int) ((binaryData[i] & 0xf0) >> 4);
+ int low = binaryData[i] & 0x0f;
+ int high = (binaryData[i] & 0xf0) >> 4;
buffer[i * 2] = HexUtils.hexadecimal[high];
buffer[i * 2 + 1] = HexUtils.hexadecimal[low];
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=828850&r1=828849&r2=828850&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Thu Oct 22 20:55:23 2009
@@ -53,7 +53,7 @@
* @return
* The character offset at the given location.
*/
- public int getCharacterAt(int x, int y);
+ public int getInsertionPoint(int x, int y);
/**
* Returns the bounds of the character at a given offset within the
@@ -574,9 +574,9 @@
// TODO
}
- public int getCharacterAt(int x, int y) {
+ public int getInsertionPoint(int x, int y) {
TextArea.Skin textAreaSkin = (TextArea.Skin)getSkin();
- return textAreaSkin.getCharacterAt(x, y);
+ return textAreaSkin.getInsertionPoint(x, y);
}
public Bounds getCharacterBounds(int offset) {
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=828850&r1=828849&r2=828850&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Thu Oct 22 20:55:23 2009
@@ -225,7 +225,7 @@
}
public abstract NodeView getNext();
- public abstract int getCharacterAt(int x, int y);
+ public abstract int getInsertionPoint(int x, int y);
public abstract Bounds getCharacterBounds(int offset);
@Override
@@ -377,24 +377,6 @@
}
@Override
- public int getCharacterAt(int x, int y) {
- int offset = -1;
-
- for (int i = 0, n = nodeViews.getLength(); i < n; i++) {
- NodeView nodeView = nodeViews.get(i);
- Bounds nodeViewBounds = nodeView.getBounds();
-
- if (nodeViewBounds.contains(x, y)) {
- offset = nodeView.getCharacterAt(x - nodeView.getX(), y - nodeView.getY())
- + nodeView.getOffset();
- break;
- }
- }
-
- return offset;
- }
-
- @Override
public Bounds getCharacterBounds(int offset) {
Bounds characterBounds = null;
@@ -496,6 +478,24 @@
}
@Override
+ public int getInsertionPoint(int x, int y) {
+ int offset = -1;
+
+ for (int i = 0, n = getLength(); i < n; i++) {
+ NodeView nodeView = get(i);
+ Bounds nodeViewBounds = nodeView.getBounds();
+
+ if (nodeViewBounds.contains(x, y)) {
+ offset = nodeView.getInsertionPoint(x - nodeView.getX(), y - nodeView.getY())
+ + nodeView.getOffset();
+ break;
+ }
+ }
+
+ return offset;
+ }
+
+ @Override
public NodeView getNext() {
return null;
}
@@ -630,20 +630,25 @@
}
@Override
- public void paint(Graphics2D graphics) {
- super.paint(graphics);
-
- // TODO Paint the terminator character (make this styleable)
- }
-
- @Override
public NodeView getNext() {
return null;
}
@Override
- public int getCharacterAt(int x, int y) {
- int offset = super.getCharacterAt(x, y);
+ public int getInsertionPoint(int x, int y) {
+ // TODO Use row bounds to determine insertion point
+ int offset = -1;
+
+ for (int i = 0, n = getLength(); i < n; i++) {
+ NodeView nodeView = get(i);
+ Bounds nodeViewBounds = nodeView.getBounds();
+
+ if (nodeViewBounds.contains(x, y)) {
+ offset = nodeView.getInsertionPoint(x - nodeView.getX(), y - nodeView.getY())
+ + nodeView.getOffset();
+ break;
+ }
+ }
if (offset == -1) {
offset = getCharacterCount() - 1;
@@ -806,7 +811,7 @@
}
@Override
- public int getCharacterAt(int x, int y) {
+ public int getInsertionPoint(int x, int y) {
validate();
LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
@@ -817,21 +822,23 @@
while (i < n) {
Shape glyphLogicalBounds = glyphVector.getGlyphLogicalBounds(i);
+
if (glyphLogicalBounds.contains(x, y - ascent)) {
+ Rectangle2D glyphLogicalBounds2D = glyphLogicalBounds.getBounds2D();
+
+ if (x - glyphLogicalBounds2D.getX() > glyphLogicalBounds2D.getWidth() / 2) {
+ // The user clicked on the right half of the character; select
+ // the next character
+ i++;
+ }
+
break;
}
i++;
}
- int offset;
- if (i < n) {
- offset = i;
- } else {
- offset = -1;
- }
-
- return offset;
+ return i;
}
@Override
@@ -918,7 +925,7 @@
}
@Override
- public int getCharacterAt(int x, int y) {
+ public int getInsertionPoint(int x, int y) {
return 0;
}
@@ -1056,13 +1063,13 @@
}
@Override
- public int getCharacterAt(int x, int y) {
+ public int getInsertionPoint(int x, int y) {
int offset;
if (documentView == null) {
offset = -1;
} else {
- offset = documentView.getCharacterAt(x - margin.left, y - margin.top);
+ offset = documentView.getInsertionPoint(x - margin.left, y - margin.top);
}
return offset;
@@ -1161,16 +1168,8 @@
if (button == Mouse.Button.LEFT) {
// Move the caret to the insertion point
- int offset = getCharacterAt(x, y);
-
+ int offset = getInsertionPoint(x, y);
if (offset != -1) {
- Bounds characterBounds = getCharacterBounds(offset);
- if (!characterBounds.isEmpty()
- && x - characterBounds.x > characterBounds.width / 2) {
- // The user clicked on the right half of the character; select offset + 1
- offset++;
- }
-
textArea.setSelection(offset, 0);
}
@@ -1283,9 +1282,8 @@
consumed = true;
} else if (keyCode == Keyboard.KeyCode.UP) {
- // TODO We shouldn't need a "magic" number like 5 here; what is a more
- // reliable way to do this?
- int offset = documentView.getCharacterAt(caretX, caret.y - 5);
+ // TODO Use getInsertionPoint(int, int, Direction) to determine the next index
+ int offset = documentView.getInsertionPoint(caretX, caret.y - 5);
// TODO Modify selection based on SHIFT key
textArea.setSelection(offset, 0);
@@ -1295,8 +1293,8 @@
consumed = true;
} else if (keyCode == Keyboard.KeyCode.DOWN) {
- // TODO What is a more reliable way to do this?
- int offset = documentView.getCharacterAt(caretX, caret.y + caret.height + 1);
+ // TODO Use getInsertionPoint(int, int, Direction) to determine the next index
+ int offset = documentView.getInsertionPoint(caretX, caret.y + caret.height + 1);
// TODO Modify selection based on SHIFT key
textArea.setSelection(offset, 0);