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(); } } } }); }
private void tratarNovoXEditor(XNumberEditor editor) { for (MouseWheelListener l : super.getMouseWheelListeners()) { if (l instanceof XNumberEditor) { super.removeMouseWheelListener(l); } } super.addMouseWheelListener(editor); JComponent textField = editor.getTextField(); for (KeyListener l : textField.getKeyListeners()) { if (l instanceof XNumberEditor) { textField.removeKeyListener(l); } } textField.addKeyListener(editor); }
public PannerHandler(JComponent target, Dimension size, int percent, Point offset) { this.target = target; this.size = size; this.percent = percent; this.offset = offset; this.corner = percent < 50 ? UL : CENTER; target.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (!affixed) { int modifiers = e.getModifiers(); if ((modifiers & PANNER_MASK) == PANNER_MASK) { if (panner == null || !panner.isAttached()) show(false); } } } public void keyReleased(KeyEvent e) { if (!affixed) { hide(); } } }); ComponentListener listener = new ComponentAdapter() { private void refresh() { if (panner != null && panner.isShowing()) show(affixed); } public void componentResized(ComponentEvent e) { refresh(); } public void componentMoved(ComponentEvent e) { refresh(); } }; target.addComponentListener(listener); if (target.getParent() instanceof JViewport) { target.getParent().addComponentListener(listener); } }
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()); } }); }
// This method is called when editing is completed. // It must return the new value to be stored in the cell. public DblCellEditor() { component.addKeyListener(this); ((JRtaTextField) component).listenerLoeschen(); }
private void trackModifiers() { assert !isAutopopupCompletion(); final JComponent contentComponent = myEditor.getContentComponent(); contentComponent.addKeyListener(new ModifierTracker(contentComponent)); }
public static void numpad(JComponent comp, final JLabel lbl_qty) { comp.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { String qty = lbl_qty.getText(); if (e.getKeyCode() == 96 || e.getKeyCode() == 48) { qty = qty + "0"; lbl_qty.setText(qty); } if (e.getKeyCode() == 97 || e.getKeyCode() == 49) { qty = qty + "1"; lbl_qty.setText(qty); } if (e.getKeyCode() == 98 || e.getKeyCode() == 50) { qty = qty + "2"; lbl_qty.setText(qty); } if (e.getKeyCode() == 99 || e.getKeyCode() == 51) { qty = qty + "3"; lbl_qty.setText(qty); } if (e.getKeyCode() == 100 || e.getKeyCode() == 52) { qty = qty + "4"; lbl_qty.setText(qty); } if (e.getKeyCode() == 101 || e.getKeyCode() == 53) { qty = qty + "5"; lbl_qty.setText(qty); } if (e.getKeyCode() == 102 || e.getKeyCode() == 54) { qty = qty + "6"; lbl_qty.setText(qty); } if (e.getKeyCode() == 103 || e.getKeyCode() == 55) { qty = qty + "7"; lbl_qty.setText(qty); } if (e.getKeyCode() == 104 || e.getKeyCode() == 56) { qty = qty + "8"; lbl_qty.setText(qty); } if (e.getKeyCode() == 105 || e.getKeyCode() == 57) { qty = qty + "9"; lbl_qty.setText(qty); } if (e.getKeyCode() == 110 || e.getKeyCode() == 46) { qty = qty + "."; lbl_qty.setText(qty); } if (e.getKeyCode() == 8) { int length = lbl_qty.getText().length(); if (length > 0) { String var = lbl_qty.getText(); var = var.substring(0, length - 1); lbl_qty.setText(var); } } } }); }