Search in sources :

Example 31 with JTextComponent

use of javax.swing.text.JTextComponent in project jabref by JabRef.

the class AutoCompleteListener method keyPressed.

@Override
public void keyPressed(KeyEvent e) {
    if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) {
        JTextComponent comp = (JTextComponent) e.getSource();
        // replace typed characters by characters from completion
        lastBeginning = lastCompletions.get(lastShownCompletion);
        int end = comp.getSelectionEnd();
        comp.select(end, end);
        toSetIn = null;
        if (consumeEnterKey) {
            e.consume();
        }
    } else // Cycle through alternative completions when user presses PGUP/PGDN:
    if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (toSetIn != null)) {
        cycle((JTextComponent) e.getSource(), 1);
        e.consume();
    } else if ((e.getKeyCode() == KeyEvent.VK_PAGE_UP) && (toSetIn != null)) {
        cycle((JTextComponent) e.getSource(), -1);
        e.consume();
    } else //        }
    if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
        if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
            // shift is OK, everything else leads to a reset
            LOGGER.debug("Special case: shift pressed. No action.");
        } else {
            resetAutoCompletion();
        }
    } else {
        LOGGER.debug("Special case: defined character, but not caught above");
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent)

Example 32 with JTextComponent

use of javax.swing.text.JTextComponent in project jabref by JabRef.

the class EmacsKeyBindings method createBackup.

private static void createBackup() {
    Keymap oldBackup = JTextComponent.getKeymap(EmacsKeyBindings.JTCS[0].getClass().getName());
    if (oldBackup != null) {
        // if there is already a backup, do not create a new backup
        return;
    }
    for (JTextComponent jtc : EmacsKeyBindings.JTCS) {
        Keymap orig = jtc.getKeymap();
        Keymap backup = JTextComponent.addKeymap(jtc.getClass().getName(), null);
        Action[] bound = orig.getBoundActions();
        for (Action aBound : bound) {
            KeyStroke[] strokes = orig.getKeyStrokesForAction(aBound);
            for (KeyStroke stroke : strokes) {
                backup.addActionForKeyStroke(stroke, aBound);
            }
        }
        backup.setDefaultAction(orig.getDefaultAction());
    }
}
Also used : Action(javax.swing.Action) TextAction(javax.swing.text.TextAction) KeyStroke(javax.swing.KeyStroke) JTextComponent(javax.swing.text.JTextComponent) Keymap(javax.swing.text.Keymap)

Example 33 with JTextComponent

use of javax.swing.text.JTextComponent in project jabref by JabRef.

the class EmacsKeyBindings method loadEmacsKeyBindings.

/**
     * Activates Emacs keybindings for all text components extending {@link
     * JTextComponent}.
     */
private static void loadEmacsKeyBindings() {
    EmacsKeyBindings.LOGGER.debug("Loading emacs keybindings");
    for (JTextComponent jtc : EmacsKeyBindings.JTCS) {
        Action[] origActions = jtc.getActions();
        Action[] actions = new Action[origActions.length + EmacsKeyBindings.EMACS_ACTIONS.length];
        System.arraycopy(origActions, 0, actions, 0, origActions.length);
        System.arraycopy(EmacsKeyBindings.EMACS_ACTIONS, 0, actions, origActions.length, EmacsKeyBindings.EMACS_ACTIONS.length);
        Keymap k = jtc.getKeymap();
        JTextComponent.KeyBinding[] keybindings;
        boolean rebindCA = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CA);
        boolean rebindCF = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CF);
        if (rebindCA || rebindCF) {
            // if we additionally rebind C-a or C-f, we have to add the shortcuts to EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE
            // determine size of new array and position of the new key bindings in the array
            int size = EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE.length;
            int posCA = -1;
            int posCF = -1;
            if (rebindCA) {
                posCA = size;
                size++;
            }
            if (rebindCF) {
                posCF = size;
                size++;
            }
            // generate new array
            keybindings = new JTextComponent.KeyBinding[size];
            System.arraycopy(EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE, 0, keybindings, 0, EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE.length);
            if (rebindCA) {
                keybindings[posCA] = EmacsKeyBindings.EMACS_KEY_BINDING_C_A;
            }
            if (rebindCF) {
                keybindings[posCF] = EmacsKeyBindings.EMACS_KEY_BINDING_C_F;
            }
        } else {
            keybindings = EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE;
        }
        JTextComponent.loadKeymap(k, keybindings, actions);
    }
}
Also used : Action(javax.swing.Action) TextAction(javax.swing.text.TextAction) JTextComponent(javax.swing.text.JTextComponent) Keymap(javax.swing.text.Keymap)

Example 34 with JTextComponent

use of javax.swing.text.JTextComponent in project jdk8u_jdk by JetBrains.

the class ParagraphView method isVisible.

/**
     * Indicates whether or not this view should be
     * displayed.  If none of the children wish to be
     * displayed and the only visible child is the
     * break that ends the paragraph, the paragraph
     * will not be considered visible.  Otherwise,
     * it will be considered visible and return true.
     *
     * @return true if the paragraph should be displayed
     */
public boolean isVisible() {
    int n = getLayoutViewCount() - 1;
    for (int i = 0; i < n; i++) {
        View v = getLayoutView(i);
        if (v.isVisible()) {
            return true;
        }
    }
    if (n > 0) {
        View v = getLayoutView(n);
        if ((v.getEndOffset() - v.getStartOffset()) == 1) {
            return false;
        }
    }
    // be visible.
    if (getStartOffset() == getDocument().getLength()) {
        boolean editable = false;
        Component c = getContainer();
        if (c instanceof JTextComponent) {
            editable = ((JTextComponent) c).isEditable();
        }
        if (!editable) {
            return false;
        }
    }
    return true;
}
Also used : JTextComponent(javax.swing.text.JTextComponent) JTextComponent(javax.swing.text.JTextComponent) View(javax.swing.text.View)

Example 35 with JTextComponent

use of javax.swing.text.JTextComponent in project intellij-plugins by JetBrains.

the class DartGeneratorPeer method addSettingsStateListener.

@Override
public void addSettingsStateListener(@NotNull final WebProjectGenerator.SettingsStateListener stateListener) {
    // invalid Dartium path is not a blocking error
    final JTextComponent editorComponent = (JTextComponent) mySdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
    editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            stateListener.stateChanged(validate() == null);
        }
    });
    myCreateSampleProjectCheckBox.addActionListener(e -> stateListener.stateChanged(validate() == null));
    myTemplatesList.addListSelectionListener(e -> stateListener.stateChanged(validate() == null));
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) JTextComponent(javax.swing.text.JTextComponent) DocumentEvent(javax.swing.event.DocumentEvent)

Aggregations

JTextComponent (javax.swing.text.JTextComponent)89 NotNull (org.jetbrains.annotations.NotNull)9 Component (java.awt.Component)7 DocumentEvent (javax.swing.event.DocumentEvent)6 DocumentAdapter (com.intellij.ui.DocumentAdapter)5 Disposable (com.intellij.openapi.Disposable)3 JButton (javax.swing.JButton)3 Project (com.intellij.openapi.project.Project)2 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)2 FocusEvent (java.awt.event.FocusEvent)2 KeyEvent (java.awt.event.KeyEvent)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Accessible (javax.accessibility.Accessible)2 Action (javax.swing.Action)2 JComboBox (javax.swing.JComboBox)2 JFrame (javax.swing.JFrame)2 JLabel (javax.swing.JLabel)2 JMenuItem (javax.swing.JMenuItem)2