Java Code Examples for javax.swing.plaf.TextUI

The following examples show how to use javax.swing.plaf.TextUI. These examples are extracted from open source projects. 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
void repaintNewCaret() {
    if (component != null) {
        TextUI mapper = component.getUI();
        Document doc = component.getDocument();
        if ((mapper != null) && (doc != null)) {
            Rectangle2D newLoc;
            try {
                newLoc = mapper.modelToView2D(component, this.dot, this.dotBias);
            } catch (BadLocationException e) {
                newLoc = null;
            }
            if (newLoc != null) {
                adjustVisibility(newLoc.getBounds());
                if (getMagicCaretPosition() == null) {
                    setMagicCaretPosition(new Point((int) newLoc.getX(),
                                                    (int) newLoc.getY()));
                }
            }
            damage(newLoc.getBounds());
        }
    }
}
 
Example 2
void repaintNewCaret() {
    if (component != null) {
        TextUI mapper = component.getUI();
        Document doc = component.getDocument();
        if ((mapper != null) && (doc != null)) {
            Rectangle2D newLoc;
            try {
                newLoc = mapper.modelToView2D(component, this.dot, this.dotBias);
            } catch (BadLocationException e) {
                newLoc = null;
            }
            if (newLoc != null) {
                adjustVisibility(newLoc.getBounds());
                if (getMagicCaretPosition() == null) {
                    setMagicCaretPosition(new Point((int) newLoc.getX(),
                                                    (int) newLoc.getY()));
                }
            }
            damage(newLoc.getBounds());
        }
    }
}
 
Example 3
Source Project: netbeans   Source File: DocumentationScrollPane.java    License: 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 Project: jdk8u-jdk   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int getNextVisualPositionFrom(JTextComponent a, int b, Position.Bias c, int d, Position.Bias[] e)
        throws BadLocationException {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(a,b,c,d,e);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(a,b,c,d,e);
    }
    return returnValue;
}
 
Example 5
Source Project: hottub   Source File: HTMLEditorKit.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a string anchor if the passed in element has a
 * USEMAP that contains the passed in location.
 */
private String getMapHREF(JEditorPane html, HTMLDocument hdoc,
                          Element elem, AttributeSet attr, int offset,
                          int x, int y) {
    Object useMap = attr.getAttribute(HTML.Attribute.USEMAP);
    if (useMap != null && (useMap instanceof String)) {
        Map m = hdoc.getMap((String)useMap);
        if (m != null && offset < hdoc.getLength()) {
            Rectangle bounds;
            TextUI ui = html.getUI();
            try {
                Shape lBounds = ui.modelToView(html, offset,
                                           Position.Bias.Forward);
                Shape rBounds = ui.modelToView(html, offset + 1,
                                           Position.Bias.Backward);
                bounds = lBounds.getBounds();
                bounds.add((rBounds instanceof Rectangle) ?
                            (Rectangle)rBounds : rBounds.getBounds());
            } catch (BadLocationException ble) {
                bounds = null;
            }
            if (bounds != null) {
                AttributeSet area = m.getArea(x - bounds.x,
                                              y - bounds.y,
                                              bounds.width,
                                              bounds.height);
                if (area != null) {
                    return (String)area.getAttribute(HTML.Attribute.
                                                     HREF);
                }
            }
        }
    }
    return null;
}
 
Example 6
Source Project: jdk1.8-source-analysis   Source File: HTMLEditorKit.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a string anchor if the passed in element has a
 * USEMAP that contains the passed in location.
 */
private String getMapHREF(JEditorPane html, HTMLDocument hdoc,
                          Element elem, AttributeSet attr, int offset,
                          int x, int y) {
    Object useMap = attr.getAttribute(HTML.Attribute.USEMAP);
    if (useMap != null && (useMap instanceof String)) {
        Map m = hdoc.getMap((String)useMap);
        if (m != null && offset < hdoc.getLength()) {
            Rectangle bounds;
            TextUI ui = html.getUI();
            try {
                Shape lBounds = ui.modelToView(html, offset,
                                           Position.Bias.Forward);
                Shape rBounds = ui.modelToView(html, offset + 1,
                                           Position.Bias.Backward);
                bounds = lBounds.getBounds();
                bounds.add((rBounds instanceof Rectangle) ?
                            (Rectangle)rBounds : rBounds.getBounds());
            } catch (BadLocationException ble) {
                bounds = null;
            }
            if (bounds != null) {
                AttributeSet area = m.getArea(x - bounds.x,
                                              y - bounds.y,
                                              bounds.width,
                                              bounds.height);
                if (area != null) {
                    return (String)area.getAttribute(HTML.Attribute.
                                                     HREF);
                }
            }
        }
    }
    return null;
}
 
Example 7
Source Project: Darcula   Source File: SnippetHighlighter.java    License: 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 8
Source Project: openjdk-jdk9   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public int viewToModel2D(JTextComponent a, Point2D b, Position.Bias[] c) {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).viewToModel2D(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).viewToModel2D(a,b,c);
    }
    return returnValue;
}
 
Example 9
Source Project: openjdk-8-source   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getRootView</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public View getRootView(JTextComponent a) {
    View returnValue =
        ((TextUI) (uis.elementAt(0))).getRootView(a);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getRootView(a);
    }
    return returnValue;
}
 
Example 10
Source Project: jdk1.8-source-analysis   Source File: MultiTextUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the <code>modelToView</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Rectangle modelToView(JTextComponent a, int b, Position.Bias c)
        throws BadLocationException {
    Rectangle returnValue =
        ((TextUI) (uis.elementAt(0))).modelToView(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).modelToView(a,b,c);
    }
    return returnValue;
}
 
Example 11
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
/**
 * Invokes the <code>modelToView</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Rectangle modelToView(JTextComponent a, int b, Position.Bias c)
        throws BadLocationException {
    Rectangle returnValue =
        ((TextUI) (uis.elementAt(0))).modelToView(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).modelToView(a,b,c);
    }
    return returnValue;
}
 
Example 13
Source Project: openjdk-jdk9   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int getNextVisualPositionFrom(JTextComponent a, int b, Position.Bias c, int d, Position.Bias[] e)
        throws BadLocationException {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(a,b,c,d,e);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(a,b,c,d,e);
    }
    return returnValue;
}
 
Example 14
Source Project: openjdk-jdk9   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Rectangle2D modelToView2D(JTextComponent a, int b, Position.Bias c) throws BadLocationException {
    Rectangle2D returnValue =
        ((TextUI) (uis.elementAt(0))).modelToView2D(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).modelToView2D(a,b,c);
    }
    return returnValue;
}
 
Example 15
/**
 * Returns true if the View representing <code>e</code> contains
 * the location <code>x</code>, <code>y</code>. <code>offset</code>
 * gives the offset into the Document to check for.
 */
private boolean doesElementContainLocation(JEditorPane editor,
                                           Element e, int offset,
                                           int x, int y) {
    if (e != null && offset > 0 && e.getStartOffset() == offset) {
        try {
            TextUI ui = editor.getUI();
            Shape s1 = ui.modelToView(editor, offset,
                                      Position.Bias.Forward);
            if (s1 == null) {
                return false;
            }
            Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle)s1 :
                            s1.getBounds();
            Shape s2 = ui.modelToView(editor, e.getEndOffset(),
                                      Position.Bias.Backward);
            if (s2 != null) {
                Rectangle r2 = (s2 instanceof Rectangle) ? (Rectangle)s2 :
                            s2.getBounds();
                r1.add(r2);
            }
            return r1.contains(x, y);
        } catch (BadLocationException ble) {
        }
    }
    return true;
}
 
Example 16
Source Project: jdk8u_jdk   Source File: HTMLEditorKit.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the View representing <code>e</code> contains
 * the location <code>x</code>, <code>y</code>. <code>offset</code>
 * gives the offset into the Document to check for.
 */
private boolean doesElementContainLocation(JEditorPane editor,
                                           Element e, int offset,
                                           int x, int y) {
    if (e != null && offset > 0 && e.getStartOffset() == offset) {
        try {
            TextUI ui = editor.getUI();
            Shape s1 = ui.modelToView(editor, offset,
                                      Position.Bias.Forward);
            if (s1 == null) {
                return false;
            }
            Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle)s1 :
                            s1.getBounds();
            Shape s2 = ui.modelToView(editor, e.getEndOffset(),
                                      Position.Bias.Backward);
            if (s2 != null) {
                Rectangle r2 = (s2 instanceof Rectangle) ? (Rectangle)s2 :
                            s2.getBounds();
                r1.add(r2);
            }
            return r1.contains(x, y);
        } catch (BadLocationException ble) {
        }
    }
    return true;
}
 
Example 17
Source Project: dragonwell8_jdk   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>modelToView</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Rectangle modelToView(JTextComponent a, int b, Position.Bias c)
        throws BadLocationException {
    Rectangle returnValue =
        ((TextUI) (uis.elementAt(0))).modelToView(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).modelToView(a,b,c);
    }
    return returnValue;
}
 
Example 18
Source Project: dragonwell8_jdk   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>viewToModel</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int viewToModel(JTextComponent a, Point b) {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).viewToModel(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).viewToModel(a,b);
    }
    return returnValue;
}
 
Example 19
Source Project: dragonwell8_jdk   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>viewToModel</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int viewToModel(JTextComponent a, Point b, Position.Bias[] c) {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).viewToModel(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).viewToModel(a,b,c);
    }
    return returnValue;
}
 
Example 20
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 21
Source Project: openjdk-jdk8u   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>viewToModel</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int viewToModel(JTextComponent a, Point b) {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).viewToModel(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).viewToModel(a,b);
    }
    return returnValue;
}
 
Example 22
Source Project: Bytecoder   Source File: MultiTextUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the <code>viewToModel</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
@Deprecated(since = "9")
@Override
public int viewToModel(JTextComponent a, Point b) {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).viewToModel(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).viewToModel(a,b);
    }
    return returnValue;
}
 
Example 23
Source Project: dragonwell8_jdk   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getRootView</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public View getRootView(JTextComponent a) {
    View returnValue =
        ((TextUI) (uis.elementAt(0))).getRootView(a);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getRootView(a);
    }
    return returnValue;
}
 
Example 24
Source Project: jdk8u-jdk   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int getNextVisualPositionFrom(JTextComponent a, int b, Position.Bias c, int d, Position.Bias[] e)
        throws BadLocationException {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(a,b,c,d,e);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(a,b,c,d,e);
    }
    return returnValue;
}
 
Example 25
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 26
Source Project: netbeans   Source File: BraceMatchingSidebarComponent.java    License: 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 27
/**
 * Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int getNextVisualPositionFrom(JTextComponent a, int b, Position.Bias c, int d, Position.Bias[] e)
        throws BadLocationException {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(a,b,c,d,e);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(a,b,c,d,e);
    }
    return returnValue;
}
 
Example 28
Source Project: openjdk-8   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int getNextVisualPositionFrom(JTextComponent a, int b, Position.Bias c, int d, Position.Bias[] e)
        throws BadLocationException {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(a,b,c,d,e);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(a,b,c,d,e);
    }
    return returnValue;
}
 
Example 29
Source Project: TencentKona-8   Source File: MultiTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getToolTipText</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public String getToolTipText(JTextComponent a, Point b) {
    String returnValue =
        ((TextUI) (uis.elementAt(0))).getToolTipText(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getToolTipText(a,b);
    }
    return returnValue;
}
 
Example 30
Source Project: hottub   Source File: AquaTextFieldSearch.java    License: 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);
    }
}