Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |
file stats: | LOC: | 154 |  | Methods: | 6
| NCLOC: | 121 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
MainFrame.java | 0% | 0% | 0% | 0% |

1 |  | package net.sourceforge.pmd.util.viewer.gui;
2 |  |
3 |  | import net.sourceforge.pmd.TargetJDK1_3;
4 |  | import net.sourceforge.pmd.TargetJDK1_4;
5 |  | import net.sourceforge.pmd.TargetJDK1_5;
6 |  | import net.sourceforge.pmd.TargetJDKVersion;
7 |  | import net.sourceforge.pmd.ast.ParseException;
8 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModel;
9 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
10 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
11 |  | import net.sourceforge.pmd.util.viewer.util.NLS;
12 |  |
13 |  | import javax.swing.*;
14 |  | import java.awt.BorderLayout;
15 |  | import java.awt.FlowLayout;
16 |  | import java.awt.event.ActionEvent;
17 |  | import java.awt.event.ActionListener;
18 |  |
19 |  |
20 |  | /**
21 |  | * viewer's main frame
22 |  | *
23 |  | * @author Boris Gruschko ( boris at gruschko.org )
24 |  | * @version $Id: MainFrame.java,v 1.13 2006/02/10 14:15:31 tomcopeland Exp $
25 |  | */
26 |  |
27 |  | public class MainFrame
28 |  | extends JFrame
29 |  | implements ActionListener, ActionCommands, ViewerModelListener {
30 |  | private ViewerModel model;
31 |  | private SourceCodePanel sourcePanel;
32 |  | private ASTPanel astPanel;
33 |  | private XPathPanel xPathPanel;
34 |  | private JButton compileBtn;
35 |  | private JButton evalBtn;
36 |  | private JLabel statusLbl;
37 |  | private JRadioButtonMenuItem jdk13MenuItem;
38 |  | private JRadioButtonMenuItem jdk14MenuItem;
39 |  | private JRadioButtonMenuItem jdk15MenuItem;
40 |  |
41 |  | /**
42 |  | * constructs and shows the frame
43 |  | */
44 | 0 | public MainFrame() {
45 | 0 | super(NLS.nls("MAIN.FRAME.TITLE"));
46 | 0 | init();
47 |  | }
48 |  |
49 | 0 | private void init() {
50 | 0 | model = new ViewerModel();
51 | 0 | model.addViewerModelListener(this);
52 | 0 | sourcePanel = new SourceCodePanel(model);
53 | 0 | astPanel = new ASTPanel(model);
54 | 0 | xPathPanel = new XPathPanel(model);
55 | 0 | getContentPane().setLayout(new BorderLayout());
56 | 0 | JSplitPane editingPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sourcePanel, astPanel);
57 | 0 | editingPane.setResizeWeight(0.5d);
58 | 0 | JPanel interactionsPane = new JPanel(new BorderLayout());
59 | 0 | interactionsPane.add(xPathPanel, BorderLayout.SOUTH);
60 | 0 | interactionsPane.add(editingPane, BorderLayout.CENTER);
61 | 0 | getContentPane().add(interactionsPane, BorderLayout.CENTER);
62 | 0 | compileBtn = new JButton(NLS.nls("MAIN.FRAME.COMPILE_BUTTON.TITLE"));
63 | 0 | compileBtn.setActionCommand(COMPILE_ACTION);
64 | 0 | compileBtn.addActionListener(this);
65 | 0 | evalBtn = new JButton(NLS.nls("MAIN.FRAME.EVALUATE_BUTTON.TITLE"));
66 | 0 | evalBtn.setActionCommand(EVALUATE_ACTION);
67 | 0 | evalBtn.addActionListener(this);
68 | 0 | evalBtn.setEnabled(false);
69 | 0 | statusLbl = new JLabel();
70 | 0 | statusLbl.setHorizontalAlignment(SwingConstants.RIGHT);
71 | 0 | JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
72 | 0 | btnPane.add(compileBtn);
73 | 0 | btnPane.add(evalBtn);
74 | 0 | btnPane.add(statusLbl);
75 | 0 | getContentPane().add(btnPane, BorderLayout.SOUTH);
76 |  |
77 | 0 | JMenuBar menuBar = new JMenuBar();
78 | 0 | JMenu menu = new JMenu("JDK");
79 | 0 | ButtonGroup group = new ButtonGroup();
80 | 0 | jdk13MenuItem = new JRadioButtonMenuItem("JDK 1.3");
81 | 0 | jdk13MenuItem.setSelected(false);
82 | 0 | group.add(jdk13MenuItem);
83 | 0 | menu.add(jdk13MenuItem);
84 | 0 | jdk14MenuItem = new JRadioButtonMenuItem("JDK 1.4");
85 | 0 | jdk14MenuItem.setSelected(true);
86 | 0 | group.add(jdk14MenuItem);
87 | 0 | menu.add(jdk14MenuItem);
88 | 0 | jdk15MenuItem = new JRadioButtonMenuItem("JDK 1.5");
89 | 0 | jdk15MenuItem.setSelected(false);
90 | 0 | group.add(jdk15MenuItem);
91 | 0 | menu.add(jdk15MenuItem);
92 | 0 | menuBar.add(menu);
93 | 0 | setJMenuBar(menuBar);
94 |  |
95 | 0 | setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
96 | 0 | pack();
97 | 0 | setSize(800, 600);
98 | 0 | setVisible(true);
99 |  | }
100 |  |
101 | 0 | private TargetJDKVersion createJDKVersion() {
102 | 0 | if (jdk14MenuItem.isSelected()) {
103 | 0 | return new TargetJDK1_4();
104 | 0 | } else if (jdk13MenuItem.isSelected()) {
105 | 0 | return new TargetJDK1_3();
106 |  | }
107 | 0 | return new TargetJDK1_5();
108 |  | }
109 |  |
110 |  | /**
111 |  | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
112 |  | */
113 | 0 | public void actionPerformed(ActionEvent e) {
114 | 0 | String command = e.getActionCommand();
115 | 0 | long t0, t1;
116 | 0 | if (command.equals(COMPILE_ACTION)) {
117 | 0 | try {
118 | 0 | t0 = System.currentTimeMillis();
119 | 0 | model.commitSource(sourcePanel.getSourceCode(), createJDKVersion());
120 | 0 | t1 = System.currentTimeMillis();
121 | 0 | setStatus(NLS.nls("MAIN.FRAME.COMPILATION.TOOK") + " " + (t1 - t0) + " ms");
122 |  | } catch (ParseException exc) {
123 | 0 | setStatus(NLS.nls("MAIN.FRAME.COMPILATION.PROBLEM") + " " + exc.toString());
124 | 0 | new ParseExceptionHandler(this, exc);
125 |  | }
126 | 0 | } else if (command.equals(EVALUATE_ACTION)) {
127 | 0 | try {
128 | 0 | t0 = System.currentTimeMillis();
129 | 0 | model.evaluateXPathExpression(xPathPanel.getXPathExpression(), this);
130 | 0 | t1 = System.currentTimeMillis();
131 | 0 | setStatus(NLS.nls("MAIN.FRAME.EVALUATION.TOOK") + " " + (t1 - t0) + " ms");
132 |  | } catch (Exception exc) {
133 | 0 | setStatus(NLS.nls("MAIN.FRAME.EVALUATION.PROBLEM") + " " + exc.toString());
134 | 0 | new ParseExceptionHandler(this, exc);
135 |  | }
136 |  | }
137 |  | }
138 |  |
139 |  | /**
140 |  | * Sets the status bar message
141 |  | *
142 |  | * @param string the new status, the empty string will be set if the value is <code>null</code>
143 |  | */
144 | 0 | private void setStatus(String string) {
145 | 0 | statusLbl.setText(string == null ? "" : string);
146 |  | }
147 |  |
148 |  | /**
149 |  | * @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
150 |  | */
151 | 0 | public void viewerModelChanged(ViewerModelEvent e) {
152 | 0 | evalBtn.setEnabled(model.hasCompiledTree());
153 |  | }
154 |  | }