private HighlightersSet installHighlighterSet(Info info, Editor editor) { final JComponent internalComponent = editor.getContentComponent(); internalComponent.addKeyListener(myEditorKeyListener); editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); final Cursor cursor = internalComponent.getCursor(); internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener); List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); TextAttributes attributes = myEditorColorsManager .getGlobalScheme() .getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR); for (TextRange range : info.getRanges()) { TextAttributes attr = patchAttributesColor(attributes, range, editor); final RangeHighlighter highlighter = editor .getMarkupModel() .addRangeHighlighter( range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION + 1, attr, HighlighterTargetArea.EXACT_RANGE); highlighters.add(highlighter); } return new HighlightersSet(highlighters, editor, cursor, info); }
/** * Set up key bindings and focus listener for the FieldEditor. * * @param component */ public void setupJTextComponent(final JComponent component, final AutoCompleteListener acl) { // Here we add focus listeners to the component. The funny code is because we need // to guarantee that the AutoCompleteListener - if used - is called before fieldListener // on a focus lost event. The AutoCompleteListener is responsible for removing any // current suggestion when focus is lost, and this must be done before fieldListener // stores the current edit. Swing doesn't guarantee the order of execution of event // listeners, so we handle this by only adding the AutoCompleteListener and telling // it to call fieldListener afterwards. If no AutoCompleteListener is used, we // add the fieldListener normally. if (acl != null) { component.addKeyListener(acl); component.addFocusListener(acl); acl.setNextFocusListener(fieldListener); } else component.addFocusListener(fieldListener); InputMap im = component.getInputMap(JComponent.WHEN_FOCUSED); ActionMap am = component.getActionMap(); im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev"); am.put("prev", parent.prevEntryAction); im.put(Globals.prefs.getKey("Entry editor, next entry"), "next"); am.put("next", parent.nextEntryAction); im.put(Globals.prefs.getKey("Entry editor, store field"), "store"); am.put("store", parent.storeFieldAction); im.put(Globals.prefs.getKey("Entry editor, next panel"), "right"); im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right"); am.put("left", parent.switchLeftAction); im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left"); im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left"); am.put("right", parent.switchRightAction); im.put(Globals.prefs.getKey("Help"), "help"); am.put("help", parent.helpAction); im.put(Globals.prefs.getKey("Save database"), "save"); am.put("save", parent.saveDatabaseAction); im.put(Globals.prefs.getKey("Next tab"), "nexttab"); am.put("nexttab", parent.frame.nextTab); im.put(Globals.prefs.getKey("Previous tab"), "prevtab"); am.put("prevtab", parent.frame.prevTab); try { HashSet<AWTKeyStroke> keys = new HashSet<AWTKeyStroke>( component.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB")); component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); keys = new HashSet<AWTKeyStroke>( component.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(KeyStroke.getKeyStroke("shift pressed TAB")); component.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys); } catch (Throwable t) { System.err.println(t); } }
public void setFocusEnter(JComponent sebelum, final JComponent sesudah) { sebelum.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { sesudah.requestFocus(); } } }); }
/** * Creates a new {@code SwingTerminalImplementation} * * @param component JComponent that is the Swing terminal surface * @param fontConfiguration Font configuration to use * @param initialTerminalSize Initial size of the terminal * @param deviceConfiguration Device configuration * @param colorConfiguration Color configuration * @param scrollController Controller to be used when inspecting scroll status */ SwingTerminalImplementation( JComponent component, SwingTerminalFontConfiguration fontConfiguration, TerminalSize initialTerminalSize, TerminalEmulatorDeviceConfiguration deviceConfiguration, TerminalEmulatorColorConfiguration colorConfiguration, TerminalScrollController scrollController) { super(initialTerminalSize, deviceConfiguration, colorConfiguration, scrollController); this.component = component; this.fontConfiguration = fontConfiguration; // Prevent us from shrinking beyond one character component.setMinimumSize( new Dimension(fontConfiguration.getFontWidth(), fontConfiguration.getFontHeight())); //noinspection unchecked component.setFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.<AWTKeyStroke>emptySet()); //noinspection unchecked component.setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.<AWTKeyStroke>emptySet()); // Make sure the component is double-buffered to prevent flickering component.setDoubleBuffered(true); component.addKeyListener(new TerminalInputListener()); component.addMouseListener( new TerminalMouseListener() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); SwingTerminalImplementation.this.component.requestFocusInWindow(); } }); component.addHierarchyListener( new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent e) { if (e.getChangeFlags() == HierarchyEvent.DISPLAYABILITY_CHANGED) { if (e.getChanged().isDisplayable()) { onCreated(); } else { onDestroyed(); } } } }); }
public Java2DWindow(Core core, int width, int height) { this.core = core; this._frame = new JFrame(); this._frame.setSize(width, height); this._frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this._rootcomp = new JComponent() { @Override protected void paintComponent(Graphics graphics) { Graphics2D gfx = (Graphics2D) graphics; _update(gfx, this); } }; this._frame.add(_rootcomp); MasterListener ml = new MasterListener(_rootcomp, this); _rootcomp.addMouseListener(ml); _rootcomp.addMouseMotionListener(ml); _rootcomp.addKeyListener(ml); }
private HighlightersSet installHighlighterSet(Info info, Editor editor) { final JComponent internalComponent = editor.getContentComponent(); internalComponent.addKeyListener(myEditorKeyListener); editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); final Cursor cursor = internalComponent.getCursor(); internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener); List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); for (TextRange range : info.getRanges()) { final RangeHighlighter highlighter = editor .getMarkupModel() .addRangeHighlighter( range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION + 1, ourReferenceAttributes, HighlighterTargetArea.EXACT_RANGE); highlighters.add(highlighter); } return new HighlightersSet(highlighters, editor, cursor, info); }
private void installFocusable( final JComponent comp, final AnAction action, final int prevKeyCode, final int nextKeyCode, final boolean focusListOnLeft) { comp.setFocusable(true); comp.setFocusTraversalKeysEnabled(true); comp.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { final JList list = UIUtil.findComponentOfType(FlatWelcomeFrame.this.getComponent(), JList.class); if (e.getKeyCode() == KeyEvent.VK_ENTER) { InputEvent event = e; if (e.getComponent() instanceof JComponent) { ActionLink link = UIUtil.findComponentOfType((JComponent) e.getComponent(), ActionLink.class); if (link != null) { event = new MouseEvent( link, MouseEvent.MOUSE_CLICKED, e.getWhen(), e.getModifiers(), 0, 0, 1, false, MouseEvent.BUTTON1); } } action.actionPerformed( AnActionEvent.createFromAnAction( action, event, ActionPlaces.WELCOME_SCREEN, DataManager.getInstance().getDataContext())); } else if (e.getKeyCode() == prevKeyCode) { focusPrev(comp); } else if (e.getKeyCode() == nextKeyCode) { focusNext(comp); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { if (focusListOnLeft) { if (list != null) { list.requestFocus(); } } else { focusPrev(comp); } } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { focusNext(comp); } } }); comp.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) { comp.setOpaque(true); comp.setBackground(getActionLinkSelectionColor()); } @Override public void focusLost(FocusEvent e) { comp.setOpaque(false); comp.setBackground(getMainBackground()); } }); }
private void trackModifiers() { assert !isAutopopupCompletion(); final JComponent contentComponent = myEditor.getContentComponent(); contentComponent.addKeyListener(new ModifierTracker(contentComponent)); }