From ef791720f010bcc2a05da76cac8021085bc71155 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Sun, 2 Jul 2006 11:52:19 +0000 Subject: [PATCH] Patch to add a TextArea to the GUI. --- .../tools/checkstyle/gui/JTreeTable.java | 6 ++- .../puppycrawl/tools/checkstyle/gui/Main.java | 4 +- .../checkstyle/gui/ParseTreeInfoPanel.java | 37 ++++++++++++++++--- .../tools/checkstyle/gui/ParseTreeModel.java | 3 +- src/xdocs/releasenotes.xml | 5 +++ 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/JTreeTable.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/JTreeTable.java index 3927c20e1..900a54e87 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/JTreeTable.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/JTreeTable.java @@ -218,8 +218,10 @@ public class JTreeTable extends JTable { if (newRowHeight > 0) { super.setRowHeight(newRowHeight); - if (getRowHeight() != newRowHeight) { - setRowHeight(getRowHeight()); + if ((JTreeTable.this != null) && + (JTreeTable.this.getRowHeight() != newRowHeight)) + { + JTreeTable.this.setRowHeight(getRowHeight()); } } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/Main.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/Main.java index 77b6b85b7..83a3ffbed 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/Main.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/Main.java @@ -28,9 +28,11 @@ import javax.swing.JFrame; */ public class Main { + static JFrame frame; + public static void main(String[] args) { - final JFrame frame = new JFrame("CheckStyle"); + frame = new JFrame("CheckStyle"); final ParseTreeInfoPanel panel = new ParseTreeInfoPanel(); frame.getContentPane().add(panel); if (args.length >= 1) { diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/ParseTreeInfoPanel.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/ParseTreeInfoPanel.java index 57c7deccd..51e27691f 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/ParseTreeInfoPanel.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/ParseTreeInfoPanel.java @@ -37,6 +37,7 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter; +import javax.swing.JTextArea; import antlr.ANTLRException; @@ -56,6 +57,7 @@ public class ParseTreeInfoPanel extends JPanel { private JTreeTable mTreeTable; private ParseTreeModel mParseTreeModel; + private JTextArea mJTextArea; private File mLastDirectory = null; private File mCurrentFile = null; private final Action reloadAction; @@ -94,6 +96,7 @@ public class ParseTreeInfoPanel extends JPanel fc.showDialog(parent, "Open"); File file = fc.getSelectedFile(); openFile(file, parent); + } } @@ -104,7 +107,7 @@ public class ParseTreeInfoPanel extends JPanel super("Reload Java File"); putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R)); } - + public void actionPerformed(ActionEvent e) { final Component parent = @@ -133,15 +136,32 @@ public class ParseTreeInfoPanel extends JPanel } } + public void openFile(File aFile, final Component aParent) { if (aFile != null) { try { - DetailAST parseTree = parseFile(aFile.getAbsolutePath()); + Main.frame.setTitle("Checkstyle : " + aFile.getName()); + final DetailAST parseTree = parseFile(aFile.getAbsolutePath()); mParseTreeModel.setParseTree(parseTree); mCurrentFile = aFile; mLastDirectory = aFile.getParentFile(); reloadAction.setEnabled(true); + + String[] sourceLines = Utils.getLines(aFile.getAbsolutePath()); + //clean the text area before inserting the lines of the new file + if (mJTextArea.getText().length() != 0) { + mJTextArea.replaceRange("", 0, mJTextArea.getText() + .length()); + } + + // insert the contents of the file to the text area + for (int i = 0; i < sourceLines.length; i++) { + mJTextArea.append(sourceLines[i] + "\n"); + } + + // move back to the top of the file + mJTextArea.moveCaretPosition(0); } catch (IOException ex) { showErrorDialog( @@ -182,10 +202,7 @@ public class ParseTreeInfoPanel extends JPanel mParseTreeModel = new ParseTreeModel(treeRoot); mTreeTable = new JTreeTable(mParseTreeModel); final JScrollPane sp = new JScrollPane(mTreeTable); - this.add(sp, BorderLayout.CENTER); - - final JPanel p = new JPanel(new GridLayout(1,2)); - this.add(p, BorderLayout.SOUTH); + this.add(sp, BorderLayout.NORTH); final JButton fileSelectionButton = new JButton(new FileSelectionAction()); @@ -194,6 +211,14 @@ public class ParseTreeInfoPanel extends JPanel reloadAction.setEnabled(false); final JButton reloadButton = new JButton(reloadAction); + mJTextArea = new JTextArea(20, 15); + mJTextArea.setEditable(false); + + final JScrollPane sp2 = new JScrollPane(mJTextArea); + this.add(sp2, BorderLayout.CENTER); + + final JPanel p = new JPanel(new GridLayout(1,2)); + this.add(p, BorderLayout.SOUTH); p.add(fileSelectionButton); p.add(reloadButton); diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/ParseTreeModel.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/ParseTreeModel.java index b3c30ff40..7fb947e27 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/ParseTreeModel.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/ParseTreeModel.java @@ -28,7 +28,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; * The model that backs the parse tree in the GUI. * * @author Lars Kühne - * @version $Id: ParseTreeModel.java,v 1.5 2004-06-22 11:13:58 rickgiles Exp $ + * @version $Id: ParseTreeModel.java,v 1.6 2006-07-02 11:52:19 oburn Exp $ */ public class ParseTreeModel extends AbstractTreeTableModel { @@ -55,7 +55,6 @@ public class ParseTreeModel extends AbstractTreeTableModel DetailAST root = (DetailAST) getRoot(); root.setFirstChild(parseTree); Object[] path = {root}; - // no need to setup remaining info, as the call results in a // table structure changed event anyway - we just pass nulls fireTreeStructureChanged(this, path, null, null); diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index 3b6134315..570bd687d 100755 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -55,6 +55,11 @@
  • Upgraded to ANTLR 2.7.6.
  • + +
  • + GUI now displays a TextArea with the contents of the file + parsed. Based on patch from sermojohn (RFE 1499180). +
  • Fixed Bugs: