From cba40c31d991bcfbf4606076290984f0a92637f6 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Fri, 3 Oct 2014 17:50:44 +0400 Subject: [PATCH] Move the SwingActionLink class --- .../ui/components/labels/SwingActionLink.java} | 16 +++++++--------- .../openapi/options/newEditor/Banner.java | 11 +++++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) rename platform/{platform-impl/src/com/intellij/openapi/options/newEditor/ActionLink.java => platform-api/src/com/intellij/ui/components/labels/SwingActionLink.java} (74%) diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/ActionLink.java b/platform/platform-api/src/com/intellij/ui/components/labels/SwingActionLink.java similarity index 74% rename from platform/platform-impl/src/com/intellij/openapi/options/newEditor/ActionLink.java rename to platform/platform-api/src/com/intellij/ui/components/labels/SwingActionLink.java index a133f724a0a8..993cb3d8da7b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/ActionLink.java +++ b/platform/platform-api/src/com/intellij/ui/components/labels/SwingActionLink.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.openapi.options.newEditor; +package com.intellij.ui.components.labels; -import com.intellij.ui.components.labels.LinkLabel; import org.jetbrains.annotations.NotNull; import javax.swing.Action; @@ -28,20 +27,19 @@ import static java.beans.EventHandler.create; /** * @author Sergey.Malenkov */ -final class ActionLink extends LinkLabel { +public class SwingActionLink extends LinkLabel implements LinkListener { private final ActionEvent myEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Action.ACTION_COMMAND_KEY); - private final Action myAction; - ActionLink(@NotNull Action action) { - super("" + action.getValue(Action.NAME), (Icon)action.getValue(Action.SMALL_ICON)); + public SwingActionLink(@NotNull Action action) { + super((String)action.getValue(Action.NAME), (Icon)action.getValue(Action.SMALL_ICON)); setToolTipText((String)action.getValue(Action.SHORT_DESCRIPTION)); setVisible(action.isEnabled()); - myAction = action; + setListener(this, action); action.addPropertyChangeListener(create(PropertyChangeListener.class, this, "visible", "source.enabled")); } @Override - public void doClick() { - myAction.actionPerformed(myEvent); + public void linkSelected(LinkLabel link, Action action) { + action.actionPerformed(myEvent); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/Banner.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/Banner.java index 4a2c00d902d3..0728b9c5479c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/Banner.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/Banner.java @@ -19,6 +19,7 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.options.OptionsBundle; import com.intellij.openapi.project.Project; import com.intellij.ui.JBColor; +import com.intellij.ui.components.labels.SwingActionLink; import javax.swing.Action; import javax.swing.BorderFactory; @@ -27,23 +28,29 @@ import javax.swing.JLabel; import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.Component; +import java.awt.Font; /** * @author Sergey.Malenkov */ final class Banner extends JPanel { - private final JPanel myLeftPanel = new JPanel(); + private final JPanel myLeftPanel = new JPanel(null); private final JLabel myProjectIcon = new JLabel(); Banner(Action action) { super(new BorderLayout(10, 0)); + SwingActionLink link = new SwingActionLink(action); myLeftPanel.setLayout(new BoxLayout(myLeftPanel, BoxLayout.X_AXIS)); myProjectIcon.setIcon(AllIcons.General.ProjectConfigurableBanner); myProjectIcon.setForeground(JBColor.GRAY); myProjectIcon.setVisible(false); add(BorderLayout.WEST, myLeftPanel); add(BorderLayout.CENTER, myProjectIcon); - add(BorderLayout.EAST, new ActionLink(action)); + add(BorderLayout.EAST, link); + Font font = link.getFont(); + if (font != null) { + link.setFont(font.deriveFont(Font.BOLD)); + } } void setText(String... text) {