/** * A convience method to read a font from a style. * * @param style Style being modified * @return The font inside the passed style */ public static String getFontString(Style style) { String font = StyleConstants.getFontFamily(style) + "-"; if (StyleConstants.isBold(style)) font += "BOLD"; if (StyleConstants.isItalic(style)) font += "ITALIC"; if (!StyleConstants.isBold(style) && !StyleConstants.isItalic(style)) font += "PLAIN"; font += "-" + StyleConstants.getFontSize(style); return font; }
@Override public void actionPerformed(ActionEvent e) { JEditorPane editor = getEditor(e); if (editor != null) { StyledEditorKit kit = getStyledEditorKit(editor); MutableAttributeSet attr = kit.getInputAttributes(); isItalic = (StyleConstants.isItalic(attr)) ? false : true; SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setItalic(sas, isItalic); setCharacterAttributes(editor, sas, false); boolean isEnabling = (StyleConstants.isBold(attr)) ? false : true; Integer position = getCursorPosition(); if (editor != null && editor.getSelectedText() != null && editor.getSelectedText().length() > 0) controller.sendStyleChangeRequest( currentDocID, StyleChange.StyleType.ITALIC, isEnabling, position, editor.getSelectedText().length()); updateDocToDataModel(); } }
/** * Diese Methode prüft ob eine Stelle im Text kursiv ist * * @param pos (int) welche position soll abgefragt werden * @return (boolean) kursiv true / false */ public boolean isItalic(int pos) { Element element = getCharacterElement(pos); return StyleConstants.isItalic(element.getAttributes()); }