public void openAst(DetailAST parseTree) {
    parseTreeModel.setParseTree(parseTree);
    reloadAction.setEnabled(true);

    // clear for each new file
    clearLinesToPosition();
    // starts line counting at 1
    addLineToPosition(0);
    // insert the contents of the file to the text area

    // clean the text area before inserting the lines of the new file
    if (!textArea.getText().isEmpty()) {
      textArea.replaceRange("", 0, textArea.getText().length());
    }

    // move back to the top of the file
    textArea.moveCaretPosition(0);
  }
  public void openFile(File file, final Component parent) {
    if (file != null) {
      try {
        Main.getFrame().setTitle("Checkstyle : " + file.getName());
        final FileText text = new FileText(file.getAbsoluteFile(), getEncoding());
        final DetailAST parseTree = parseFile(text);
        parseTreeModel.setParseTree(parseTree);
        currentFile = file;
        lastDirectory = file.getParentFile();
        reloadAction.setEnabled(true);

        final String[] sourceLines = text.toLinesArray();

        // clear for each new file
        clearLinesToPosition();
        // starts line counting at 1
        addLineToPosition(0);
        // insert the contents of the file to the text area
        for (String element : sourceLines) {
          addLineToPosition(textArea.getText().length());
          textArea.append(element + System.lineSeparator());
        }

        // clean the text area before inserting the lines of the new file
        if (!textArea.getText().isEmpty()) {
          textArea.replaceRange("", 0, textArea.getText().length());
        }

        // insert the contents of the file to the text area
        for (final String element : sourceLines) {
          textArea.append(element + System.lineSeparator());
        }

        // move back to the top of the file
        textArea.moveCaretPosition(0);
      } catch (final IOException | ANTLRException ex) {
        showErrorDialog(parent, "Could not parse" + file + ": " + ex.getMessage());
      }
    }
  }