800 |
private Color selectionColor; |
private Color selectionColor; |
801 |
private boolean editable; |
private boolean editable; |
802 |
private Insets margin; |
private Insets margin; |
803 |
|
private boolean dragEnabled; |
804 |
|
|
805 |
/** |
/** |
806 |
* Creates a new <code>JTextComponent</code> instance. |
* Creates a new <code>JTextComponent</code> instance. |
922 |
} |
} |
923 |
|
|
924 |
/** |
/** |
925 |
|
* Retrieves the currently selected text in this text document. |
926 |
|
* |
927 |
|
* @return the selected text |
928 |
|
* |
929 |
|
* @exception NullPointerException if the underlaying document is null |
930 |
|
*/ |
931 |
|
public String getSelectedText() |
932 |
|
{ |
933 |
|
try |
934 |
|
{ |
935 |
|
return doc.getText(getSelectionStart(), getSelectionEnd()); |
936 |
|
} |
937 |
|
catch (BadLocationException e) |
938 |
|
{ |
939 |
|
// This should never happen. |
940 |
|
return null; |
941 |
|
} |
942 |
|
} |
943 |
|
|
944 |
|
/** |
945 |
* Returns a string that specifies the name of the Look and Feel class |
* Returns a string that specifies the name of the Look and Feel class |
946 |
* that renders this component. |
* that renders this component. |
947 |
* |
* |
1246 |
|
|
1247 |
try |
try |
1248 |
{ |
{ |
1249 |
|
int start = getSelectionStart(); |
1250 |
|
int end = getSelectionEnd(); |
1251 |
|
|
1252 |
// Remove selected text. |
// Remove selected text. |
1253 |
if (dot != mark) |
if (dot != mark) |
1254 |
doc.remove(Math.min(dot, mark), Math.max(dot, mark)); |
doc.remove(start, end - start); |
1255 |
|
|
1256 |
// Insert new text. |
// Insert new text. |
1257 |
doc.insertString(Math.min(dot, mark), content, null); |
doc.insertString(start, content, null); |
1258 |
|
|
1259 |
|
// Set dot to new position. |
1260 |
|
setCaretPosition(start + content.length()); |
1261 |
} |
} |
1262 |
catch (BadLocationException e) |
catch (BadLocationException e) |
1263 |
{ |
{ |
1360 |
{ |
{ |
1361 |
return getUI().modelToView(this, position); |
return getUI().modelToView(this, position); |
1362 |
} |
} |
1363 |
|
|
1364 |
|
public boolean getDragEnabled() |
1365 |
|
{ |
1366 |
|
return dragEnabled; |
1367 |
|
} |
1368 |
|
|
1369 |
|
public void setDragEnabled(boolean enabled) |
1370 |
|
{ |
1371 |
|
dragEnabled = enabled; |
1372 |
|
} |
1373 |
} |
} |