Java Code Examples for javax.swing.plaf.TextUI#getEditorKit()

The following examples show how to use javax.swing.plaf.TextUI#getEditorKit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentationScrollPane.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
    // This method is implemented due to the issue
    // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
    KeyStroke[] ret = new KeyStroke[] { defaultKey };
    if (component != null) {
        TextUI componentUI = component.getUI();
        Keymap km = component.getKeymap();
        if (componentUI != null && km != null) {
            EditorKit kit = componentUI.getEditorKit(component);
            if (kit instanceof BaseKit) {
                 Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        ret = keys;
                    }
                }
            }
        }
    }
    return ret;
}
 
Example 2
Source File: DocumentationScrollPane.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
    // This method is implemented due to the issue
    // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
    KeyStroke[] ret = new KeyStroke[] { defaultKey };
    if (component != null) {
        TextUI componentUI = component.getUI();
        Keymap km = component.getKeymap();
        if (componentUI != null && km != null) {
            EditorKit kit = componentUI.getEditorKit(component);
            if (kit instanceof BaseKit) {
                Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        ret = keys;
                    }
                }
            }
        }
    }
    return ret;
}
 
Example 3
Source File: DocumentationScrollPane.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
    // This method is implemented due to the issue
    // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
    KeyStroke[] ret = new KeyStroke[] { defaultKey };
    if (component != null) {
        TextUI componentUI = component.getUI();
        Keymap km = component.getKeymap();
        if (componentUI != null && km != null) {
            EditorKit kit = componentUI.getEditorKit(component);
            if (kit instanceof BaseKit) {
                Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        ret = keys;
                    }
                }
            }
        }
    }
    return ret;
}
 
Example 4
Source File: PresenterEditorAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    // Find the right action for the corresponding editor kit
    JTextComponent component = getTextComponent(evt);
    if (component != null) {
        TextUI ui = component.getUI();
        if (ui != null) {
            EditorKit kit = ui.getEditorKit(component);
            if (kit != null) {
                Action action = EditorUtilities.getAction(kit, actionName);
                if (action != null) {
                    action.actionPerformed(evt);
                } else {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("Action '" + actionName + "' not found in editor kit " + kit + '\n'); // NOI18N
                    }
                }
            }
        }
    }
}
 
Example 5
Source File: DocumentationScrollPane.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
    // This method is implemented due to the issue
    // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
    KeyStroke[] ret = new KeyStroke[] { defaultKey };
    if (component != null) {
        TextUI componentUI = component.getUI();
        Keymap km = component.getKeymap();
        if (componentUI != null && km != null) {
            EditorKit kit = componentUI.getEditorKit(component);
            if (kit instanceof BaseKit) {
                 Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        ret = keys;
                    }
                }
            }
        }
    }
    return ret;
}
 
Example 6
Source File: CompletionImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName) {
    // This method is implemented due to the issue
    // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
    if (editorActionName != null && getActiveComponent() != null) {
        TextUI ui = getActiveComponent().getUI();
        Keymap km = getActiveComponent().getKeymap();
        if (ui != null && km != null) {
            EditorKit kit = ui.getEditorKit(getActiveComponent());
            if (kit instanceof BaseKit) {
                Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        return keys;
                    } else {
                        // try kit's keymap
                        Keymap km2 = ((BaseKit)kit).getKeymap();
                        KeyStroke[] keys2 = km2.getKeyStrokesForAction(a);
                        if (keys2 != null && keys2.length > 0) {
                            return keys2;
                        }
                    }
                }
            }
        }
    }
    return new KeyStroke[0];
}
 
Example 7
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Attempt to find the editor keystroke for the given action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey) {
    KeyStroke[] ret = new KeyStroke[] { defaultKey };
    JTextComponent comp = getComponent();
    if (editorActionName != null && comp != null) {
        TextUI textUI = comp.getUI();
        Keymap km = comp.getKeymap();
        if (textUI != null && km != null) {
            EditorKit kit = textUI.getEditorKit(comp);
            if (kit instanceof BaseKit) {
                Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        ret = keys;
                    } else {
                        // try kit's keymap
                        Keymap km2 = ((BaseKit)kit).getKeymap();
                        KeyStroke[] keys2 = km2.getKeyStrokesForAction(a);
                        if (keys2 != null && keys2.length > 0) {
                            ret = keys2;
                        }                            
                    }
                }
            }
        }
    }
    return ret;
}
 
Example 8
Source File: PresenterEditorAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if (EditorRegistry.FOCUS_GAINED_PROPERTY.equals(evt.getPropertyName())) {
        JTextComponent focusedTextComponent = (JTextComponent) evt.getNewValue();
        SearchableEditorKit oldActiveKit = activeKit();
        EditorKit kit = null;
        if (focusedTextComponent != null) {
            TextUI ui = focusedTextComponent.getUI();
            if (ui != null) {
                kit = ui.getEditorKit(focusedTextComponent);
            }
        }

        synchronized (PresenterEditorAction.class) {
            SearchableEditorKit newActiveKit = (kit != null)
                    ? EditorActionUtilities.getSearchableKit(kit)
                    : null;
            boolean kitChanged;
            if (newActiveKit != oldActiveKit) {
                if (oldActiveKit != null) {
                    oldActiveKit.removeActionsChangeListener(actionsChangeListener);
                }
                activeKitRef = (newActiveKit != null)
                        ? new WeakReference<SearchableEditorKit>(newActiveKit)
                        : null;
                if (newActiveKit != null) {
                    newActiveKit.addActionsChangeListener(actionsChangeListener);
                }
                kitChanged = true;
            } else {
                kitChanged = false;
            }
            boolean focusChanged = (activeKitLastFocused == false);
            activeKitLastFocused = true;
            if (focusChanged || kitChanged) {
                refreshActiveKitActions(newActiveKit, kitChanged);
            }
        }

    } else if (EditorRegistry.FOCUS_LOST_PROPERTY.equals(evt.getPropertyName())) {
        synchronized (PresenterEditorAction.class) {
            boolean newActiveKitLastFocused = (EditorRegistry.lastFocusedComponent() != null);
            if (newActiveKitLastFocused != activeKitLastFocused) {
                activeKitLastFocused = newActiveKitLastFocused;
                for (PresenterEditorAction a : presenterActions) {
                    a.refreshActiveKitAction(null, false);
                }
            }
        }
    }
}