My extended text area widget is still not working, despite the hints by Gene...
I now split the client side into two parts, an UIXTextArea.class and a
DocumentSizeFilter.class, code follows below...
When I run the code, I get in the console window
createBasicObject!
UIXTextArea.setMaxCharacters : 20
DocumentSizeFilter.setMaxCharacters : 20
but after that the widget flatly refuses to invoke methods "insertString" and
"replace", whatever type in it... Replacing the "BasicTextArea" by a JTextArea
object doesn't work either (get runtime error)....
Please please if somebody can shine light on this (maybe someone at Canoo
????)...
Thanks in advance,
Alberto Smulders
HostDat Lda. - Portugal
package pt.hostdat.hcc.common.util.component.xtextarea.client;
import javax.swing.text.AbstractDocument;
import com.ulcjava.base.client.UITextArea;
/**
* Client-side code of extended TextArea component
*
* @author Alberto Smulders
*/
public class UIXTextArea extends UITextArea {
private BasicTextArea fTextArea = null;
private DocumentSizeFilter fDocumentSizeFilter = null;
protected Object createBasicObject(Object[] a) {
System.out.println("createBasicObject!");
if (fTextArea == null) {
fTextArea = new BasicTextArea();
fDocumentSizeFilter = new DocumentSizeFilter();
((AbstractDocument)fTextArea.getDocument())
.setDocumentFilter(fDocumentSizeFilter);
}
return fTextArea;
}
public int getMaxCharacter() {
return fDocumentSizeFilter.getMaxCharacters();
}
public void setMaxCharacters(int maxCharacters) {
System.out.println("UIXTextArea.setMaxCharacters : " +
maxCharacters);
if (maxCharacters >= 0) {
fDocumentSizeFilter.setMaxCharacters(maxCharacters);
}
}
}
package pt.hostdat.hcc.common.util.component.xtextarea.client;
import java.awt.Toolkit;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;
/**
* Custom document filter to limit size of entry in text fields
*
* @author Alberto Smulders
*/
public class DocumentSizeFilter extends DocumentFilter {
private int fMaxCharacters = 0;
public int getMaxCharacters() {
return fMaxCharacters;
}
public void setMaxCharacters(int maxCharacters) {
System.out.println("DocumentSizeFilter.setMaxCharacters : " +
maxCharacters);
fMaxCharacters = maxCharacters;
}
public void insertString(DocumentFilter.FilterBypass fb,
int offset, String string,
AttributeSet attr)
throws BadLocationException {
System.out.println("insertString");
replace(fb, offset, 0, string, attr);
}
public void replace(DocumentFilter.FilterBypass fb,
int offset, int length, String
text,
AttributeSet attrs)
throws BadLocationException {
System.out.println("replace");
int newLength = fb.getDocument().getLength() - length +
text.length();
if (fMaxCharacters == 0 || newLength <= fMaxCharacters) {
fb.replace(offset, length, text, attrs);
}
else {
Toolkit.getDefaultToolkit().beep();
}
}
}
--
Echte DSL-Flatrate dauerhaft für 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer