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.configuration;
012:
013: import java.awt.BorderLayout;
014: import java.awt.Dimension;
015: import java.awt.event.ActionEvent;
016: import java.awt.event.ActionListener;
017: import java.awt.event.KeyEvent;
018:
019: import javax.swing.*;
020: import javax.swing.text.AttributeSet;
021: import javax.swing.text.BadLocationException;
022: import javax.swing.text.Document;
023: import javax.swing.text.PlainDocument;
024:
025: public class ViewSelector extends JDialog {
026:
027: private JTextField maxTooltipLinesInputField;
028: private JCheckBox showWholeTacletCB;
029:
030: /**
031: * creates a new ViewSelector
032: * @param parent The parent widget of this ViewSelector
033: */
034: public ViewSelector(JFrame parent) {
035: super (parent, "Maximum line number for tooltips", true);
036: layoutViewSelector();
037: pack();
038: setLocation(70, 70);
039: }
040:
041: private void updateButtons() {
042:
043: }
044:
045: /** lays out the selector */
046: protected void layoutViewSelector() {
047: int maxLinesInt = ProofSettings.DEFAULT_SETTINGS
048: .getViewSettings().getMaxTooltipLines();
049: boolean showWholeTaclet = ProofSettings.DEFAULT_SETTINGS
050: .getViewSettings().getShowWholeTaclet();
051:
052: getContentPane().setLayout(new BorderLayout());
053:
054: JPanel maxLinesPanel = new JPanel();
055: maxLinesPanel.setLayout(new BoxLayout(maxLinesPanel,
056: BoxLayout.X_AXIS));
057: maxTooltipLinesInputField = new NumberInputField(maxLinesInt, 4);
058: maxTooltipLinesInputField.setMaximumSize(new Dimension(40, 30));
059: maxLinesPanel
060: .add(new JLabel(
061: "<html><font color=\"#000000\">"
062: + "Maximum size (line count) of the tooltips of applicable rules"
063: + "<br> with schema variable instantiations displayed. "
064: + "In case of longer <br>tooltips the instantiation will be "
065: + "suppressed. </font></html>"));
066: maxLinesPanel.add(maxTooltipLinesInputField);
067:
068: JPanel showWholeTacletPanel = new JPanel();
069: showWholeTacletPanel.setLayout(new BoxLayout(
070: showWholeTacletPanel, BoxLayout.X_AXIS));
071: showWholeTacletCB = new JCheckBox(
072: "pretty-print whole Taclet including "
073: + "'name', 'find', 'varCond' and 'heuristics'",
074: showWholeTaclet);
075: showWholeTacletPanel.add(showWholeTacletCB);
076:
077: JButton okButton = new JButton("OK");
078: okButton.setMnemonic(KeyEvent.VK_ENTER);
079:
080: okButton.addActionListener(new ActionListener() {
081: public void actionPerformed(ActionEvent e) {
082: int maxSteps = Integer
083: .parseInt(maxTooltipLinesInputField.getText());
084: ProofSettings.DEFAULT_SETTINGS.getViewSettings()
085: .setMaxTooltipLines(maxSteps);
086: boolean ifind = showWholeTacletCB.isSelected();
087: ProofSettings.DEFAULT_SETTINGS.getViewSettings()
088: .setShowWholeTaclet(ifind);
089:
090: setVisible(false);
091: }
092: });
093: JButton saveButton = new JButton("Save as Default");
094:
095: saveButton.addActionListener(new ActionListener() {
096: public void actionPerformed(ActionEvent e) {
097: int maxSteps = Integer
098: .parseInt(maxTooltipLinesInputField.getText());
099: ProofSettings dflt = ProofSettings.DEFAULT_SETTINGS;
100: boolean ifind = showWholeTacletCB.isSelected();
101: dflt.getViewSettings().setMaxTooltipLines(maxSteps);
102: dflt.getViewSettings().setShowWholeTaclet(ifind);
103: //temporary solution, stores more than wanted %%%%
104: dflt.saveSettings();
105: setVisible(false);
106: }
107: });
108: JButton cancelButton = new JButton("Cancel");
109: cancelButton.setMnemonic(KeyEvent.VK_ESCAPE);
110: cancelButton.addActionListener(new ActionListener() {
111: public void actionPerformed(ActionEvent e) {
112: setVisible(false);
113: dispose();
114: }
115: });
116:
117: JPanel buttonPanel = new JPanel();
118: buttonPanel.add(okButton);
119: buttonPanel.add(saveButton);
120: buttonPanel.add(cancelButton);
121:
122: getContentPane().setLayout(
123: new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
124: getContentPane().add(maxLinesPanel);
125: getContentPane().add(showWholeTacletPanel);
126: getContentPane().add(buttonPanel);
127:
128: updateButtons();
129:
130: }
131:
132: // INNER CLASS TO READ ONLY NUMBERS FOR MAX APPs
133: static class NumberDocument extends PlainDocument {
134:
135: public void insertString(int offs, String str, AttributeSet a)
136: throws BadLocationException {
137: if (str == null) {
138: return;
139: }
140: char[] upper = str.toCharArray();
141: for (int i = 0; i < upper.length; i++) {
142: if (upper[i] < '0' || upper[i] > '9') {
143: return;
144: }
145: }
146: super .insertString(offs, new String(upper), a);
147: }
148:
149: }
150:
151: static class NumberInputField extends JTextField {
152: public NumberInputField(int number, int cols) {
153: super (cols);
154: setText("" + number);
155: }
156:
157: protected Document createDefaultModel() {
158: return new NumberDocument();
159: }
160: }
161:
162: }
|