本文整理汇总了Java中javax.swing.text.html.HTMLDocument类的典型用法代码示例。如果您正苦于以下问题:Java HTMLDocument类的具体用法?Java HTMLDocument怎么用?Java HTMLDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HTMLDocument类属于javax.swing.text.html包,在下文中一共展示了HTMLDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setDocument
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
public void setDocument(Note note) {
// Note note = CurrentProject.getNoteList().getActiveNote();
// try {
// this.editor.editor.setPage(CurrentStorage.get().getNoteURL(note));
editor.document = (HTMLDocument) CurrentStorage.get().openNote(note);
editor.initEditor();
if (note != null)
titleField.setText(note.getTitle());
else
titleField.setText("");
initialTitle = titleField.getText();
/*
* } catch (Exception ex) { new ExceptionDialog(ex); }
*/
/*
* Document doc = CurrentStorage.get().openNote(note); try {
* this.editor.editor.setText(doc.getText(0, doc.getLength())); } catch
* (Exception ex){ ex.printStackTrace(); }
*/
// .setDocument(CurrentStorage.get().openNote(note));
}
示例2: createAndShowGUI
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
private static void createAndShowGUI() {
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (Exception ex) {
throw new RuntimeException(ex);
}
JFrame frame = new JFrame("bug8058120");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JEditorPane editorPane = new JEditorPane();
editorPane.setContentType("text/html");
editorPane.setEditorKit(new HTMLEditorKit());
document = (HTMLDocument) editorPane.getDocument();
editorPane.setText(text);
frame.add(editorPane);
frame.setSize(200, 200);
frame.setVisible(true);
}
示例3: openPSP
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
public javax.swing.text.Document openPSP(PSP psp) {
HTMLDocument doc = (HTMLDocument) editorKit.createDefaultDocument();
if (psp == null)
return doc;
String filename = getPSPPath(psp);
try {
/*DEBUG*/
// Util.debug("Open note: " + filename);
// Util.debug("Note Title: " + note.getTitle());
doc.setBase(new URL(getPSPURL(psp)));
editorKit.read(
new InputStreamReader(new FileInputStream(filename), "UTF-8"),
doc,
0);
}
catch (Exception ex) {
//ex.printStackTrace();
// Do nothing - we've got a new empty document!
}
return doc;
}
示例4: SvnOptionsPanel
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
/** Creates new form SvnOptionsPanel */
public SvnOptionsPanel() {
initComponents();
if(Utilities.isWindows()) {
jLabel5.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel5.windows.text"));
jLabel11.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel11.text"));
} else {
jLabel5.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel5.unix.text"));
jLabel11.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel11.unix.text"));
}
Document doc = textPaneClient.getDocument();
if (doc instanceof HTMLDocument) { // Issue 185505
HTMLDocument htmlDoc = (HTMLDocument)doc;
Font font = UIManager.getFont("Label.font"); // NOI18N
String bodyRule = "body { font-family: " + font.getFamily() + "; " // NOI18N
+ "color: " + SvnUtils.getColorString(textPaneClient.getForeground()) + "; " //NOI18N
+ "font-size: " + font.getSize() + "pt; }"; // NOI18N
htmlDoc.getStyleSheet().addRule(bodyRule);
}
textPaneClient.setOpaque(false);
textPaneClient.setBackground(new Color(0,0,0,0)); // windows and nimbus workaround see issue 145826
}
示例5: main
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ParserCB cb = new ParserCB();
HTMLEditorKit htmlKit = new HTMLEditorKit();
HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
htmlDoc.getParser().parse(new StringReader(text), cb, true);
synchronized (lock) {
if (!isCallbackInvoked) {
lock.wait(5000);
}
}
if (!isCallbackInvoked) {
throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text);
}
if (exception != null) {
throw exception;
}
}
示例6: setDocumentation
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
private synchronized void setDocumentation(CompletionDocumentation doc) {
currentDocumentation = doc;
if (currentDocumentation != null) {
String text = currentDocumentation.getText();
URL url = currentDocumentation.getURL();
if (text != null){
Document document = view.getDocument();
document.putProperty(Document.StreamDescriptionProperty, null);
if (url!=null){
// fix of issue #58658
if (document instanceof HTMLDocument){
((HTMLDocument)document).setBase(url);
}
}
view.setContent(text, url != null ? url.getRef() : null);
} else if (url != null){
try{
view.setPage(url);
}catch(IOException ioe){
StatusDisplayer.getDefault().setStatusText(ioe.toString());
}
}
bShowWeb.setEnabled(url != null);
bGoToSource.setEnabled(currentDocumentation.getGotoSourceAction() != null);
}
}
示例7: showInThreads
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
public void showInThreads(Instance instance) {
if (!showThreads) {
showThreads = true;
instanceToSelect = instance;
refreshSummary();
return;
}
String referenceId = String.valueOf(instance.getInstanceId());
dataArea.scrollToReference(referenceId);
Document d = dataArea.getDocument();
HTMLDocument doc = (HTMLDocument) d;
HTMLDocument.Iterator iter = doc.getIterator(HTML.Tag.A);
for (; iter.isValid(); iter.next()) {
AttributeSet a = iter.getAttributes();
String nm = (String) a.getAttribute(HTML.Attribute.NAME);
if ((nm != null) && nm.equals(referenceId)) {
dataArea.select(iter.getStartOffset(),iter.getEndOffset());
dataArea.requestFocusInWindow();
}
}
}
示例8: getContentHeightOfEditor
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
/**
* Calculates the preferred height of the editor pane with the given fixed width.
*
* @param width
* the width of the pane
* @return the preferred height given the current editor pane content or {@code -1} if there was
* a problem. Value will never exceed {@link WorkflowAnnotation#MAX_HEIGHT}
*/
private int getContentHeightOfEditor(final int width) {
HTMLDocument document = (HTMLDocument) editPane.getDocument();
StringWriter writer = new StringWriter();
try {
editPane.getEditorKit().write(writer, document, 0, document.getLength());
} catch (IndexOutOfBoundsException | IOException | BadLocationException e1) {
// should not happen
return -1;
}
String comment = writer.toString();
comment = AnnotationDrawUtils.removeStyleFromComment(comment);
int maxHeight = model.getSelected() instanceof ProcessAnnotation ? ProcessAnnotation.MAX_HEIGHT
: OperatorAnnotation.MAX_HEIGHT;
return Math.min(
AnnotationDrawUtils.getContentHeight(
AnnotationDrawUtils.createStyledCommentString(comment, model.getSelected().getStyle()), width),
maxHeight);
}
示例9: getPlaintextFromEditor
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
/**
* Returns plain text from the editor.
*
* @param editor
* the editor from which to take the text.
* @param onlySelected
* if {@code true} will only return the selected text
* @return the text of the editor converted to plain text
* @throws BadLocationException
* @throws IOException
*/
public static String getPlaintextFromEditor(final JEditorPane editor, final boolean onlySelected) throws IOException,
BadLocationException {
if (editor == null) {
throw new IllegalArgumentException("editor must not be null!");
}
HTMLDocument document = (HTMLDocument) editor.getDocument();
StringWriter writer = new StringWriter();
int start = 0;
int length = document.getLength();
if (onlySelected) {
start = editor.getSelectionStart();
length = editor.getSelectionEnd() - start;
}
editor.getEditorKit().write(writer, document, start, length);
String text = writer.toString();
text = AnnotationDrawUtils.removeStyleFromComment(text);
// switch <br> and <br/> to actual newline (current system)
text = text.replaceAll("<br.*?>", System.lineSeparator());
// kill all other html tags
text = text.replaceAll("\\<.*?>", "");
text = StringEscapeUtils.unescapeHtml(text);
return text;
}
示例10: getAttribute
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
@Override public String getAttribute(final String name) {
if ("text".equals(name)) {
return getText();
}
if ("hRefIndex".equals(name)) {
return getHRefIndex() + "";
}
if ("textIndex".equals(name)) {
return getTextIndex() + "";
}
return EventQueueWait.exec(new Callable<String>() {
@Override public String call() throws Exception {
Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument());
AttributeSet attributes = iterator.getAttributes();
Attribute attr = findAttribute(name);
if (attr != null && attributes.isDefined(attr)) {
return attributes.getAttribute(attr).toString();
}
return null;
}
});
}
示例11: checkImages
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
private static void checkImages() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
HTMLEditorKit c = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
try {
c.read(new StringReader("<HTML><TITLE>Test</TITLE><BODY><IMG id=test></BODY></HTML>"), doc, 0);
} catch (Exception e) {
throw new RuntimeException("The test failed", e);
}
Element elem = doc.getElement("test");
ImageView iv = new ImageView(elem);
if (iv.getLoadingImageIcon() == null) {
throw new RuntimeException("getLoadingImageIcon returns null");
}
if (iv.getNoImageIcon() == null) {
throw new RuntimeException("getNoImageIcon returns null");
}
}
});
}
示例12: setHRef
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
public void setHRef(int pos, Document doc) {
hRef = null;
text = null;
if (!(doc instanceof HTMLDocument)) {
return;
}
HTMLDocument hdoc = (HTMLDocument) doc;
Iterator iterator = hdoc.getIterator(HTML.Tag.A);
while (iterator.isValid()) {
if (pos >= iterator.getStartOffset() && pos < iterator.getEndOffset()) {
AttributeSet attributes = iterator.getAttributes();
if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) {
try {
text = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset()).trim();
hRef = attributes.getAttribute(HTML.Attribute.HREF).toString();
setIndexOfHrefAndText(hdoc, pos, text, hRef);
} catch (BadLocationException e) {
e.printStackTrace();
}
return;
}
}
iterator.next();
}
}
示例13: setDocument
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
public void setDocument(Note note) {
// Note note = CurrentProject.getNoteList().getActiveNote();
// try {
// this.editor.editor.setPage(CurrentStorage.get().getNoteURL(note));
editor.document = (HTMLDocument) CurrentStorage.get().openNote(note);
editor.initEditor();
if (note != null) {
titleField.setText(note.getTitle());
tagsField.setText(note.getTags());
}
else {
titleField.setText("");
tagsField.setText("");
}
initialTitle = titleField.getText();
initialTags = tagsField.getText();
/*
* } catch (Exception ex) { new ExceptionDialog(ex); }
*/
/*
* Document doc = CurrentStorage.get().openNote(note); try {
* this.editor.editor.setText(doc.getText(0, doc.getLength())); } catch
* (Exception ex){ ex.printStackTrace(); }
*/
// .setDocument(CurrentStorage.get().openNote(note));
}
示例14: insertDocument
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
protected void insertDocument(String msg) {
try {
HTMLEditorKit kit = (HTMLEditorKit) historyWidget.getEditorKit();
HTMLDocument doc = (HTMLDocument) historyWidget.getDocument();
// historyWidget.getDocument().insertString(len - offset,
// trimMsg(msg), null);
// Element root = doc.getDefaultRootElement();
// Element body = root.getElement(1);
// doc.insertBeforeEnd(body, msg);
int pos = historyWidget.getCaretPosition();
kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
historyWidget.setCaretPosition(scrollLock ? pos : doc.getLength());
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: JTextPaneTableCellRenderer
import javax.swing.text.html.HTMLDocument; //导入依赖的package包/类
public JTextPaneTableCellRenderer() {
textPane.setContentType("text/html");
textPane.setEditable(false);
textPane.setOpaque(true);
textPane.setBorder(null);
textPane.setForeground(UIManager.getColor("Table.selectionForeground"));
textPane.setBackground(UIManager.getColor("Table.selectionBackground"));
Font font = UIManager.getFont("Label.font");
String bodyRule =
"body { font-family: " + font.getFamily() + "; " + "font-size: "
+ font.getSize() + "pt; "
+ (font.isBold() ? "font-weight: bold;" : "") + "}";
((HTMLDocument)textPane.getDocument()).getStyleSheet().addRule(bodyRule);
textPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
MainFrame.getInstance().showHelpFrame(e.getURL().toString(), "CREOLE Plugin Manager");
}
});
}