Hi Eugene, Yes there is a little problem in your extension code: you should override the method UIProxy.createBasicObject() instead of creating your basic object in the method getBasicTextArea(). When using ULC 6.0.x, please see the ULC Essentials Guide Section 5.3.2 for details (things are explained there). It is also helpful to study the rest of the Pie Chart Extension example in this context.
Greetings, Dani -----Original Message----- From: Eugene Coelho [mailto:[EMAIL PROTECTED] Sent: Mittwoch, 24. Mai 2006 10:30 To: Daniel Pfeifer Subject: RE: [ULC-developer] Restrict No of Lines in a Text Area Hi , Based on the suggestions i tried the following code, The Same Code (Documentfilter) works perfectly with JTextPane (it limits the No of lines) but if i try to use it in the following way the document filter doesnt get applied to the JTextArea ... Am i doing something wrong in the code ? Thanks and Regards, Gene package com.isfsdc; import javax.swing.JTextArea; import javax.swing.text.AbstractDocument; import javax.swing.text.Document; import javax.swing.text.PlainDocument; import javax.swing.text.StyledDocument; import com.ulcjava.base.client.UITextArea; public class UIMyTextArea extends UITextArea { AbstractDocument doc; static final int MAX_CHARACTERS=100; private JTextArea MyTextArea = null ; public UIMyTextArea() { super(); } public JTextArea getBasicTextArea() { if (MyTextArea == null ) { MyTextArea = new JTextArea(); ((PlainDocument) MyTextArea.getDocument()).setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } return MyTextArea; } } public class DocumentSizeFilter extends DocumentFilter { int maxCharacters; boolean DEBUG = true; 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); } } Daniel Pfeifer <[EMAIL PROTECTED]> wrote: 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 /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 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 How low will we go? Check out Yahoo! Messenger’s low PC-to-Phone call rates. _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
