### Eclipse Workspace Patch 1.0
#P RSyntaxTextArea
Index: src/org/fife/ui/rtextarea/RTextArea.java
===================================================================
--- src/org/fife/ui/rtextarea/RTextArea.java (revision 677)
+++ src/org/fife/ui/rtextarea/RTextArea.java (working copy)
@@ -1315,10 +1315,10 @@
/**
- * This method is overridden to make sure that instances of
- * RTextArea only use {@link ConfigurableCaret}s.
- * To set the style of caret (vertical line, block, etc.) used for
- * insert or overwrite mode, use {@link #setCaretStyle(int, int)}.
+ * Sets the caret to use in this text area. It is strongly encouraged to
+ * use {@link ConfigurableCaret}s (which is used by default), or a
+ * subclass, since they know how to render themselves differently when the
+ * user toggles between insert and overwrite modes.
*
* @param caret The caret to use. If this is not an instance of
* ConfigurableCaret, an exception is thrown.
@@ -1327,12 +1327,9 @@
* @see #setCaretStyle(int, int)
*/
public void setCaret(Caret caret) {
- if (!(caret instanceof ConfigurableCaret)) {
- throw new IllegalArgumentException(
- "RTextArea needs ConfigurableCaret");
- }
super.setCaret(caret);
- if (carets!=null) { // Called by setUI() before carets is initialized
+ if (carets!=null && // Called by setUI() before carets is initialized
+ caret instanceof ConfigurableCaret) {
((ConfigurableCaret)caret).setStyle(carets[getTextMode()]);
}
}
@@ -1351,7 +1348,7 @@
style<=ConfigurableCaret.MAX_STYLE ?
style : ConfigurableCaret.THICK_VERTICAL_LINE_STYLE);
carets[mode] = style;
- if (mode==getTextMode()) {
+ if (mode==getTextMode() && getCaret() instanceof ConfigurableCaret) {
// Will repaint the caret if necessary.
((ConfigurableCaret)getCaret()).setStyle(style);
}
@@ -1488,9 +1485,13 @@
/**
- * Sets the text mode for this editor pane.
+ * Sets the text mode for this editor pane. If the currently installed
+ * caret is an instance of {@link ConfigurableCaret}, it will be
+ * automatically updated to render itself appropriately for the new text
+ * mode.
*
* @param mode Either {@link #INSERT_MODE} or {@link #OVERWRITE_MODE}.
+ * @see #getTextMode()
*/
public void setTextMode(int mode) {
@@ -1498,8 +1499,10 @@
mode = INSERT_MODE;
if (textMode != mode) {
- ConfigurableCaret cc = (ConfigurableCaret)getCaret();
- cc.setStyle(carets[mode]);
+ Caret caret = getCaret();
+ if (caret instanceof ConfigurableCaret) {
+ ((ConfigurableCaret)caret).setStyle(carets[mode]);
+ }
textMode = mode;
}
Index: src/org/fife/ui/rtextarea/RTextAreaBase.java
===================================================================
--- src/org/fife/ui/rtextarea/RTextAreaBase.java (revision 665)
+++ src/org/fife/ui/rtextarea/RTextAreaBase.java (working copy)
@@ -26,6 +26,7 @@
import javax.swing.plaf.TextUI;
import javax.swing.text.AbstractDocument;
import javax.swing.text.BadLocationException;
+import javax.swing.text.Caret;
import javax.swing.text.StyleContext;
@@ -1034,10 +1035,12 @@
public void setRoundedSelectionEdges(boolean rounded) {
if (roundedSelectionEdges!=rounded) {
roundedSelectionEdges = rounded;
- ConfigurableCaret cc = (ConfigurableCaret)getCaret();
- cc.setRoundedSelectionEdges(rounded);
- if (cc.getDot()!=cc.getMark()) { // ie, if there is a selection
- repaint();
+ Caret c = getCaret();
+ if (c instanceof ConfigurableCaret) {
+ ((ConfigurableCaret)c).setRoundedSelectionEdges(rounded);
+ if (c.getDot()!=c.getMark()) { // e.g., there's is a selection
+ repaint();
+ }
}
firePropertyChange(ROUNDED_SELECTION_PROPERTY, !rounded,
rounded);