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/11/01 20:55:14 UTC
svn commit: r831749 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk:
media/drawing/Text.java skin/LabelSkin.java skin/TextAreaSkin.java
skin/terra/TerraTextInputSkin.java
Author: gbrown
Date: Sun Nov 1 19:55:14 2009
New Revision: 831749
URL: http://svn.apache.org/viewvc?rev=831749&view=rev
Log:
Restore most scrolling functionality to TextInput; standardize on some glyph vector naming conventions.
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java?rev=831749&r1=831748&r2=831749&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java Sun Nov 1 19:55:14 2009
@@ -205,8 +205,8 @@
for (int i = 0, n = glyphVectors.getLength(); i < n; i++) {
GlyphVector glyphVector = glyphVectors.get(i);
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- float lineWidth = (float)logicalBounds.getWidth();
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ float lineWidth = (float)textBounds.getWidth();
float x = 0;
switch(alignment) {
@@ -246,7 +246,7 @@
graphics.translate(-x, -(y + ascent));
}
- y += logicalBounds.getHeight();
+ y += textBounds.getHeight();
}
}
}
@@ -267,9 +267,9 @@
GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, text);
glyphVectors.add(glyphVector);
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- width = (int)Math.ceil(logicalBounds.getWidth());
- height = (int)Math.ceil(logicalBounds.getHeight());
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ width = (int)Math.ceil(textBounds.getWidth());
+ height = (int)Math.ceil(textBounds.getHeight());
}
} else {
float textWidth = 0;
@@ -305,9 +305,9 @@
GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
glyphVectors.add(glyphVector);
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- textWidth = (float)Math.max(logicalBounds.getWidth(), textWidth);
- textHeight += logicalBounds.getHeight();
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ textWidth = (float)Math.max(textBounds.getWidth(), textWidth);
+ textHeight += textBounds.getHeight();
}
start = i + 1;
@@ -322,9 +322,9 @@
GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
glyphVectors.add(glyphVector);
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- textWidth = (float)Math.max(logicalBounds.getWidth(), textWidth);
- textHeight += logicalBounds.getHeight();
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ textWidth = (float)Math.max(textBounds.getWidth(), textWidth);
+ textHeight += textBounds.getHeight();
}
width = (int)Math.ceil(textWidth);
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java?rev=831749&r1=831748&r2=831749&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java Sun Nov 1 19:55:14 2009
@@ -226,8 +226,8 @@
GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
glyphVectors.add(glyphVector);
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- textHeight += logicalBounds.getHeight();
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ textHeight += textBounds.getHeight();
}
start = i + 1;
@@ -242,15 +242,15 @@
GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
glyphVectors.add(glyphVector);
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- textHeight += logicalBounds.getHeight();
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ textHeight += textBounds.getHeight();
}
} else {
GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, text);
glyphVectors.add(glyphVector);
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- textHeight += logicalBounds.getHeight();
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ textHeight += textBounds.getHeight();
}
}
}
@@ -314,8 +314,8 @@
for (int i = 0, n = glyphVectors.getLength(); i < n; i++) {
GlyphVector glyphVector = glyphVectors.get(i);
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- float lineWidth = (float)logicalBounds.getWidth();
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ float lineWidth = (float)textBounds.getWidth();
float x = 0;
switch(horizontalAlignment) {
@@ -359,7 +359,7 @@
graphics.draw(line);
}
- y += logicalBounds.getHeight();
+ y += textBounds.getHeight();
}
}
}
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=831749&r1=831748&r2=831749&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 Sun Nov 1 19:55:14 2009
@@ -999,9 +999,9 @@
length = ci.getEndIndex() - start;
}
- Rectangle2D logicalBounds = glyphVector.getLogicalBounds();
- setSize((int)Math.ceil(logicalBounds.getWidth()),
- (int)Math.ceil(logicalBounds.getHeight()));
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ setSize((int)Math.ceil(textBounds.getWidth()),
+ (int)Math.ceil(textBounds.getHeight()));
}
super.validate();
@@ -1091,10 +1091,10 @@
int i = 0;
while (i < n) {
- Shape glyphLogicalBounds = glyphVector.getGlyphLogicalBounds(i);
+ Shape glyphBounds = glyphVector.getGlyphLogicalBounds(i);
- if (glyphLogicalBounds.contains(x, y - ascent)) {
- Rectangle2D glyphBounds2D = glyphLogicalBounds.getBounds2D();
+ if (glyphBounds.contains(x, y - ascent)) {
+ Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
if (x - glyphBounds2D.getX() > glyphBounds2D.getWidth() / 2) {
// The user clicked on the right half of the character; select
@@ -1120,8 +1120,8 @@
int i = 0;
while (i < n) {
- Shape glyphLogicalBounds = glyphVector.getGlyphLogicalBounds(i);
- Rectangle2D glyphBounds2D = glyphLogicalBounds.getBounds2D();
+ Shape glyphBounds = glyphVector.getGlyphLogicalBounds(i);
+ Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
float glyphX = (float)glyphBounds2D.getX();
float glyphWidth = (float)glyphBounds2D.getWidth();
@@ -1156,11 +1156,11 @@
@Override
public Bounds getCharacterBounds(int offset) {
- Shape glyphLogicalBounds = glyphVector.getGlyphLogicalBounds(offset);
- Rectangle2D bounds2D = glyphLogicalBounds.getBounds2D();
+ Shape glyphBounds = glyphVector.getGlyphLogicalBounds(offset);
+ Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
- return new Bounds((int)Math.floor(bounds2D.getX()), 0,
- (int)Math.ceil(bounds2D.getWidth()), getHeight());
+ return new Bounds((int)Math.floor(glyphBounds2D.getX()), 0,
+ (int)Math.ceil(glyphBounds2D.getWidth()), getHeight());
}
@Override
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=831749&r1=831748&r2=831749&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Sun Nov 1 19:55:14 2009
@@ -221,18 +221,32 @@
}
glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, ci);
+
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ int textWidth = (int)textBounds.getWidth();
+ int width = getWidth();
+
+ if (textWidth - scrollLeft + padding.left + 1 < width - padding.right - 1) {
+ // The right edge of the text is less than the right inset; align
+ // the text's right edge with the inset
+ scrollLeft = Math.max(textWidth + (padding.left + padding.right + 2) - width, 0);
+ } else {
+ // Scroll lead selection to visible
+ int selectionStart = textInput.getSelectionStart();
+ if (selectionStart < n) {
+ scrollCharacterToVisible(selectionStart);
+ }
+ }
}
+ } else {
+ // Set scrollLeft to 0
+ scrollLeft = 0;
+ updateSelection();
}
updateSelection();
showCaret(textInput.isFocused()
&& textInput.getSelectionLength() == 0);
-
- if (textNode.getCharacterCount() > 0) {
- scrollCharacterToVisible(textInput.getSelectionStart());
- } else {
- scrollLeft = 0;
- }
}
@Override
@@ -280,15 +294,6 @@
graphics.setColor(borderColor);
GraphicsUtilities.drawRect(graphics, 0, 0, width, height);
- // TODO Remove
- /*
- // Paint the padding border
- graphics.setColor(Color.RED);
- graphics.drawRect(padding.left + 1, padding.top + 1,
- width - (padding.left + padding.right + 2),
- height - (padding.top + padding.bottom + 2));
- */
-
// Paint the content
if (FONT_RENDER_CONTEXT.isAntiAliased()) {
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
@@ -382,19 +387,21 @@
x -= (padding.left - scrollLeft + 1);
y -= (padding.top + 1);
- int n = glyphVector.getNumGlyphs();
+
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
if (x < 0) {
offset = 0;
- } else if (x > glyphVector.getLogicalBounds().getWidth()) {
- offset = n;
+ } else if (x > textBounds.getWidth()) {
+ offset = glyphVector.getNumGlyphs();
} else {
+ int n = glyphVector.getNumGlyphs();
int i = 0;
while (i < n) {
- Shape glyphLogicalBounds = glyphVector.getGlyphLogicalBounds(i);
+ Shape glyphBounds = glyphVector.getGlyphLogicalBounds(i);
- if (glyphLogicalBounds.contains(x, y - ascent)) {
- Rectangle2D glyphBounds2D = glyphLogicalBounds.getBounds2D();
+ if (glyphBounds.contains(x, y - ascent)) {
+ Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
if (x - glyphBounds2D.getX() > glyphBounds2D.getWidth() / 2) {
// The user clicked on the right half of the character; select
@@ -415,29 +422,33 @@
}
public Bounds getCharacterBounds(int offset) {
- Shape glyphLogicalBounds = glyphVector.getGlyphLogicalBounds(offset);
- Rectangle2D bounds2D = glyphLogicalBounds.getBounds2D();
+ Shape glyphBounds = glyphVector.getGlyphLogicalBounds(offset);
+ Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
- int x = (int)Math.floor(bounds2D.getX()) + padding.left - scrollLeft + 1;
+ int x = (int)Math.floor(glyphBounds2D.getX()) + padding.left - scrollLeft + 1;
int y = padding.top + 1;
- int width = (int)Math.ceil(bounds2D.getWidth());
+ int width = (int)Math.ceil(glyphBounds2D.getWidth());
int height = getHeight() - (padding.top + padding.bottom + 2);
return new Bounds(x, y, width, height);
}
+ private void setScrollLeft(int scrollLeft) {
+ this.scrollLeft = scrollLeft;
+ updateSelection();
+ repaintComponent();
+ }
+
private void scrollCharacterToVisible(int offset) {
int width = getWidth();
Bounds characterBounds = getCharacterBounds(offset);
int glyphX = characterBounds.x - (padding.left + 1) + scrollLeft;
if (characterBounds.x < padding.left + 1) {
- scrollLeft = glyphX;
+ setScrollLeft(glyphX);
} else if (characterBounds.x + characterBounds.width > width - (padding.right + 1)) {
- scrollLeft = glyphX + (padding.left + padding.right + 2) + characterBounds.width - width;
+ setScrollLeft(glyphX + (padding.left + padding.right + 2) + characterBounds.width - width);
}
-
- repaintComponent();
}
public Font getFont() {
@@ -454,10 +465,10 @@
int missingGlyphCode = font.getMissingGlyphCode();
GlyphVector missingGlyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT,
new int[] {missingGlyphCode});
- Rectangle2D logicalBounds = missingGlyphVector.getLogicalBounds();
+ Rectangle2D textBounds = missingGlyphVector.getLogicalBounds();
Rectangle2D maxCharBounds = font.getMaxCharBounds(FONT_RENDER_CONTEXT);
- averageCharacterSize = new Dimensions((int)Math.ceil(logicalBounds.getWidth()),
+ averageCharacterSize = new Dimensions((int)Math.ceil(textBounds.getWidth()),
(int)Math.ceil(maxCharBounds.getHeight()));
invalidateComponent();
@@ -1101,7 +1112,7 @@
if (textNode.getCharacterCount() > 0) {
scrollCharacterToVisible(selectionStart);
} else {
- scrollLeft = 0;
+ setScrollLeft(0);
}
consumed = true;
@@ -1145,6 +1156,7 @@
scrollCharacterToVisible(selectionStart + selectionLength - 1);
} else {
scrollLeft = 0;
+ updateSelection();
}
consumed = true;
@@ -1348,8 +1360,8 @@
leadingSelectionBounds = getCharacterBounds(selectionStart);
} else {
// The insertion point is after the last character
- Rectangle2D glyphVectorBounds = glyphVector.getLogicalBounds();
- int x = (int)Math.ceil(glyphVectorBounds.getWidth()) + (padding.left - scrollLeft + 1);
+ Rectangle2D textBounds = glyphVector.getLogicalBounds();
+ int x = (int)Math.ceil(textBounds.getWidth()) + (padding.left - scrollLeft + 1);
int y = padding.top + 1;
leadingSelectionBounds = new Bounds(x, y, 0, averageCharacterSize.height);
}