nice dotted border
[fedora-idea.git] / platform / platform-api / src / com / intellij / ui / EditorNotificationPanel.java
blobe6bb687ab640543fa60f544b8bae9cadfa8c3733
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);
47 myLinksPanel = new JPanel(new FlowLayout());
48 myLinksPanel.setBackground(LightColors.YELLOW);
49 add(myLinksPanel, BorderLayout.EAST);
52 public void setText(String text) {
53 myLabel.setText(text);
56 public HyperlinkLabel createActionLabel(final String text, @NonNls final String actionId) {
57 return createActionLabel(text, new Runnable() {
58 public void run() {
59 executeAction(actionId);
61 });
64 public HyperlinkLabel createActionLabel(final String text, final Runnable action) {
65 HyperlinkLabel label = new HyperlinkLabel(text, Color.BLUE, LightColors.YELLOW, Color.BLUE);
66 label.addHyperlinkListener(new HyperlinkListener() {
67 public void hyperlinkUpdate(final HyperlinkEvent e) {
68 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
69 action.run();
72 });
73 myLinksPanel.add(label);
74 return label;
77 protected void executeAction(final String actionId) {
78 final AnAction action = ActionManager.getInstance().getAction(actionId);
79 final AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(this), ActionPlaces.UNKNOWN,
80 action.getTemplatePresentation(), ActionManager.getInstance(),
81 0);
82 action.beforeActionPerformedUpdate(event);
83 action.update(event);
85 if (event.getPresentation().isEnabled() && event.getPresentation().isVisible()) {
86 action.actionPerformed(event);