// CONV:TF:21 Jul 2009:Fixed this to work properly
if (isEditable() && isEnabled()) {
int finalCursorPosition = 0;
boolean didManualPaste = false;
if (getDocument() instanceof FixedLengthDocument){
FixedLengthDocument doc = (FixedLengthDocument)getDocument();
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (doc.getMaxLength() > 0 && t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String text = (String)t.getTransferData(DataFlavor.stringFlavor);
// CONV:TF:21 Jul 2009:Insert the text at the correct spot in the current String. The String is truncated
// to the maximum number of characters, and the cursor is moved to the end of the selection or the
// end of string, whichever is smaller.
if (text.length()+doc.getLength() > doc.getMaxLength()) {
String currentText = doc.getText(0, doc.getLength());
int caretMark = this.getCaret().getMark();
int caretDot = this.getCaret().getDot();
String newText = currentText.substring(0, Math.min(caretMark, caretDot)) + text + currentText.substring(Math.max(caretMark, caretDot));
this.setText(newText);
finalCursorPosition = Math.min(caretDot+text.length(), doc.getMaxLength());
didManualPaste = true;
}
}
} catch (UnsupportedFlavorException e) {
} catch (IOException e) {