1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.dependencyfinder.gui; |
34 |
| |
35 |
| import java.awt.*; |
36 |
| import java.awt.event.*; |
37 |
| import java.io.*; |
38 |
| import javax.swing.*; |
39 |
| import javax.swing.border.*; |
40 |
| import javax.swing.table.*; |
41 |
| import javax.swing.text.*; |
42 |
| |
43 |
| import com.jeantessier.commandline.*; |
44 |
| import com.jeantessier.metrics.*; |
45 |
| import org.apache.log4j.*; |
46 |
| |
47 |
| public class OOMetrics extends JFrame { |
48 |
| private static final TableCellRenderer RENDERER = new MeasurementTableCellRenderer(); |
49 |
| |
50 |
| private MetricsFactory factory; |
51 |
| |
52 |
| private JMenuBar menuBar = new JMenuBar(); |
53 |
| private JMenu fileMenu = new JMenu(); |
54 |
| private JMenu helpMenu = new JMenu(); |
55 |
| private JToolBar toolbar = new JToolBar(); |
56 |
| private JTextArea projectArea = new JTextArea(); |
57 |
| private JButton filterButton = new JButton("Filter:"); |
58 |
| private JTextField filterField = new JTextField("//"); |
59 |
| private StatusLine statusLine = new StatusLine(420); |
60 |
| private JProgressBar progressBar = new JProgressBar(); |
61 |
| |
62 |
| private OOMetricsTableModel groupsModel; |
63 |
| private OOMetricsTableModel classesModel; |
64 |
| private OOMetricsTableModel methodsModel; |
65 |
| |
66 |
| private File inputFile = new File("."); |
67 |
| |
68 |
| private boolean enableCrossClassMeasurements; |
69 |
| |
70 |
0
| public OOMetrics(MetricsFactory factory, boolean enableCrossClassMeasurements) {
|
71 |
0
| this.factory = factory;
|
72 |
0
| this.enableCrossClassMeasurements = enableCrossClassMeasurements;
|
73 |
| |
74 |
0
| this.setSize(new Dimension(800, 600));
|
75 |
0
| this.setTitle("OO Metrics");
|
76 |
0
| this.setIconImage(new ImageIcon(getClass().getResource("icons/logoicon.gif")).getImage());
|
77 |
0
| this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
78 |
0
| this.addWindowListener(new WindowKiller());
|
79 |
| |
80 |
0
| groupsModel = new OOMetricsTableModel(factory.getConfiguration().getGroupMeasurements());
|
81 |
0
| classesModel = new OOMetricsTableModel(factory.getConfiguration().getClassMeasurements());
|
82 |
0
| methodsModel = new OOMetricsTableModel(factory.getConfiguration().getMethodMeasurements());
|
83 |
| |
84 |
0
| buildMenus();
|
85 |
0
| buildUI();
|
86 |
| |
87 |
0
| try {
|
88 |
0
| UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
|
89 |
0
| SwingUtilities.updateComponentTreeUI(this);
|
90 |
| } catch (Exception ex) { |
91 |
0
| Logger.getLogger(OOMetrics.class).error("Unable to set look and feel", ex);
|
92 |
| } |
93 |
| |
94 |
0
| statusLine.showInfo("Ready.");
|
95 |
| } |
96 |
| |
97 |
0
| MetricsFactory getMetricsFactory() {
|
98 |
0
| return factory;
|
99 |
| } |
100 |
| |
101 |
0
| void setMetricsFactory(MetricsFactory factory) {
|
102 |
0
| this.factory = factory;
|
103 |
| } |
104 |
| |
105 |
0
| JTextArea getProjectArea() {
|
106 |
0
| return projectArea;
|
107 |
| } |
108 |
| |
109 |
0
| OOMetricsTableModel getGroupsModel() {
|
110 |
0
| return groupsModel;
|
111 |
| } |
112 |
| |
113 |
0
| OOMetricsTableModel getClassesModel() {
|
114 |
0
| return classesModel;
|
115 |
| } |
116 |
| |
117 |
0
| OOMetricsTableModel getMethodsModel() {
|
118 |
0
| return methodsModel;
|
119 |
| } |
120 |
| |
121 |
0
| File getInputFile() {
|
122 |
0
| return inputFile;
|
123 |
| } |
124 |
| |
125 |
0
| void setInputFile(File inputFile) {
|
126 |
0
| this.inputFile = inputFile;
|
127 |
| } |
128 |
| |
129 |
0
| JTextComponent getFilterField() {
|
130 |
0
| return filterField;
|
131 |
| } |
132 |
| |
133 |
0
| StatusLine getStatusLine() {
|
134 |
0
| return statusLine;
|
135 |
| } |
136 |
| |
137 |
0
| JProgressBar getProgressBar() {
|
138 |
0
| return progressBar;
|
139 |
| } |
140 |
| |
141 |
0
| public boolean isEnableCrossClassMeasurements() {
|
142 |
0
| return enableCrossClassMeasurements;
|
143 |
| } |
144 |
| |
145 |
0
| private void buildMenus() {
|
146 |
0
| buildFileMenu();
|
147 |
0
| buildHelpMenu();
|
148 |
| |
149 |
0
| this.setJMenuBar(menuBar);
|
150 |
| } |
151 |
| |
152 |
0
| private void buildFileMenu() {
|
153 |
0
| menuBar.add(fileMenu);
|
154 |
| |
155 |
0
| fileMenu.setText("File");
|
156 |
| |
157 |
0
| Action action;
|
158 |
0
| JMenuItem menuItem;
|
159 |
0
| JButton button;
|
160 |
| |
161 |
0
| action = new MetricsExtractAction(this);
|
162 |
0
| menuItem = fileMenu.add(action);
|
163 |
0
| menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK));
|
164 |
0
| menuItem.setMnemonic('e');
|
165 |
0
| button = toolbar.add(action);
|
166 |
0
| button.setToolTipText((String) action.getValue(Action.LONG_DESCRIPTION));
|
167 |
| |
168 |
0
| toolbar.addSeparator();
|
169 |
0
| fileMenu.addSeparator();
|
170 |
| |
171 |
0
| action = new NewMetricsAction(this);
|
172 |
0
| menuItem = fileMenu.add(action);
|
173 |
0
| menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
|
174 |
0
| menuItem.setMnemonic('n');
|
175 |
0
| button = toolbar.add(action);
|
176 |
0
| button.setToolTipText((String) action.getValue(Action.LONG_DESCRIPTION));
|
177 |
| |
178 |
0
| toolbar.addSeparator();
|
179 |
0
| fileMenu.addSeparator();
|
180 |
| |
181 |
0
| action = new ExitAction(this);
|
182 |
0
| menuItem = fileMenu.add(action);
|
183 |
0
| menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK));
|
184 |
0
| menuItem.setMnemonic('x');
|
185 |
| |
186 |
0
| this.setJMenuBar(menuBar);
|
187 |
| } |
188 |
| |
189 |
0
| private void buildHelpMenu() {
|
190 |
0
| menuBar.add(helpMenu);
|
191 |
| |
192 |
0
| helpMenu.setText("Help");
|
193 |
| |
194 |
0
| Action action;
|
195 |
0
| JMenuItem menuItem;
|
196 |
| |
197 |
0
| action = new AboutAction(this);
|
198 |
0
| menuItem = helpMenu.add(action);
|
199 |
0
| menuItem.setMnemonic('a');
|
200 |
| } |
201 |
| |
202 |
0
| private void buildUI() {
|
203 |
0
| this.getContentPane().setLayout(new BorderLayout());
|
204 |
0
| this.getContentPane().add(buildControlPanel(), BorderLayout.NORTH);
|
205 |
0
| this.getContentPane().add(buildResultPanel(), BorderLayout.CENTER);
|
206 |
0
| this.getContentPane().add(buildStatusPanel(), BorderLayout.SOUTH);
|
207 |
| } |
208 |
| |
209 |
0
| private JComponent buildControlPanel() {
|
210 |
0
| return toolbar;
|
211 |
| } |
212 |
| |
213 |
0
| private JComponent buildResultPanel() {
|
214 |
0
| JPanel result = new JPanel();
|
215 |
| |
216 |
0
| result.setLayout(new BorderLayout());
|
217 |
0
| result.add(new JSplitPane(JSplitPane.VERTICAL_SPLIT, buildProjectPanel(), buildChartsPanel()), BorderLayout.CENTER);
|
218 |
0
| result.add(buildFilterPanel(), BorderLayout.SOUTH);
|
219 |
| |
220 |
0
| return result;
|
221 |
| } |
222 |
| |
223 |
0
| private JComponent buildProjectPanel() {
|
224 |
0
| JComponent result = new JScrollPane(projectArea);
|
225 |
| |
226 |
0
| projectArea.setEditable(false);
|
227 |
| |
228 |
0
| return result;
|
229 |
| } |
230 |
| |
231 |
0
| private JComponent buildChartsPanel() {
|
232 |
0
| JTabbedPane result = new JTabbedPane();
|
233 |
| |
234 |
| |
235 |
0
| result.addTab("Groups", buildGroupsChartPanel());
|
236 |
0
| result.addTab("Classes", buildClassesChartPanel());
|
237 |
0
| result.addTab("Methods", buildMethodsChartPanel());
|
238 |
| |
239 |
0
| return result;
|
240 |
| } |
241 |
| |
242 |
0
| private JComponent buildGroupsChartPanel() {
|
243 |
0
| return buildChartPanel(getGroupsModel());
|
244 |
| } |
245 |
| |
246 |
0
| private JComponent buildClassesChartPanel() {
|
247 |
0
| return buildChartPanel(getClassesModel());
|
248 |
| } |
249 |
| |
250 |
0
| private JComponent buildMethodsChartPanel() {
|
251 |
0
| return buildChartPanel(getMethodsModel());
|
252 |
| } |
253 |
| |
254 |
0
| private JComponent buildChartPanel(OOMetricsTableModel model) {
|
255 |
0
| JComponent result;
|
256 |
| |
257 |
0
| JTable table = new JTable(model);
|
258 |
| |
259 |
0
| table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
260 |
0
| table.setRowSelectionAllowed(true);
|
261 |
0
| table.setDefaultRenderer(Object.class, RENDERER);
|
262 |
0
| table.setShowHorizontalLines(false);
|
263 |
0
| table.setShowVerticalLines(false);
|
264 |
0
| TableHeaderListener listener = new TableHeaderListener(table, model);
|
265 |
0
| table.getTableHeader().addMouseListener(listener);
|
266 |
0
| table.getTableHeader().addMouseMotionListener(listener);
|
267 |
| |
268 |
0
| result = new JScrollPane(table);
|
269 |
| |
270 |
0
| return result;
|
271 |
| } |
272 |
| |
273 |
0
| private JComponent buildFilterPanel() {
|
274 |
0
| JPanel result = new JPanel();
|
275 |
| |
276 |
0
| result.setLayout(new BorderLayout());
|
277 |
0
| result.add(filterButton, BorderLayout.WEST);
|
278 |
0
| result.add(filterField, BorderLayout.CENTER);
|
279 |
| |
280 |
0
| filterButton.addActionListener(new FilterActionListener(this));
|
281 |
| |
282 |
0
| return result;
|
283 |
| } |
284 |
| |
285 |
0
| private JComponent buildStatusPanel() {
|
286 |
0
| JPanel result = new JPanel();
|
287 |
| |
288 |
0
| Dimension size = getProgressBar().getPreferredSize();
|
289 |
0
| size.width = 100;
|
290 |
0
| getProgressBar().setPreferredSize(size);
|
291 |
0
| getProgressBar().setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
|
292 |
| |
293 |
0
| result.setLayout(new BorderLayout());
|
294 |
0
| result.add(getStatusLine(), BorderLayout.CENTER);
|
295 |
0
| result.add(getProgressBar(), BorderLayout.EAST);
|
296 |
| |
297 |
0
| return result;
|
298 |
| } |
299 |
| |
300 |
0
| public static void showError(CommandLineUsage clu, String msg) {
|
301 |
0
| System.err.println(msg);
|
302 |
0
| showError(clu);
|
303 |
| } |
304 |
| |
305 |
0
| public static void showError(CommandLineUsage clu) {
|
306 |
0
| System.err.println(clu);
|
307 |
| } |
308 |
| |
309 |
0
| public static void main(String[] args) throws Exception {
|
310 |
| |
311 |
0
| CommandLine commandLine = new CommandLine(new NullParameterStrategy());
|
312 |
0
| commandLine.addSingleValueSwitch("default-configuration", true);
|
313 |
0
| commandLine.addSingleValueSwitch("configuration");
|
314 |
0
| commandLine.addToggleSwitch("validate");
|
315 |
0
| commandLine.addToggleSwitch("enable-cross-class-measurements");
|
316 |
0
| commandLine.addToggleSwitch("help");
|
317 |
| |
318 |
0
| CommandLineUsage usage = new CommandLineUsage("OOMetrics");
|
319 |
0
| commandLine.accept(usage);
|
320 |
| |
321 |
0
| try {
|
322 |
0
| commandLine.parse(args);
|
323 |
| } catch (IllegalArgumentException ex) { |
324 |
0
| showError(usage, ex.toString());
|
325 |
0
| System.exit(1);
|
326 |
| } |
327 |
| |
328 |
0
| if (commandLine.getToggleSwitch("help")) {
|
329 |
0
| showError(usage);
|
330 |
0
| System.exit(1);
|
331 |
| } |
332 |
| |
333 |
0
| MetricsFactory factory;
|
334 |
| |
335 |
0
| if (commandLine.isPresent("configuration")) {
|
336 |
0
| factory = new MetricsFactory("Project", new MetricsConfigurationLoader(commandLine.getToggleSwitch("validate")).load(commandLine.getSingleSwitch("configuration")));
|
337 |
| } else { |
338 |
0
| factory = new MetricsFactory("Project", new MetricsConfigurationLoader(commandLine.getToggleSwitch("validate")).load(commandLine.getSingleSwitch("default-configuration")));
|
339 |
| } |
340 |
| |
341 |
| |
342 |
| |
343 |
| |
344 |
| |
345 |
0
| try {
|
346 |
0
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
347 |
| } catch (Exception ex) { |
348 |
| |
349 |
| } |
350 |
| |
351 |
0
| OOMetrics model = new OOMetrics(factory, commandLine.isPresent("enable-cross-class-measurements"));
|
352 |
0
| model.setVisible(true);
|
353 |
| } |
354 |
| } |