Hi Eugene, judging from the style you write an extension, you seem to be working with ULC 6.0.x. (Note that the extension API has been streamlined with ULC 6.1.)
Some suggestions concerning your extension: - Why don't you try to extend ULCTextArea instead of ULCComponent? In this context you could simply inherit from UITextArea on the client side and provide your specific basic object class "MyBasicTextArea" which extends ULCTextArea.BasicTextArea I think you can apply the document filter stuff as well to BasicTextArea (which is itself a sublass of JTextArea). - Client server communication in the context of an extension is illustrated in the PieChart example of ULC (see <ulc-home>/sample/pie). E.g., you can send event via sendOptionalEventULC(). See also the ULC Essential Guide of ULC 6.0.x. Greetings, Daniel -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Eugene Coelho Sent: Freitag, 19. Mai 2006 09:45 To: [EMAIL PROTECTED] Canoo. Com Subject: RE: [ULC-developer] Restrict No of Lines in a Text Area Hi, I have written following extension and it restricts the no of lines in the textpanel but there seems to a small problem ... i am unable to get the updated text that the user enters in the Text Panel how do i get this updated text when i say MyTextPanel.getText(). public class ULCMyTextPane extends ULCComponent { String text; public ULCMyTextPane() { text = new String(); } public void handleRequest(String request, Anything args) { super.handleRequest(request, args); } protected void saveState(Anything a) { super.saveState(a); saveState(a, "setText",text,""); } protected String typeString() { return "com.isfsdc.wwm.client.UIMyTextPane"; } public void setText(String text1){ update("setText",this.text,text1); this.text = text1; System.out.println("printing Comments settext"+text); } protected String getPropertyPrefix() { // TODO Auto-generated method stub return null; } public String getText() { System.out.println("printing Comments "+text); return text; } } public class UIMyTextPane extends UIComponent { private MyJTextPane myJTextPane; private String text; public UIMyTextPane() { myJTextPane = new MyJTextPane(); text = new String(); } protected Object createBasicObject(Anything args) { return myJTextPane; } public MyJTextPane getBasicMyTextPane() { return (MyJTextPane) getBasicObject(); } public void handleRequest(String request, Anything args) { super.handleRequest(request, args); if (request.equals("setText") ) { text = (String)args.get("setText",""); myJTextPane.setText(text); } } public void restoreState(Anything args) { super.restoreState(args); if (args.isDefined("setText")) { text = (String)args.get("setText",""); myJTextPane.setText(text); } } } public class MyJTextPane extends JTextPane { AbstractDocument doc; static final int MAX_CHARACTERS = 100; public MyJTextPane() { super(); StyledDocument styledDoc = getStyledDocument(); if (styledDoc instanceof AbstractDocument) { doc = (AbstractDocument)styledDoc; doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } } } public class DocumentSizeFilter extends DocumentFilter { int maxCharacters; boolean DEBUG = false; public DocumentSizeFilter(int maxChars) { maxCharacters = maxChars; } public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException { if (DEBUG) { System.out.println("in DocumentSizeFilter's insertString method"); } //This rejects the entire insertion if it would make //the contents too long. Another option would be //to truncate the inserted string so the contents //would be exactly maxCharacters in length. if ((fb.getDocument().getLength() + str.length()) <= maxCharacters) super.insertString(fb, offs, str, a); } public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a) throws BadLocationException { if (DEBUG) { System.out.println("in DocumentSizeFilter's replace method"); } //This rejects the entire replacement if it would make //the contents too long. Another option would be //to truncate the replacement string so the contents //would be exactly maxCharacters in length. if ((fb.getDocument().getLength() + str.length() - length) <= maxCharacters) super.replace(fb, offs, length, str, a); } } Regards, Gene Daniel Pfeifer <[EMAIL PROTECTED]> wrote: Hi Eugene, by default ULCTextArea does not limit the number of characters you may enter. This behaviour is similar to the Swing-based JTextArea component. To limit the number of lines or the number of characters, you should write an extension as you already suggested. If you do this, you can rely on the Swing and write a document filter that performs this task. The following URL gives an example of writing a related document filter for Swing: http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html# filter Greetings, Daniel -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Eugene Coelho Sent: Donnerstag, 18. Mai 2006 15:18 To: UlC Devleoper list Subject: [ULC-developer] Restrict No of Lines in a Text Area Hi Is there a way in which i can restrict the no of lines entered in text area Current behaviour seems to allow user to enter any no of lines i need to restrict this to allow only 4 lines and not more that . I tried overriding the caret update in my own extension it started giving Attempt to mutate in notification exception public class UIMyTextArea extends UITextArea { @Override public void caretUpdate(CaretEvent e) { // TODO Auto-generated method stub //super.caretUpdate(e); String text = getValue().toString(); StringBuffer textbuf = new StringBuffer(text); final int size = text.length(); final int maxSize = 50; // no of characters could be anything System.out.println("Text Area String "+size + " Max Size"+maxSize); if (size > maxSize) { textbuf.delete(0, size - maxSize); setText(textbuf.toString()); } //vBar.setValue(vBar.getMaximum()); } } Tried the samething with filterinput only to give me heap overflow errors Thanks and Regards , Gene __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com Blab-away for as little as 1ยข/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice. _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
