本文整理汇总了Java中javax.swing.JEditorPane.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.setContentType方法的具体用法?Java JEditorPane.setContentType怎么用?Java JEditorPane.setContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.setContentType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExcludeTwoLayers
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testExcludeTwoLayers() {
OffsetsBag bag = new OffsetsBag(new PlainDocument());
MemoryMimeDataProvider.reset(null);
MemoryMimeDataProvider.addInstances(
"text/plain", new SingletonLayerFactory("layer", ZOrder.DEFAULT_RACK, true, bag));
JEditorPane pane = new JEditorPane();
String [] removed = new String[] {"^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\..*$", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.TextSelectionHighlighting$"};
pane.putClientProperty("HighlightsLayerExcludes", removed);
pane.setContentType("text/plain");
assertEquals("The pane has got wrong mime type", "text/plain", pane.getContentType());
HighlightingManager hm = HighlightingManager.getInstance(pane);
HighlightsContainer hc = hm.getHighlights(HighlightsLayerFilter.IDENTITY);
assertNotNull("Can't get fixed HighlightsContainer", hc);
assertFalse("There should be no fixed highlights", hc.getHighlights(0, Integer.MAX_VALUE).moveNext());
}
示例2: createComponent
import javax.swing.JEditorPane; //导入方法依赖的package包/类
@Override
public JComponent createComponent() {
JScrollPane pane = new JScrollPane();
editorPane = new JEditorPane();
pane.setViewportView(editorPane);
if (scriptPath.endsWith(".js"))
editorPane.setContentType("text/javascript");
byte[] bs = framework.getEngine().getStream(scriptPath);
if (bs == null)
bs = new byte[]{};
try {
editorPane.setText(new String(bs, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (!saveScriptAction.isEnabled())
editorPane.setEditable(false);
return pane;
}
示例3: mxCellEditor
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
*
*/
public mxCellEditor(mxGraphComponent graphComponent)
{
this.graphComponent = graphComponent;
// Creates the plain text editor
textArea = new JTextArea();
textArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
textArea.setOpaque(false);
// Creates the HTML editor
editorPane = new JEditorPane();
editorPane.setOpaque(false);
editorPane.setBackground(new Color(0,0,0,0));
editorPane.setContentType("text/html");
// Workaround for inserted linefeeds in HTML markup with
// lines that are longar than 80 chars
editorPane.setEditorKit(new NoLinefeedHtmlEditorKit());
// Creates the scollpane that contains the editor
// FIXME: Cursor not visible when scrolling
scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createEmptyBorder());
scrollPane.getViewport().setOpaque(false);
scrollPane.setVisible(false);
scrollPane.setOpaque(false);
// Installs custom actions
editorPane.getActionMap().put(CANCEL_EDITING, cancelEditingAction);
textArea.getActionMap().put(CANCEL_EDITING, cancelEditingAction);
editorPane.getActionMap().put(SUBMIT_TEXT, textSubmitAction);
textArea.getActionMap().put(SUBMIT_TEXT, textSubmitAction);
// Remembers the action map key for the enter keystroke
editorEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke);
textEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke);
}
示例4: testSimpleLayer
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testSimpleLayer() {
OffsetsBag bag = new OffsetsBag(new PlainDocument());
MemoryMimeDataProvider.reset(null);
MemoryMimeDataProvider.addInstances(
"text/plain", new SingletonLayerFactory("layer", ZOrder.DEFAULT_RACK, true, bag));
JEditorPane pane = new JEditorPane();
pane.putClientProperty("HighlightsLayerExcludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\..*$");
pane.setContentType("text/plain");
assertEquals("The pane has got wrong mime type", "text/plain", pane.getContentType());
HighlightingManager hm = HighlightingManager.getInstance(pane);
HighlightsContainer hc = hm.getHighlights(HighlightsLayerFilter.IDENTITY);
assertNotNull("Can't get fixed HighlightsContainer", hc);
assertFalse("There should be no fixed highlights", hc.getHighlights(0, Integer.MAX_VALUE).moveNext());
SimpleAttributeSet attributes = new SimpleAttributeSet();
attributes.addAttribute("attrib-A", "value");
bag.addHighlight(10, 20, attributes);
HighlightsSequence highlights = hc.getHighlights(0, Integer.MAX_VALUE);
assertTrue("Highlight has not been added", moveNextSkipNullAttrs(highlights));
assertEquals("Wrong start offset", 10, highlights.getStartOffset());
assertEquals("Wrong end offset", 20, highlights.getEndOffset());
assertEquals("Can't find attribute", "value", highlights.getAttributes().getAttribute("attrib-A"));
}
示例5: testCaching
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testCaching() {
MemoryMimeDataProvider.reset(null);
JEditorPane pane1 = new JEditorPane();
HighlightingManager hm1 = HighlightingManager.getInstance(pane1);
pane1.setContentType("text/plain");
assertEquals("The pane has got wrong mime type", "text/plain", pane1.getContentType());
JEditorPane pane2 = new JEditorPane();
HighlightingManager hm2 = HighlightingManager.getInstance(pane2);
pane2.setContentType("text/plain");
assertEquals("The pane has got wrong mime type", "text/plain", pane2.getContentType());
{
HighlightsContainer hc1_A = hm1.getHighlights(HighlightsLayerFilter.IDENTITY);
HighlightsContainer hc1_B = hm1.getHighlights(HighlightsLayerFilter.IDENTITY);
// Current impl of hm.getHighlights() does not cache HC instances so the following test would fail
// assertSame("HighlightsContainer is not cached", hc1_A, hc1_B);
HighlightsContainer hc2 = hm2.getHighlights(HighlightsLayerFilter.IDENTITY);
assertNotSame("HighlightsContainer should not be shared between JEPs", hc1_A, hc2);
}
gc();
{
int hc1_A_hash = System.identityHashCode(hm1.getHighlights(HighlightsLayerFilter.IDENTITY));
int hc1_B_hash = System.identityHashCode(hm1.getHighlights(HighlightsLayerFilter.IDENTITY));
// Current impl of hm.getHighlights() does not cache HC instances so the following test would fail
// assertEquals("HighlightsContainer is not cached (different hash codes)", hc1_A_hash, hc1_B_hash);
}
}
示例6: testCachedInstancesGCed
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testCachedInstancesGCed() {
MemoryMimeDataProvider.reset(null);
// Hold MimePath instance and lookup result; the highlighting container should still
// be GCed
final MimePath mimePath = MimePath.parse("text/plain");
final Lookup.Result<FontColorSettings> lookupResult = MimeLookup.getLookup(mimePath).lookupResult(FontColorSettings.class);
Collection<? extends FontColorSettings> fcs = lookupResult.allInstances();
assertTrue("There should be FontColorSettings for " + mimePath.getPath(), fcs.size() > 0);
JEditorPane pane = new JEditorPane();
HighlightingManager hm = HighlightingManager.getInstance(pane);
pane.setContentType("text/plain");
assertEquals("The pane has got wrong mime type", "text/plain", pane.getContentType());
HighlightsContainer hc = hm.getHighlights(HighlightsLayerFilter.IDENTITY);
assertNotNull("Can't get HighlightsContainer", hc);
WeakReference<JEditorPane> refPane = new WeakReference<JEditorPane>(pane);
WeakReference<HighlightsContainer> refHc = new WeakReference<HighlightsContainer>(hc);
// reset hard references
pane = null;
hm = null;
hc = null;
assertGC("JEP has not been GCed", refPane);
assertGC("HC has not been GCed", refHc);
}
示例7: initComponents
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/** This method is called from within the constructor to
* initialize the form.
*/
private void initComponents() {
setLayout(new BorderLayout());
editorPane = new JEditorPane();
editorPane.setContentType("text/x-properties"); // NOI18N
// XXX pretty arbitrary! No way to set by rows & columns??
editorPane.setPreferredSize(new Dimension(200, 100));
add(new JScrollPane(editorPane), BorderLayout.CENTER);
warnings = new JTextField(30);
warnings.setEditable(false);
add(warnings, BorderLayout.SOUTH);
}
示例8: redraw
import javax.swing.JEditorPane; //导入方法依赖的package包/类
@Override
public void redraw() {
// Redraws only if data has changed - Bertoli Marco
if (!redrawNeeded)
return;
if (data.hasResults() && data.areResultsOK()
&& data.getResults().getSaturationSectors().size() > 0) {
if (data.getClasses() == 2) {
this.removeAll();
s2dp = new Sectors2DGraph(data);
this.setLayout(new BorderLayout());
this.add(new JabaCanvas(s2dp), BorderLayout.CENTER);
this.add(new JLabel(JabaConstants.DESCRIPITION_GRAPH),
BorderLayout.PAGE_END);
repaint();
} else if (data.getClasses() == 3) {
this.removeAll();
Sectors3DGraph s3dp = new Sectors3DGraph(data);
this.setLayout(new BorderLayout());
this.add(new JabaCanvas(s3dp), BorderLayout.CENTER);
this.add(new JLabel(JabaConstants.DESCRIPITION_GRAPH),
BorderLayout.PAGE_END);
repaint();
}
} else {
this.removeAll();
JEditorPane synView = new JTextPane();
synView.setContentType("text/html");
synView.setEditable(false);
JScrollPane synScroll = new JScrollPane(synView);
synScroll
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
synScroll
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
synView.setText("<html><body><center><font face=\"bold\" size=\"3\">Saturation Sectors will be here displayed once you solve the model.</font></center></body></html>");
this.add(synScroll, BorderLayout.CENTER);
}
redrawNeeded = false;
}
示例9: rtf2html
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public String rtf2html(final String rtf) {
final JEditorPane p = new JEditorPane();
p.setContentType("text/rtf");
final EditorKit kitRtf = p.getEditorKitForContentType("text/rtf");
try {
kitRtf.read(new StringReader(rtf), p.getDocument(), 0);
final Writer writer = new StringWriter();
final EditorKit editorKitForContentType = p.getEditorKitForContentType("text/html");
editorKitForContentType.write(writer, p.getDocument(), 0, p.getDocument().getLength());
return writer.toString();
} catch (IOException | BadLocationException e) {
throw new RTF2HTMLException("Could not convert RTF to HTML.", e);
}
}
示例10: mxCellEditor
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
*
*/
public mxCellEditor(mxGraphComponent graphComponent) {
this.graphComponent = graphComponent;
// Creates the plain text editor
textArea = new JTextArea();
textArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
textArea.setOpaque(false);
// Creates the HTML editor
editorPane = new JEditorPane();
editorPane.setOpaque(false);
editorPane.setBackground(new Color(0, 0, 0, 0));
editorPane.setContentType("text/html");
// Workaround for inserted linefeeds in HTML markup with
// lines that are longar than 80 chars
editorPane.setEditorKit(new NoLinefeedHtmlEditorKit());
// Creates the scollpane that contains the editor
// FIXME: Cursor not visible when scrolling
scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createEmptyBorder());
scrollPane.getViewport().setOpaque(false);
scrollPane.setVisible(false);
scrollPane.setOpaque(false);
// Installs custom actions
editorPane.getActionMap().put(CANCEL_EDITING, cancelEditingAction);
textArea.getActionMap().put(CANCEL_EDITING, cancelEditingAction);
editorPane.getActionMap().put(SUBMIT_TEXT, textSubmitAction);
textArea.getActionMap().put(SUBMIT_TEXT, textSubmitAction);
// Remembers the action map key for the enter keystroke
editorEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke);
textEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke);
}
示例11: SwingSpyPanel
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* Initialization.
*/
public SwingSpyPanel() {
setPreferredSize(new Dimension(INITIAL_WIDTH, INITIAL_HEIGHT));
setLayout(new BorderLayout());
root = new DefaultMutableTreeNode();
componentTree = new JTree(root);
componentTree.setRootVisible(false);
componentTree.setCellRenderer(new SwingComponentRenderer());
componentTree.addTreeSelectionListener(new CustomSelectionListener());
// add(new JScrollPane(componentTree), BorderLayout.CENTER);
detailsData = new JEditorPane();
detailsData.setBackground(new Color(250, 250, 250));
detailsData.setForeground(new Color(33, 33, 33));
detailsData.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 244), 1));
detailsData.setPreferredSize(new Dimension(150, INITIAL_HEIGHT));
detailsData.setEditable(false);
detailsData.setContentType("text/html");
SwingUtil.enforceJEditorPaneFont(detailsData, font);
detailsScrollPane = new JScrollPane(detailsData);
// add(detailsScrollPane, BorderLayout.EAST);
JSplitPane hPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(componentTree), detailsScrollPane);
hPane.setContinuousLayout(true);
hPane.setOneTouchExpandable(true);
hPane.setDividerLocation(INITIAL_WIDTH - 200);
add(hPane, BorderLayout.CENTER);
componentData = new JEditorPane();
componentData.setBackground(new Color(250, 250, 250));
componentData.setForeground(new Color(33, 33, 33));
componentData.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 244), 1));
componentData.setPreferredSize(new Dimension(INITIAL_WIDTH, 36));
componentData.setEditable(false);
componentData.setContentType("text/html");
SwingUtil.enforceJEditorPaneFont(componentData, font);
add(componentData, BorderLayout.SOUTH);
}
示例12: DialogHelpWindow
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public DialogHelpWindow(String title, URL contents, Dialog parent) {
super(parent);
setTitle(title);
setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
//setJMenuBar(MenuManager.getInstance().getMenuBarFor(this));
pane = new JEditorPane();
pane.setEditable(false);
pane.addHyperlinkListener(this);
/*
* Allow <src> tag to display images from the module DataArchive
* where no pathname included in the image name.
*/
pane.setContentType("text/html"); //$NON-NLS-1$
XTMLEditorKit myHTMLEditorKit = new HtmlChart.XTMLEditorKit();
pane.setEditorKit(myHTMLEditorKit);
JScrollPane scroll = new ScrollPane(pane);
add(scroll);
update(contents);
pack();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int width = Math.max(d.width / 2, getSize().width);
int height = Math.max(d.height / 2, getSize().height);
width = Math.min(width, d.width * 2 / 3);
height = Math.min(height, d.height * 2 / 3);
setSize(width, height);
setLocation(d.width / 2 - width / 2, 0);
}
示例13: redraw
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void redraw() {
// Redraws only if data has changed - Bertoli Marco
if (old_data == data) {
return;
} else {
old_data = data;
}
if (data.hasResults() && data.areResultsOK() && data.getResults().size() > 0) {
if (data.getClasses() == 2) {
this.removeAll();
PanelConvex2D s2dp = new PanelConvex2D(data, mainWin);
this.add(new JScrollPane(s2dp));
repaint();
} else if (data.getClasses() == 3) {
this.removeAll();
// Under costruction
repaint();
}
} else {
this.removeAll();
JEditorPane synView = new JTextPane();
synView.setContentType("text/html");
synView.setEditable(false);
JScrollPane synScroll = new JScrollPane(synView);
synScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
synScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
synView
.setText("<html><body><center><font face=\"bold\" size=\"3\">Saturation Sectors will be here displayed once you solve the model.</font></center></body></html>");
this.add(synScroll);
}
}
示例14: getHardwareReportComponent
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public static JComponent getHardwareReportComponent(CLPlatform platform) {
List<Map<String, Object>> list = listInfos(platform);
final String html = toHTML(list);
JEditorPane ed = new JEditorPane();
ed.setContentType("text/html");
ed.setText(html);
ed.setEditable(false);
JPanel ret = new JPanel(new BorderLayout());
ret.add("Center", new JScrollPane(ed));
final String fileName = "HardwareReport.html";
JButton bWrite = new JButton("Save " + fileName + "...");
bWrite.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog((Frame)null, "Save " + fileName, FileDialog.SAVE);
fd.setFile(fileName);
fd.setVisible(true);
if (fd.getFile() == null)
return;
try {
File file = new File(new File(fd.getDirectory()), fd.getFile());
file.getParentFile().mkdirs();
Writer w = new OutputStreamWriter(new FileOutputStream(file), "utf-8");
w.write(html);
w.close();
Platform.show(file);
} catch (Throwable ex) {
SetupUtils.exception(ex);
}
}
});
ret.add("South", bWrite);
return ret;
}
示例15: testChangesInLayerFireEvents
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testChangesInLayerFireEvents() {
OffsetsBag bagA = new OffsetsBag(new PlainDocument());
OffsetsBag bagB = new OffsetsBag(new PlainDocument());
OffsetsBag bagC = new OffsetsBag(new PlainDocument());
OffsetsBag bagD = new OffsetsBag(new PlainDocument());
MemoryMimeDataProvider.reset(null);
MemoryMimeDataProvider.addInstances("text/plain",
new SingletonLayerFactory("layerB", ZOrder.DEFAULT_RACK.forPosition(2), false, bagB),
new SingletonLayerFactory("layerD", ZOrder.DEFAULT_RACK.forPosition(6), true, bagD),
new SingletonLayerFactory("layerA", ZOrder.DEFAULT_RACK, true, bagA),
new SingletonLayerFactory("layerC", ZOrder.DEFAULT_RACK.forPosition(4), true, bagC)
);
JEditorPane pane = new JEditorPane();
pane.putClientProperty("HighlightsLayerExcludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\..*$");
pane.setContentType("text/plain");
assertEquals("The pane has got wrong mime type", "text/plain", pane.getContentType());
HighlightingManager hm = HighlightingManager.getInstance(pane);
// Test the variable-size layers - A,B
Listener variableL = new Listener();
HighlightsContainer variableHC = hm.getHighlights(VARIABLE_SIZE_LAYERS);
assertNotNull("Can't get variable HighlightsContainer", variableHC);
assertFalse("There should be no variable highlights", variableHC.getHighlights(0, Integer.MAX_VALUE).moveNext());
variableHC.addHighlightsChangeListener(variableL);
bagA.addHighlight(10, 20, SimpleAttributeSet.EMPTY);
assertEquals("Wrong number of events", 1, variableL.eventsCnt);
assertEquals("Wrong change start offset", 10, variableL.lastStartOffset);
assertEquals("Wrong change end offset", 20, variableL.lastEndOffset);
variableL.reset();
bagB.addHighlight(5, 15, SimpleAttributeSet.EMPTY);
assertEquals("Wrong number of events", 1, variableL.eventsCnt);
assertEquals("Wrong change start offset", 5, variableL.lastStartOffset);
assertEquals("Wrong change end offset", 15, variableL.lastEndOffset);
// Test the fixed-size layers
Listener fixedL = new Listener();
HighlightsContainer fixedHC = hm.getHighlights(FIXED_SIZE_LAYERS);
assertNotNull("Can't get fixed HighlightsContainer", fixedHC);
assertFalse("There should be no fixed highlights", fixedHC.getHighlights(0, Integer.MAX_VALUE).moveNext());
fixedHC.addHighlightsChangeListener(fixedL);
bagC.addHighlight(20, 50, SimpleAttributeSet.EMPTY);
assertEquals("Wrong number of events", 1, fixedL.eventsCnt);
assertEquals("Wrong change start offset", 20, fixedL.lastStartOffset);
assertEquals("Wrong change end offset", 50, fixedL.lastEndOffset);
fixedL.reset();
bagD.addHighlight(0, 30, SimpleAttributeSet.EMPTY);
assertEquals("Wrong number of events", 1, fixedL.eventsCnt);
assertEquals("Wrong change start offset", 0, fixedL.lastStartOffset);
assertEquals("Wrong change end offset", 30, fixedL.lastEndOffset);
}