Java Code Examples for javax.swing.text.JTextComponent#getUI()

The following examples show how to use javax.swing.text.JTextComponent#getUI() . 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: AquaTextFieldSearch.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected static void installSearchField(final JTextComponent c) {
    final SearchFieldBorder border = getSearchTextFieldBorder();
    c.setBorder(border);
    c.setLayout(border.getCustomLayout());
    c.add(getFindButton(c), BorderLayout.WEST);
    c.add(getCancelButton(c), BorderLayout.EAST);
    c.add(getPromptLabel(c), BorderLayout.CENTER);

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(border);
    }
}
 
Example 3
Source File: SnippetHighlighter.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
        * Paints a highlight.
        *
        * @param g the graphics context
        * @param offs0 the starting model offset >= 0
        * @param offs1 the ending model offset >= offs1
        * @param bounds the bounding box for the highlight
        * @param c the editor
        */
       public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
	// --- determine locations ---
	TextUI mapper = c.getUI();
	Rectangle p0 = mapper.modelToView(c, offs0);
	Rectangle p1 = mapper.modelToView(c, offs1);

	// --- render ---
	Color color = getColor();

	if (color == null) {
	    g.setColor(c.getSelectionColor());
	}
	else {
	    g.setColor(color);
	}
	if (p0.y == p1.y) {
	    // same line, render a rectangle
	    Rectangle r = p0.union(p1);
	    g.fillRect(r.x, r.y, r.width, r.height);
	} else {
	    // different lines
	    int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
	    g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
	    if ((p0.y + p0.height) != p1.y) {
		g.fillRect(alloc.x, p0.y + p0.height, alloc.width, 
			   p1.y - (p0.y + p0.height));
	    } 
	    g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
	}
    } catch (BadLocationException e) {
	// can't render
    }
}
 
Example 4
Source File: AquaTextFieldBorder.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static int getShrinkageFor(final JTextComponent jc, final int height) {
    if (jc == null) return 0;
    final TextUI ui = jc.getUI();
    if (ui == null) return 0;
    final Dimension size = ui.getPreferredSize(jc);
    if (size == null) return 0;
    final int shrinkage = size.height - height;
    return (shrinkage < 0) ? 0 : (shrinkage > 3) ? 3 : shrinkage;
}
 
Example 5
Source File: AquaTextFieldBorder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static int getShrinkageFor(final JTextComponent jc, final int height) {
    if (jc == null) return 0;
    final TextUI ui = jc.getUI();
    if (ui == null) return 0;
    final Dimension size = ui.getPreferredSize(jc);
    if (size == null) return 0;
    final int shrinkage = size.height - height;
    return (shrinkage < 0) ? 0 : (shrinkage > 3) ? 3 : shrinkage;
}
 
Example 6
Source File: AquaTextFieldSearch.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected static void uninstallSearchField(final JTextComponent c) {
    c.setBorder(UIManager.getBorder("TextField.border"));
    c.removeAll();

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(null);
    }
}
 
Example 7
Source File: AnnotationBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Paints one view that corresponds to a line (or
 * multiple lines if folding takes effect).
 */
private void paintView(View view, Graphics g, int yBase) {
    JTextComponent component = editorUI.getComponent();
    if (component == null) return;
    BaseTextUI textUI = (BaseTextUI)component.getUI();

    Element rootElem = textUI.getRootView(component).getElement();
    int line = rootElem.getElementIndex(view.getStartOffset());

    String annotation = "";  // NOI18N
    AnnotateLine al = null;
    if (!elementAnnotations.isEmpty()) {
        al = getAnnotateLine(line);
        if (al != null) {
            annotation = getDisplayName(al);  // NOI18N
        }
    } else {
        annotation = elementAnnotationsSubstitute;
    }

    if (al != null && al.getRevision().equals(recentRevision)) {
        g.setColor(selectedColor());
    } else {
        g.setColor(foregroundColor());
    }
    int texty = yBase + editorUI.getLineAscent();
    int textx = 2;
    g.drawString(annotation, textx, texty);
}
 
Example 8
Source File: ComponentUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Object getEditorUI(JTextComponent c) throws Exception {
    // TODO: fix this, do not use reflection
    TextUI textUI = c.getUI();
    Method getEuiMethod = null;
    try {
        getEuiMethod = textUI.getClass().getMethod("getEditorUI"); //NOI18N
    } catch (NoSuchMethodException nsme) {
        LOG.log(Level.INFO, nsme.getMessage(), nsme);
    }
    if (getEuiMethod != null) {
        return getEuiMethod.invoke(textUI);
    } else {
        return null;
    }
}
 
Example 9
Source File: BraceMatchingSidebarComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public BraceMatchingSidebarComponent(JTextComponent editor) {
    this.editor = editor;
    this.mimeType = DocumentUtilities.getMimeType(editor);
    this.prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    
    final Lookup.Result r = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(editor)).lookupResult(
            FontColorSettings.class);
    prefListenerGC = new PrefListener();
    this.colorResult = r;
    r.addLookupListener(WeakListeners.create(LookupListener.class, this , r));
    prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefListenerGC, prefs));
    loadPreferences();
    
    editorPane = findEditorPane(editor);
    Component parent = editor.getParent();
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }
    if (parent instanceof JViewport) {
        this.viewport = (JViewport)parent;
        // see #219015; need to listen on viewport change to show/hide the tooltip
        viewport.addChangeListener(WeakListeners.change(this, viewport));
    }
    TextUI ui = editor.getUI();
    if (ui instanceof BaseTextUI) {
        baseUI = (BaseTextUI)ui;
        MasterMatcher.get(editor).addMatchListener(this);
    } else {
        baseUI = null;
    }
    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    updatePreferredSize();
}
 
Example 10
Source File: AquaTextFieldSearch.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected static void uninstallSearchField(final JTextComponent c) {
    c.setBorder(UIManager.getBorder("TextField.border"));
    c.removeAll();

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(null);
    }
}
 
Example 11
Source File: AquaTextFieldSearch.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected static void uninstallSearchField(final JTextComponent c) {
    c.setBorder(UIManager.getBorder("TextField.border"));
    c.removeAll();

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(null);
    }
}
 
Example 12
Source File: SubstanceTextUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Color getTextBackgroundFillColor(JComponent comp) {
    Color backgroundFillColor = SubstanceColorUtilities.getBackgroundFillColor(comp);

    JTextComponent componentForTransitions = SubstanceCoreUtilities
            .getTextComponentForTransitions(comp);

    if (componentForTransitions != null) {
        ComponentUI ui = componentForTransitions.getUI();
        if (ui instanceof TransitionAwareUI) {
            TransitionAwareUI trackable = (TransitionAwareUI) ui;
            StateTransitionTracker stateTransitionTracker = trackable.getTransitionTracker();

            Color lighterFill = SubstanceColorUtilities.getLighterColor(backgroundFillColor,
                    0.4f);
            lighterFill = SubstanceColorUtilities.getInterpolatedColor(lighterFill,
                    backgroundFillColor, 0.6);

            float selectionStrength = stateTransitionTracker
                    .getFacetStrength(ComponentStateFacet.SELECTION);
            float rolloverStrength = stateTransitionTracker
                    .getFacetStrength(ComponentStateFacet.ROLLOVER);
            backgroundFillColor = SubstanceColorUtilities.getInterpolatedColor(lighterFill,
                    backgroundFillColor, Math.max(selectionStrength, rolloverStrength) / 4.0f);
        }
    }
    return backgroundFillColor;
}
 
Example 13
Source File: AquaTextFieldBorder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static int getShrinkageFor(final JTextComponent jc, final int height) {
    if (jc == null) return 0;
    final TextUI ui = jc.getUI();
    if (ui == null) return 0;
    final Dimension size = ui.getPreferredSize(jc);
    if (size == null) return 0;
    final int shrinkage = size.height - height;
    return (shrinkage < 0) ? 0 : (shrinkage > 3) ? 3 : shrinkage;
}
 
Example 14
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get first view in the hierarchy that is an instance of the given class.
 * It allows to skip various wrapper-views around the doc-view that holds
 * the child views for the lines.
 *
 * @param component component from which the root view is fetched.
 * @param rootViewClass class of the view to return.
 * @return view being instance of the requested class or null if there
 *  is not one.
 */
public static View getRootView(JTextComponent component, Class rootViewClass) {
    View view = null;
    TextUI textUI = component.getUI();
    if (textUI != null) {
        view = textUI.getRootView(component);
        while (view != null && !rootViewClass.isInstance(view)
            && view.getViewCount() == 1 // must be wrapper view
        ) {
            view = view.getView(0); // get the only child
        }
    }
    
    return view;
}
 
Example 15
Source File: AquaTextFieldSearch.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected static void installSearchField(final JTextComponent c) {
    final SearchFieldBorder border = getSearchTextFieldBorder();
    c.setBorder(border);
    c.setLayout(border.getCustomLayout());
    c.add(getFindButton(c), BorderLayout.WEST);
    c.add(getCancelButton(c), BorderLayout.EAST);
    c.add(getPromptLabel(c), BorderLayout.CENTER);

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(border);
    }
}
 
Example 16
Source File: AquaTextFieldBorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static int getShrinkageFor(final JTextComponent jc, final int height) {
    if (jc == null) return 0;
    final TextUI ui = jc.getUI();
    if (ui == null) return 0;
    final Dimension size = ui.getPreferredSize(jc);
    if (size == null) return 0;
    final int shrinkage = size.height - height;
    return (shrinkage < 0) ? 0 : (shrinkage > 3) ? 3 : shrinkage;
}
 
Example 17
Source File: AquaTextFieldSearch.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected static void uninstallSearchField(final JTextComponent c) {
    c.setBorder(UIManager.getBorder("TextField.border"));
    c.removeAll();

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(null);
    }
}
 
Example 18
Source File: AquaTextFieldSearch.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected static void uninstallSearchField(final JTextComponent c) {
    c.setBorder(UIManager.getBorder("TextField.border"));
    c.removeAll();

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(null);
    }
}
 
Example 19
Source File: AquaTextFieldBorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static int getShrinkageFor(final JTextComponent jc, final int height) {
    if (jc == null) return 0;
    final TextUI ui = jc.getUI();
    if (ui == null) return 0;
    final Dimension size = ui.getPreferredSize(jc);
    if (size == null) return 0;
    final int shrinkage = size.height - height;
    return (shrinkage < 0) ? 0 : (shrinkage > 3) ? 3 : shrinkage;
}
 
Example 20
Source File: AquaTextFieldSearch.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected static void uninstallSearchField(final JTextComponent c) {
    c.setBorder(UIManager.getBorder("TextField.border"));
    c.removeAll();

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(null);
    }
}