use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class MacUtil method adjustFocusTraversal.
public static void adjustFocusTraversal(@NotNull Disposable disposable) {
if (!SystemInfo.isMacOSSnowLeopard)
return;
final AWTEventListener listener = new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
if (event instanceof KeyEvent && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_TAB && (!(event.getSource() instanceof JTextComponent)) && (!(event.getSource() instanceof JList)) && !isFullKeyboardAccessEnabled())
((KeyEvent) event).consume();
}
};
Disposer.register(disposable, new Disposable() {
@Override
public void dispose() {
Toolkit.getDefaultToolkit().removeAWTEventListener(listener);
}
});
Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK);
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class LineTooltipRenderer method show.
@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull final Point p, final boolean alignToRight, @NotNull final TooltipGroup group, @NotNull final HintHint hintHint) {
if (myText == null)
return null;
//setup text
myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);
final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
final JComponent contentComponent = editor.getContentComponent();
final JComponent editorComponent = editor.getComponent();
if (!editorComponent.isShowing())
return null;
final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
final JEditorPane pane = IdeTooltipManager.initPane(new Html(myText).setKeepFont(true), hintHint, layeredPane);
hintHint.setContentActive(isActiveHtml(myText));
if (!hintHint.isAwtTooltip()) {
correctLocation(editor, pane, p, alignToRight, expanded, myCurrentWidth);
}
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
scrollPane.setBorder(null);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setOpaque(hintHint.isOpaqueAllowed());
scrollPane.getViewport().setOpaque(hintHint.isOpaqueAllowed());
scrollPane.setBackground(hintHint.getTextBackground());
scrollPane.getViewport().setBackground(hintHint.getTextBackground());
scrollPane.setViewportBorder(null);
if (hintHint.isRequestFocus()) {
pane.setFocusable(true);
}
final Ref<AnAction> actionRef = new Ref<>();
final LightweightHint hint = new LightweightHint(scrollPane) {
@Override
public void hide() {
onHide(pane);
super.hide();
final AnAction action = actionRef.get();
if (action != null) {
action.unregisterCustomShortcutSet(contentComponent);
}
}
};
actionRef.set(new AnAction() {
// an action to expand description when tooltip was shown after mouse move; need to unregister from editor component
{
registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)), contentComponent);
}
@Override
public void actionPerformed(final AnActionEvent e) {
// The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut.
hintHint.setRequestFocus(ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent));
expand(hint, editor, p, pane, alignToRight, group, hintHint);
}
});
pane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
myActiveLink = true;
if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
myActiveLink = false;
return;
}
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
final URL url = e.getURL();
if (url != null) {
BrowserUtil.browse(url);
hint.hide();
return;
}
final String description = e.getDescription();
if (description != null && handle(description, editor)) {
hint.hide();
return;
}
if (!expanded) {
expand(hint, editor, p, pane, alignToRight, group, hintHint);
} else {
stripDescription();
hint.hide();
TooltipController.getInstance().showTooltip(editor, new Point(p.x - 3, p.y - 3), createRenderer(myText, 0), false, group, hintHint);
}
}
}
});
// This listener makes hint transparent for mouse events. It means that hint is closed
// by MousePressed and this MousePressed goes into the underlying editor component.
pane.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(final MouseEvent e) {
if (!myActiveLink) {
MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
hint.hide();
contentComponent.dispatchEvent(newMouseEvent);
}
}
@Override
public void mouseExited(final MouseEvent e) {
if (!expanded) {
hint.hide();
}
}
});
hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
return hint;
}
use of java.awt.event.KeyEvent 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.KeyEvent in project intellij-community by JetBrains.
the class ColorPipetteBase method getOrCreatePickerDialog.
@NotNull
protected Dialog getOrCreatePickerDialog() {
if (myPickerFrame == null) {
Window owner = SwingUtilities.getWindowAncestor(myParent);
if (owner instanceof Dialog) {
myPickerFrame = new JDialog((Dialog) owner);
} else if (owner instanceof Frame) {
myPickerFrame = new JDialog((Frame) owner);
} else {
myPickerFrame = new JDialog(new JFrame());
}
myPickerFrame.setTitle("intellijPickerDialog");
}
myPickerFrame.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
e.consume();
pickAndClose();
}
@Override
public void mouseClicked(MouseEvent e) {
e.consume();
}
});
myPickerFrame.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()) {
case KeyEvent.VK_ESCAPE:
cancelPipette();
break;
case KeyEvent.VK_ENTER:
pickAndClose();
break;
}
}
});
myPickerFrame.setUndecorated(true);
myPickerFrame.setAlwaysOnTop(!SystemInfo.isJavaVersionAtLeast("1.8.0") || canUseMacPipette());
JRootPane rootPane = myPickerFrame.getRootPane();
rootPane.putClientProperty("Window.shadow", Boolean.FALSE);
return myPickerFrame;
}
use of java.awt.event.KeyEvent in project intellij-plugins by JetBrains.
the class DartProblemsViewPanel method createTable.
@NotNull
private TableView<DartProblem> createTable() {
final TableView<DartProblem> table = new TableView<>(new DartProblemsTableModel(myProject, myPresentationHelper));
table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
// as in NewErrorTreeViewPanel
navigate(false);
}
}
});
EditSourceOnDoubleClickHandler.install(table);
table.addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
popupInvoked(comp, x, y);
}
});
//noinspection unchecked
((DefaultRowSorter) table.getRowSorter()).setRowFilter(myPresentationHelper.getRowFilter());
table.getRowSorter().addRowSorterListener(e -> {
final List<? extends RowSorter.SortKey> sortKeys = myTable.getRowSorter().getSortKeys();
assert sortKeys.size() == 1 : sortKeys;
((DartProblemsTableModel) myTable.getModel()).setSortKey(sortKeys.get(0));
});
new TableSpeedSearch(table, object -> object instanceof DartProblem ? ((DartProblem) object).getErrorMessage() + " " + ((DartProblem) object).getPresentableLocation() : "");
table.setShowVerticalLines(false);
table.setShowHorizontalLines(false);
table.setStriped(true);
table.setRowHeight(table.getRowHeight() + JBUI.scale(4));
JTableHeader tableHeader = table.getTableHeader();
tableHeader.setPreferredSize(new Dimension(0, table.getRowHeight()));
return table;
}
Aggregations