/images/src/org/intellij/images/options/impl/OptionsConfigurabe.java

https://github.com/machak/intellij-community · Java · 114 lines · 79 code · 15 blank · 20 comment · 8 complexity · fac75677fb3ae56da15a00b336478d21 MD5 · raw file

  1. /*
  2. * Copyright 2004-2005 Alexey Efimov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.intellij.images.options.impl;
  17. import com.intellij.openapi.options.BaseConfigurableWithChangeSupport;
  18. import com.intellij.openapi.options.SearchableConfigurable;
  19. import com.intellij.openapi.options.ShowSettingsUtil;
  20. import com.intellij.openapi.project.Project;
  21. import com.intellij.openapi.util.IconLoader;
  22. import org.intellij.images.ImagesBundle;
  23. import org.intellij.images.options.Options;
  24. import org.intellij.images.options.OptionsManager;
  25. import org.jetbrains.annotations.NonNls;
  26. import org.jetbrains.annotations.NotNull;
  27. import org.jetbrains.annotations.Nullable;
  28. import javax.swing.*;
  29. import java.beans.PropertyChangeEvent;
  30. import java.beans.PropertyChangeListener;
  31. /**
  32. * Configurable for Options.
  33. *
  34. * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
  35. */
  36. public final class OptionsConfigurabe extends BaseConfigurableWithChangeSupport implements SearchableConfigurable, PropertyChangeListener {
  37. private static final String DISPLAY_NAME = ImagesBundle.message("settings.page.name");
  38. private OptionsUIForm uiForm;
  39. public String getDisplayName() {
  40. return DISPLAY_NAME;
  41. }
  42. public Icon getIcon() {
  43. return IconLoader.getIcon("/org/intellij/images/icons/ImagesConfigurable.png");
  44. }
  45. public String getHelpTopic() {
  46. return "preferences.images";
  47. }
  48. public JComponent createComponent() {
  49. if (uiForm == null) {
  50. uiForm = new OptionsUIForm();
  51. Options options = OptionsManager.getInstance().getOptions();
  52. options.addPropertyChangeListener(this);
  53. uiForm.getOptions().inject(options);
  54. uiForm.updateUI();
  55. uiForm.getOptions().addPropertyChangeListener(this);
  56. setModified(false);
  57. }
  58. return uiForm.getContentPane();
  59. }
  60. public void apply() {
  61. if (uiForm != null) {
  62. Options options = OptionsManager.getInstance().getOptions();
  63. options.inject(uiForm.getOptions());
  64. }
  65. }
  66. public void reset() {
  67. if (uiForm != null) {
  68. Options options = OptionsManager.getInstance().getOptions();
  69. uiForm.getOptions().inject(options);
  70. uiForm.updateUI();
  71. }
  72. }
  73. public void disposeUIResources() {
  74. if (uiForm != null) {
  75. Options options = OptionsManager.getInstance().getOptions();
  76. options.removePropertyChangeListener(this);
  77. uiForm.getOptions().removePropertyChangeListener(this);
  78. uiForm = null;
  79. }
  80. }
  81. public void propertyChange(PropertyChangeEvent evt) {
  82. Options options = OptionsManager.getInstance().getOptions();
  83. Options uiOptions = uiForm.getOptions();
  84. setModified(!options.equals(uiOptions));
  85. }
  86. public static void show(Project project) {
  87. final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
  88. util.editConfigurable(project, new OptionsConfigurabe());
  89. }
  90. @NotNull
  91. @NonNls
  92. public String getId() {
  93. return "Images";
  94. }
  95. @Nullable
  96. public Runnable enableSearch(String option) {
  97. return null;
  98. }
  99. }