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

The following examples show how to use javax.swing.text.JTextComponent#getClientProperty() . 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: AddToDictionaryCompletionItem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void defaultAction (
    final JTextComponent    component
) {
    Completion.get ().hideCompletion ();
    Completion.get ().hideDocumentation ();
    Document document = component.getDocument ();
    DataObject dataObject = (DataObject) document.getProperty (Document.StreamDescriptionProperty);
    FileObject fileObject = dataObject.getPrimaryFile ();
    Project project = FileOwnerQuery.getOwner (fileObject);
    Locale locale = LocaleQuery.findLocale(fileObject);
    DictionaryImpl dictionary = projects && project != null ?
        ComponentPeer.getProjectDictionary (project, locale) :
        ComponentPeer.getUsersLocalDictionary (locale);
    dictionary.addEntry (word);
    ComponentPeer componentPeer = (ComponentPeer) component.getClientProperty (ComponentPeer.class);
    componentPeer.reschedule();
}
 
Example 2
Source File: AquaTextFieldSearch.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected static JButton getFindButton(final JTextComponent c) {
    final DynamicallySizingJRSUIIcon findIcon = getFindIcon(c);
    final JButton b = createButton(c, findIcon);
    b.setName("find");

    final Object findPopup = c.getClientProperty(FIND_POPUP_KEY);
    if (findPopup instanceof JPopupMenu) {
        // if we have a popup, indicate that in the icon
        findIcon.painter.state.set(Variant.MENU_GLYPH);

        b.addMouseListener(new MouseAdapter() {
            public void mousePressed(final MouseEvent e) {
                ((JPopupMenu)findPopup).show(b, 8, b.getHeight() - 2);
                c.requestFocusInWindow();
                c.repaint();
            }
        });
    }

    final Object findAction = c.getClientProperty(FIND_ACTION_KEY);
    if (findAction instanceof ActionListener) {
        b.addActionListener((ActionListener)findAction);
    }

    return b;
}
 
Example 3
Source File: AquaTextFieldSearch.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected static JButton getFindButton(final JTextComponent c) {
    final DynamicallySizingJRSUIIcon findIcon = getFindIcon(c);
    final JButton b = createButton(c, findIcon);
    b.setName("find");

    final Object findPopup = c.getClientProperty(FIND_POPUP_KEY);
    if (findPopup instanceof JPopupMenu) {
        // if we have a popup, indicate that in the icon
        findIcon.painter.state.set(Variant.MENU_GLYPH);

        b.addMouseListener(new MouseAdapter() {
            public void mousePressed(final MouseEvent e) {
                ((JPopupMenu)findPopup).show(b, 8, b.getHeight() - 2);
                c.requestFocusInWindow();
                c.repaint();
            }
        });
    }

    final Object findAction = c.getClientProperty(FIND_ACTION_KEY);
    if (findAction instanceof ActionListener) {
        b.addActionListener((ActionListener)findAction);
    }

    return b;
}
 
Example 4
Source File: DocumentViewOp.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void updateLineWrapType() {
    // Should be able to run without mutex
    String lwt = null;
    JTextComponent textComponent = docView.getTextComponent();
    if (textComponent != null) {
        lwt = (String) textComponent.getClientProperty(SimpleValueNames.TEXT_LINE_WRAP);
    }
    if (lwt == null) {
        Document doc = docView.getDocument();
        lwt = (String) doc.getProperty(SimpleValueNames.TEXT_LINE_WRAP);
    }
    if (lwt != null) {
        lineWrapType = LineWrapType.fromSettingValue(lwt);
    }
    if (asTextField || lineWrapType == null) {
        lineWrapType = LineWrapType.NONE;
    }
    clearStatusBits(AVAILABLE_WIDTH_VALID);
}
 
Example 5
Source File: SelectCodeElementAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        int selectionStartOffset = target.getSelectionStart();
        int selectionEndOffset = target.getSelectionEnd();
        if (selectionEndOffset > selectionStartOffset || selectNext) {
            SelectionHandler handler = (SelectionHandler)target.getClientProperty(SelectionHandler.class);
            if (handler == null) {
                handler = new SelectionHandler(target);
                target.addCaretListener(handler);
                // No need to remove the listener above as the handler
                // is stored is the client-property of the component itself
                target.putClientProperty(SelectionHandler.class, handler);
            }
            
            if (selectNext) { // select next element
                handler.selectNext();
            } else { // select previous
                handler.selectPrevious();
            }
        }
    }
}
 
Example 6
Source File: AquaTextFieldSearch.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected static DynamicallySizingJRSUIIcon getFindIcon(final JTextComponent text) {
    return (text.getClientProperty(FIND_POPUP_KEY) == null) ?
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, -5))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    :
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, 2))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    ;
}
 
Example 7
Source File: AquaTextFieldSearch.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected static DynamicallySizingJRSUIIcon getFindIcon(final JTextComponent text) {
    return (text.getClientProperty(FIND_POPUP_KEY) == null) ?
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, -5))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    :
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, 2))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    ;
}
 
Example 8
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Return the MouseEvent's click count, possibly reduced by the value of
 * the component's {@code SKIP_CLICK_COUNT} client property. Clears
 * the {@code SKIP_CLICK_COUNT} property if the mouse event's click count
 * is 1. In order for clearing of the property to work correctly, there
 * must be a mousePressed implementation on the caller with this
 * call as the first line.
 */
public static int getAdjustedClickCount(JTextComponent comp, MouseEvent e) {
    int cc = e.getClickCount();

    if (cc == 1) {
        comp.putClientProperty(SKIP_CLICK_COUNT, null);
    } else {
        Integer sub = (Integer) comp.getClientProperty(SKIP_CLICK_COUNT);
        if (sub != null) {
            return cc - sub;
        }
    }

    return cc;
}
 
Example 9
Source File: AquaTextFieldSearch.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void updatePromptLabelOnEDT(final JLabel label, final JTextComponent text) {
    String promptText = " ";
    if (!text.hasFocus() && "".equals(text.getText())) {
        final Object prompt = text.getClientProperty(PROMPT_KEY);
        if (prompt != null) promptText = prompt.toString();
    }
    label.setText(promptText);
}
 
Example 10
Source File: AquaTextFieldSearch.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected static DynamicallySizingJRSUIIcon getFindIcon(final JTextComponent text) {
    return (text.getClientProperty(FIND_POPUP_KEY) == null) ?
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, -5))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    :
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, 2))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    ;
}
 
Example 11
Source File: AquaTextFieldSearch.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected static DynamicallySizingJRSUIIcon getFindIcon(final JTextComponent text) {
    return (text.getClientProperty(FIND_POPUP_KEY) == null) ?
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, -5))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    :
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, 2))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    ;
}
 
Example 12
Source File: AquaTextFieldSearch.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void updatePromptLabelOnEDT(final JLabel label, final JTextComponent text) {
    String promptText = " ";
    if (!text.hasFocus() && "".equals(text.getText())) {
        final Object prompt = text.getClientProperty(PROMPT_KEY);
        if (prompt != null) promptText = prompt.toString();
    }
    label.setText(promptText);
}
 
Example 13
Source File: ZoomTextAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    String actionName = actionName();
    int delta = (EditorActionNames.zoomTextIn.equals(actionName)) ? +1 : -1;
    if (target != null) {
        int newZoom = 0;
        Integer currentZoom = (Integer) target.getClientProperty(TEXT_ZOOM_PROPERTY);
        if (currentZoom != null) {
            newZoom += currentZoom;
        }
        newZoom += delta;
        target.putClientProperty(TEXT_ZOOM_PROPERTY, newZoom);
    }
}
 
Example 14
Source File: AquaTextFieldSearch.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected static DynamicallySizingJRSUIIcon getFindIcon(final JTextComponent text) {
    return (text.getClientProperty(FIND_POPUP_KEY) == null) ?
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, -5))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    :
        new DynamicallySizingJRSUIIcon(new SizeDescriptor(new SizeVariant(25, 22).alterMargins(0, 4, 0, 2))) {
            public void initJRSUIState() {
                painter.state.set(Widget.BUTTON_SEARCH_FIELD_FIND);
            }
        }
    ;
}
 
Example 15
Source File: AnnotationBarManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Tests wheteher given editor shows annotations.
 */
public static boolean annotationBarVisible(JTextComponent target) {
    if (target == null) return false;
    AnnotationBar ab = (AnnotationBar) target.getClientProperty(AnnotationBarManager.BAR_KEY);
    return ab != null && ab.isAnnotated();
}
 
Example 16
Source File: AquaTextFieldSearch.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
protected static boolean hasPopupMenu(final JTextComponent c) {
    return (c.getClientProperty(FIND_POPUP_KEY) instanceof JPopupMenu);
}
 
Example 17
Source File: AnnotationMarkInstaller.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static AnnotationMarkProvider getMarkProvider(JTextComponent pane) {
    return (AnnotationMarkProvider) pane.getClientProperty(PROVIDER_KEY);
}
 
Example 18
Source File: AquaTextFieldSearch.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected static boolean hasPopupMenu(final JTextComponent c) {
    return (c.getClientProperty(FIND_POPUP_KEY) instanceof JPopupMenu);
}
 
Example 19
Source File: ControlPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static String getFwdLookahead(JTextComponent component) {
    Object value = component.getClientProperty(MasterMatcher.PROP_MAX_FORWARD_LOOKAHEAD);
    return value == null ? "" : value.toString();
}
 
Example 20
Source File: AquaTextFieldSearch.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected static boolean hasPopupMenu(final JTextComponent c) {
    return (c.getClientProperty(FIND_POPUP_KEY) instanceof JPopupMenu);
}