Java Code Examples for org.netbeans.editor.Utilities#getKit()

The following examples show how to use org.netbeans.editor.Utilities#getKit() . 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: ToolTipSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Update the tooltip by running corresponding action
 * {@link ExtKit#buildToolTipAction}. This method gets
 * called once the enterTimer fires and it can be overriden
 * by children.
 */
protected void updateToolTip() {
    EditorUI ui = extEditorUI;
    if (ui == null)
        return;
    JTextComponent comp = ui.getComponent();
    if (comp == null)
        return;
    
    JComponent oldTooltip = this.toolTip;
    if (isGlyphGutterMouseEvent(lastMouseEvent)) {
        setToolTipText(extEditorUI.getGlyphGutter().getToolTipText(lastMouseEvent));
    } else { // over the text component
        BaseKit kit = Utilities.getKit(comp);
        if (kit != null) {
            Action a = kit.getActionByName(ExtKit.buildToolTipAction);
            if (a != null) {
                a.actionPerformed(new ActionEvent(comp, 0, "")); // NOI18N
            }
        }
    }
    // tooltip has changed, mark it as 'automatic'
    if (this.toolTip != oldTooltip) {
        tooltipFromView = true;
    }
}
 
Example 2
Source File: CompletionImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getMimePathBasic(JTextComponent component) {
    final Document doc = component.getDocument();
    // original mimeType code
    Object mimeTypeObj =  doc == null ? null : DocumentUtilities.getMimeType(doc);  //NOI18N
    String mimeType;

    if (mimeTypeObj instanceof String) {
        mimeType = (String) mimeTypeObj;
    } else {
        BaseKit kit = Utilities.getKit(component);
        
        if (kit == null) {
            return null;
        }
        
        mimeType = kit.getContentType();
    }
    return mimeType;
}
 
Example 3
Source File: JavaKit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void addAction(JTextComponent target, JMenu menu,
String actionName) {
    BaseKit kit = Utilities.getKit(target);
    if (kit == null) return;
    Action a = kit.getActionByName(actionName);
    if (a!=null){
        addAction(target, menu, a);
    } else { // action-name is null, add the separator
        menu.addSeparator();
    }
}
 
Example 4
Source File: JavaKit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }
        BaseDocument doc = (BaseDocument)target.getDocument();
        StringBuffer sb = new StringBuffer("System.out.println(\""); // NOI18N
        String title = (String)doc.getProperty(Document.TitleProperty);
        if (title != null) {
            sb.append(title);
            sb.append(':');
        }
        try {
            sb.append(Utilities.getLineOffset(doc, target.getCaret().getDot()) + 1);
        } catch (BadLocationException e) {
        }
        sb.append(' ');

        BaseKit kit = Utilities.getKit(target);
        if (kit == null) return;
        Action a = kit.getActionByName(BaseKit.insertContentAction);
        if (a != null) {
            Utilities.performAction(
                a,
                new ActionEvent(target, ActionEvent.ACTION_PERFORMED, sb.toString()),
                target
            );
        }
    }
}
 
Example 5
Source File: ExtKit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    BaseAction action = null;
    
    if (delegateAction != null) {
        action = delegateAction;
    } else {
        BaseKit kit = Utilities.getKit(target);
        Action a = kit == null ? null : kit.getActionByName(toggleCommentAction);
        if (a instanceof BaseAction) {
            action = (BaseAction) a;
        }
    }

    if (action instanceof ToggleCommentAction) {
        ((ToggleCommentAction) action).commentUncomment(evt, target, Boolean.TRUE);
    } else {
        if (action != null) {
            action.putValue("force-comment", Boolean.TRUE); // NOI18N
            try {
                action.actionPerformed(evt, target);
            } finally {
                action.putValue("force-comment", null); // NOI18N
            }
        } else {
            target.getToolkit().beep();
        }
    }
}
 
Example 6
Source File: ExtKit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    BaseAction action = null;
    
    if (delegateAction != null) {
        action = delegateAction;
    } else {
        BaseKit kit = Utilities.getKit(target);
        Action a = kit == null ? null : kit.getActionByName(toggleCommentAction);
        if (a instanceof BaseAction) {
            action = (BaseAction) a;
        }
    }

    if (action instanceof ToggleCommentAction) {
        ((ToggleCommentAction) action).commentUncomment(evt, target, Boolean.FALSE);
    } else {
        if (action != null) {
            action.putValue("force-uncomment", Boolean.TRUE); // NOI18N
            try {
                action.actionPerformed(evt, target);
            } finally {
                action.putValue("force-uncomment", null); // NOI18N
            }
        } else {
            target.getToolkit().beep();
        }
    }
}
 
Example 7
Source File: CslEditorKit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addAction(JTextComponent target, JMenu menu, String actionName) {
    BaseKit kit = Utilities.getKit(target);

    if (kit == null) {
        return;
    }

    Action a = kit.getActionByName(actionName);

    if (a != null) {
        addAction(target, menu, a);
    } else { // action-name is null, add the separator
        menu.addSeparator();
    }
}
 
Example 8
Source File: NbEditorUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized Action getEditorAction(JTextComponent component) {
    if (editorAction == null) {
        BaseKit kit = Utilities.getKit(component);
        if (kit != null) {
            editorAction = kit.getActionByName(editorActionName);
        }
    }
    return editorAction;
}
 
Example 9
Source File: NbEditorUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized Action getEditorAction() {
    if (editorAction == null) {
        BaseKit kit = Utilities.getKit(getComponent());
        if (kit != null) {
            editorAction = kit.getActionByName(editorActionName);
        }
    }
    return editorAction;
}
 
Example 10
Source File: GotoDialogSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Perform the goto operation.
 * @return whether the dialog should be made invisible or not
 */
protected boolean performGoto() {
    JTextComponent c = EditorRegistry.lastFocusedComponent();
    if (c != null) {
        try {
            int line = Integer.parseInt(getGotoValueText());

            //issue 188976
            if (line==0)
                line = 1;
            //end of issue 188976
            
            BaseDocument doc = Utilities.getDocument(c);
            if (doc != null) {
                int rowCount = Utilities.getRowCount(doc);
                if (line > rowCount)
                    line = rowCount;
                
                // Obtain the offset where to jump
                int pos = Utilities.getRowStartFromLineOffset(doc, line - 1);
                
                BaseKit kit = Utilities.getKit(c);
                if (kit != null) {
                    Action a = kit.getActionByName(ExtKit.gotoAction);
                    if (a instanceof ExtKit.GotoAction) {
                        pos = ((ExtKit.GotoAction)a).getOffsetFromLine(doc, line - 1);
                    }
                }
                
                if (pos != -1) {
                    Caret caret = c.getCaret();
                    caret.setDot(pos);
                } else {
                    c.getToolkit().beep();
                    return false;
                }
            }
        } catch (NumberFormatException e) {
            c.getToolkit().beep();
            return false;
        }
    }
    return true;
}
 
Example 11
Source File: NbCodeFoldingAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private BaseKit getKit(){
    JTextComponent component = getComponent();
    return (component == null) ? BaseKit.getKit(NbEditorKit.class) : Utilities.getKit(component);
}
 
Example 12
Source File: MainMenuAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Gets the editor kit */
private static BaseKit getKit(){
    JTextComponent component = getComponent();
    return (component == null) ? null : Utilities.getKit(component);
}
 
Example 13
Source File: MacroDialogSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("actionCommand='" + evt.getActionCommand() //NOI18N
                + "', modifiers=" + evt.getModifiers() //NOI18N
                + ", when=" + evt.getWhen() //NOI18N
                + ", paramString='" + evt.paramString() + "'"); //NOI18N
    }
    
    if (target == null) {
        return;
    }

    BaseKit kit = Utilities.getKit(target);
    if (kit == null) {
        return;
    }

    BaseDocument doc = Utilities.getDocument(target);
    if (doc == null) {
        return;
    }

    // changed as reponse to #250157: other events may get fired during
    // the course of key binding processing and if an event is processed
    // as nested (i.e. hierarchy change resulting from a component retracting from the screen),
    // thie following test would fail.
    AWTEvent maybeKeyEvent = EventQueue.getCurrentEvent();
    KeyStroke keyStroke = null;
    
    if (maybeKeyEvent instanceof KeyEvent) {
        keyStroke = KeyStroke.getKeyStrokeForEvent((KeyEvent) maybeKeyEvent);
    }

    // try simple keystorkes first
    MimePath mimeType = MimePath.parse(NbEditorUtilities.getMimeType(target));
    MacroDescription macro = null;
    if (keyStroke != null) {
        macro = findMacro(mimeType, keyStroke);
    } else {
        LOG.warning("KeyStroke could not be created for event " + maybeKeyEvent);
    }
    if (macro == null) {
        // if not found, try action command, which should contain complete multi keystroke
        KeyStroke[] shortcut = KeyStrokeUtils.getKeyStrokes(evt.getActionCommand());
        if (shortcut != null) {
            macro = findMacro(mimeType, shortcut);
        } else {
            LOG.warning("KeyStroke could not be created for action command " + evt.getActionCommand());
        }
    }

    if (macro == null) {
        error(target, "macro-not-found", KeyStrokeUtils.getKeyStrokeAsText(keyStroke)); // NOI18N
        return;
    }

    if (!runningActions.add(macro.getName())) { // this macro is already running, beware of loops
        error(target, "macro-loop", macro.getName()); // NOI18N
        return;
    }
    try {
        runMacro(target, doc, kit, macro);
    } finally {
        runningActions.remove(macro.getName());
    }
}
 
Example 14
Source File: CollapsedView.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Fetches the factory to be used for building the
 * various view fragments that make up the view that
 * represents the model.  This is what determines
 * how the model will be represented.  This is implemented
 * to fetch the factory provided by the associated
 * EditorKit unless that is null, in which case this
 * simply returns the BasicTextUI itself which allows
 * subclasses to implement a simple factory directly without
 * creating extra objects.  
 *
 * @return the factory
 */
public @Override ViewFactory getViewFactory() {
    EditorUI editorUI = getEditorUI();
    if (editorUI != null) {
        BaseKit kit = Utilities.getKit(editorUI.getComponent());
        ViewFactory f = kit.getViewFactory();
        if (f != null) {
            return f;
        }
    }
    return getBaseTextUI();
}