本文整理汇总了Java中javax.swing.JEditorPane类的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane类的具体用法?Java JEditorPane怎么用?Java JEditorPane使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JEditorPane类属于javax.swing包,在下文中一共展示了JEditorPane类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPerform
import javax.swing.JEditorPane; //导入依赖的package包/类
/**Currently, this method is supposed to be runned inside the AWT thread.
* If this condition is not fullfilled, an IllegalStateException is
* thrown. Do NOT modify this behaviour, or deadlock (or even Swing
* or NetBeans winsys data corruption) may occur.
*
* Currently threading model of this method is compatible with
* editor code completion threading model. Revise if this changes
* in future.
*/
private void testPerform(PrintWriter out, PrintWriter log,
JEditorPane editor,
boolean unsorted,
String assign,
int lineIndex,
int queryType) throws BadLocationException, IOException {
if (!SwingUtilities.isEventDispatchThread())
throw new IllegalStateException("The testPerform method may be called only inside AWT event dispatch thread.");
BaseDocument doc = Utilities.getDocument(editor);
int lineOffset = Utilities.getRowStartFromLineOffset(doc, lineIndex -1);
editor.grabFocus();
editor.getCaret().setDot(lineOffset);
doc.insertString(lineOffset, assign, null);
reparseDocument((DataObject) doc.getProperty(doc.StreamDescriptionProperty));
completionQuery(out, log, editor, unsorted, queryType);
}
示例2: setupContext
import javax.swing.JEditorPane; //导入依赖的package包/类
private static void setupContext(final JEditorPane editorPane, Pair<Line.Part, FileObject> context) {
assert SwingUtilities.isEventDispatchThread();
if (context != null) {
final Line.Part lp = context.first();
final FileObject file = context.second();
//System.err.println("WatchPanel.setupContext("+file+", "+line+", "+offset+")");
// Do the binding for text files only:
if (file != null && file.getMIMEType().startsWith("text/")) { // NOI18N
String origText = editorPane.getText();
DialogBinding.bindComponentToFile(file,
lp.getLine().getLineNumber(),
lp.getColumn(),
lp.getLength(),
editorPane);
Document editPaneDoc = editorPane.getDocument();
//editPaneDoc.putProperty("org.netbeans.modules.editor.java.JavaCompletionProvider.skipAccessibilityCheck", "true");
editorPane.setText(origText);
}
}
setupUI(editorPane);
}
示例3: getTextComponent
import javax.swing.JEditorPane; //导入依赖的package包/类
protected JTextComponent getTextComponent(URL url) {
FileObject f = org.openide.filesystems.URLMapper.findFileObject(url);
if (f != null) {
DataObject d = null;
try {
d = DataObject.find(f);
} catch (DataObjectNotFoundException e) {
LOG.log(Level.WARNING, "Can't get DataObject for " + f, e); //NOI18N
}
if (d != null) {
EditorCookie cookie = d.getLookup().lookup(EditorCookie.class);
if (cookie != null) {
JEditorPane [] allJeps = cookie.getOpenedPanes();
if (allJeps != null) {
return allJeps[0];
}
}
}
}
return null;
}
示例4: testInsertRemoveTransaction
import javax.swing.JEditorPane; //导入依赖的package包/类
public void testInsertRemoveTransaction() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
JEditorPane pane = container.getInstance(JEditorPane.class);
final Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
final RandomTestContainer.Context context = container.context();
// ViewHierarchyRandomTesting.disableHighlighting(container);
DocumentTesting.setSameThreadInvoke(container.context(), true); // Do not post to EDT
((BaseDocument)doc).runAtomic(new Runnable() {
@Override
public void run() {
try {
for (int i = 0; i < 100; i++) {
DocumentTesting.insert(context, 0, "a\nb\n\n");
DocumentTesting.remove(context, i * 3, 1);
}
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
});
DocumentTesting.setSameThreadInvoke(container.context(), false);
DocumentTesting.undo(context, 1);
}
示例5: testWrapperAction
import javax.swing.JEditorPane; //导入依赖的package包/类
@Test
public void testWrapperAction() {
Map attrs = new HashMap(SIMPLE_ATTRS);
attrs.put(AbstractEditorAction.WRAPPER_ACTION_KEY, true);
final MyAction a = new MyAction(); // No attrs passed
attrs.put("delegate", a);
WrapperEditorAction wrapperAction = WrapperEditorAction.create(attrs);
JTextComponent c = new JEditorPane();
assertEquals("my-name", wrapperAction.getValue(Action.NAME));
assertNull(a.getValue(Action.NAME));
ActionEvent evt = new ActionEvent(c, 0, "");
wrapperAction.actionPerformed(evt);
assertEquals(Thread.currentThread(), a.actionPerformedThread);
// Properties transferred
assertEquals("my-name", a.getValue(Action.NAME));
}
示例6: isExcludedProperty1
import javax.swing.JEditorPane; //导入依赖的package包/类
private boolean isExcludedProperty1(FormProperty prop) {
if (!Boolean.TRUE.equals(prop.getValue(EXCLUSION_DETERMINED))) {
prop.setValue(EXCLUSION_DETERMINED, true);
Object propOwner = prop.getPropertyContext().getOwner();
Class type = null;
if (propOwner instanceof RADComponent) {
type = ((RADComponent)propOwner).getBeanClass();
} else if (propOwner instanceof FormProperty) {
type = ((FormProperty)propOwner).getValueType();
}
String propName = prop.getName();
boolean excl = (Component.class.isAssignableFrom(type) && "name".equals(propName)) // NOI18N
|| (JEditorPane.class.isAssignableFrom(type) && "contentType".equals(propName)); // NOI18N
prop.setValue(EXCLUDE_FROM_RESOURCING, excl);
return excl;
}
return false;
}
示例7: performContextAction
import javax.swing.JEditorPane; //导入依赖的package包/类
@Override
protected void performContextAction(Node[] nodes) {
if (visible(nodes)) {
JEditorPane pane = activatedEditorPane(nodes);
AnnotationBarManager.hideAnnotationBar(pane);
} else {
EditorCookie ec = activatedEditorCookie(nodes);
if (ec == null) return;
final File file = activatedFile(nodes);
JEditorPane[] panes = ec.getOpenedPanes();
if (panes == null) {
ec.open();
panes = ec.getOpenedPanes();
}
if (panes == null) {
return;
}
final JEditorPane currentPane = panes[0];
showAnnotations(currentPane, file, null, true);
}
}
示例8: getCaretPos
import javax.swing.JEditorPane; //导入依赖的package包/类
private static int getCaretPos(FoldHierarchy h) {
int caretPos = -1;
JTextComponent c = h.getComponent();
if (c == null) {
return -1;
}
Document doc = getDocument(h);
Object od = doc.getProperty(Document.StreamDescriptionProperty);
if (od instanceof DataObject) {
DataObject d = (DataObject)od;
EditorCookie cake = d.getCookie(EditorCookie.class);
JEditorPane[] panes = cake.getOpenedPanes();
int idx = panes == null ? -1 : Arrays.asList(panes).indexOf(c);
if (idx != -1) {
caretPos = c.getCaret().getDot();
}
}
return caretPos;
}
示例9: getEditorPane
import javax.swing.JEditorPane; //导入依赖的package包/类
/** Returns editor pane. Returns null if document loading was canceled by user
* through answering UserQuestionException or when CloneableEditor is closed.
*
* @return editor pane or null
*/
public JEditorPane getEditorPane() {
assert SwingUtilities.isEventDispatchThread();
//User selected not to load document
if (!componentCreated) {
return null;
}
//#175528: This case should not happen as modal dialog handling UQE should
//not be displayed during IDE start ie. during component deserialization.
if (CloneableEditorInitializer.modalDialog) {
LOG.log(Level.WARNING,"AWT is blocked by modal dialog. Return null from CloneableEditor.getEditorPane."
+ " Please report this to IZ.");
LOG.log(Level.WARNING,"support:" + support.getClass().getName());
Exception ex = new Exception();
StringWriter sw = new StringWriter(500);
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
LOG.log(Level.WARNING,sw.toString());
return null;
}
initialize();
CloneableEditorInitializer.waitForFinishedInitialization(this);
return pane;
}
示例10: actionPerformed
import javax.swing.JEditorPane; //导入依赖的package包/类
/**
* Sets the foreground color.
*
* @param e the action event
*/
public void actionPerformed(ActionEvent e) {
JEditorPane editor = getEditor(e);
if (editor != null) {
Color fg = this.fg;
if ((e != null) && (e.getSource() == editor)) {
String s = e.getActionCommand();
try {
fg = Color.decode(s);
} catch (NumberFormatException nfe) {
}
}
if (fg != null) {
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setForeground(attr, fg);
setCharacterAttributes(editor, attr, false);
} else {
UIManager.getLookAndFeel().provideErrorFeedback(editor);
}
}
}
示例11: getTextIndex
import javax.swing.JEditorPane; //导入依赖的package包/类
public int getTextIndex() {
return EventQueueWait.exec(new Callable<Integer>() {
@Override public Integer call() throws Exception {
String href = getText();
int hRefIndex = 0;
int current = 0;
JEditorPane editor = (JEditorPane) parent.getComponent();
HTMLDocument document = (HTMLDocument) editor.getDocument();
Iterator iterator = document.getIterator(Tag.A);
while (iterator.isValid()) {
if (current++ >= index) {
return hRefIndex;
}
String attribute = ((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument())
.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset());
if (attribute != null && attribute.equals(href)) {
hRefIndex++;
}
iterator.next();
}
return -1;
}
});
}
示例12: testFormatterDoesNotIncludeHashOnEditor
import javax.swing.JEditorPane; //导入依赖的package包/类
public void testFormatterDoesNotIncludeHashOnEditor() throws ClassNotFoundException {
LogRecord r = new LogRecord(Level.INFO, "EDIT");
JEditorPane ep = new javax.swing.JEditorPane();
ep.setName("SomeName");
r.setParameters(new Object[] { ep });
Formatter formatter = new LogFormatter();
String s = formatter.format(r);
assertEquals("No @\n" + s, -1, s.indexOf("@"));
if (s.indexOf("SomeName") == -1) {
fail("SomeName should be there:\n" + s);
}
}
示例13: canDrop
import javax.swing.JEditorPane; //导入依赖的package包/类
@Override
public boolean canDrop(DropTargetDragEvent e) {
//check if the JEditorPane contains html document
JEditorPane pane = findPane(e.getDropTargetContext().getComponent());
if (pane == null) {
return false;
}
int offset = getLineEndOffset(pane, e.getLocation());
if (!containsLanguageAtOffset(pane.getDocument(), offset)) {
return false;
} else {
//update the caret as the user drags the object
//needs to be done explicitly here as QuietEditorPane doesn't call
//the original Swings DropTarget which does this
pane.setCaretPosition(offset);
pane.requestFocusInWindow(); //pity we need to call this all the time when dragging, but ExternalDropHandler don't handle dragEnter event
return canDrop(e.getCurrentDataFlavors());
}
}
示例14: testExceptionThrownWhenDocumentIsBeingReadNo
import javax.swing.JEditorPane; //导入依赖的package包/类
public void testExceptionThrownWhenDocumentIsBeingReadNo () throws Exception {
MyEx my = new MyEx();
toThrow = my;
DD.options = null;
DD.toReturn = NotifyDescriptor.NO_OPTION;
support.open ();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JEditorPane[] panes = support.getOpenedPanes();
assertNull(panes);
}
});
}
示例15: testInitializeAndBlockInAWT
import javax.swing.JEditorPane; //导入依赖的package包/类
public void testInitializeAndBlockInAWT() throws Exception {
assertTrue("Running in AWT", SwingUtilities.isEventDispatchThread());
class R implements PropertyChangeListener {
JEditorPane p;
public void run() {
p = support.getOpenedPanes()[0];
}
public void propertyChange(PropertyChangeEvent evt) {
if (TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) {
run();
}
}
}
R r = new R();
WindowManager.getDefault().getRegistry().addPropertyChangeListener(r);
final Object LOCK = new JPanel().getTreeLock();
synchronized (LOCK) {
support.open();
assertNotNull(r.p);
}
assertKit(r.p.getEditorKit());
}