-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreetingLabelAction.java
More file actions
57 lines (48 loc) · 2.01 KB
/
Copy pathGreetingLabelAction.java
File metadata and controls
57 lines (48 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dev.simplified.tabsimile.header;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
import com.intellij.openapi.project.DumbAware;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.JComponent;
/**
* Text label in the header, shown while {@link GreetingState} is on.
*
* <p>
* Two things at once. That a header slot can hold arbitrary text rather than only
* icon buttons, because an action toolbar renders whatever component a
* {@link CustomComponentAction} hands it. And that such a component can be shown and
* hidden at runtime - hiding is an ordinary {@code setEnabledAndVisible(false)} in
* {@link #update}, and the toolbar drops the component on its next pass.
*/
public final class GreetingLabelAction extends AnAction implements CustomComponentAction, DumbAware {
private static final String GREETING = "Hello!";
/** Constructs the greeting label. */
public GreetingLabelAction() {
super(GREETING);
}
@Override
public @NotNull JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place) {
JBLabel label = new JBLabel(GREETING);
label.setForeground(UIUtil.getContextHelpForeground());
label.setBorder(JBUI.Borders.empty(0, 8));
return label;
}
@Override
public void update(@NotNull AnActionEvent event) {
event.getPresentation().setEnabledAndVisible(GreetingState.getInstance().isVisible());
}
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
// A readout, not a button.
}
}