Java Code Examples for javax.swing.JEditorPane#getEditorKit()

The following examples show how to use javax.swing.JEditorPane#getEditorKit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorSanityTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testPlainEditorKits() {
    // VIS: JEditorPane when constructed contains javax.swing.JEditorPane$PlainEditorKit
    // and calling JEP.setContenetType("text/plain") has no effect. IMO this is probably
    // a defect in JDK, becuase JEP should always honour its EditorKit registry.
    JEditorPane pane = new JEditorPane();
    pane.setEditorKit(new DefaultEditorKit() {
        public @Override String getContentType() {
            return "text/whatever";
        }
    });
    setContentTypeInAwt(pane, "text/plain");
    
    // Test JDK kit
    EditorKit kitFromJdk = pane.getEditorKit();
    assertNotNull("Can't find JDK kit for text/plain", kitFromJdk);
    assertEquals("The kit for text/plain should not be from JDK", 
        "org.netbeans.modules.editor.plain.PlainKit", kitFromJdk.getClass().getName());

    // Test Netbeans kit
    EditorKit kitFromNb = CloneableEditorSupport.getEditorKit("text/plain");
    assertNotNull("Can't find Nb kit for text/plain", kitFromNb);
    assertEquals("Wrong Nb kit for text/plain", 
        "org.netbeans.modules.editor.plain.PlainKit", kitFromNb.getClass().getName());
}
 
Example 2
Source File: StyledEditorKit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 3
Source File: StyledEditorKit.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 4
Source File: StyledEditorKit.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 5
Source File: ToggleComponentAction.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    JTextComponent target = getTextComponent(e);
    if (target instanceof JEditorPane) {
        JEditorPane jEditorPane = (JEditorPane) target;
        DefaultSyntaxKit kit = (DefaultSyntaxKit) jEditorPane.getEditorKit();
        boolean status = kit.toggleComponent(jEditorPane, componentName);
        putValue(SELECTED_KEY, status);
    }
}
 
Example 6
Source File: StyledEditorKit.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 7
Source File: StyledEditorKit.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 8
Source File: StyledEditorKit.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 9
Source File: EditorSanityTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testApplicationRtfEditorKits() {
    JEditorPane pane = new JEditorPane();
    setContentTypeInAwt(pane, "application/rtf");
    
    // Test JDK kit
    EditorKit kitFromJdk = pane.getEditorKit();
    assertNotNull("Can't find JDK kit for application/rtf", kitFromJdk);
    assertTrue("Wrong JDK kit for application/rtf", kitFromJdk instanceof RTFEditorKit);
}
 
Example 10
Source File: EditorSanityTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testTextRtfEditorKits() {
    JEditorPane pane = new JEditorPane();
    setContentTypeInAwt(pane, "text/rtf");
    
    // Test JDK kit
    EditorKit kitFromJdk = pane.getEditorKit();
    assertNotNull("Can't find JDK kit for text/rtf", kitFromJdk);
    assertTrue("Wrong JDK kit for application/rtf", kitFromJdk instanceof RTFEditorKit);
}
 
Example 11
Source File: StyledEditorKit.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 12
Source File: NbEditorDocument.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Component createEditor(JEditorPane j) {
    EditorUI editorUI = Utilities.getEditorUI(j);
    if (editorUI == null) { // Editor kit not installed yet??
        javax.swing.plaf.TextUI ui = j.getUI();
        javax.swing.text.EditorKit kit = j.getEditorKit();
        throw new IllegalStateException("NbEditorDocument.createEditor(): ui=" + ui + // NOI18N
                ", kit=" + kit + ", pane=" + j); // NOI18N
    }
    return editorUI.getExtComponent();
}
 
Example 13
Source File: FoldView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 14
Source File: StyledEditorKit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 15
Source File: StyledEditorKit.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 16
Source File: StyledEditorKit.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 17
Source File: StyledEditorKit.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the editor kit associated with an editor pane.
 *
 * @param e the editor pane
 * @return the kit
 * @exception IllegalArgumentException for the wrong document type
 */
protected final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    EditorKit k = e.getEditorKit();
    if (k instanceof StyledEditorKit) {
        return (StyledEditorKit) k;
    }
    throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
}
 
Example 18
Source File: ActionUtils.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return the DefaultSyntaxKit of this target, or null if the target does not
 * have a DefaultSyntaxKit
 * @param target
 * @return kit or null
 */
public static DefaultSyntaxKit getSyntaxKit(JTextComponent target) {
	DefaultSyntaxKit kit = null;
	if (target instanceof JEditorPane) {
		JEditorPane jEditorPane = (JEditorPane) target;
		EditorKit k = jEditorPane.getEditorKit();
		if (k instanceof DefaultSyntaxKit) {
			 kit = (DefaultSyntaxKit) k;
		}
	}
	return kit;
}
 
Example 19
Source File: CslTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void runKitAction(JEditorPane jt, String actionName, String cmd) {
    BaseKit kit = (BaseKit)jt.getEditorKit();
    Action a = kit.getActionByName(actionName);
    assertNotNull(a);
    a.actionPerformed(new ActionEvent(jt, 0, cmd));
}
 
Example 20
Source File: BaseTextUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Fetches the EditorKit for the UI.
*
* @return the component capabilities
*/
public @Override EditorKit getEditorKit(JTextComponent c) {
    JEditorPane pane = (JEditorPane)getComponent();
    return (pane == null) ? null : pane.getEditorKit();
}