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

The following examples show how to use org.netbeans.editor.Utilities#getEditorUI() . 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: DiffSidebar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private int getLineFromMouseEvent(MouseEvent e){
    int line = -1;
    EditorUI editorUI = Utilities.getEditorUI(textComponent);
    if (editorUI != null) {
        try{
            JTextComponent component = editorUI.getComponent();
            if (component != null) {
                TextUI textUI = component.getUI();
                int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
                line = Utilities.getLineOffset(document, clickOffset);
            }
        }catch (BadLocationException ble){
            LOG.log(Level.WARNING, "getLineFromMouseEvent", ble); // NOI18N
        }
    }
    return line;
}
 
Example 2
Source File: AnnotationBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new instance initializing final fields.
 */
public AnnotationBar(JTextComponent target) {
    this.textComponent = target;
    this.editorUI = Utilities.getEditorUI(target);
    this.foldHierarchy = FoldHierarchy.get(editorUI.getComponent());
    this.doc = editorUI.getDocument();
    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    elementAnnotationsSubstitute = "";                              //NOI18N
    if (textComponent instanceof JEditorPane) {
        String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(textComponent);
        FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
        renderingHints = (Map) fcs.getFontColors(FontColorNames.DEFAULT_COLORING).getAttribute(EditorStyleConstants.RenderingHints);
    } else {
        renderingHints = null;
    }
}
 
Example 3
Source File: NbToolTip.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static int getOffsetForPoint(Point p, JTextComponent c, BaseDocument doc) throws BadLocationException {
    if (p.x >= 0 && p.y >= 0) {
        int offset = c.viewToModel(p);
        Rectangle r = c.modelToView(offset);
        EditorUI eui = Utilities.getEditorUI(c);

        // Check that p is on a line with text and not completely below text,
        // ie. behind EOF.
        int relY = p.y - r.y;
        if (eui != null && relY < eui.getLineHeight()) {
            // Check that p is on a line with text before its EOL.
            if (offset < Utilities.getRowEnd(doc, offset)) {
                return offset;
            }
        }
    }
    
    return -1;
}
 
Example 4
Source File: ToolTipUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    EditorUI eui = Utilities.getEditorUI(editorPane);
    Point location = et.getLocation();
    location = eui.getStickyWindowSupport().convertPoint(location);
    eui.getToolTipSupport().setToolTipVisible(false);
    DebuggerManager dbMgr = DebuggerManager.getDebuggerManager();
    BaseDocument document = Utilities.getDocument(editorPane);
    DataObject dobj = (DataObject) document.getProperty(Document.StreamDescriptionProperty);
    FileObject fo = dobj.getPrimaryFile();
    Watch.Pin pin = new EditorPin(fo, pinnable.line, location);
    final Watch w = dbMgr.createPinnedWatch(pinnable.expression, pin);
    SwingUtilities.invokeLater(() -> {
        try {
            PinWatchUISupport.getDefault().pin(w, pinnable.valueProviderId);
        } catch (IllegalArgumentException ex) {
            Exceptions.printStackTrace(ex);
        }
    });
}
 
Example 5
Source File: AnnotationBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new instance initializing final fields.
 */
public AnnotationBar(JTextComponent target) {
    this.textComponent = target;
    this.editorUI = Utilities.getEditorUI(target);
    this.foldHierarchy = FoldHierarchy.get(editorUI.getComponent());
    this.doc = editorUI.getDocument();
    if (textComponent instanceof JEditorPane) {
        String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(textComponent);
        FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
        renderingHints = (Map) fcs.getFontColors(FontColorNames.DEFAULT_COLORING).getAttribute(EditorStyleConstants.RenderingHints);
    } else {
        renderingHints = null;
    }
    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    elementAnnotationsSubstitute = "";                              //NOI18N
}
 
Example 6
Source File: AnnotationBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new instance initializing final fields.
 */
public AnnotationBar(JTextComponent target) {
    this.textComponent = target;
    this.editorUI = Utilities.getEditorUI(target);
    this.foldHierarchy = FoldHierarchy.get(editorUI.getComponent());
    this.doc = editorUI.getDocument();
    if (textComponent instanceof JEditorPane) {
        String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(textComponent);
        FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
        renderingHints = (Map) fcs.getFontColors(FontColorNames.DEFAULT_COLORING).getAttribute(EditorStyleConstants.RenderingHints);
    } else {
        renderingHints = null;
    }
    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    elementAnnotationsSubstitute = "";                              //NOI18N
}
 
Example 7
Source File: AnnotationBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new instance initializing final fields.
 */
public AnnotationBar(JTextComponent target) {
    this.textComponent = target;
    this.editorUI = Utilities.getEditorUI(target);
    this.foldHierarchy = FoldHierarchy.get(editorUI.getComponent());
    this.doc = editorUI.getDocument();
    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    elementAnnotationsSubstitute = "";                              //NOI18N
    if (textComponent instanceof JEditorPane) {
        String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(textComponent);
        FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
        renderingHints = (Map) fcs.getFontColors(FontColorNames.DEFAULT_COLORING).getAttribute(EditorStyleConstants.RenderingHints);
    } else {
        renderingHints = null;
    }
}
 
Example 8
Source File: ExtKit.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        try {
            int dotPos = target.getCaret().getDot();
            Rectangle r = target.getUI().modelToView(target, dotPos);
            if (r != null) {
                EditorUI eui = Utilities.getEditorUI(target);
                if (eui != null) {
                    eui.showPopupMenu(r.x, r.y + r.height);
                }
            }
        } catch (BadLocationException e) {
            target.getToolkit().beep();
        }
    }
}
 
Example 9
Source File: ExtKit.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected JPopupMenu buildPopupMenu(JTextComponent target) {
    JPopupMenu pm = createPopupMenu(target);

    EditorUI ui = Utilities.getEditorUI(target);
    String settingName = ui == null || ui.hasExtComponent()
            ? "popup-menu-action-name-list" //NOI18N
            : "dialog-popup-menu-action-name-list"; //NOI18N
    
    Preferences prefs = MimeLookup.getLookup(DocumentUtilities.getMimeType(target)).lookup(Preferences.class);
    String actionNames = prefs.get(settingName, null);

    if (actionNames != null) {
        for(StringTokenizer t = new StringTokenizer(actionNames, ","); t.hasMoreTokens(); ) {
            String action = t.nextToken().trim();
            addAction(target, pm, action);
        }
    }
    
    return pm;
}
 
Example 10
Source File: BraceMatchingSidebarComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isEditorValid() {
    if (editor.isVisible() && Utilities.getEditorUI(editor) != null) {
        // do not operate on editors, which do not have focus
        return editor.hasFocus();
    } else {
        return false;
    }
}
 
Example 11
Source File: DiffSidebar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Point scrollToDifference(Difference diff) {
    int lineStart = diff.getSecondStart() - 1;
    int lineEnd = diff.getSecondEnd() - 1;
    if (lineStart == -1) {
        // the change was delete starting on the first line, show the diff on the next line
        // since in this case the file cannot be empty, 0 index does not throw BLE
        lineStart = 0;
    }
    if (diff.getType() == Difference.DELETE) {
        lineEnd = lineStart;
    }
    try {
        EditorUI editorUI = Utilities.getEditorUI(textComponent);
        int visibleBorder = editorUI.getLineHeight() * 5;
        int startOffset = Utilities.getRowStartFromLineOffset((BaseDocument) textComponent.getDocument(), lineStart);
        int endOffset = Utilities.getRowStartFromLineOffset((BaseDocument) textComponent.getDocument(), lineEnd);
        Rectangle startRect = textComponent.getUI().modelToView(textComponent, startOffset);
        Rectangle endRect = textComponent.getUI().modelToView(textComponent, endOffset);
        Rectangle visibleRect = new Rectangle(startRect.x - visibleBorder, startRect.y - visibleBorder, 
                                              startRect.x, endRect.y - startRect.y + endRect.height + visibleBorder * 2);
        textComponent.scrollRectToVisible(visibleRect);
       
        //make sure the y coordinate isn't outside the editor bounds otherwise the popup will 'float' beneath the editor
        Rectangle extent = editorUI.getExtentBounds();
        int maxVisibleY = extent.y + extent.height;
        
        Point p = new Point(endRect.x, Math.min(maxVisibleY, endRect.y + endRect.height + 1));
        
        //XXX: The resulting screen coordinates could still be outside the main screen
        SwingUtilities.convertPointToScreen(p, textComponent);
        return p;
    } catch (BadLocationException e) {
        LOG.log(Level.WARNING, "scrollToDifference", e); // NOI18N
    }
    return null;
}
 
Example 12
Source File: AnnotationBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new instance initializing final fields.
 */
public AnnotationBar(JTextComponent target) {
    this.textComponent = target;
    this.editorUI = Utilities.getEditorUI(target);
    this.foldHierarchy = FoldHierarchy.get(editorUI.getComponent());
    this.doc = editorUI.getDocument();
    this.caret = textComponent.getCaret();
    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
}
 
Example 13
Source File: ToolTipUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Show the tooltip on the given editor pane.
 * @param editorPane The editor pane to show the tooltip on.
 * @return An instance of tooltip support that allows to control the display
 * of the tooltip, or <code>null</code> when it's not possible to show the
 * tooltip on the editor pane.
 * It can be used e.g. to close the tooltip when it's no longer applicable,
 * when the debugger resumes, etc.
 */
public ToolTipSupport show(JEditorPane editorPane) {
    EditorUI eui = Utilities.getEditorUI(editorPane);
    if (eui != null) {
        eui.getToolTipSupport().setToolTip(et);
        this.editorPane = editorPane;
        return eui.getToolTipSupport();
    } else {
        return null;
    }
}
 
Example 14
Source File: AbstractExpandToolTipAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Open a tooltip view for the expression and variable the expression evaluates to.
 * @param expression the tooltip's expression
 * @param var the evaluated variable
 * @return An instance of tooltip support that allows to control the display
 * of the tooltip, or <code>null</code> when it's not possible to show it.
 * It can be used e.g. to close the tooltip when it's no longer applicable,
 * when the debugger resumes, etc.
 */
protected final ToolTipSupport openTooltipView(String expression, Object var) {
    ToolTipView toolTipView = ToolTipView.createToolTipView(expression, var);
    JEditorPane currentEditor = EditorContextDispatcher.getDefault().getMostRecentEditor();
    EditorUI eui = Utilities.getEditorUI(currentEditor);
    if (eui != null) {
        final ToolTipSupport toolTipSupport = eui.getToolTipSupport();
        toolTipSupport.setToolTipVisible(true, false);
        toolTipSupport.setToolTip(toolTipView);
        toolTipSupport.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if (ToolTipSupport.PROP_STATUS.equals(evt.getPropertyName())) {
                    if (!toolTipSupport.isToolTipVisible()) {
                        expanded = false;
                        putValue(Action.SMALL_ICON, toExpandIcon);
                        putValue(Action.LARGE_ICON_KEY, toExpandIcon);
                        toolTipSupport.removePropertyChangeListener(this);
                    }
                }
            }
        });
        return toolTipSupport;
    } else {
        return null;
    }
}
 
Example 15
Source File: AbstractExpandToolTipAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void hideTooltipView() {
    JEditorPane currentEditor = EditorContextDispatcher.getDefault().getMostRecentEditor();
    EditorUI eui = Utilities.getEditorUI(currentEditor);
    if (eui != null) {
        eui.getToolTipSupport().setToolTipVisible(false, false);
    }
}
 
Example 16
Source File: NbEditorDocument.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Component createEditor(JEditorPane j) {
    EditorUI editorUI = Utilities.getEditorUI(j);
    if (editorUI == null) { // Editor kit not installed yet??
        javax.swing.plaf.TextUI ui = j.getUI();
        javax.swing.text.EditorKit kit = j.getEditorKit();
        throw new IllegalStateException("NbEditorDocument.createEditor(): ui=" + ui + // NOI18N
                ", kit=" + kit + ", pane=" + j); // NOI18N
    }
    return editorUI.getExtComponent();
}
 
Example 17
Source File: StatusLineFactories.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void refreshStatusLine() {
    LOG.fine("StatusLineFactories.refreshStatusLine()\n");
    List<? extends JTextComponent> componentList = EditorRegistry.componentList();
    for (JTextComponent component : componentList) {
        boolean underMainWindow = (SwingUtilities.isDescendingFrom(component,
                WindowManager.getDefault().getMainWindow()));
        EditorUI editorUI = Utilities.getEditorUI(component);
        if (LOG.isLoggable(Level.FINE)) {
            String componentDesc = component.toString();
            Document doc = component.getDocument();
            Object streamDesc;
            if (doc != null && ((streamDesc = doc.getProperty(Document.StreamDescriptionProperty)) != null)) {
                componentDesc = streamDesc.toString();
            }
            LOG.fine("  underMainWindow=" + underMainWindow + // NOI18N
                    ", text-component: " + componentDesc + "\n");
        }
        if (editorUI != null) {
            StatusBar statusBar = editorUI.getStatusBar();
            statusBar.setVisible(!underMainWindow);
            boolean shouldUpdateGlobal = underMainWindow && component.isShowing();
            if (shouldUpdateGlobal) {
                statusBar.updateGlobal();
                LOG.fine("  end of refreshStatusLine() - found main window component\n\n"); // NOI18N
                return; // First non-docked one found and updated -> quit
            }
        }
    }
    clearStatusLine();
    LOG.fine("  end of refreshStatusLine() - no components - status line cleared\n\n"); // NOI18N
}
 
Example 18
Source File: NbEditorDocument.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public JToolBar createToolbar(JEditorPane j) {
    final EditorUI ui = Utilities.getEditorUI(j);
    return ui != null ? ui.getToolBarComponent() : null;
}
 
Example 19
Source File: CodeFoldingSideBar.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected EditorUI getEditorUI(){
    return Utilities.getEditorUI(component);
}
 
Example 20
Source File: InstantRefactoringPerformer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
   public synchronized void removeUpdate(DocumentEvent e) {
if (inSync)
    return ;

       if (e.getLength() == 1) {
           if ((e.getOffset() < region.getFirstRegionStartOffset() || e.getOffset() > region.getFirstRegionEndOffset())) {
               release(true);
               return;
           }

           if (e.getOffset() == region.getFirstRegionStartOffset() && region.getFirstRegionLength() > 0 && region.getFirstRegionLength() == span) {
               if (LOG.isLoggable(Level.FINE)) {
                   LOG.log(Level.FINE, "e.getOffset()={0}", e.getOffset ());
                   LOG.log(Level.FINE, "region.getFirstRegionStartOffset()={0}", region.getFirstRegionStartOffset ());
                   LOG.log(Level.FINE, "region.getFirstRegionEndOffset()={0}", region.getFirstRegionEndOffset ());
                   LOG.log(Level.FINE, "span= {0}", span);
               }
               release(true);
               return;
           }
           
           if (e.getOffset() == region.getFirstRegionEndOffset() && region.getFirstRegionLength() > 0 && region.getFirstRegionLength() == span) {
               if (LOG.isLoggable(Level.FINE)) {
                   LOG.log(Level.FINE, "e.getOffset()={0}", e.getOffset ());
                   LOG.log(Level.FINE, "region.getFirstRegionStartOffset()={0}", region.getFirstRegionStartOffset ());
                   LOG.log(Level.FINE, "region.getFirstRegionEndOffset()={0}", region.getFirstRegionEndOffset ());
                   LOG.log(Level.FINE, "span= {0}", span);
               }

               release(true);
               return;
           }
           if (e.getOffset() == region.getFirstRegionEndOffset() && e.getOffset() == region.getFirstRegionStartOffset() && region.getFirstRegionLength() == 0 && region.getFirstRegionLength() == span) {
               if (LOG.isLoggable(Level.FINE)) {
                   LOG.log(Level.FINE, "e.getOffset()={0}", e.getOffset ());
                   LOG.log(Level.FINE, "region.getFirstRegionStartOffset()={0}", region.getFirstRegionStartOffset ());
                   LOG.log(Level.FINE, "region.getFirstRegionEndOffset()={0}", region.getFirstRegionEndOffset ());
                   LOG.log(Level.FINE, "span= {0}", span);
               }
               
              
               release(true);
               return;
           }
       } else {
           //selection/multiple characters removed:
           int removeSpan = e.getLength() + region.getFirstRegionLength();
           
           if (span < removeSpan) {
               release(true);
               return;
           }
       }
       
       //#89997: do not sync the regions for the "remove" part of replace selection,
       //as the consequent insert may use incorrect offset, and the regions will be synced
       //after the insert anyway.
       EditorUI editorUI = Utilities.getEditorUI(target);
       Boolean ovr = (Boolean) editorUI.getProperty(EditorUI.OVERWRITE_MODE_PROPERTY);
       if (doc.getProperty(BaseKit.DOC_REPLACE_SELECTION_PROPERTY) != null || (ovr != null && ovr == true)) {
           return ;
       }
       
       inSync = true;
       region.sync();
       span = region.getFirstRegionLength();
       inSync = false;
       
       requestRepaint();
   }