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);
}
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;}");
}
}
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;
}
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);
}
}
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());
}
}
Aggregations