示例#1
0
 public void insertStyle(String styleName, String value) {
   if (currentEditor.getValue().getMediaType().equals(MediaType.XHTML)) {
     XHTMLCodeEditor xhtmlCodeEditor = (XHTMLCodeEditor) currentEditor.getValue();
     XMLTagPair pair =
         xhtmlCodeEditor.findSurroundingTags(new XHTMLCodeEditor.BlockTagInspector());
     if (pair != null) {
       logger.info("found xml block tag " + pair.getTagName());
       String tagAtttributes =
           xhtmlCodeEditor.getRange(pair.getOpenTagEnd(), pair.getTagAttributesEnd());
       if (tagAtttributes.contains(
           "style=")) // wenn bereits styles vorhanden, dann diese modifizieren
       {
         tagAtttributes =
             tagAtttributes.replaceAll(
                 "style\\s*=\\s*\"(.*)" + styleName + ":([^;]*)(;?)(.*)\\s*\"",
                 "style=\"$1" + styleName + ":" + value + "$3$4\"");
         xhtmlCodeEditor.replaceRange(
             tagAtttributes, pair.getOpenTagEnd(), pair.getTagAttributesEnd());
       } else {
         EditorPosition pos =
             new EditorPosition(
                 pair.getOpenTagBegin().getLine(),
                 pair.getOpenTagBegin().getColumn() + pair.getTagName().length());
         xhtmlCodeEditor.insertAt(" style=\"" + styleName + ":" + value + "\"", pos);
       }
       refreshPreview();
       xhtmlCodeEditor.requestFocus();
     }
   }
 }
示例#2
0
 public void surroundSelectionWithTag(String tagName) {
   if (currentEditor.getValue().getMediaType().equals(MediaType.XHTML)) {
     XHTMLCodeEditor xhtmlCodeEditor = (XHTMLCodeEditor) currentEditor.getValue();
     EditorRange range = xhtmlCodeEditor.getSelection();
     xhtmlCodeEditor.replaceRange(
         "<" + tagName + ">" + range.getSelection() + "</" + tagName + ">",
         range.getFrom(),
         range.getTo());
     refreshPreview();
     xhtmlCodeEditor.requestFocus();
   }
 }
示例#3
0
 public void surroundParagraphWithTag(String tagName) {
   if (currentEditor.getValue().getMediaType().equals(MediaType.XHTML)) {
     XHTMLCodeEditor xhtmlCodeEditor = (XHTMLCodeEditor) currentEditor.getValue();
     XMLTagPair pair =
         xhtmlCodeEditor.findSurroundingTags(new XHTMLCodeEditor.BlockTagInspector());
     if (pair != null) {
       logger.info("found xml block tag " + pair.getTagName());
       // erst das schließende Tag ersetzen, da sich sonst die Koordinaten verschieben können
       xhtmlCodeEditor.replaceRange(tagName, pair.getCloseTagBegin(), pair.getCloseTagEnd());
       xhtmlCodeEditor.replaceRange(tagName, pair.getOpenTagBegin(), pair.getOpenTagEnd());
       refreshPreview();
     }
   }
 }