nice dotted border
[fedora-idea.git] / platform / platform-api / src / com / intellij / ui / EditorNotificationPanel.java
blob333ee61e1ceb203aeed523113cc5dd7b7439e62a
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.
16 package com.intellij.ui;
18 import com.intellij.ide.DataManager;
19 import com.intellij.openapi.actionSystem.ActionManager;
20 import com.intellij.openapi.actionSystem.ActionPlaces;
21 import com.intellij.openapi.actionSystem.AnAction;
22 import com.intellij.openapi.actionSystem.AnActionEvent;
23 import org.jetbrains.annotations.NonNls;
25 import javax.swing.*;
26 import javax.swing.event.HyperlinkEvent;
27 import javax.swing.event.HyperlinkListener;
28 import java.awt.*;
30 /**
31 * @author Dmitry Avdeev
33 public class EditorNotificationPanel extends JPanel {
35 protected final JLabel myLabel = new JLabel();
36 protected final JPanel myLinksPanel;
38 public EditorNotificationPanel() {
39 super(new BorderLayout());
41 setBackground(LightColors.YELLOW);
42 setBorder(new SideBorder(Color.black, SideBorder.BOTTOM, true));
44 setPreferredSize(new Dimension(-1, 24));
45 add(myLabel, BorderLayout.CENTER);
46 myLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
48 myLinksPanel = new JPanel(new FlowLayout());
49 myLinksPanel.setBackground(LightColors.YELLOW);
50 add(myLinksPanel, BorderLayout.EAST);
53 public void setText(String text) {
54 myLabel.setText(text);
57 public HyperlinkLabel createActionLabel(final String text, @NonNls final String actionId) {
58 return createActionLabel(text, new Runnable() {
59 public void run() {
60 executeAction(actionId);
62 });
65 public HyperlinkLabel createActionLabel(final String text, final Runnable action) {
66 HyperlinkLabel label = new HyperlinkLabel(text, Color.BLUE, LightColors.YELLOW, Color.BLUE);
67 label.addHyperlinkListener(new HyperlinkListener() {
68 public void hyperlinkUpdate(final HyperlinkEvent e) {
69 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
70 action.run();
73 });
74 myLinksPanel.add(label);
75 return label;
78 protected void executeAction(final String actionId) {
79 final AnAction action = ActionManager.getInstance().getAction(actionId);
80 final AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(this), ActionPlaces.UNKNOWN,
81 action.getTemplatePresentation(), ActionManager.getInstance(),
82 0);
83 action.beforeActionPerformedUpdate(event);
84 action.update(event);
86 if (event.getPresentation().isEnabled() && event.getPresentation().isVisible()) {
87 action.actionPerformed(event);