pivot-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Imbue Lab (Created) (JIRA)" <j...@apache.org>
Subject [jira] [Created] (PIVOT-841) TextArea - ParagraphListener - textInserted method problem - count is equal 0
Date Tue, 21 Feb 2012 10:13:34 GMT
TextArea - ParagraphListener - textInserted method problem - count is equal 0

                 Key: PIVOT-841
                 URL: https://issues.apache.org/jira/browse/PIVOT-841
             Project: Pivot
          Issue Type: Bug
          Components: wtk
    Affects Versions: 2.0.1
         Environment: Windows 7, Java 1.7.0_01
            Reporter: Imbue Lab
             Fix For: 2.0.2

I use TextArea and want to listen to the inserted text (simply by using keyboard). I do it
using ParagraphListener. Every time new character is typed a listener's method textInserted(Paragraph
paragraph, int index, int count) is invoked. Everything works fine till I press ENTER. In
that case textInserted method is invoked with "count" parameter set to 0. Does it make any

I've prepared the simplest example I could imagine, it looks ugly, but it's simple and works

Please take a look on the code below and description after it:

import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.TextArea;
import org.apache.pivot.wtk.TextArea.Paragraph;
import org.apache.pivot.wtk.TextArea.ParagraphListener;
import org.apache.pivot.wtk.TextAreaContentListener;
import org.apache.pivot.wtk.Window;

public class TextAreaListenersExample extends Application.Adapter {
  public void startup(Display display, Map<String, String> properties) throws Exception
    TextArea textArea = new TextArea();
    final ParagraphListener paragraphListener = new ParagraphListener.Adapter() {
      public void textInserted(Paragraph paragraph, int index, int count) {
        System.out.println("Text inserted\n\tparagraph content: '" + paragraph.getCharacters()
+ "" + "'\n\tindex: " + index + "\n\tcount: " + count);

      public void textRemoved(Paragraph paragraph, int index, int count) {
        System.out.println("Text removed\n\tparagraph content: '" + paragraph.getCharacters()
+ "'\n\tindex: " + index + "\n\tcount: " + count);      }
    textArea.getTextAreaContentListeners().add(new TextAreaContentListener.Adapter() {
      public void paragraphInserted(TextArea textArea, int index) {
        Paragraph paragraph = textArea.getParagraphs().get(index);
        System.out.println("Paragraph inserted\n\tparagraph content: '" + paragraph.getCharacters()
+ "'\n\tindex: " + index);
    Window window = new Window(textArea);

  public static void main(String[] args) throws Exception {
    DesktopApplicationContext.main(TextAreaListenersExample.class, new String[0]);

When you place carret after the "c" character in the TextArea and press ENTER, you get following

Text removed
    paragraph content: 'abc' <- text 'xyz' was removed from the first paragraph 'abcxyz'
    index: 3
    count: 3
Text inserted
    paragraph content: 'abc' <- first paragraph insertion, probably it was ENTER
    index: 3
    count: 0 <- count is 0!!!
Paragraph inserted
    paragraph content: 'xyz' <- new paragraph is inserted together with the content
    index: 1
Text inserted
    paragraph content: 'xyz' <- I don't know why insertion happens here
    index: 0
    count: 0 <- again, count is 0!!!

One more thing, maybe it would be better to have paragraph insertion without any content (not
like it is now), and after that text insertion with the all content of the new created paragraph,
it would be more intuitive and easier to handle, I really struggle with that now. Can you
consider that?

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message