diff options
Diffstat (limited to 'plugins/IntelliLang/java-support/org/intellij')
2 files changed, 170 insertions, 144 deletions
diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/AdvancedSettingsUI.form b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/AdvancedSettingsUI.form index 9aba68ac9b46..b894b8ced19b 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/AdvancedSettingsUI.form +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/AdvancedSettingsUI.form @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.intellij.plugins.intelliLang.AdvancedSettingsUI"> +<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.intellij.plugins.intelliLang.AdvancedSettingsUI.AdvancedSettingsPanel"> <grid id="27dc6" binding="myRoot" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="5" left="8" bottom="5" right="8"/> <constraints> diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/AdvancedSettingsUI.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/AdvancedSettingsUI.java index e9083b065605..adb4b51057a8 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/AdvancedSettingsUI.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/AdvancedSettingsUI.java @@ -44,166 +44,36 @@ import java.util.Arrays; */ public class AdvancedSettingsUI implements SearchableConfigurable { private final Configuration.AdvancedConfiguration myConfiguration; - - @SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"}) - private JPanel myRoot; - - private JRadioButton myNoInstrumentation; - private JRadioButton myAssertInstrumentation; - private JRadioButton myExceptionInstrumentation; - private JPanel myLanguageAnnotationPanel; - private JPanel myPatternAnnotationPanel; - private JPanel mySubstAnnotationPanel; - private JRadioButton myDfaOff; - private JRadioButton myAnalyzeReferences; - private JRadioButton myUseDfa; - private JRadioButton myLookForAssignments; - private JCheckBox myIncludeUncomputableOperandsAsCheckBox; - private JCheckBox mySourceModificationAllowedCheckBox; - - private final ReferenceEditorWithBrowseButton myAnnotationField; - private final ReferenceEditorWithBrowseButton myPatternField; - private final ReferenceEditorWithBrowseButton mySubstField; + private AdvancedSettingsPanel myPanel; + private final Project myProject; public AdvancedSettingsUI(@NotNull final Project project, Configuration configuration) { + myProject = project; myConfiguration = configuration.getAdvancedConfiguration(); - - myAnnotationField = new ReferenceEditorWithBrowseButton(null, project, new Function<String, Document>() { - public Document fun(String s) { - return PsiUtilEx.createDocument(s, project); - } - }, myConfiguration.getLanguageAnnotationClass()); - myAnnotationField.addActionListener(new BrowseClassListener(project, myAnnotationField)); - myAnnotationField.setEnabled(!project.isDefault()); - addField(myLanguageAnnotationPanel, myAnnotationField); - - myPatternField = new ReferenceEditorWithBrowseButton(null, project, new Function<String, Document>() { - public Document fun(String s) { - return PsiUtilEx.createDocument(s, project); - } - }, myConfiguration.getPatternAnnotationClass()); - myPatternField.addActionListener(new BrowseClassListener(project, myPatternField)); - myPatternField.setEnabled(!project.isDefault()); - addField(myPatternAnnotationPanel, myPatternField); - - mySubstField = new ReferenceEditorWithBrowseButton(null, project, new Function<String, Document>() { - public Document fun(String s) { - return PsiUtilEx.createDocument(s, project); - } - }, myConfiguration.getPatternAnnotationClass()); - mySubstField.addActionListener(new BrowseClassListener(project, mySubstField)); - mySubstField.setEnabled(!project.isDefault()); - addField(mySubstAnnotationPanel, mySubstField); - } - // - /** - * Adds textfield into placeholder panel and assigns a directly preceding label - */ - private static void addField(JPanel panel, ReferenceEditorWithBrowseButton field) { - panel.add(field, BorderLayout.CENTER); - - final Component[] components = panel.getParent().getComponents(); - final int index = Arrays.asList(components).indexOf(panel); - if (index > 0) { - final Component component = components[index - 1]; - if (component instanceof JLabel) { - ((JLabel)component).setLabelFor(field); - } - } } public JComponent createComponent() { - return myRoot; - } - - @SuppressWarnings({"SimplifiableIfStatement"}) - public boolean isModified() { - if (getInstrumentation() != myConfiguration.getInstrumentation()) { - return true; - } - if (!myAnnotationField.getText().equals(myConfiguration.getLanguageAnnotationClass())) { - return true; - } - if (!myPatternField.getText().equals(myConfiguration.getPatternAnnotationClass())) { - return true; - } - if (!mySubstField.getText().equals(myConfiguration.getSubstAnnotationClass())) { - return true; - } - if (!myConfiguration.getDfaOption().equals(getDfaOption())) { - return true; - } - if (myConfiguration.isIncludeUncomputablesAsLiterals() != myIncludeUncomputableOperandsAsCheckBox.isSelected()) { - return true; - } - if (myConfiguration.isSourceModificationAllowed() != mySourceModificationAllowedCheckBox.isSelected()) { - return true; - } - return false; - } - - @NotNull - private Configuration.InstrumentationType getInstrumentation() { - if (myNoInstrumentation.isSelected()) return Configuration.InstrumentationType.NONE; - if (myAssertInstrumentation.isSelected()) return Configuration.InstrumentationType.ASSERT; - if (myExceptionInstrumentation.isSelected()) return Configuration.InstrumentationType.EXCEPTION; - - assert false; - return null; + myPanel = new AdvancedSettingsPanel(); + return myPanel.myRoot; } + @Override public void apply() throws ConfigurationException { - myConfiguration.setInstrumentationType(getInstrumentation()); - myConfiguration.setLanguageAnnotation(myAnnotationField.getText()); - myConfiguration.setPatternAnnotation(myPatternField.getText()); - myConfiguration.setSubstAnnotation(mySubstField.getText()); - - myConfiguration.setDfaOption(getDfaOption()); - myConfiguration.setIncludeUncomputablesAsLiterals(myIncludeUncomputableOperandsAsCheckBox.isSelected()); - myConfiguration.setSourceModificationAllowed(mySourceModificationAllowedCheckBox.isSelected()); + myPanel.apply(); } - @NotNull - private Configuration.DfaOption getDfaOption() { - if (myDfaOff.isSelected()) return Configuration.DfaOption.OFF; - if (myAnalyzeReferences.isSelected()) return Configuration.DfaOption.RESOLVE; - if (myLookForAssignments.isSelected()) return Configuration.DfaOption.ASSIGNMENTS; - if (myUseDfa.isSelected()) return Configuration.DfaOption.DFA; - return Configuration.DfaOption.OFF; + @Override + public boolean isModified() { + return myPanel.isModified(); } + @Override public void reset() { - myAnnotationField.setText(myConfiguration.getLanguageAnnotationClass()); - myPatternField.setText(myConfiguration.getPatternAnnotationClass()); - mySubstField.setText(myConfiguration.getSubstAnnotationClass()); - - myNoInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.NONE); - myAssertInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.ASSERT); - myExceptionInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.EXCEPTION); - - setDfaOption(myConfiguration.getDfaOption()); - myIncludeUncomputableOperandsAsCheckBox.setSelected(myConfiguration.isIncludeUncomputablesAsLiterals()); - mySourceModificationAllowedCheckBox.setSelected(myConfiguration.isSourceModificationAllowed()); - } - - private void setDfaOption(@NotNull final Configuration.DfaOption dfaOption) { - switch (dfaOption) { - case OFF: - myDfaOff.setSelected(true); - break; - case RESOLVE: - myAnalyzeReferences.setSelected(true); - break; - case ASSIGNMENTS: - myLookForAssignments.setSelected(true); - break; - case DFA: - myUseDfa.setSelected(true); - break; - } + myPanel.reset(); } public void disposeUIResources() { + myPanel = null; } @Nls @@ -255,4 +125,160 @@ public class AdvancedSettingsUI implements SearchableConfigurable { } } } + + public class AdvancedSettingsPanel { + @SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"}) + private JPanel myRoot; + + private JRadioButton myNoInstrumentation; + private JRadioButton myAssertInstrumentation; + private JRadioButton myExceptionInstrumentation; + private JPanel myLanguageAnnotationPanel; + private JPanel myPatternAnnotationPanel; + private JPanel mySubstAnnotationPanel; + private JRadioButton myDfaOff; + private JRadioButton myAnalyzeReferences; + private JRadioButton myUseDfa; + private JRadioButton myLookForAssignments; + private JCheckBox myIncludeUncomputableOperandsAsCheckBox; + private JCheckBox mySourceModificationAllowedCheckBox; + + private final ReferenceEditorWithBrowseButton myAnnotationField; + private final ReferenceEditorWithBrowseButton myPatternField; + private final ReferenceEditorWithBrowseButton mySubstField; + + public AdvancedSettingsPanel() { + myAnnotationField = new ReferenceEditorWithBrowseButton(null, myProject, new Function<String, Document>() { + public Document fun(String s) { + return PsiUtilEx.createDocument(s, myProject); + } + }, myConfiguration.getLanguageAnnotationClass()); + myAnnotationField.addActionListener(new BrowseClassListener(myProject, myAnnotationField)); + myAnnotationField.setEnabled(!myProject.isDefault()); + addField(myLanguageAnnotationPanel, myAnnotationField); + + myPatternField = new ReferenceEditorWithBrowseButton(null, myProject, new Function<String, Document>() { + public Document fun(String s) { + return PsiUtilEx.createDocument(s, myProject); + } + }, myConfiguration.getPatternAnnotationClass()); + myPatternField.addActionListener(new BrowseClassListener(myProject, myPatternField)); + myPatternField.setEnabled(!myProject.isDefault()); + addField(myPatternAnnotationPanel, myPatternField); + + mySubstField = new ReferenceEditorWithBrowseButton(null, myProject, new Function<String, Document>() { + public Document fun(String s) { + return PsiUtilEx.createDocument(s, myProject); + } + }, myConfiguration.getPatternAnnotationClass()); + mySubstField.addActionListener(new BrowseClassListener(myProject, mySubstField)); + mySubstField.setEnabled(!myProject.isDefault()); + addField(mySubstAnnotationPanel, mySubstField); + } + // + + /** + * Adds textfield into placeholder panel and assigns a directly preceding label + */ + private void addField(JPanel panel, ReferenceEditorWithBrowseButton field) { + panel.add(field, BorderLayout.CENTER); + + final Component[] components = panel.getParent().getComponents(); + final int index = Arrays.asList(components).indexOf(panel); + if (index > 0) { + final Component component = components[index - 1]; + if (component instanceof JLabel) { + ((JLabel)component).setLabelFor(field); + } + } + } + + + @SuppressWarnings({"SimplifiableIfStatement"}) + public boolean isModified() { + if (getInstrumentation() != myConfiguration.getInstrumentation()) { + return true; + } + if (!myAnnotationField.getText().equals(myConfiguration.getLanguageAnnotationClass())) { + return true; + } + if (!myPatternField.getText().equals(myConfiguration.getPatternAnnotationClass())) { + return true; + } + if (!mySubstField.getText().equals(myConfiguration.getSubstAnnotationClass())) { + return true; + } + if (!myConfiguration.getDfaOption().equals(getDfaOption())) { + return true; + } + if (myConfiguration.isIncludeUncomputablesAsLiterals() != myIncludeUncomputableOperandsAsCheckBox.isSelected()) { + return true; + } + if (myConfiguration.isSourceModificationAllowed() != mySourceModificationAllowedCheckBox.isSelected()) { + return true; + } + return false; + } + + @NotNull + private Configuration.InstrumentationType getInstrumentation() { + if (myNoInstrumentation.isSelected()) return Configuration.InstrumentationType.NONE; + if (myAssertInstrumentation.isSelected()) return Configuration.InstrumentationType.ASSERT; + if (myExceptionInstrumentation.isSelected()) return Configuration.InstrumentationType.EXCEPTION; + + assert false; + return null; + } + + public void apply() throws ConfigurationException { + myConfiguration.setInstrumentationType(getInstrumentation()); + myConfiguration.setLanguageAnnotation(myAnnotationField.getText()); + myConfiguration.setPatternAnnotation(myPatternField.getText()); + myConfiguration.setSubstAnnotation(mySubstField.getText()); + + myConfiguration.setDfaOption(getDfaOption()); + myConfiguration.setIncludeUncomputablesAsLiterals(myIncludeUncomputableOperandsAsCheckBox.isSelected()); + myConfiguration.setSourceModificationAllowed(mySourceModificationAllowedCheckBox.isSelected()); + } + + @NotNull + private Configuration.DfaOption getDfaOption() { + if (myDfaOff.isSelected()) return Configuration.DfaOption.OFF; + if (myAnalyzeReferences.isSelected()) return Configuration.DfaOption.RESOLVE; + if (myLookForAssignments.isSelected()) return Configuration.DfaOption.ASSIGNMENTS; + if (myUseDfa.isSelected()) return Configuration.DfaOption.DFA; + return Configuration.DfaOption.OFF; + } + + public void reset() { + myAnnotationField.setText(myConfiguration.getLanguageAnnotationClass()); + myPatternField.setText(myConfiguration.getPatternAnnotationClass()); + mySubstField.setText(myConfiguration.getSubstAnnotationClass()); + + myNoInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.NONE); + myAssertInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.ASSERT); + myExceptionInstrumentation.setSelected(myConfiguration.getInstrumentation() == Configuration.InstrumentationType.EXCEPTION); + + setDfaOption(myConfiguration.getDfaOption()); + myIncludeUncomputableOperandsAsCheckBox.setSelected(myConfiguration.isIncludeUncomputablesAsLiterals()); + mySourceModificationAllowedCheckBox.setSelected(myConfiguration.isSourceModificationAllowed()); + } + + private void setDfaOption(@NotNull final Configuration.DfaOption dfaOption) { + switch (dfaOption) { + case OFF: + myDfaOff.setSelected(true); + break; + case RESOLVE: + myAnalyzeReferences.setSelected(true); + break; + case ASSIGNMENTS: + myLookForAssignments.setSelected(true); + break; + case DFA: + myUseDfa.setSelected(true); + break; + } + } + } } |