001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008:
009: /**
010: * @author koenn
011: *
012: */package de.uka.ilkd.key.gui;
013:
014: import java.awt.BorderLayout;
015: import java.awt.event.ActionEvent;
016: import java.awt.event.ActionListener;
017:
018: import javax.swing.*;
019: import javax.swing.tree.DefaultMutableTreeNode;
020:
021: import de.uka.ilkd.key.pp.LogicPrinter;
022: import de.uka.ilkd.key.pp.NotationInfo;
023: import de.uka.ilkd.key.pp.ProgramPrinter;
024: import de.uka.ilkd.key.proof.mgt.Contract;
025: import de.uka.ilkd.key.rule.Taclet;
026:
027: public class TacletView implements ActionListener {
028:
029: private JFrame frame;
030: private JTextArea content;
031: private JScrollPane scrollPane;
032:
033: private static TacletView instance = null;
034:
035: public static TacletView getInstance() {
036: if (instance == null) {
037: instance = new TacletView();
038: }
039: return instance;
040: }
041:
042: private TacletView() {
043:
044: frame = new JFrame("Taclet View");
045:
046: frame.getContentPane().setLayout(new BorderLayout());
047:
048: content = new JTextArea("", 15, 30);
049: content.setEditable(false);
050: content.setLineWrap(true);
051: content.setWrapStyleWord(true);
052:
053: scrollPane = new JScrollPane(content,
054: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
055: JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
056:
057: scrollPane.setWheelScrollingEnabled(true);
058:
059: scrollPane
060: .setBorder(BorderFactory.createTitledBorder("Taclet"));
061:
062: JButton button = new JButton("Close");
063: button.addActionListener(this );
064:
065: JPanel buttonPane = new JPanel();
066: buttonPane.add(button);
067:
068: frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
069: frame.getContentPane().add(buttonPane, BorderLayout.SOUTH);
070:
071: frame.pack();
072: }
073:
074: public void actionPerformed(ActionEvent e) {
075: frame.setVisible(false);
076: }
077:
078: public void showTacletView(DefaultMutableTreeNode node) {
079: Taclet tac = null;
080: if (node.getUserObject() instanceof Taclet) {
081: tac = (Taclet) node.getUserObject();
082: } else if (node.getUserObject() instanceof Contract) {
083: tac = null; //TODO ((Contract)node.getUserObject()).getLemmaAndRegister();
084: } else
085: return;
086: scrollPane.setBorder(BorderFactory
087: .createTitledBorder(getDisplayName(tac)));
088: content.setText(getTacletByName(tac));
089:
090: content.setCaretPosition(0);
091:
092: frame.validate();
093: frame.setVisible(true);
094: }
095:
096: private String getDisplayName(Taclet tac) {
097: String title = tac.displayName();
098: return title;
099: }
100:
101: private String getTacletByName(Taclet tac) {
102: String rule = "";
103: LogicPrinter lp = new LogicPrinter(new ProgramPrinter(),
104: new NotationInfo(), null, true);
105: lp.printTaclet(tac);
106: rule = lp.toString();
107:
108: return rule;
109: }
110: }
|