1123 * editable, beep and return. |
1123 * editable, beep and return. |
1124 * |
1124 * |
1125 * @param content the content to replace the selection with. This |
1125 * @param content the content to replace the selection with. This |
1126 * value can be <code>null</code> |
1126 * value can be <code>null</code> |
1127 */ |
1127 */ |
|
1128 @Override |
1128 public void replaceSelection(String content) { |
1129 public void replaceSelection(String content) { |
1129 if (! isEditable()) { |
1130 if (! isEditable()) { |
1130 UIManager.getLookAndFeel().provideErrorFeedback(JEditorPane.this); |
1131 UIManager.getLookAndFeel().provideErrorFeedback(JEditorPane.this); |
1131 return; |
1132 return; |
1132 } |
1133 } |
1133 EditorKit kit = getEditorKit(); |
1134 EditorKit kit = getEditorKit(); |
1134 if(kit instanceof StyledEditorKit) { |
1135 if(kit instanceof StyledEditorKit) { |
1135 try { |
1136 try { |
1136 Document doc = getDocument(); |
1137 Document doc = getDocument(); |
1137 Caret caret = getCaret(); |
1138 Caret caret = getCaret(); |
|
1139 boolean composedTextSaved = saveComposedText(caret.getDot()); |
1138 int p0 = Math.min(caret.getDot(), caret.getMark()); |
1140 int p0 = Math.min(caret.getDot(), caret.getMark()); |
1139 int p1 = Math.max(caret.getDot(), caret.getMark()); |
1141 int p1 = Math.max(caret.getDot(), caret.getMark()); |
1140 if (doc instanceof AbstractDocument) { |
1142 if (doc instanceof AbstractDocument) { |
1141 ((AbstractDocument)doc).replace(p0, p1 - p0, content, |
1143 ((AbstractDocument)doc).replace(p0, p1 - p0, content, |
1142 ((StyledEditorKit)kit).getInputAttributes()); |
1144 ((StyledEditorKit)kit).getInputAttributes()); |
1147 } |
1149 } |
1148 if (content != null && content.length() > 0) { |
1150 if (content != null && content.length() > 0) { |
1149 doc.insertString(p0, content, ((StyledEditorKit)kit). |
1151 doc.insertString(p0, content, ((StyledEditorKit)kit). |
1150 getInputAttributes()); |
1152 getInputAttributes()); |
1151 } |
1153 } |
|
1154 } |
|
1155 if (composedTextSaved) { |
|
1156 restoreComposedText(); |
1152 } |
1157 } |
1153 } catch (BadLocationException e) { |
1158 } catch (BadLocationException e) { |
1154 UIManager.getLookAndFeel().provideErrorFeedback(JEditorPane.this); |
1159 UIManager.getLookAndFeel().provideErrorFeedback(JEditorPane.this); |
1155 } |
1160 } |
1156 } |
1161 } |