本文整理匯總了Java中javax.swing.JEditorPane.getDocument方法的典型用法代碼示例。如果您正苦於以下問題:Java JEditorPane.getDocument方法的具體用法?Java JEditorPane.getDocument怎麽用?Java JEditorPane.getDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.getDocument方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testBeyondEndDocHighlightsLayer
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testBeyondEndDocHighlightsLayer() throws Exception {
loggingOn();
String mimeType = "text/plain";
// MimeLookup.getLookup(MimePath.get(mimeType)).lookup(HighlightsLayer.class); // Init ML
// HighlightsLayerProvider.clear();
HighlightsLayerProvider.add("text/x-java", new HLFactory());
HighlightsLayerProvider.add(mimeType, new HLFactory());
// MemoryMimeDataProvider.reset(null);
// MemoryMimeDataProvider.addInstances("text/x-java", new HLFactory());
// MemoryMimeDataProvider.addInstances(mimeType, new HLFactory());
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
Document doc = pane.getDocument();
doc.putProperty("mimeType", mimeType);
DocumentTesting.setSameThreadInvoke(container.context(), true); // Do not post to EDT
RandomTestContainer.Context gContext = container.context();
DocumentTesting.insert(gContext, 0, "a\nb");
DocumentTesting.insert(gContext, 1, "c");
DocumentTesting.remove(gContext, 2, 1);
DocumentTesting.insert(gContext, 1, "d\nx");
}
示例2: testMemoryRelease
import javax.swing.JEditorPane; //導入方法依賴的package包/類
@RandomlyFails
public void testMemoryRelease() throws Exception { // Issue #147984
org.netbeans.junit.Log.enableInstances(Logger.getLogger("TIMER"), "CodeTemplateInsertHandler", Level.FINEST);
JEditorPane pane = new JEditorPane();
NbEditorKit kit = new NbEditorKit();
pane.setEditorKit(kit);
Document doc = pane.getDocument();
assertTrue(doc instanceof BaseDocument);
CodeTemplateManager mgr = CodeTemplateManager.get(doc);
String templateText = "Test with parm ";
CodeTemplate ct = mgr.createTemporary(templateText + " ${a}");
ct.insert(pane);
assertEquals(templateText + " a", doc.getText(0, doc.getLength()));
// Send Enter to stop editing
KeyEvent enterKeyEvent = new KeyEvent(pane, KeyEvent.KEY_PRESSED,
EventQueue.getMostRecentEventTime(),
0, KeyEvent.VK_ENTER, KeyEvent.CHAR_UNDEFINED);
SwingUtilities.processKeyBindings(enterKeyEvent);
// CT editing should be finished
org.netbeans.junit.Log.assertInstances("CodeTemplateInsertHandler instances not GCed");
}
示例3: testDeleteAterInsertBreak
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testDeleteAterInsertBreak() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
ViewHierarchyRandomTesting.initRandomText(container);
RandomTestContainer.Context context = container.context();
DocumentTesting.insert(context, 0,
" osen \n\n\n esl\t\ta \t\t \n\n\nabcd\td m\t\tabcdef\te\t\tab\tcdef\tef\tkojd \t\t \n\n\n t\t vpjm\ta\ngooywzmj q\tugos\tdefy\t i xs us tg z"
);
EditorPaneTesting.setCaretOffset(context, 70);
DocumentTesting.remove(context, 50, 10);
EditorPaneTesting.performAction(context, pane, DefaultEditorKit.insertBreakAction);
EditorPaneTesting.performAction(context, pane, DefaultEditorKit.deleteNextCharAction);
}
示例4: testAddCaretUndoableEdit
import javax.swing.JEditorPane; //導入方法依賴的package包/類
@Test
public void testAddCaretUndoableEdit() throws Exception {
final JEditorPane pane = new JEditorPane("text/plain", "Haf");
//final CompoundEdit compoundEdit = new CompoundEdit();
final boolean[] editAdded = { false };
final Document doc = pane.getDocument();
doc.putProperty(CustomUndoDocument.class, new CustomUndoDocument() {
@Override
public void addUndoableEdit(UndoableEdit edit) {
editAdded[0] = true;
}
});
final EditorCaret editorCaret = new EditorCaret();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
pane.setCaret(editorCaret);
EditorUtilities.addCaretUndoableEdit(doc, editorCaret);
}
});
assertTrue(editAdded[0]);
}
示例5: testNewlineInEmptyDoc
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testNewlineInEmptyDoc() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
RandomTestContainer.Context gContext = container.context();
DocumentTesting.insert(gContext, 0, "\n");
}
示例6: testRemoveAtBegining
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testRemoveAtBegining() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
ViewHierarchyRandomTesting.initRandomText(container);
RandomTestContainer.Context context = container.context();
DocumentTesting.insert(context, 0,
" \t\tabcdef\ta\nebxsu"
);
DocumentTesting.remove(context, 0, 1);
}
示例7: getApplicableFileObject
import javax.swing.JEditorPane; //導入方法依賴的package包/類
private FileObject getApplicableFileObject(int[] caretPosHolder) {
if (!EventQueue.isDispatchThread()) {
// Unsafe to ask for an editor pane from a random thread.
// E.g. org.netbeans.lib.uihandler.LogRecords.write asking for getName().
Collection<? extends FileObject> dobs = Utilities.actionsGlobalContext().lookupAll(FileObject.class);
return dobs.size() == 1 ? dobs.iterator().next() : null;
}
// TODO: Use the new editor library to compute this:
// JTextComponent pane = EditorRegistry.lastFocusedComponent();
TopComponent comp = TopComponent.getRegistry().getActivated();
if(comp == null) {
return null;
}
Node[] nodes = comp.getActivatedNodes();
if (nodes != null && nodes.length == 1) {
if (comp instanceof CloneableEditorSupport.Pane) { //OK. We have an editor
EditorCookie ec = nodes[0].getLookup().lookup(EditorCookie.class);
if (ec != null) {
JEditorPane editorPane = NbDocument.findRecentEditorPane(ec);
if (editorPane != null) {
if (editorPane.getCaret() != null) {
caretPosHolder[0] = editorPane.getCaret().getDot();
}
Document document = editorPane.getDocument();
return Source.create(document).getFileObject();
}
}
} else {
return UICommonUtils.getFileObjectFromNode(nodes[0]);
}
}
return null;
}
示例8: getDocument
import javax.swing.JEditorPane; //導入方法依賴的package包/類
/**
* Get document from test container by consulting either an editor pane's document
* or a document property.
*
* @param provider non-null property provider
* @return document instance or null.
*/
public static Document getDocument(PropertyProvider provider) {
JEditorPane pane = provider.getInstanceOrNull(JEditorPane.class);
if (pane != null) {
return pane.getDocument();
} else {
return provider.getInstanceOrNull(Document.class);
}
}
示例9: insertNewline
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void insertNewline(String source, String reformatted, IndentPrefs preferences) throws Exception {
int sourcePos = source.indexOf('^');
assertNotNull(sourcePos);
source = source.substring(0, sourcePos) + source.substring(sourcePos+1);
Formatter formatter = getFormatter(null);
int reformattedPos = reformatted.indexOf('^');
assertNotNull(reformattedPos);
reformatted = reformatted.substring(0, reformattedPos) + reformatted.substring(reformattedPos+1);
JEditorPane ta = getPane(source);
Caret caret = ta.getCaret();
caret.setDot(sourcePos);
BaseDocument doc = (BaseDocument) ta.getDocument();
if (formatter != null) {
configureIndenters(doc, formatter, true);
}
setupDocumentIndentation(doc, preferences);
runKitAction(ta, DefaultEditorKit.insertBreakAction, "\n");
String formatted = doc.getText(0, doc.getLength());
assertEquals(reformatted, formatted);
if (reformattedPos != -1) {
assertEquals(reformattedPos, caret.getDot());
}
}
示例10: ResultPanelOutput
import javax.swing.JEditorPane; //導入方法依賴的package包/類
/**
* Creates a new instance of ResultPanelOutput
*/
ResultPanelOutput(ResultDisplayHandler displayHandler) {
super();
if (LOG) {
System.out.println("ResultPanelOutput.<init>");
}
textPane = new JEditorPane();
textPane.setFont(new Font("monospaced", Font.PLAIN, getFont().getSize()));
textPane.setEditorKit(new OutputEditorKit());
textPane.setEditable(false);
textPane.getCaret().setVisible(true);
textPane.getCaret().setBlinkRate(0);
textPane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
setViewportView(textPane);
/*
* On GTK L&F, background of the text pane is gray, even though it is
* white on a JTextArea. The following is a hack to fix it:
*/
Color background = UIManager.getColor("TextPane.background"); //NOI18N
if (background != null) {
textPane.setBackground(background);
}
doc = textPane.getDocument();
AccessibleContext ac = textPane.getAccessibleContext();
ac.setAccessibleName(NbBundle.getMessage(getClass(),
"ACSN_OutputTextPane"));//NOI18N
ac.setAccessibleDescription(NbBundle.getMessage(getClass(),
"ACSD_OutputTextPane"));//NOI18N
this.displayHandler = displayHandler;
}
示例11: testSimple1
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testSimple1() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
RandomTestContainer.Context gContext = container.context();
DocumentTesting.insert(gContext, 0, "a\nb");
DocumentTesting.insert(gContext, 1, "c");
}
示例12: testRandomModsJavaSeed1
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testRandomModsJavaSeed1() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
Document doc = pane.getDocument();
doc.putProperty(Language.class, JavaTokenId.language());
doc.putProperty("mimeType", "text/x-java");
ViewHierarchyRandomTesting.initRandomText(container);
ViewHierarchyRandomTesting.addRound(container).setOpCount(OP_COUNT);
ViewHierarchyRandomTesting.testFixedScenarios(container);
container.run(1286796912276L);
// Exclude caret row highlighting
excludeHighlights(pane);
container.run(1286796912276L);
}
示例13: getMostRecentEditorCookie
import javax.swing.JEditorPane; //導入方法依賴的package包/類
private EditorCookie getMostRecentEditorCookie() {
JEditorPane editor = getMostRecentEditor();
if (editor != null) {
Document document = editor.getDocument();
DataObject dataObject = NbEditorUtilities.getDataObject(document);
if (dataObject != null) {
EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
return ec;
}
}
return null;
}
示例14: testUndoRedoSimple
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testUndoRedoSimple() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
ViewHierarchyRandomTesting.initRandomText(container);
RandomTestContainer.Context context = container.context();
DocumentTesting.insert(context, 0, "ab\nglanm\nq\n \nv nyk\n \ndy qucjfn\tfh cdk \t\t \nj\nsm\n t\ngqa \nsjj\n\n\n");
EditorPaneTesting.setCaretOffset(context, 38);
EditorPaneTesting.moveCaret(context, 31);
EditorPaneTesting.moveOrSelect(context, SwingConstants.EAST, true);
EditorPaneTesting.moveOrSelect(context, SwingConstants.EAST, false);
EditorPaneTesting.typeChar(context, 'j'); // #1: INSERT: off=38 len=1 "j"
EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, false);
EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, false);
EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, false);
EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, false);
EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, true);
EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, true);
EditorPaneTesting.typeChar(context, 'q'); // #2: REMOVE: off=23 len=8; INSERT: off=23 len=1 text="q"
EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, true);
EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, false);
EditorPaneTesting.performAction(context, pane, DefaultEditorKit.insertTabAction); // #3: INSERT: off=24 len=4 " "
// #3.replaceEdit(#2) => false (not replaced; added)
EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, true);
DocumentTesting.undo(context, 1);
// #3.undo() (AtomicCompoundEdit)
EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, true);
EditorPaneTesting.moveOrSelect(context, SwingConstants.EAST, false);
EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, true);
EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, true);
EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, false);
EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, false);
EditorPaneTesting.performAction(context, pane, DefaultEditorKit.insertTabAction); // #4: INSERT: off=28 len=1 " "
//
DocumentTesting.undo(context, 1);
}
示例15: testInsertTextWithNewlines
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testInsertTextWithNewlines() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
RandomTestContainer.Context context = container.context();
DocumentTesting.insert(context, 0, "a\n");
}