Fields Summary |
---|
public static final String | EndOfLineStringPropertyWhen reading a document if a CRLF is encountered a property
with this name is added and the value will be "\r\n". |
public static final String | insertContentActionName of the action to place content into the associated
document. If there is a selection, it is removed before
the new content is added. |
public static final String | insertBreakActionName of the action to place a line/paragraph break into
the document. If there is a selection, it is removed before
the break is added. |
public static final String | insertTabActionName of the action to place a tab character into
the document. If there is a selection, it is removed before
the tab is added. |
public static final String | deletePrevCharActionName of the action to delete the character of content that
precedes the current caret position. |
public static final String | deleteNextCharActionName of the action to delete the character of content that
follows the current caret position. |
public static final String | deleteNextWordActionName of the action to delete the word that
follows the beginning of the selection. |
public static final String | deletePrevWordActionName of the action to delete the word that
precedes the beginning of the selection. |
public static final String | readOnlyActionName of the action to set the editor into read-only
mode. |
public static final String | writableActionName of the action to set the editor into writeable
mode. |
public static final String | cutActionName of the action to cut the selected region
and place the contents into the system clipboard. |
public static final String | copyActionName of the action to copy the selected region
and place the contents into the system clipboard. |
public static final String | pasteActionName of the action to paste the contents of the
system clipboard into the selected region, or before the
caret if nothing is selected. |
public static final String | beepActionName of the action to create a beep. |
public static final String | pageUpActionName of the action to page up vertically. |
public static final String | pageDownActionName of the action to page down vertically. |
static final String | selectionPageUpActionName of the action to page up vertically, and move the
selection. |
static final String | selectionPageDownActionName of the action to page down vertically, and move the
selection. |
static final String | selectionPageLeftActionName of the action to page left horizontally, and move the
selection. |
static final String | selectionPageRightActionName of the action to page right horizontally, and move the
selection. |
public static final String | forwardActionName of the Action for moving the caret
logically forward one position. |
public static final String | backwardActionName of the Action for moving the caret
logically backward one position. |
public static final String | selectionForwardActionName of the Action for extending the selection
by moving the caret logically forward one position. |
public static final String | selectionBackwardActionName of the Action for extending the selection
by moving the caret logically backward one position. |
public static final String | upActionName of the Action for moving the caret
logically upward one position. |
public static final String | downActionName of the Action for moving the caret
logically downward one position. |
public static final String | selectionUpActionName of the Action for moving the caret
logically upward one position, extending the selection. |
public static final String | selectionDownActionName of the Action for moving the caret
logically downward one position, extending the selection. |
public static final String | beginWordActionName of the Action for moving the caret
to the beginning of a word. |
public static final String | endWordActionName of the Action for moving the caret
to the end of a word. |
public static final String | selectionBeginWordActionName of the Action for moving the caret
to the beginning of a word, extending the selection. |
public static final String | selectionEndWordActionName of the Action for moving the caret
to the end of a word, extending the selection. |
public static final String | previousWordActionName of the Action for moving the caret to the
beginning of the previous word. |
public static final String | nextWordActionName of the Action for moving the caret to the
beginning of the next word. |
public static final String | selectionPreviousWordActionName of the Action for moving the selection to the
beginning of the previous word, extending the selection. |
public static final String | selectionNextWordActionName of the Action for moving the selection to the
beginning of the next word, extending the selection. |
public static final String | beginLineActionName of the Action for moving the caret
to the beginning of a line. |
public static final String | endLineActionName of the Action for moving the caret
to the end of a line. |
public static final String | selectionBeginLineActionName of the Action for moving the caret
to the beginning of a line, extending the selection. |
public static final String | selectionEndLineActionName of the Action for moving the caret
to the end of a line, extending the selection. |
public static final String | beginParagraphActionName of the Action for moving the caret
to the beginning of a paragraph. |
public static final String | endParagraphActionName of the Action for moving the caret
to the end of a paragraph. |
public static final String | selectionBeginParagraphActionName of the Action for moving the caret
to the beginning of a paragraph, extending the selection. |
public static final String | selectionEndParagraphActionName of the Action for moving the caret
to the end of a paragraph, extending the selection. |
public static final String | beginActionName of the Action for moving the caret
to the beginning of the document. |
public static final String | endActionName of the Action for moving the caret
to the end of the document. |
public static final String | selectionBeginActionName of the Action for moving the caret
to the beginning of the document. |
public static final String | selectionEndActionName of the Action for moving the caret
to the end of the document. |
public static final String | selectWordActionName of the Action for selecting a word around the caret. |
public static final String | selectLineActionName of the Action for selecting a line around the caret. |
public static final String | selectParagraphActionName of the Action for selecting a paragraph around the caret. |
public static final String | selectAllActionName of the Action for selecting the entire document |
static final String | unselectActionName of the Action for removing selection |
static final String | toggleComponentOrientationActionName of the Action for toggling the component's orientation. |
public static final String | defaultKeyTypedActionName of the action that is executed by default if
a key typed event is received and there
is no keymap entry. |
private static final Action[] | defaultActions |
Methods Summary |
---|
public javax.swing.text.Caret | createCaret()Fetches a caret that can navigate through views
produced by the associated ViewFactory.
return null;
|
public javax.swing.text.Document | createDefaultDocument()Creates an uninitialized text storage model (PlainDocument)
that is appropriate for this type of editor.
return new PlainDocument();
|
public javax.swing.Action[] | getActions()Fetches the set of commands that can be used
on a text component that is using a model and
view produced by this kit.
return defaultActions;
|
public java.lang.String | getContentType()Gets the MIME type of the data that this
kit represents support for. The default
is text/plain .
return "text/plain";
|
javax.swing.text.MutableAttributeSet | getInputAttributes()Gets the input attributes for the pane. This method exists for
the benefit of StyledEditorKit so that the read method will
pick up the correct attributes to apply to inserted text.
This class's implementation simply returns null.
return null;
|
public javax.swing.text.ViewFactory | getViewFactory()Fetches a factory that is suitable for producing
views of any models that are produced by this
kit. The default is to have the UI produce the
factory, so this method has no implementation.
return null;
|
public void | read(java.io.Reader in, javax.swing.text.Document doc, int pos)Inserts content from the given stream, which will be
treated as plain text.
char[] buff = new char[4096];
int nch;
boolean lastWasCR = false;
boolean isCRLF = false;
boolean isCR = false;
int last;
boolean wasEmpty = (doc.getLength() == 0);
AttributeSet attr = getInputAttributes();
// Read in a block at a time, mapping \r\n to \n, as well as single
// \r's to \n's. If a \r\n is encountered, \r\n will be set as the
// newline string for the document, if \r is encountered it will
// be set as the newline character, otherwise the newline property
// for the document will be removed.
while ((nch = in.read(buff, 0, buff.length)) != -1) {
last = 0;
for(int counter = 0; counter < nch; counter++) {
switch(buff[counter]) {
case '\r":
if (lastWasCR) {
isCR = true;
if (counter == 0) {
doc.insertString(pos, "\n", attr);
pos++;
}
else {
buff[counter - 1] = '\n";
}
}
else {
lastWasCR = true;
}
break;
case '\n":
if (lastWasCR) {
if (counter > (last + 1)) {
doc.insertString(pos, new String(buff, last,
counter - last - 1), attr);
pos += (counter - last - 1);
}
// else nothing to do, can skip \r, next write will
// write \n
lastWasCR = false;
last = counter;
isCRLF = true;
}
break;
default:
if (lastWasCR) {
isCR = true;
if (counter == 0) {
doc.insertString(pos, "\n", attr);
pos++;
}
else {
buff[counter - 1] = '\n";
}
lastWasCR = false;
}
break;
}
}
if (last < nch) {
if(lastWasCR) {
if (last < (nch - 1)) {
doc.insertString(pos, new String(buff, last,
nch - last - 1), attr);
pos += (nch - last - 1);
}
}
else {
doc.insertString(pos, new String(buff, last,
nch - last), attr);
pos += (nch - last);
}
}
}
if (lastWasCR) {
doc.insertString(pos, "\n", attr);
isCR = true;
}
if (wasEmpty) {
if (isCRLF) {
doc.putProperty(EndOfLineStringProperty, "\r\n");
}
else if (isCR) {
doc.putProperty(EndOfLineStringProperty, "\r");
}
else {
doc.putProperty(EndOfLineStringProperty, "\n");
}
}
|
public void | read(java.io.InputStream in, javax.swing.text.Document doc, int pos)Inserts content from the given stream which is expected
to be in a format appropriate for this kind of content
handler.
read(new InputStreamReader(in), doc, pos);
|
public void | write(java.io.Writer out, javax.swing.text.Document doc, int pos, int len)Writes content from a document to the given stream
as plain text.
if ((pos < 0) || ((pos + len) > doc.getLength())) {
throw new BadLocationException("DefaultEditorKit.write", pos);
}
Segment data = new Segment();
int nleft = len;
int offs = pos;
Object endOfLineProperty = doc.getProperty(EndOfLineStringProperty);
if (endOfLineProperty == null) {
try {
endOfLineProperty = System.getProperty("line.separator");
} catch (SecurityException se) { }
}
String endOfLine;
if (endOfLineProperty instanceof String) {
endOfLine = (String)endOfLineProperty;
}
else {
endOfLine = null;
}
if (endOfLineProperty != null && !endOfLine.equals("\n")) {
// There is an end of line string that isn't \n, have to iterate
// through and find all \n's and translate to end of line string.
while (nleft > 0) {
int n = Math.min(nleft, 4096);
doc.getText(offs, n, data);
int last = data.offset;
char[] array = data.array;
int maxCounter = last + data.count;
for (int counter = last; counter < maxCounter; counter++) {
if (array[counter] == '\n") {
if (counter > last) {
out.write(array, last, counter - last);
}
out.write(endOfLine);
last = counter + 1;
}
}
if (maxCounter > last) {
out.write(array, last, maxCounter - last);
}
offs += n;
nleft -= n;
}
}
else {
// Just write out text, will already have \n, no mapping to
// do.
while (nleft > 0) {
int n = Math.min(nleft, 4096);
doc.getText(offs, n, data);
out.write(data.array, data.offset, data.count);
offs += n;
nleft -= n;
}
}
out.flush();
|
public void | write(java.io.OutputStream out, javax.swing.text.Document doc, int pos, int len)Writes content from a document to the given stream
in a format appropriate for this kind of content handler.
OutputStreamWriter osw = new OutputStreamWriter(out);
write(osw, doc, pos, len);
osw.flush();
|