jdk/src/share/classes/javax/swing/JTextPane.java
changeset 3750 4195b035138f
parent 715 f16baef3a20e
child 5506 202f599c92aa
equal deleted inserted replaced
3749:d0ecbd7075b1 3750:4195b035138f
   168      * attributes currently defined for input at the point of
   168      * attributes currently defined for input at the point of
   169      * insertion.  If the document is not editable, beep and return.
   169      * insertion.  If the document is not editable, beep and return.
   170      *
   170      *
   171      * @param content  the content to replace the selection with
   171      * @param content  the content to replace the selection with
   172      */
   172      */
       
   173     @Override
   173     public void replaceSelection(String content) {
   174     public void replaceSelection(String content) {
   174         replaceSelection(content, true);
   175         replaceSelection(content, true);
   175     }
   176     }
   176 
   177 
   177     private void replaceSelection(String content, boolean checkEditable) {
   178     private void replaceSelection(String content, boolean checkEditable) {
   181         }
   182         }
   182         Document doc = getStyledDocument();
   183         Document doc = getStyledDocument();
   183         if (doc != null) {
   184         if (doc != null) {
   184             try {
   185             try {
   185                 Caret caret = getCaret();
   186                 Caret caret = getCaret();
       
   187                 boolean composedTextSaved = saveComposedText(caret.getDot());
   186                 int p0 = Math.min(caret.getDot(), caret.getMark());
   188                 int p0 = Math.min(caret.getDot(), caret.getMark());
   187                 int p1 = Math.max(caret.getDot(), caret.getMark());
   189                 int p1 = Math.max(caret.getDot(), caret.getMark());
   188                 AttributeSet attr = getInputAttributes().copyAttributes();
   190                 AttributeSet attr = getInputAttributes().copyAttributes();
   189                 if (doc instanceof AbstractDocument) {
   191                 if (doc instanceof AbstractDocument) {
   190                     ((AbstractDocument)doc).replace(p0, p1 - p0, content,attr);
   192                     ((AbstractDocument)doc).replace(p0, p1 - p0, content,attr);
   194                         doc.remove(p0, p1 - p0);
   196                         doc.remove(p0, p1 - p0);
   195                     }
   197                     }
   196                     if (content != null && content.length() > 0) {
   198                     if (content != null && content.length() > 0) {
   197                         doc.insertString(p0, content, attr);
   199                         doc.insertString(p0, content, attr);
   198                     }
   200                     }
       
   201                 }
       
   202                 if (composedTextSaved) {
       
   203                     restoreComposedText();
   199                 }
   204                 }
   200             } catch (BadLocationException e) {
   205             } catch (BadLocationException e) {
   201                 UIManager.getLookAndFeel().provideErrorFeedback(JTextPane.this);
   206                 UIManager.getLookAndFeel().provideErrorFeedback(JTextPane.this);
   202             }
   207             }
   203         }
   208         }