You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by no...@apache.org on 2010/07/19 14:06:17 UTC
svn commit: r965445 - in /pivot/trunk: ./
demos/src/org/apache/pivot/demos/richtexteditor/
wtk/src/org/apache/pivot/wtk/skin/ wtk/src/org/apache/pivot/wtk/text/
Author: noelgrandin
Date: Mon Jul 19 12:06:17 2010
New Revision: 965445
URL: http://svn.apache.org/viewvc?rev=965445&view=rev
Log:
add support for underlining and strikethrough to TextArea
Modified:
pivot/trunk/ (props changed)
pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/RichTextEditorDemo.java
pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/richtexteditor.bxml
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinElementView.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ElementListener.java
Propchange: pivot/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Jul 19 12:06:17 2010
@@ -4,3 +4,4 @@
container-child-access.6aug.patch
bin
noel
+pivot-433-tablepane-limits.patch
Modified: pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/RichTextEditorDemo.java
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/RichTextEditorDemo.java?rev=965445&r1=965444&r2=965445&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/RichTextEditorDemo.java (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/RichTextEditorDemo.java Mon Jul 19 12:06:17 2010
@@ -70,6 +70,10 @@ public class RichTextEditorDemo implemen
@BXML
private PushButton italicButton = null;
@BXML
+ private PushButton underlineButton = null;
+ @BXML
+ private PushButton strikethroughButton = null;
+ @BXML
private ListButton fontFamilyListButton = null;
@BXML
private ListButton fontSizeListButton = null;
@@ -245,6 +249,32 @@ public class RichTextEditorDemo implemen
}
});
+ underlineButton.getButtonPressListeners().add(new ButtonPressListener() {
+ @Override
+ public void buttonPressed(Button button) {
+ org.apache.pivot.wtk.Span span = textarea.getSelection();
+ applyStyle(textarea.getDocument(), span, new StyleApplicator() {
+ @Override
+ public void apply(org.apache.pivot.wtk.text.Span span) {
+ span.setUnderline(!span.isUnderline());
+ }
+ });
+ }
+ });
+
+ strikethroughButton.getButtonPressListeners().add(new ButtonPressListener() {
+ @Override
+ public void buttonPressed(Button button) {
+ org.apache.pivot.wtk.Span span = textarea.getSelection();
+ applyStyle(textarea.getDocument(), span, new StyleApplicator() {
+ @Override
+ public void apply(org.apache.pivot.wtk.text.Span span) {
+ span.setStrikethrough(!span.isStrikethrough());
+ }
+ });
+ }
+ });
+
ListButtonSelectionListener fontButtonPressListener = new ListButtonSelectionListener() {
@Override
public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
Modified: pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/richtexteditor.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/richtexteditor.bxml?rev=965445&r1=965444&r2=965445&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/richtexteditor.bxml (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/richtexteditor/richtexteditor.bxml Mon Jul 19 12:06:17 2010
@@ -31,6 +31,8 @@ limitations under the License.
<Label text=" "/> <!-- spacer -->
<PushButton bxml:id="boldButton" buttonData="Bold"/>
<PushButton bxml:id="italicButton" buttonData="Italic"/>
+ <PushButton bxml:id="underlineButton" buttonData="Underline"/>
+ <PushButton bxml:id="strikethroughButton" buttonData="Strikethrough"/>
<ListButton bxml:id="fontFamilyListButton"/>
<ListButton bxml:id="fontSizeListButton"/>
<Checkbox bxml:id="wrapTextCheckbox" buttonData="Wrap Text" selected="false"/>
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinElementView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinElementView.java?rev=965445&r1=965444&r2=965445&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinElementView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinElementView.java Mon Jul 19 12:06:17 2010
@@ -231,8 +231,18 @@ abstract class TextAreaSkinElementView e
public void foregroundColorChanged(Element element, Color previousForegroundColor) {
invalidate();
}
+
+ @Override
+ public void underlineChanged(Element element) {
+ invalidate();
+ }
@Override
+ public void strikethroughChanged(Element element) {
+ invalidate();
+ }
+
+ @Override
public Iterator<TextAreaSkinNodeView> iterator() {
return new ImmutableIterator<TextAreaSkinNodeView>(nodeViews.iterator());
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java?rev=965445&r1=965444&r2=965445&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkinTextNodeView.java Mon Jul 19 12:06:17 2010
@@ -164,6 +164,10 @@ class TextAreaSkinTextNodeView extends T
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
LineMetrics lm = getEffectiveFont().getLineMetrics("", fontRenderContext);
float ascent = lm.getAscent();
+ int strikethroughX = Math.round(lm.getAscent() + lm.getStrikethroughOffset());
+ int underlineX = Math.round(lm.getAscent() + lm.getUnderlineOffset());
+ boolean underline = getEffectiveUnderline();
+ boolean strikethrough = getEffectiveStrikethrough();
graphics.setFont(getEffectiveFont());
@@ -174,12 +178,12 @@ class TextAreaSkinTextNodeView extends T
int documentOffset = getDocumentOffset();
Span characterRange = new Span(documentOffset, documentOffset + getCharacterCount() - 1);
+ int width = getWidth();
+ int height = getHeight();
+
if (selectionLength > 0
&& characterRange.intersects(selectionRange)) {
// Determine the selection bounds
- int width = getWidth();
- int height = getHeight();
-
int x0;
if (selectionRange.start > characterRange.start) {
Bounds leadingSelectionBounds = getCharacterBounds(selectionRange.start - documentOffset);
@@ -207,6 +211,12 @@ class TextAreaSkinTextNodeView extends T
textGraphics.setColor(getEffectiveForegroundColor());
textGraphics.clip(unselectedArea);
textGraphics.drawGlyphVector(glyphVector, 0, ascent);
+ if (underline) {
+ textGraphics.drawLine(x0, underlineX, x1 - x0, underlineX);
+ }
+ if (strikethrough) {
+ textGraphics.drawLine(x0, strikethroughX, x1 - x0, strikethroughX);
+ }
textGraphics.dispose();
// Paint the selection
@@ -222,11 +232,23 @@ class TextAreaSkinTextNodeView extends T
textArea.isEditable() ? selectionColor : textAreaSkin.getInactiveSelectionColor());
selectedTextGraphics.clip(selection.getBounds());
selectedTextGraphics.drawGlyphVector(glyphVector, 0, ascent);
+ if (underline) {
+ selectedTextGraphics.drawLine(0, underlineX, width, underlineX);
+ }
+ if (strikethrough) {
+ selectedTextGraphics.drawLine(0, strikethroughX, width, strikethroughX);
+ }
selectedTextGraphics.dispose();
} else {
// Draw the text
graphics.setColor(getEffectiveForegroundColor());
graphics.drawGlyphVector(glyphVector, 0, ascent);
+ if (underline) {
+ graphics.drawLine(0, underlineX, width, underlineX);
+ }
+ if (strikethrough) {
+ graphics.drawLine(0, strikethroughX, width, strikethroughX);
+ }
}
}
}
@@ -315,6 +337,32 @@ class TextAreaSkinTextNodeView extends T
return foregroundColor;
}
+ private boolean getEffectiveUnderline() {
+ // run up the tree until we find an element's style to apply
+ Element element = getNode().getParent();
+ while (element != null) {
+ if (element.isUnderline()) {
+ return true;
+ }
+
+ element = element.getParent();
+ }
+ return false;
+ }
+
+ private boolean getEffectiveStrikethrough() {
+ // run up the tree until we find an element's style to apply
+ Element element = getNode().getParent();
+ while (element != null) {
+ if (element.isStrikethrough()) {
+ return true;
+ }
+
+ element = element.getParent();
+ }
+ return false;
+ }
+
@Override
public int getNextInsertionPoint(int x, int from, FocusTraversalDirection direction) {
int offset = -1;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java?rev=965445&r1=965444&r2=965445&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java Mon Jul 19 12:06:17 2010
@@ -73,6 +73,18 @@ public abstract class Element extends No
listener.foregroundColorChanged(element, previousForegroundColor);
}
}
+ @Override
+ public void underlineChanged(Element element) {
+ for (ElementListener listener : this) {
+ listener.underlineChanged(element);
+ }
+ }
+ @Override
+ public void strikethroughChanged(Element element) {
+ for (ElementListener listener : this) {
+ listener.strikethroughChanged(element);
+ }
+ }
}
private int characterCount = 0;
@@ -80,6 +92,8 @@ public abstract class Element extends No
private java.awt.Font font;
private Color foregroundColor;
private Color backgroundColor;
+ private boolean underline;
+ private boolean strikethrough;
private ElementListenerList elementListeners = new ElementListenerList();
@@ -87,6 +101,11 @@ public abstract class Element extends No
}
public Element(Element element, boolean recursive) {
+ this.font = element.getFont();
+ this.foregroundColor = element.getForegroundColor();
+ this.backgroundColor = element.getBackgroundColor();
+ this.underline = element.isUnderline();
+ this.strikethrough = element.isStrikethrough();
if (recursive) {
for (Node node : element) {
add(node.duplicate(true));
@@ -708,6 +727,30 @@ public abstract class Element extends No
setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColor));
}
+ public boolean isUnderline() {
+ return underline;
+ }
+
+ public void setUnderline(boolean underline) {
+ boolean previousUnderline = this.underline;
+ if (previousUnderline != underline) {
+ this.underline = underline;
+ elementListeners.underlineChanged(this);
+ }
+ }
+
+ public boolean isStrikethrough() {
+ return strikethrough;
+ }
+
+ public void setStrikethrough(boolean strikethrough) {
+ boolean previousStrikethrough = this.strikethrough;
+ if (previousStrikethrough != strikethrough) {
+ this.strikethrough = strikethrough;
+ elementListeners.strikethroughChanged(this);
+ }
+ }
+
public ListenerList<ElementListener> getElementListeners() {
return elementListeners;
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ElementListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ElementListener.java?rev=965445&r1=965444&r2=965445&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ElementListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ElementListener.java Mon Jul 19 12:06:17 2010
@@ -25,6 +25,7 @@ import org.apache.pivot.collections.Sequ
* Element listener interface.
*/
public interface ElementListener {
+
public class Adapter implements ElementListener {
@Override
public void nodeInserted(Element element, int index) {
@@ -41,7 +42,14 @@ public interface ElementListener {
@Override
public void foregroundColorChanged(Element element, Color previousForegroundColor) {
}
+ @Override
+ public void underlineChanged(Element element) {
+ }
+ @Override
+ public void strikethroughChanged(Element element) {
+ }
}
+
/**
* Called when a node has been inserted into an element.
*
@@ -84,4 +92,17 @@ public interface ElementListener {
*/
public void foregroundColorChanged(Element element, Color previousForegroundColor);
+ /**
+ * Called when underline style has changed.
+ *
+ * @param element
+ */
+ public void underlineChanged(Element element);
+
+ /**
+ * Called when strikethrough style has changed.
+ *
+ * @param element
+ */
+ public void strikethroughChanged(Element element);
}