always use getIcon instead of findIcon
[fedora-idea.git] / plugins / IntelliLang / src / org / intellij / plugins / intelliLang / Settings.java
blobba942d086416dd0f1084c8af75864fce84d799fc
1 /*
2 * Copyright 2006 Sascha Weinreuter
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.intellij.plugins.intelliLang;
19 import com.intellij.openapi.options.Configurable;
20 import com.intellij.openapi.options.ConfigurationException;
21 import com.intellij.openapi.project.Project;
22 import com.intellij.openapi.project.ProjectManager;
23 import com.intellij.openapi.util.IconLoader;
24 import com.intellij.openapi.wm.ex.WindowManagerEx;
25 import org.jetbrains.annotations.NonNls;
26 import org.jetbrains.annotations.Nullable;
28 import javax.swing.*;
29 import java.awt.*;
31 /**
32 * Provides UI for global {@link org.intellij.plugins.intelliLang.Configuration}. This is
33 * split into this and the SettingsUI class to avoid holding strong application-wide
34 * references on the UI objects.
35 * <p/>
36 * Even though this class is an application component, it determines the currently focused
37 * Project and passes it to the SettingsUI instance. This is kinda unconventional, but has
38 * the benefit of having a centralized IDE-wide configuration that doesn't need to be
39 * recreated and maintained for each project, and still being able to use class-choosers
40 * that will allow to browse the current project's classes.
42 public class Settings implements Configurable {
44 private final Configuration myConfiguration;
46 Settings(Configuration configuration) {
47 myConfiguration = configuration;
50 private SettingsUI mySettingsUI;
52 public String getDisplayName() {
53 return "Language Injection";
56 @Nullable
57 public Icon getIcon() {
58 return IconLoader.getIcon("icon.png");
61 @Nullable
62 @NonNls
63 public String getHelpTopic() {
64 return "IntelliLang.Configuration";
67 public JComponent createComponent() {
68 final ProjectManager projectManager = ProjectManager.getInstance();
69 final Project[] projects = projectManager.getOpenProjects();
71 Project project = null;
72 if (projects.length == 0) {
73 project = projectManager.getDefaultProject();
75 else {
76 final WindowManagerEx windowManager = WindowManagerEx.getInstanceEx();
77 final Window focusedWindow = windowManager.getMostRecentFocusedWindow();
78 if (focusedWindow != null) {
79 for (Project p : projects) {
80 final Window w = windowManager.suggestParentWindow(p);
81 if (w == focusedWindow || w.isAncestorOf(focusedWindow) || focusedWindow.isAncestorOf(w)) {
82 project = p;
83 break;
87 if (project == null) {
88 project = projectManager.getDefaultProject();
92 mySettingsUI = new SettingsUI(project, myConfiguration);
94 return mySettingsUI.createComponent();
97 public boolean isModified() {
98 return mySettingsUI != null && mySettingsUI.isModified();
101 public void apply() throws ConfigurationException {
102 mySettingsUI.apply();
105 public void reset() {
106 mySettingsUI.reset();
109 public void disposeUIResources() {
110 mySettingsUI = null;