package jetbrains.mps.ide.modelchecker.platform.actions;
/*Generated by MPS */
import com.intellij.openapi.options.SearchableConfigurable;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JCheckBox;
import javax.swing.JTextArea;
import java.util.Hashtable;
import javax.swing.JLabel;
import java.awt.Dimension;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.BorderFactory;
import java.awt.BorderLayout;
import javax.swing.border.EtchedBorder;
import java.awt.GridBagLayout;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagConstraints;
import javax.swing.Icon;
import com.intellij.openapi.options.ConfigurationException;
import java.util.Arrays;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Nls;
import javax.swing.JComponent;
public class ModelCheckerPreferencesPage implements SearchableConfigurable {
private JPanel myPage;
private JSlider myCheckingLevelSlider = new JSlider(JSlider.VERTICAL, 0, ModelCheckerSettings.CheckingLevel.values().length - 1, 0);
private JCheckBox myCheckStubsCheckBox = new JCheckBox("Check stub models");
private JCheckBox myCheckSpecificCheckBox = new JCheckBox("Perform additional checks");
private ModelCheckerSettings myModelCheckerSettings;
private JTextArea myDescriptionText = new JTextArea();
public ModelCheckerPreferencesPage(ModelCheckerSettings settings) {
myModelCheckerSettings = settings;
Hashtable t = new Hashtable();
for (ModelCheckerSettings.CheckingLevel level : ModelCheckerSettings.CheckingLevel.values()) {
t.put(level.ordinal(), new JLabel(level.getPresentation()));
}
myCheckingLevelSlider.setLabelTable(t);
myCheckingLevelSlider.setPaintLabels(true);
myCheckingLevelSlider.setPaintTicks(true);
myCheckingLevelSlider.setMajorTickSpacing(1);
myCheckingLevelSlider.setSnapToTicks(true);
myCheckingLevelSlider.setPreferredSize(new Dimension(140, 180));
myCheckingLevelSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent p0) {
myDescriptionText.setText(ModelCheckerSettings.CheckingLevel.values()[myCheckingLevelSlider.getValue()].getLongDescription());
}
});
myDescriptionText.setEditable(false);
myDescriptionText.setOpaque(false);
myDescriptionText.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
JPanel levelSelectionPanel = new JPanel(new BorderLayout());
levelSelectionPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Model checking level"));
levelSelectionPanel.add(myCheckingLevelSlider, BorderLayout.WEST);
levelSelectionPanel.add(myDescriptionText, BorderLayout.CENTER);
myPage = new JPanel(new GridBagLayout());
myPage.setBorder(new EmptyBorder(10, 10, 10, 10));
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTHWEST;
c.fill = GridBagConstraints.HORIZONTAL;
myPage.add(levelSelectionPanel, c);
c.fill = GridBagConstraints.NONE;
c.gridy++;
myPage.add(myCheckStubsCheckBox, c);
c.gridy++;
myPage.add(myCheckSpecificCheckBox, c);
c.gridy++;
c.weightx = 1.0;
c.weighty = 1.0;
c.fill = GridBagConstraints.BOTH;
myPage.add(new JPanel(), c);
}
public String getName() {
return "Model Checker";
}
public Icon getIcon() {
return null;
}
public boolean validate() {
return true;
}
public void apply() throws ConfigurationException {
myModelCheckerSettings.setCheckingLevel(ModelCheckerSettings.CheckingLevel.values()[myCheckingLevelSlider.getValue()]);
myModelCheckerSettings.setCheckStubs(myCheckStubsCheckBox.isSelected());
myModelCheckerSettings.setIncludeAdditionalChecks(myCheckSpecificCheckBox.isSelected());
}
public void reset() {
myCheckingLevelSlider.setValue(Arrays.binarySearch(ModelCheckerSettings.CheckingLevel.values(), myModelCheckerSettings.getCheckingLevel()));
myCheckStubsCheckBox.setSelected(myModelCheckerSettings.isCheckStubs());
myCheckSpecificCheckBox.setSelected(myModelCheckerSettings.isIncludeAdditionalChecks());
}
@Override
public boolean isModified() {
if (myCheckingLevelSlider.getValue() != Arrays.binarySearch(ModelCheckerSettings.CheckingLevel.values(), myModelCheckerSettings.getCheckingLevel())) {
return true;
}
if (myModelCheckerSettings.isCheckStubs() != myCheckStubsCheckBox.isSelected()) {
return true;
}
if (myModelCheckerSettings.isIncludeAdditionalChecks() != myCheckSpecificCheckBox.isSelected()) {
return true;
}
return false;
}
@NotNull
@NonNls
public String getId() {
return "model.checker";
}
@Nullable
public Runnable enableSearch(String string) {
return null;
}
@Nls
public String getDisplayName() {
return "Model Checker";
}
@Nullable
@NonNls
public String getHelpTopic() {
return "Model_Checker";
}
@Nullable
public JComponent createComponent() {
return myPage;
}
public void disposeUIResources() {
}
}