Search in sources :

Example 1 with EditorKit

use of javax.swing.text.EditorKit in project pcgen by PCGen.

the class InfoPane method setText.

public void setText(String text) {
    //This is done so the vertical scroll bar goes back up to the top when the text is changed
    EditorKit kit = textPane.getEditorKit();
    Document newDoc = kit.createDefaultDocument();
    try {
        kit.read(new StringReader(text), newDoc, 0);
    } catch (IOException | BadLocationException ex) {
        throw new UnreachableError(ex);
    }
    textPane.setDocument(newDoc);
}
Also used : EditorKit(javax.swing.text.EditorKit) StringReader(java.io.StringReader) IOException(java.io.IOException) UnreachableError(pcgen.base.lang.UnreachableError) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 2 with EditorKit

use of javax.swing.text.EditorKit in project intellij-community by JetBrains.

the class JBLabel method updateStyle.

private void updateStyle(@NotNull JEditorPane pane) {
    EditorKit kit = pane.getEditorKit();
    if (kit instanceof HTMLEditorKit) {
        StyleSheet css = ((HTMLEditorKit) kit).getStyleSheet();
        css.addRule("body, p {" + "color:#" + ColorUtil.toHex(getForeground()) + ";" + "font-family:" + getFont().getFamily() + ";" + "font-size:" + getFont().getSize() + "pt;" + "white-space:nowrap;}");
    }
}
Also used : EditorKit(javax.swing.text.EditorKit) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) StyleSheet(javax.swing.text.html.StyleSheet) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit)

Example 3 with EditorKit

use of javax.swing.text.EditorKit in project jdk8u_jdk by JetBrains.

the class TextComponentPrintable method createPrintShellOnEDT.

private JTextComponent createPrintShellOnEDT(final JTextComponent textComponent) {
    assert SwingUtilities.isEventDispatchThread();
    JTextComponent ret = null;
    if (textComponent instanceof JPasswordField) {
        ret = new JPasswordField() {

            {
                setEchoChar(((JPasswordField) textComponent).getEchoChar());
                setHorizontalAlignment(((JTextField) textComponent).getHorizontalAlignment());
            }

            @Override
            public FontMetrics getFontMetrics(Font font) {
                return (frc.get() == null) ? super.getFontMetrics(font) : FontDesignMetrics.getMetrics(font, frc.get());
            }
        };
    } else if (textComponent instanceof JTextField) {
        ret = new JTextField() {

            {
                setHorizontalAlignment(((JTextField) textComponent).getHorizontalAlignment());
            }

            @Override
            public FontMetrics getFontMetrics(Font font) {
                return (frc.get() == null) ? super.getFontMetrics(font) : FontDesignMetrics.getMetrics(font, frc.get());
            }
        };
    } else if (textComponent instanceof JTextArea) {
        ret = new JTextArea() {

            {
                JTextArea textArea = (JTextArea) textComponent;
                setLineWrap(textArea.getLineWrap());
                setWrapStyleWord(textArea.getWrapStyleWord());
                setTabSize(textArea.getTabSize());
            }

            @Override
            public FontMetrics getFontMetrics(Font font) {
                return (frc.get() == null) ? super.getFontMetrics(font) : FontDesignMetrics.getMetrics(font, frc.get());
            }
        };
    } else if (textComponent instanceof JTextPane) {
        ret = new JTextPane() {

            @Override
            public FontMetrics getFontMetrics(Font font) {
                return (frc.get() == null) ? super.getFontMetrics(font) : FontDesignMetrics.getMetrics(font, frc.get());
            }

            @Override
            public EditorKit getEditorKit() {
                if (getDocument() == textComponent.getDocument()) {
                    return ((JTextPane) textComponent).getEditorKit();
                } else {
                    return super.getEditorKit();
                }
            }
        };
    } else if (textComponent instanceof JEditorPane) {
        ret = new JEditorPane() {

            @Override
            public FontMetrics getFontMetrics(Font font) {
                return (frc.get() == null) ? super.getFontMetrics(font) : FontDesignMetrics.getMetrics(font, frc.get());
            }

            @Override
            public EditorKit getEditorKit() {
                if (getDocument() == textComponent.getDocument()) {
                    return ((JEditorPane) textComponent).getEditorKit();
                } else {
                    return super.getEditorKit();
                }
            }
        };
    }
    //want to occupy the whole width and height by text
    ret.setBorder(null);
    //set properties from the component to print
    ret.setOpaque(textComponent.isOpaque());
    ret.setEditable(textComponent.isEditable());
    ret.setEnabled(textComponent.isEnabled());
    ret.setFont(textComponent.getFont());
    ret.setBackground(textComponent.getBackground());
    ret.setForeground(textComponent.getForeground());
    ret.setComponentOrientation(textComponent.getComponentOrientation());
    if (ret instanceof JEditorPane) {
        ret.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, textComponent.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES));
        ret.putClientProperty(JEditorPane.W3C_LENGTH_UNITS, textComponent.getClientProperty(JEditorPane.W3C_LENGTH_UNITS));
        ret.putClientProperty("charset", textComponent.getClientProperty("charset"));
    }
    ret.setDocument(textComponent.getDocument());
    return ret;
}
Also used : EditorKit(javax.swing.text.EditorKit) FontMetrics(java.awt.FontMetrics) JTextComponent(javax.swing.text.JTextComponent) Font(java.awt.Font)

Example 4 with EditorKit

use of javax.swing.text.EditorKit in project adempiere by adempiere.

the class CompiereTextAreaUI method updateFocusTraversalKeysX.

//	propertyChange
/**
     * 	UpdateFocusTraversalKeysX
     */
void updateFocusTraversalKeysX() {
    if (m_editor == null)
        return;
    //
    EditorKit editorKit = getEditorKit(m_editor);
    if (editorKit != null && editorKit instanceof DefaultEditorKit) {
        Set<AWTKeyStroke> storedForwardTraversalKeys = m_editor.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
        Set<AWTKeyStroke> storedBackwardTraversalKeys = m_editor.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
        Set<AWTKeyStroke> forwardTraversalKeys = new HashSet<AWTKeyStroke>(storedForwardTraversalKeys);
        Set<AWTKeyStroke> backwardTraversalKeys = new HashSet<AWTKeyStroke>(storedBackwardTraversalKeys);
        //
        forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
        forwardTraversalKeys.remove(s_stroke);
        backwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
        //
        LookAndFeel.installProperty(m_editor, "focusTraversalKeysForward", forwardTraversalKeys);
        LookAndFeel.installProperty(m_editor, "focusTraversalKeysBackward", backwardTraversalKeys);
    }
}
Also used : EditorKit(javax.swing.text.EditorKit) DefaultEditorKit(javax.swing.text.DefaultEditorKit) AWTKeyStroke(java.awt.AWTKeyStroke) DefaultEditorKit(javax.swing.text.DefaultEditorKit) HashSet(java.util.HashSet)

Example 5 with EditorKit

use of javax.swing.text.EditorKit in project adempiere by adempiere.

the class HTMLEditor_MenuAction method cmd_export.

//	cmd_import
/**
	 *	Export Text to File
	 */
private void cmd_export() {
    JFileChooser jc = new JFileChooser();
    jc.setDialogTitle(Msg.getMsg(Env.getCtx(), "Export"));
    jc.setDialogType(JFileChooser.SAVE_DIALOG);
    jc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    //
    if (jc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
        return;
    try {
        EditorKit kit = editorPane.getEditorKit();
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(jc.getSelectedFile()));
        editorPane.write(writer);
        writer.flush();
        writer.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, "HTMLEditor.export" + e.getMessage());
    }
}
Also used : HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) EditorKit(javax.swing.text.EditorKit) JFileChooser(javax.swing.JFileChooser) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

EditorKit (javax.swing.text.EditorKit)5 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)2 AWTKeyStroke (java.awt.AWTKeyStroke)1 Font (java.awt.Font)1 FontMetrics (java.awt.FontMetrics)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 JFileChooser (javax.swing.JFileChooser)1 BadLocationException (javax.swing.text.BadLocationException)1 DefaultEditorKit (javax.swing.text.DefaultEditorKit)1 Document (javax.swing.text.Document)1 JTextComponent (javax.swing.text.JTextComponent)1 StyleSheet (javax.swing.text.html.StyleSheet)1 UnreachableError (pcgen.base.lang.UnreachableError)1