You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Sandro Martini (Updated) (JIRA)" <ji...@apache.org> on 2012/02/21 11:17:34 UTC

[jira] [Updated] (PIVOT-841) TextArea - ParagraphListener - textInserted method problem - count is equal 0

     [ https://issues.apache.org/jira/browse/PIVOT-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sandro Martini updated PIVOT-841:
---------------------------------

    Priority: Minor  (was: Major)
    Assignee: Chris Bartlett
    
> 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
>            Assignee: Chris Bartlett
>            Priority: Minor
>             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 sense?
> 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 {
>   @Override
>   public void startup(Display display, Map<String, String> properties) throws Exception {
>     TextArea textArea = new TextArea();
>     textArea.setText("abcxyz");
>     //---
>     final ParagraphListener paragraphListener = new ParagraphListener.Adapter() {
>       @Override
>       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);
>       }
>       @Override
>       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.getParagraphs().get(0).getParagraphListeners().add(paragraphListener);
>    
>     textArea.getTextAreaContentListeners().add(new TextAreaContentListener.Adapter() {
>       @Override
>       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);
>        
>         paragraph.getParagraphListeners().add(paragraphListener);
>       }
>     });
>    
>     Window window = new Window(textArea);
>    
>     window.open(display);
>   }
>   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 output:
> 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