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