8a09957588b6f2523cfa4ef7427577ef14d378e3
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInsight / intention / impl / FileLevelIntentionComponent.java
blob8a09957588b6f2523cfa4ef7427577ef14d378e3
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
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 com.intellij.codeInsight.intention.impl;
19 import com.intellij.codeInsight.daemon.impl.HighlightInfo;
20 import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
21 import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass;
22 import com.intellij.lang.annotation.HighlightSeverity;
23 import com.intellij.openapi.editor.Editor;
24 import com.intellij.openapi.project.Project;
25 import com.intellij.openapi.util.IconLoader;
26 import com.intellij.openapi.util.Pair;
27 import com.intellij.openapi.util.TextRange;
28 import com.intellij.psi.PsiFile;
29 import com.intellij.ui.LightColors;
31 import javax.swing.*;
32 import java.awt.*;
33 import java.awt.event.MouseAdapter;
34 import java.awt.event.MouseEvent;
35 import java.util.List;
37 /**
38 * @author max
40 public class FileLevelIntentionComponent extends JPanel {
41 private static final Icon ourIntentionIcon = IconLoader.getIcon("/actions/intentionBulb.png");
42 private static final Icon ourQuickFixIcon = IconLoader.getIcon("/actions/quickfixBulb.png");
44 private final Project myProject;
45 private final Editor myEditor;
47 public FileLevelIntentionComponent(final String description,
48 final HighlightSeverity severity,
49 List<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>> intentions,
50 final Project project, final PsiFile psiFile, final Editor editor) {
51 super(new BorderLayout());
52 myEditor = editor;
53 myProject = project;
55 final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
57 if (intentions != null) {
58 for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> intention : intentions) {
59 info.intentionsToShow.add(intention.getFirst());
63 JLabel content =
64 new JLabel(description, SeverityRegistrar.getInstance(project).compare(severity, HighlightSeverity.ERROR) >= 0 ? ourQuickFixIcon : ourIntentionIcon,
65 SwingConstants.LEADING);
66 add(content, BorderLayout.WEST);
67 content.setBackground(null);
68 setBackground(getColor(severity));
70 content.addMouseListener(new MouseAdapter() {
71 public void mouseClicked(MouseEvent e) {
72 Point location = SwingUtilities.convertPoint(FileLevelIntentionComponent.this,
73 new Point(0, 0),
74 myEditor.getComponent().getRootPane().getLayeredPane());
75 IntentionHintComponent.showIntentionHint(myProject, psiFile, myEditor, info, true, location);
77 });
80 private Color getColor(HighlightSeverity severity) {
81 if (SeverityRegistrar.getInstance(myProject).compare(severity, HighlightSeverity.ERROR) >= 0) {
82 return LightColors.RED;
85 if (SeverityRegistrar.getInstance(myProject).compare(severity, HighlightSeverity.WARNING) >= 0) {
86 return LightColors.YELLOW;
89 return Color.white;