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: package de.uka.ilkd.key.util.install;
011:
012: import java.awt.BorderLayout;
013: import java.awt.GridLayout;
014: import java.awt.event.ActionEvent;
015: import java.awt.event.ActionListener;
016: import java.io.File;
017:
018: import javax.swing.*;
019:
020: /** The installer frame consists of a header, the content pane and a
021: * button panel. This content pane is an instance of this class.
022: */
023: public class GlobalSettingsPane extends InstallationPane {
024:
025: private InstallationPathChooser[] installPath = new InstallationPathChooser[3];
026:
027: private String localOs;
028:
029: private String localTg;
030:
031: public GlobalSettingsPane(KeYInstaller installer) {
032: super ("Global", installer);
033: this .localOs = os();
034: this .localTg = togetherVersion();
035: setup();
036: }
037:
038: private void setup() {
039:
040: setLayout(new BorderLayout());
041: Box entries = Box.createVerticalBox();
042:
043: // which os
044: entries.add(createRadioPanel("Operation System: ",
045: supportedOS(), os(), new ActionListener() {
046: public void actionPerformed(ActionEvent ae) {
047: if (ae.getSource() instanceof JRadioButton) {
048: localOs = ((JRadioButton) ae.getSource())
049: .getText();
050: }
051: }
052: }));
053:
054: //"Where do you have unpacked KeY.tgz?"
055: installPath[0] = new InstallationPathChooser("key.jar",
056: keyJarFile(), JFileChooser.FILES_ONLY);
057: // "From where do you want to start KeY?"
058: installPath[1] = new InstallationPathChooser(
059: "Installation-Path", keyHome(),
060: JFileChooser.DIRECTORIES_ONLY);
061: // "Where do you have installed TogetherCC?"
062: installPath[2] = new InstallationPathChooser("TogetherCC",
063: togetherHome(), JFileChooser.DIRECTORIES_ONLY);
064:
065: for (int i = 0; i < installPath.length; i++) {
066: entries.add(installPath[i]);
067: }
068:
069: // which together version
070: entries.add(createRadioPanel("Together Version",
071: supportedTgVersion(), togetherVersion(),
072: new ActionListener() {
073: public void actionPerformed(ActionEvent ae) {
074: if (ae.getSource() instanceof JRadioButton) {
075: localTg = ((JRadioButton) ae.getSource())
076: .getText();
077: }
078: }
079: }));
080: add(entries, BorderLayout.NORTH);
081: }
082:
083: public JPanel createRadioPanel(String title,
084: String[] radioDescription, String selected,
085: ActionListener listener) {
086:
087: JPanel radioPanel = new JPanel(new GridLayout(1, 2));
088: radioPanel.add(new JLabel(title));
089: JRadioButton[] box = new JRadioButton[radioDescription.length];
090: ButtonGroup group = new ButtonGroup();
091: Box radioBox = Box.createHorizontalBox();
092: for (int i = 0; i < radioDescription.length; i++) {
093:
094: box[i] = new JRadioButton(radioDescription[i],
095: radioDescription[i].equals(selected));
096:
097: box[i].addActionListener(listener);
098: group.add(box[i]);
099: radioBox.add(box[i]);
100: }
101: radioPanel.add(radioBox);
102:
103: return radioPanel;
104: }
105:
106: private boolean checkModel() {
107: for (int i = 0; i < installPath.length; i++) {
108: if (!installPath[i].updateModel()) {
109: JOptionPane.showMessageDialog(null, "Wrong path for "
110: + installPath[i].label(), "Wong Path",
111: JOptionPane.ERROR_MESSAGE);
112: return false;
113: }
114: }
115: return true;
116: }
117:
118: public boolean updateModel() {
119:
120: if (!checkModel()) {
121: return false;
122: }
123:
124: os(localOs);
125:
126: String keyJarPath = path(0);
127: File f = new File(keyJarPath);
128:
129: if (f.exists() && f.isFile()
130: || keyJarPath.lastIndexOf("key.jar") > 0) {
131:
132: keyJarPath = f.getParent();
133:
134: if (keyJarPath == null) { // assume current directory
135: keyJarPath = ".";
136: }
137: }
138:
139: keyJarPath(keyJarPath);
140:
141: keyHome(path(1));
142:
143: togetherHome(path(2));
144:
145: togetherVersion(localTg);
146:
147: return true;
148: }
149:
150: public String path(int index) {
151: return installPath[index].getPath();
152: }
153:
154: }
|