01: /*
02: * Copyright 2007 Jens Dietrich
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
06: * Unless required by applicable law or agreed to in writing, software distributed under the
07: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
08: * either express or implied. See the License for the specific language governing permissions
09: * and limitations under the License.
10: */
11:
12: package example.nz.org.take.compiler.userv.main;
13:
14: import java.awt.BorderLayout;
15: import java.awt.Dimension;
16: import java.awt.FlowLayout;
17: import java.awt.event.ActionEvent;
18: import java.awt.event.ActionListener;
19: import java.util.List;
20: import javax.swing.JButton;
21: import javax.swing.JComponent;
22: import javax.swing.JDialog;
23: import javax.swing.JOptionPane;
24: import javax.swing.JPanel;
25: import javax.swing.JScrollPane;
26: import javax.swing.JTree;
27: import nz.org.take.rt.DerivationLogEntry;
28:
29: /**
30: * Utility to show the derivation log in a pop up window.
31: * @author <a href="http://www-ist.massey.ac.nz/JBDietrich/">Jens Dietrich</a>
32: */
33:
34: public class DerivationLogViewer {
35:
36: public static void displayUsedRules(List<DerivationLogEntry> log,
37: JComponent parentComponent) {
38:
39: if (log.size() == 0)
40: JOptionPane.showMessageDialog(parentComponent,
41: "There are no applicable rules", "",
42: JOptionPane.WARNING_MESSAGE);
43: else {
44: DerivationModel treeModel = new DerivationModel(log);
45: JTree tree = new JTree(treeModel);
46: tree.setShowsRootHandles(true);
47: tree.setRootVisible(false);
48: tree.setPreferredSize(new Dimension(700, 400));
49: final JDialog win = new JDialog();
50: win.setResizable(true);
51: JPanel pane = new JPanel();
52: pane.setLayout(new BorderLayout(5, 5));
53: win.setContentPane(pane);
54: pane.add(new JScrollPane(tree), BorderLayout.CENTER);
55: JPanel bPane = new JPanel(new FlowLayout());
56: JButton cButton = new JButton("close");
57: cButton.addActionListener(new ActionListener() {
58: public void actionPerformed(ActionEvent e) {
59: win.dispose();
60: }
61: });
62: bPane.add(cButton);
63: pane.add(bPane, BorderLayout.SOUTH);
64: win.setTitle("rules used");
65: win.setSize(700, 300);
66: win.setLocation(100, 100);
67: win.setVisible(true);
68: }
69: }
70:
71: }
|