use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class IdePopupManager method dispatch.
public boolean dispatch(@NotNull final AWTEvent e) {
LOG.assertTrue(isPopupActive());
if (e.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
ApplicationManager.getApplication().invokeLater(() -> {
if (!isPopupActive())
return;
boolean shouldCloseAllPopup = false;
Window focused = ((WindowEvent) e).getOppositeWindow();
if (focused == null) {
focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
}
if (focused == null) {
shouldCloseAllPopup = true;
}
Component ultimateParentForFocusedComponent = UIUtil.findUltimateParent(focused);
Window sourceWindow = ((WindowEvent) e).getWindow();
Component ultimateParentForEventWindow = UIUtil.findUltimateParent(sourceWindow);
if (!shouldCloseAllPopup && ultimateParentForEventWindow == null || ultimateParentForFocusedComponent == null) {
shouldCloseAllPopup = true;
}
if (!shouldCloseAllPopup && ultimateParentForEventWindow instanceof IdeFrameEx) {
IdeFrameEx ultimateParentWindowForEvent = ((IdeFrameEx) ultimateParentForEventWindow);
if (ultimateParentWindowForEvent.isInFullScreen() && !ultimateParentForFocusedComponent.equals(ultimateParentForEventWindow)) {
shouldCloseAllPopup = true;
}
}
if (!shouldCloseAllPopup && isPopupWindow(sourceWindow) && sourceWindow.getParent() == ((WindowEvent) e).getOppositeWindow()) {
shouldCloseAllPopup = true;
}
if (shouldCloseAllPopup) {
closeAllPopups();
}
});
}
if (e instanceof KeyEvent || e instanceof MouseEvent) {
for (int i = myDispatchStack.size() - 1; (i >= 0 && i < myDispatchStack.size()); i--) {
final boolean dispatched = myDispatchStack.get(i).dispatch(e);
if (dispatched)
return true;
}
}
return false;
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class ChooseElementsDialog method initializeDialog.
private void initializeDialog(final List<? extends T> items, final String title, boolean sort) {
setTitle(title);
myChooser = new ElementsChooser<T>(false) {
protected String getItemText(@NotNull final T item) {
return ChooseElementsDialog.this.getItemText(item);
}
};
myChooser.setColorUnmarkedElements(false);
List<? extends T> elements = new ArrayList<T>(items);
if (sort) {
Collections.sort(elements, new Comparator<T>() {
public int compare(final T o1, final T o2) {
return getItemText(o1).compareToIgnoreCase(getItemText(o2));
}
});
}
setElements(elements, elements.size() > 0 ? elements.subList(0, 1) : Collections.<T>emptyList());
myChooser.getComponent().registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doOKAction();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
doOKAction();
return true;
}
}.installOn(myChooser.getComponent());
init();
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class EventLogConsole method createLogEditor.
private Editor createLogEditor() {
Project project = myProjectModel.getProject();
final EditorEx editor = ConsoleViewUtil.setupConsoleEditor(project, false, false);
editor.getSettings().setWhitespacesShown(false);
installNotificationsFont(editor);
myProjectModel.getProject().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerAdapter() {
@Override
public void projectClosed(Project project) {
if (project == myProjectModel.getProject()) {
EditorFactory.getInstance().releaseEditor(editor);
}
}
});
((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
final ClearLogAction clearLog = new ClearLogAction(this);
clearLog.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.CONSOLE_CLEAR_ALL).getShortcutSet(), editor.getContentComponent());
// disabling default context menu
editor.setContextMenuGroupId(null);
editor.addEditorMouseListener(new EditorPopupHandler() {
public void invokePopup(final EditorMouseEvent event) {
final ActionManager actionManager = ActionManager.getInstance();
DefaultActionGroup actions = createPopupActions(actionManager, clearLog, editor, event);
final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.EDITOR_POPUP, actions);
final MouseEvent mouseEvent = event.getMouseEvent();
menu.getComponent().show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
}
});
return editor;
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class ToolWindowContentUi method initMouseListeners.
public static void initMouseListeners(final JComponent c, final ToolWindowContentUi ui) {
if (c.getClientProperty(ui) != null)
return;
final Point[] myLastPoint = new Point[1];
c.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(final MouseEvent e) {
if (myLastPoint[0] == null)
return;
final Window window = SwingUtilities.windowForComponent(c);
if (window instanceof IdeFrame)
return;
final Point windowLocation = window.getLocationOnScreen();
PointerInfo info = MouseInfo.getPointerInfo();
if (info == null)
return;
final Point newPoint = info.getLocation();
Point p = myLastPoint[0];
windowLocation.translate(newPoint.x - p.x, newPoint.y - p.y);
window.setLocation(windowLocation);
myLastPoint[0] = newPoint;
}
});
c.addMouseListener(new MouseAdapter() {
public void mousePressed(final MouseEvent e) {
PointerInfo info = MouseInfo.getPointerInfo();
myLastPoint[0] = info != null ? info.getLocation() : e.getLocationOnScreen();
if (!e.isPopupTrigger()) {
if (!UIUtil.isCloseClick(e)) {
ui.myWindow.fireActivated();
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (!e.isPopupTrigger()) {
if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) {
ui.processHide(e);
}
}
}
});
c.addMouseListener(new PopupHandler() {
public void invokePopup(final Component comp, final int x, final int y) {
final Content content = c instanceof BaseLabel ? ((BaseLabel) c).getContent() : null;
ui.showContextMenu(comp, x, y, ui.myWindow.getPopupGroup(), content);
}
});
c.putClientProperty(ui, Boolean.TRUE);
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class ShowUIDefaultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final UIDefaults defaults = UIManager.getDefaults();
Enumeration keys = defaults.keys();
final Object[][] data = new Object[defaults.size()][2];
int i = 0;
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
data[i][0] = key;
data[i][1] = defaults.get(key);
i++;
}
Arrays.sort(data, (o1, o2) -> StringUtil.naturalCompare(o1[0].toString(), o2[0].toString()));
final Project project = getEventProject(e);
new DialogWrapper(project) {
{
setTitle("Edit LaF Defaults");
setModal(false);
init();
}
public JBTable myTable;
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return myTable;
}
@Nullable
@Override
protected String getDimensionServiceKey() {
return project == null ? null : "UI.Defaults.Dialog";
}
@Override
protected JComponent createCenterPanel() {
final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 1 && getValueAt(row, column) instanceof Color;
}
}) {
@Override
public boolean editCellAt(int row, int column, EventObject e) {
if (isCellEditable(row, column) && e instanceof MouseEvent) {
final Object color = getValueAt(row, column);
final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true, null, true);
if (newColor != null) {
final ColorUIResource colorUIResource = new ColorUIResource(newColor);
final Object key = getValueAt(row, 0);
UIManager.put(key, colorUIResource);
setValueAt(colorUIResource, row, column);
}
}
return false;
}
};
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final JPanel panel = new JPanel(new BorderLayout());
final JLabel label = new JLabel(value == null ? "" : value.toString());
panel.add(label, BorderLayout.CENTER);
if (value instanceof Color) {
final Color c = (Color) value;
label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(), c.getBlue(), ColorUtil.toHex(c)));
label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
panel.setBackground(c);
return panel;
} else if (value instanceof Icon) {
try {
final Icon icon = new IconWrap((Icon) value);
if (icon.getIconHeight() <= 20) {
label.setIcon(icon);
}
label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(), icon.getIconHeight(), label.getText()));
} catch (Throwable e1) {
//
}
return panel;
} else if (value instanceof Border) {
try {
final Insets i = ((Border) value).getBorderInsets(null);
label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
return panel;
} catch (Exception ignore) {
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
final JBScrollPane pane = new JBScrollPane(table);
new TableSpeedSearch(table, (o, cell) -> cell.column == 1 ? null : String.valueOf(o));
table.setShowGrid(false);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(pane, BorderLayout.CENTER);
myTable = table;
TableUtil.ensureSelectionExists(myTable);
return panel;
}
}.show();
}
Aggregations