use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.
the class AbstractCustomizeWizardStep method createBigButtonPanel.
protected static JPanel createBigButtonPanel(LayoutManager layout, final JToggleButton anchorButton, final Runnable action) {
final JPanel panel = new JPanel(layout) {
@Override
public Color getBackground() {
return anchorButton.isSelected() ? getSelectionBackground() : super.getBackground();
}
};
panel.setOpaque(anchorButton.isSelected());
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
anchorButton.setSelected(true);
return true;
}
}.installOn(panel);
anchorButton.addItemListener(new ItemListener() {
boolean curState = anchorButton.isSelected();
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED && curState != anchorButton.isSelected()) {
action.run();
}
curState = anchorButton.isSelected();
panel.setOpaque(curState);
panel.repaint();
}
});
return panel;
}
use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.
the class TextFieldAction method createCustomComponent.
@Override
public JComponent createCustomComponent(Presentation presentation) {
// honestly borrowed from SearchTextField
final JPanel panel = new JPanel(new BorderLayout());
final JLabel label = new JLabel(myIcon);
label.setOpaque(true);
label.setBackground(myField.getBackground());
myField.setOpaque(true);
panel.add(myField, BorderLayout.WEST);
panel.add(label, BorderLayout.EAST);
myField.setToolTipText(myDescription);
label.setToolTipText(myDescription);
final Border originalBorder;
if (SystemInfo.isMac) {
originalBorder = BorderFactory.createLoweredBevelBorder();
} else {
originalBorder = myField.getBorder();
}
panel.setBorder(new CompoundBorder(IdeBorderFactory.createEmptyBorder(4, 0, 4, 0), originalBorder));
myField.setOpaque(true);
myField.setBorder(IdeBorderFactory.createEmptyBorder(0, 5, 0, 5));
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
actionPerformed(null);
return true;
}
}.installOn(label);
return panel;
}
use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.
the class XWatchesViewImpl method installEditListeners.
private void installEditListeners() {
final XDebuggerTree watchTree = getTree();
final Alarm quitePeriod = new Alarm();
final Alarm editAlarm = new Alarm();
final ClickListener mouseListener = new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
if (!SwingUtilities.isLeftMouseButton(event) || ((event.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) != 0)) {
return false;
}
boolean sameRow = isAboveSelectedItem(event, watchTree, false);
if (!sameRow || clickCount > 1) {
editAlarm.cancelAllRequests();
return false;
}
final AnAction editWatchAction = ActionManager.getInstance().getAction(XDebuggerActions.XEDIT_WATCH);
Presentation presentation = editWatchAction.getTemplatePresentation().clone();
DataContext context = DataManager.getInstance().getDataContext(watchTree);
final AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0);
Runnable runnable = () -> editWatchAction.actionPerformed(actionEvent);
if (editAlarm.isEmpty() && quitePeriod.isEmpty()) {
editAlarm.addRequest(runnable, UIUtil.getMultiClickInterval());
} else {
editAlarm.cancelAllRequests();
}
return false;
}
};
final ClickListener mouseEmptySpaceListener = new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent event) {
if (!isAboveSelectedItem(event, watchTree, true)) {
myRootNode.addNewWatch();
return true;
}
return false;
}
};
ListenerUtil.addClickListener(watchTree, mouseListener);
ListenerUtil.addClickListener(watchTree, mouseEmptySpaceListener);
final FocusListener focusListener = new FocusListener() {
@Override
public void focusGained(@NotNull FocusEvent e) {
quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
}
@Override
public void focusLost(@NotNull FocusEvent e) {
editAlarm.cancelAllRequests();
}
};
ListenerUtil.addFocusListener(watchTree, focusListener);
final TreeSelectionListener selectionListener = new TreeSelectionListener() {
@Override
public void valueChanged(@NotNull TreeSelectionEvent e) {
quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
}
};
watchTree.addTreeSelectionListener(selectionListener);
myDisposables.add(new Disposable() {
@Override
public void dispose() {
ListenerUtil.removeClickListener(watchTree, mouseListener);
ListenerUtil.removeClickListener(watchTree, mouseEmptySpaceListener);
ListenerUtil.removeFocusListener(watchTree, focusListener);
watchTree.removeTreeSelectionListener(selectionListener);
}
});
}
use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.
the class OptionTreeWithPreviewPanel method createOptionsTree.
protected JTree createOptionsTree() {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
String groupName = "";
DefaultMutableTreeNode groupNode = null;
List<BooleanOptionKey> result = sortOptions(orderByGroup(myKeys));
for (BooleanOptionKey key : result) {
String newGroupName = key.groupName;
if (!newGroupName.equals(groupName) || groupNode == null) {
groupName = newGroupName;
groupNode = new DefaultMutableTreeNode(newGroupName);
rootNode.add(groupNode);
}
if (isOptionVisible(key)) {
groupNode.add(new MyToggleTreeNode(key, key.title));
}
}
DefaultTreeModel model = new DefaultTreeModel(rootNode);
final Tree optionsTree = new Tree(model);
new TreeSpeedSearch(optionsTree).setComparator(new SpeedSearchComparator(false));
TreeUtil.installActions(optionsTree);
optionsTree.setRootVisible(false);
UIUtil.setLineStyleAngled(optionsTree);
optionsTree.setShowsRootHandles(true);
optionsTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (!optionsTree.isEnabled())
return;
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
TreePath treePath = optionsTree.getLeadSelectionPath();
selectCheckbox(treePath);
e.consume();
}
}
});
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
if (!optionsTree.isEnabled())
return false;
TreePath treePath = optionsTree.getPathForLocation(e.getX(), e.getY());
selectCheckbox(treePath);
return true;
}
}.installOn(optionsTree);
int row = 0;
while (row < optionsTree.getRowCount()) {
optionsTree.expandRow(row);
row++;
}
return optionsTree;
}
use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.
the class AbstractDescriptionAwareSchemesPanel method createInfoComponent.
@NotNull
@Override
protected JPanel createInfoComponent() {
JPanel panel = new JPanel();
myLayout = new CardLayout();
panel.setLayout(myLayout);
myDescriptionTextField = new JBTextField();
myDescriptionTextField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
applyDescription();
}
});
myDescriptionTextField.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showDescription();
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(getConfigurableFocusComponent(), true);
});
}
}, ESC_KEY_STROKE, JComponent.WHEN_FOCUSED);
myDescriptionTextField.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
applyDescription();
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(getConfigurableFocusComponent(), true);
});
}
}, ENTER_KEY_STROKE, JComponent.WHEN_FOCUSED);
myDescriptionLabel = new DescriptionLabel();
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
if (clickCount != 2) {
return false;
}
editDescription(myDescriptionLabel.getText());
return true;
}
}.installOn(myDescriptionLabel);
myWarningLabel = new JLabel();
panel.add(myDescriptionTextField, EDIT_DESCRIPTION_CARD);
panel.add(myDescriptionLabel, SHOW_DESCRIPTION_CARD);
panel.add(myWarningLabel, ERROR_CARD);
myLayout.show(panel, ERROR_CARD);
return panel;
}
Aggregations