コード例 #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("}");
     }
   }
 }