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:
011: package de.uka.ilkd.key.gui;
012:
013: import java.awt.BorderLayout;
014: import java.awt.event.ActionEvent;
015: import java.awt.event.ActionListener;
016:
017: import javax.swing.*;
018:
019: import de.uka.ilkd.key.gui.configuration.ProofSettings;
020:
021: public class ModelSourceSelector extends JDialog {
022:
023: private ModelSourceSettings settings;
024: private JRadioButton xmiFile;
025: private JRadioButton tccModel;
026:
027: public ModelSourceSelector() {
028: super (new JFrame(), "Select UML Model Source", true);
029: settings = ProofSettings.DEFAULT_SETTINGS
030: .getModelSourceSettings();
031: layoutModelSourceSelector();
032: init(settings);
033:
034: pack();
035: setLocation(70, 70);
036: setVisible(true);
037: }
038:
039: public ModelSourceSettings getSettings() {
040: return settings;
041: }
042:
043: /** layout */
044: protected void layoutModelSourceSelector() {
045:
046: JButton ok = new JButton("OK");
047: ok.addActionListener(new ActionListener() {
048: public void actionPerformed(ActionEvent e) {
049: setVisible(false);
050: settings.store();
051: dispose();
052: }
053: });
054: JButton cancel = new JButton("Cancel");
055: cancel.addActionListener(new ActionListener() {
056: public void actionPerformed(ActionEvent e) {
057: setVisible(false);
058: settings.restore();
059: dispose();
060: }
061: });
062: xmiFile = new JRadioButton("XMI file");
063: xmiFile.setActionCommand("xmi");
064: tccModel = new JRadioButton("TogetherCC data structures");
065: tccModel.setActionCommand("tcc");
066:
067: RadioListener listener = new RadioListener();
068: xmiFile.addActionListener(listener);
069: tccModel.addActionListener(listener);
070:
071: ButtonGroup group = new ButtonGroup();
072: group.add(xmiFile);
073: group.add(tccModel);
074:
075: JPanel buttonPanel = new JPanel();
076: buttonPanel.add(ok);
077: buttonPanel.add(cancel);
078:
079: JPanel listPanel = new JPanel();
080: listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS));
081: listPanel.add(xmiFile);
082: listPanel.add(tccModel);
083:
084: getContentPane().setLayout(new BorderLayout());
085: getContentPane().add(new JPanel(), BorderLayout.WEST);
086: getContentPane().add(listPanel, BorderLayout.CENTER);
087: getContentPane().add(buttonPanel, BorderLayout.SOUTH);
088: }
089:
090: private void init(ModelSourceSettings msSettings) {
091: if ("0".equals(msSettings.getModelSource())) {
092: xmiFile.setSelected(true);
093: } else {
094: tccModel.setSelected(true);
095: }
096: }
097:
098: /** is called to set the chosen LDT */
099: private void setModelSource(String sel) {
100: settings.setModelSource(sel);
101: }
102:
103: class RadioListener implements ActionListener {
104: public void actionPerformed(ActionEvent e) {
105: if ("xmi".equals(e.getActionCommand()))
106: setModelSource("0");
107: else
108: setModelSource("1");
109: }
110: }
111:
112: }
|