private static void onEntityOpened(KeyEvent event) throws BadLocationException {
  JEditorPane editor=(JEditorPane)event.getSource();
  Document doc=editor.getDocument();
  int pos=editor.getCaretPosition();
  String tag=getCurrentTag(doc.getText(0,pos));
  if (tag.equals("")) {
    return;
  }
  String remainder=doc.getText(pos,doc.getLength() - pos);
  for (int i=0; i < remainder.length(); i++) {
    char c=remainder.charAt(i);
    if (c == '\n') {
      break;
    }
 else     if (!Character.isWhitespace(c)) {
      return;
    }
  }
  StringBuffer buffer=new StringBuffer();
  int newPosition=pos;
  String indent=getIndent(doc,pos);
  if (tag.equals("if")) {
    buffer.append(" var=\"\" relation=\"=\" value=\"\"/>");
    newPosition+=6;
  }
 else   if (tag.equals("set")) {
    buffer.append(" var=\"\" value=\"\"/>");
    newPosition+=6;
  }
 else   if (tag.equals("value")) {
    buffer.append(" prob=\"\"></value>");
    newPosition+=7;
  }
 else   if (tag.equals("variable")) {
    buffer.append(" id=\"\">\n");
    buffer.append(indent + "\t<value prob=\"1\"></value>\n");
    buffer.append(indent + "</variable>\n");
    newPosition+=5;
  }
 else   if (tag.equals("model")) {
    buffer.append(" trigger=\"\">\n\n");
    buffer.append(indent + "</model>");
    newPosition+=10;
  }
 else   if (tag.equals("effect")) {
    buffer.append(" prob=\"1\">\n");
    buffer.append(indent + "\t<set var=\"\" value=\"\"/>\n");
    buffer.append(indent + "</effect>\n");
    newPosition+=22 + indent.length();
  }
 else {
    return;
  }
  doc.insertString(pos,buffer.toString(),null);
  editor.setCaretPosition(newPosition);
  event.consume();
}

private static void onEntityOpened ( KeyEvent event ) throws BadLocationException { JEditorPane editor = ( JEditorPane ) event . getSource ( ) ; Document doc = editor . getDocument ( ) ; int pos = editor . getCaretPosition ( ) ; String tag = getCurrentTag ( doc . getText ( 0 , pos ) ) ; if ( tag . equals ( "" ) ) { return ; } String remainder = doc . getText ( pos , doc . getLength ( ) - pos ) ; for ( int i = 0 ; i < remainder . length ( ) ; i ++ ) { char c = remainder . charAt ( i ) ; if ( c == '\n' ) { break ; } else if ( ! Character . isWhitespace ( c ) ) { return ; } } StringBuffer buffer = new StringBuffer ( ) ; int newPosition = pos ; String indent = getIndent ( doc , pos ) ; if ( tag . equals ( "if" ) ) { buffer . append ( " var=\"\" relation=\"=\" value=\"\"/>" ) ; newPosition += 6 ; } else if ( tag . equals ( "set" ) ) { buffer . append ( " var=\"\" value=\"\"/>" ) ; newPosition += 6 ; } else if ( tag . equals ( "value" ) ) { buffer . append ( " prob=\"\"></value>" ) ; newPosition += 7 ; } else if ( tag . equals ( "variable" ) ) { buffer . append ( " id=\"\">\n" ) ; buffer . append ( indent + "\t<value prob=\"1\"></value>\n" ) ; buffer . append ( indent + "</variable>\n" ) ; newPosition += 5 ; } else if ( tag . equals ( "model" ) ) { buffer . append ( " trigger=\"\">\n\n" ) ; buffer . append ( indent + "</model>" ) ; newPosition += 10 ; } else if ( tag . equals ( "effect" ) ) { buffer . append ( " prob=\"1\">\n" ) ; buffer . append ( indent + "\t<set var=\"\" value=\"\"/>\n" ) ; buffer . append ( indent + "</effect>\n" ) ; newPosition += 22 + indent . length ( ) ; } else { return ; } doc . insertString ( pos , buffer . toString ( ) , null ) ; editor . setCaretPosition ( newPosition ) ; event . consume ( ) ; }
reacts to an empty space event . if the space is typed within a tag that is a ' if ' , ' set ' , ' value ' , ' variable ' , or ' effect ' , auto - completes the entity structure .
