/**
  * 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;
 }
示例#2
0
 @Override
 public void actionPerformed(ActionEvent e) {
   JEditorPane editor = getEditor(e);
   if (editor != null) {
     StyledEditorKit kit = getStyledEditorKit(editor);
     MutableAttributeSet attr = kit.getInputAttributes();
     isBold = (StyleConstants.isBold(attr)) ? false : true;
     SimpleAttributeSet sas = new SimpleAttributeSet();
     StyleConstants.setBold(sas, isBold);
     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.BOLD,
           isEnabling,
           position,
           editor.getSelectedText().length());
     updateDocToDataModel();
   }
 }
示例#3
0
 /**
  * Diese Methode prüft ob eine Stelle im Text fett ist
  *
  * @param pos (int) welche position soll abgefragt werden
  * @return (boolean) fett true / false
  */
 public boolean isBold(int pos) {
   Element element = getCharacterElement(pos);
   return StyleConstants.isBold(element.getAttributes());
 }