use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.
the class QuickFixAction method createCustomComponent.
@Override
public JComponent createCustomComponent(Presentation presentation) {
final JButton button = new JButton(presentation.getText());
Icon icon = presentation.getIcon();
if (icon == null) {
icon = AllIcons.Actions.CreateFromUsage;
}
button.setEnabled(presentation.isEnabled());
button.setIcon(IconLoader.getTransparentIcon(icon, 0.75f));
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
final ActionToolbar toolbar = UIUtil.getParentOfType(ActionToolbar.class, button);
actionPerformed(AnActionEvent.createFromAnAction(QuickFixAction.this, event, ActionPlaces.UNKNOWN, toolbar == null ? DataManager.getInstance().getDataContext(button) : toolbar.getToolbarDataContext()));
return true;
}
}.installOn(button);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
panel.setBorder(IdeBorderFactory.createEmptyBorder(7, 0, 8, 0));
panel.add(button);
return panel;
}
use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.
the class TrackRunningTestUtil method installStopListeners.
public static void installStopListeners(final JTree tree, final Disposable parentDisposable, final Pass<AbstractTestProxy> setSelection) {
final ClickListener userSelectionListener = new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
setSelection.pass(setUserSelection(tree.getPathForLocation(e.getX(), e.getY())));
return true;
}
};
userSelectionListener.installOn(tree);
final KeyAdapter keyAdapter = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
final int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_PAGE_DOWN || keyCode == KeyEvent.VK_PAGE_UP) {
setSelection.pass(setUserSelection(tree.getSelectionPath()));
}
}
};
tree.addKeyListener(keyAdapter);
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
userSelectionListener.uninstall(tree);
tree.removeKeyListener(keyAdapter);
}
});
}
use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.
the class RichTextActionProcessor method process.
@Override
public JComponent process(@NotNull String s) {
final ActionManager actionManager = ActionManager.getInstance();
final AnAction action = actionManager.getAction(s);
if (action == null) {
return null;
}
final Presentation presentation = action.getTemplatePresentation();
if (presentation.getIcon() != null) {
return new ActionButton(action, presentation.clone(), GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, JBUI.emptySize()) {
@Override
protected void paintButtonLook(Graphics g) {
// Don't draw border at the inline button.
ActionButtonLook look = getButtonLook();
look.paintBackground(g, this);
look.paintIcon(g, this, getIcon());
}
};
}
final String text = action.getTemplatePresentation().getText();
JLabel result = new JLabel(text) {
public void paint(Graphics g) {
super.paint(g);
final int y = g.getClipBounds().height - getFontMetrics(getFont()).getDescent() + 2;
final int width = getFontMetrics(getFont()).stringWidth(getText());
g.drawLine(0, y, width, y);
}
};
Color color = UIUtil.isUnderDarcula() ? Color.ORANGE : Color.BLUE;
result.setForeground(color);
result.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
final AsyncResult<DataContext> callback = DataManager.getInstance().getDataContextFromFocus();
final DataContext context = callback.getResult();
if (context == null) {
return false;
}
final Presentation presentation = new PresentationFactory().getPresentation(action);
action.actionPerformed(new AnActionEvent(e, context, GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, presentation, ActionManager.getInstance(), e.getModifiers()));
return true;
}
}.installOn(result);
return result;
}
Aggregations