本文整理汇总了Java中javax.swing.JEditorPane.putClientProperty方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.putClientProperty方法的具体用法?Java JEditorPane.putClientProperty怎么用?Java JEditorPane.putClientProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.putClientProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContainer
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public static RandomTestContainer createContainer(EditorKit kit) throws Exception {
// Ensure the new view hierarchy is turned on
System.setProperty("org.netbeans.editor.linewrap", "true");
// Set the property for synchronous highlights firing since otherwise
// the repeatability of problems with view hierarchy is none or limited.
System.setProperty("org.netbeans.editor.sync.highlights", "true");
System.setProperty("org.netbeans.editor.linewrap.edt", "true");
RandomTestContainer container = new RandomTestContainer();
EditorPaneTesting.initContainer(container, kit);
DocumentTesting.initContainer(container);
DocumentTesting.initUndoManager(container);
container.addCheck(new ViewHierarchyCheck());
JEditorPane pane = EditorPaneTesting.getEditorPane(container);
pane.putClientProperty("text-line-wrap", "words"); // SimpleValueNames.TEXT_LINE_WRAP
return container;
}
示例2: setupUI
import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void setupUI(JEditorPane editorPane) {
EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(editorPane);
if (eui == null) {
return;
}
editorPane.putClientProperty(
"HighlightsLayerExcludes", //NOI18N
"^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$" //NOI18N
);
// Do not draw text limit line
try {
java.lang.reflect.Field textLimitLineField = EditorUI.class.getDeclaredField("textLimitLineVisible"); // NOI18N
textLimitLineField.setAccessible(true);
textLimitLineField.set(eui, false);
} catch (Exception ex) {}
editorPane.repaint();
}
示例3: setupCodeEditorPane
import javax.swing.JEditorPane; //导入方法依赖的package包/类
@Override
public void setupCodeEditorPane(JEditorPane editor, FileObject srcFile, int ccPosition) {
DataObject dob = null;
try {
dob = DataObject.find(srcFile);
} catch (DataObjectNotFoundException dnfex) {
FormUtils.LOGGER.log(Level.INFO, dnfex.getMessage(), dnfex);
}
if (!(dob instanceof FormDataObject)) {
FormUtils.LOGGER.log(Level.INFO, "Unable to find FormDataObject for {0}", srcFile); // NOI18N
return;
}
FormDataObject formDob = (FormDataObject)dob;
Document document = formDob.getFormEditorSupport().getDocument();
DialogBinding.bindComponentToDocument(document, ccPosition, 0, editor);
// do not highlight current row
editor.putClientProperty(
"HighlightsLayerExcludes", //NOI18N
"^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$" //NOI18N
);
FormUtils.setupTextUndoRedo(editor);
}
示例4: getToolTip
import javax.swing.JEditorPane; //导入方法依赖的package包/类
@Override
public JComponent getToolTip(double x, double y, Shape allocation) {
Container container = getContainer();
if (container instanceof JEditorPane) {
JEditorPane editorPane = (JEditorPane) getContainer();
JEditorPane tooltipPane = new JEditorPane();
EditorKit kit = editorPane.getEditorKit();
Document doc = getDocument();
if (kit != null && doc != null) {
Element lineRootElement = doc.getDefaultRootElement();
tooltipPane.putClientProperty(FoldViewFactory.DISPLAY_ALL_FOLDS_EXPANDED_PROPERTY, true);
try {
// Start-offset of the fold => line start => position
int lineIndex = lineRootElement.getElementIndex(fold.getStartOffset());
Position pos = doc.createPosition(
lineRootElement.getElement(lineIndex).getStartOffset());
// DocumentView.START_POSITION_PROPERTY
tooltipPane.putClientProperty("document-view-start-position", pos); // NOI18N
// End-offset of the fold => line end => position
lineIndex = lineRootElement.getElementIndex(fold.getEndOffset());
pos = doc.createPosition(lineRootElement.getElement(lineIndex).getEndOffset());
// DocumentView.END_POSITION_PROPERTY
tooltipPane.putClientProperty("document-view-end-position", pos); // NOI18N
tooltipPane.putClientProperty("document-view-accurate-span", true); // NOI18N
// Set the same kit and document
tooltipPane.setEditorKit(kit);
tooltipPane.setDocument(doc);
tooltipPane.setEditable(false);
return new FoldToolTip(editorPane, tooltipPane, getBorderColor());
} catch (BadLocationException e) {
// => return null
}
}
}
return null;
}
示例5: buildDetail
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void buildDetail(String id, JPanel panel) {
if (this.id.equals(id)) return;
panel.setLayout(new MigLayout("wrap 1, center"));
JLabel header = Utility.localizedHeaderLabel(Messages.nameKey(id),
SwingConstants.LEADING, FontLibrary.FontSize.SMALL);
panel.add(header, "align center, wrap 20");
JEditorPane editorPane = new JEditorPane("text/html",
Messages.getDescription(id)) {
@Override
public void paintComponent(Graphics g) {
Graphics2D graphics2d = (Graphics2D) g;
graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
/*
graphics2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
graphics2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
*/
super.paintComponent(graphics2d);
}
};
editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
Boolean.TRUE);
editorPane.setFont(panel.getFont());
editorPane.setOpaque(false);
editorPane.setEditable(false);
editorPane.addHyperlinkListener(colopediaPanel);
panel.add(editorPane, "width 95%");
}
示例6: testCustomBounds
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testCustomBounds() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
doc.insertString(0, "hello\nworld\ngood\nmorning", null);
Position startPos = doc.createPosition(3);
pane.putClientProperty(DocumentView.START_POSITION_PROPERTY, startPos);
pane.modelToView(0); // Force rebuild of VH
doc.insertString(startPos.getOffset(), "a", null);
doc.insertString(startPos.getOffset() - 1, "a", null);
Element line0 = doc.getDefaultRootElement().getElement(0);
Position endPos = doc.createPosition(line0.getEndOffset() + 3); // Middle of line 1
pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, endPos);
pane.modelToView(0); // Force rebuild of VH
TestHighlightsViewFactory testFactory = ViewUpdatesTesting.getTestFactory(pane);
List<TestHighlight> hlts = ViewUpdatesTesting.getHighlightsCopy(testFactory);
int hlStartOffset = startPos.getOffset() + 1;
int hlEndOffset = endPos.getOffset() - 1;
TestHighlight hi = TestHighlight.create(doc, hlStartOffset, hlEndOffset, colorAttrs[0]);
hlts.add(hi);
testFactory.setHighlights(hlts);
testFactory.fireChange(hlStartOffset, hlEndOffset);
pane.modelToView(0); // Force rebuild of VH
doc.insertString(doc.getLength(), "test\ntest2", null);
Position endPos2 = doc.createPosition(doc.getLength() - 3);
pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, endPos2);
pane.modelToView(0); // Force rebuild of VH
doc.remove(endPos2.getOffset() - 2, 3);
pane.putClientProperty(DocumentView.START_POSITION_PROPERTY, null);
pane.modelToView(0); // Force rebuild of VH
}
示例7: testEmptyCustomBounds
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testEmptyCustomBounds() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
pane.modelToView(0);
doc.insertString(0, "hello\nworld\ngood\nmorning", null);
Position startPos = doc.createPosition(3);
pane.putClientProperty(DocumentView.START_POSITION_PROPERTY, startPos);
pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, startPos);
pane.modelToView(0); // Force rebuild of VH
Position endPos = doc.createPosition(2);
pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, endPos);
pane.modelToView(0); // Force rebuild of VH
}
示例8: testSimple
import javax.swing.JEditorPane; //导入方法依赖的package包/类
@RandomlyFails
public void testSimple() {
JEditorPane pane = new JEditorPane();
pane.putClientProperty("HighlightsLayerExcludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\..*$");
HighlightingManager hm = HighlightingManager.getInstance(pane);
assertNotNull("Can't get instance of HighlightingManager", hm);
HighlightsContainer hc = hm.getHighlights(HighlightsLayerFilter.IDENTITY);
assertNotNull("Can't get fixed HighlightsContainer", hc);
assertEquals(0, pane.getDocument().getLength());
assertFalse("There should be no fixed highlights", hc.getHighlights(0, Integer.MAX_VALUE).moveNext());
}
示例9: 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"));
}
示例10: TestNimbusOverride
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public TestNimbusOverride()
{
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
/*
* Create a frame containing a JEditorPane, and override the action for the space bar to show
* a dialog.
*/
JEditorPane pp = new JEditorPane();
UIDefaults defaults = new UIDefaults();
pp.putClientProperty("Nimbus.Overrides", defaults);
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BorderLayout());
setContentPane(contentPanel);
contentPanel.setPreferredSize(new Dimension(400, 300));
contentPanel.add(pp, BorderLayout.CENTER);
Keymap origKeymap = pp.getKeymap();
Keymap km = JEditorPane.addKeymap("Test keymap", origKeymap);
km.addActionForKeyStroke(KeyStroke.getKeyStroke(' '), new AbstractAction("SHOW_SPACE") {
@Override
public void actionPerformed(ActionEvent e)
{
passed = true;
}
});
pp.setKeymap(km);
}
示例11: adjustFontSize
import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void adjustFontSize(JEditorPane contentViewer) {
if(contentViewer != null) {
contentViewer.putClientProperty(
JEditorPane.W3C_LENGTH_UNITS, Boolean.TRUE);
contentViewer.putClientProperty(
JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
}
}
示例12: testAreas
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testAreas() throws Exception {
MockServices.setServices(MockMimeLookup.class);
MockMimeLookup.setInstances(MimePath.EMPTY, new TestMatcher());
AttributeSet EAS = SimpleAttributeSet.EMPTY;
JEditorPane c = new JEditorPane();
Document d = c.getDocument();
OffsetsBag bag = new OffsetsBag(d);
d.insertString(0, "text text { text } text", null);
c.putClientProperty(MasterMatcher.PROP_MAX_BACKWARD_LOOKAHEAD, 256);
c.putClientProperty(MasterMatcher.PROP_MAX_FORWARD_LOOKAHEAD, 256);
TestMatcher.origin = new int [] { 2, 3 };
TestMatcher.matches = new int [] { 10, 11 };
MasterMatcher.get(c).highlight(d, 7, bag, EAS, EAS, EAS, EAS);
TestMatcher.waitUntilCreated(1000);
{
TestMatcher tm = TestMatcher.lastMatcher;
assertNotNull("No matcher created", tm);
HighlightsSequence hs = bag.getHighlights(0, Integer.MAX_VALUE);
assertTrue("Wrong number of highlighted areas", hs.moveNext());
assertEquals("Wrong origin startOfset", 2, hs.getStartOffset());
assertEquals("Wrong origin endOfset", 3, hs.getEndOffset());
assertTrue("Wrong number of highlighted areas", hs.moveNext());
assertEquals("Wrong match startOfset", 10, hs.getStartOffset());
assertEquals("Wrong match endOfset", 11, hs.getEndOffset());
}
}
示例13: testRemoveAtBeginning
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testRemoveAtBeginning() throws Exception {
loggingOn();
ViewUpdatesTesting.setTestValues(ViewUpdatesTesting.NO_OP_TEST_VALUE);
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
final DocumentView docView = DocumentView.get(pane);
final PositionsBag highlights = ViewUpdatesTesting.getSingleHighlightingLayer(pane);
int offset;
String text;
int cRegionStartOffset;
int cRegionEndOffset;
offset = 0;
text = " \t\tabcdef\ta\nebxsu";
ViewUpdatesTesting.setTestValues(
/*rebuildCause*/ ViewBuilder.RebuildCause.MOD_UPDATE,
/*createLocalViews*/ true,
/*startCreationOffset*/ 0, // Insert at end of existing local view => rebuild prev one
/*matchOffset*/ offset + text.length(),
/*endCreationOffset*/ offset + text.length() + 1, // includes '\n'
/*bmReuseOffset*/ 0,
/*bmReusePView*/ docView.getParagraphView(0),
/*bmReuseLocalIndex*/ 0,
/*amReuseOffset*/ offset + text.length(),
/*amReusePIndex*/ 0,
/*amReusePView*/ docView.getParagraphView(0),
/*amReuseLocalIndex*/ 0 // Could reuse NewlineView
);
doc.insertString(offset, text, null);
ViewUpdatesTesting.checkViews(docView, 0, -1,
1, HI_VIEW,
2, TAB_VIEW,
6, HI_VIEW,
1, TAB_VIEW,
1, HI_VIEW,
1, NL_VIEW /* e:12 */,
5, HI_VIEW,
1, NL_VIEW /* e:18 */
);
// Force line wrap
// SimpleValueNames.TEXT_LINE_WRAP
pane.putClientProperty("text-line-wrap", "words"); // Force line wrap type
ViewUpdatesTesting.setTestValues(ViewUpdatesTesting.NO_OP_TEST_VALUE); // Will rebuild children
docView.ensureLayoutValidForInitedChildren(); // acquires lock
offset = 0;
int removeLength = 1;
cRegionStartOffset = 0;
cRegionEndOffset = removeLength + 1; // 2
docView.op.viewUpdates.extendCharRebuildRegion(OffsetRegion.create(doc, cRegionStartOffset, cRegionEndOffset));
ViewUpdatesTesting.setTestValues(
/*rebuildCause*/ ViewBuilder.RebuildCause.MOD_UPDATE,
/*createLocalViews*/ true,
/*startCreationOffset*/ offset,
/*matchOffset*/ offset + 2, // First HI_VIEW#1 removed and one char from second TAB_VIEW#2 removed by cRegion
/*endCreationOffset*/ docView.getParagraphView(0).getEndOffset() - removeLength,
/*bmReuseOffset*/ 0,
/*bmReusePView*/ docView.getParagraphView(0),
/*bmReuseLocalIndex*/ 0,
/*amReuseOffset*/ offset,
/*amReusePIndex*/ 0,
/*amReusePView*/ docView.getParagraphView(0),
/*amReuseLocalIndex*/ 1 // Could reuse NewlineView
);
doc.remove(offset, removeLength);
ViewUpdatesTesting.checkViews(docView, 0, -1,
2, TAB_VIEW,
6, HI_VIEW,
1, TAB_VIEW,
1, HI_VIEW,
1, NL_VIEW /* e:11 */,
5, HI_VIEW,
1, NL_VIEW /* e:17 */
);
ViewUpdatesTesting.setTestValues();
}
示例14: 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);
}
示例15: testToolTipView
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testToolTipView() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
final JEditorPane pane = container.getInstance(JEditorPane.class);
final Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
RandomTestContainer.Context context = container.context();
// ViewHierarchyRandomTesting.disableHighlighting(container);
DocumentTesting.setSameThreadInvoke(context, true); // Do not post to EDT
DocumentTesting.insert(context, 0, "abc\ndef\nghi\n");
final JEditorPane[] toolTipPaneRef = new JEditorPane[1];
final BadLocationException[] excRef = new BadLocationException[1];
final JFrame[] toolTipFrameRef = new JFrame[1];
Runnable tooltipRun = new Runnable() {
@Override
public void run() {
JEditorPane toolTipPane = new JEditorPane();
toolTipPaneRef[0] = toolTipPane;
toolTipPane.setEditorKit(pane.getEditorKit());
try {
Position startPos = doc.createPosition(4); // Line begining
Position endPos = doc.createPosition(8); // Line boundary too
toolTipPane.putClientProperty("document-view-start-position", startPos);
toolTipPane.putClientProperty("document-view-end-position", endPos);
toolTipPane.setDocument(doc);
JFrame toolTipFrame = new JFrame("ToolTip Frame");
toolTipFrameRef[0] = toolTipFrame;
toolTipFrame.getContentPane().add(new JScrollPane(toolTipPane));
toolTipFrame.setSize(100, 100);
toolTipFrame.setVisible(true);
doc.insertString(4, "o", null);
toolTipPane.setFont(new Font("Monospaced", Font.PLAIN, 22)); // Force VH rebuild
toolTipPane.modelToView(6);
doc.remove(3, 3);
doc.insertString(4, "ab", null);
assert (endPos.getOffset() == 8);
doc.remove(7, 2);
toolTipPane.setFont(new Font("Monospaced", Font.PLAIN, 23)); // Force VH rebuild
toolTipPane.modelToView(6);
} catch (BadLocationException ex) {
excRef[0] = ex;
}
}
};
SwingUtilities.invokeAndWait(tooltipRun);
if (excRef[0] != null) {
throw new IllegalStateException(excRef[0]);
}
DocumentTesting.setSameThreadInvoke(context, false);
DocumentTesting.undo(context, 2);
DocumentTesting.undo(context, 1);
DocumentTesting.undo(context, 1);
DocumentTesting.redo(context, 4);
// Hide tooltip's frame
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (toolTipFrameRef[0] != null) {
toolTipFrameRef[0].setVisible(false);
}
}
});
}