Пример #1
0
 /** {@inheritDoc} */
 @Override
 public void actionPerformed(ActionEvent e) {
   JTextComponent target = getTextComponent(e);
   if (target != null) {
     SyntaxDocument sDoc = ActionUtils.getSyntaxDocument(target);
     int pos = target.getCaretPosition();
     int start = sDoc.getParagraphElement(pos).getStartOffset();
     String line = ActionUtils.getLine(target);
     if (ActionUtils.isEmptyOrBlanks(line)) {
       try {
         sDoc.insertString(pos, "}", null);
         Token t = sDoc.getPairFor(sDoc.getTokenAt(pos));
         if (null != t) {
           String pairLine = ActionUtils.getLineAt(target, t.start);
           String indent = ActionUtils.getIndent(pairLine);
           sDoc.replace(start, line.length() + 1, indent + "}", null);
         }
       } catch (BadLocationException ble) {
         target.replaceSelection("}");
       }
     } else {
       target.replaceSelection("}");
     }
   }
 }
Пример #2
0
 /**
  * Replace the token with the replacement string
  *
  * @param token
  * @param replacement
  */
 public void replaceToken(Token token, String replacement) {
   try {
     replace(token.start, token.length, replacement, null);
   } catch (BadLocationException ex) {
     log.log(Level.WARNING, "unable to replace token: " + token, ex);
   }
 }
Пример #3
0
 /**
  * Replace the line at given position with the given string, which can span multiple lines
  *
  * @param pos
  * @param newLines
  * @throws javax.swing.text.BadLocationException
  */
 public void replaceLineAt(int pos, String newLines) throws BadLocationException {
   Element e = getParagraphElement(pos);
   replace(e.getStartOffset(), getElementLength(e), newLines, null);
 }