/** Create a new ParseTreeInfoPanel instance. */
  public ParseTreeInfoPanel() {
    setLayout(new BorderLayout());

    parseTreeModel = new ParseTreeModel(null);
    final JTreeTable treeTable = new JTreeTable(parseTreeModel);
    final JScrollPane sp = new JScrollPane(treeTable);
    add(sp, BorderLayout.PAGE_START);

    final JButton fileSelectionButton = new JButton(new FileSelectionAction());

    reloadAction = new ReloadAction();
    reloadAction.setEnabled(false);
    final JButton reloadButton = new JButton(reloadAction);

    textArea = new JTextArea(20, 15);
    textArea.setEditable(false);
    treeTable.setEditor(textArea);
    treeTable.setLinePositionMap(linesToPosition);

    final JScrollPane sp2 = new JScrollPane(textArea);
    add(sp2, BorderLayout.CENTER);

    final JPanel p = new JPanel(new GridLayout(1, 2));
    add(p, BorderLayout.PAGE_END);
    p.add(fileSelectionButton);
    p.add(reloadButton);

    try {
      new FileDrop(sp, new FileDropListener(sp));
    } catch (final TooManyListenersException ignored) {
      showErrorDialog(null, "Cannot initialize Drag and Drop support");
    }
  }
  /** Create a new ParseTreeInfoPanel instance. */
  public ParseTreeInfoPanel() {
    setLayout(new BorderLayout());

    parseTreeModel = new ParseTreeModel(null);
    final JTreeTable treeTable = new JTreeTable(parseTreeModel);
    final JScrollPane scrollPane = new JScrollPane(treeTable);
    add(scrollPane, BorderLayout.PAGE_START);

    final JButton fileSelectionButton = new JButton(new FileSelectionAction());

    reloadAction = new ReloadAction();
    reloadAction.setEnabled(false);
    final JButton reloadButton = new JButton(reloadAction);

    textArea = new JTextArea(20, 15);
    textArea.setEditable(false);
    treeTable.setEditor(textArea);
    treeTable.setLinePositionMap(linesToPosition);

    final JScrollPane sp2 = new JScrollPane(textArea);
    add(sp2, BorderLayout.CENTER);

    final JPanel pane = new JPanel(new GridLayout(1, 2));
    add(pane, BorderLayout.PAGE_END);
    pane.add(fileSelectionButton);
    pane.add(reloadButton);
  }
  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());
      }
    }
  }