Search in sources :

Example 61 with JTextComponent

use of javax.swing.text.JTextComponent in project freeplane by freeplane.

the class TimeManagement method insertTime.

void insertTime(final Dialog dialog, final JButton appendButton) {
    FormattedDate date = getCalendarDate();
    final String dateAsString = dateFormat.formatObject(date).toString();
    final Window parentWindow;
    if (dialog != null) {
        parentWindow = (Window) dialog.getParent();
    } else {
        parentWindow = SwingUtilities.getWindowAncestor(appendButton);
    }
    final Component mostRecentFocusOwner = parentWindow.getMostRecentFocusOwner();
    if (mostRecentFocusOwner instanceof JTextComponent && !(mostRecentFocusOwner.getClass().getName().contains("JSpinField"))) {
        final JTextComponent textComponent = (JTextComponent) mostRecentFocusOwner;
        textComponent.replaceSelection(dateAsString);
        return;
    }
    if (mostRecentFocusOwner instanceof JTable) {
        JTable table = (JTable) mostRecentFocusOwner;
        final int[] selectedRows = table.getSelectedRows();
        final int[] selectedColumns = table.getSelectedColumns();
        for (int r : selectedRows) for (int c : selectedColumns) table.setValueAt(date, r, c);
    } else {
        ModeController mController = Controller.getCurrentModeController();
        for (final NodeModel node : mController.getMapController().getSelectedNodes()) {
            final MTextController textController = (MTextController) TextController.getController();
            textController.setNodeObject(node, date);
        }
    }
}
Also used : Window(java.awt.Window) FormattedDate(org.freeplane.features.format.FormattedDate) NodeModel(org.freeplane.features.map.NodeModel) JTable(javax.swing.JTable) JTextComponent(javax.swing.text.JTextComponent) ModeController(org.freeplane.features.mode.ModeController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent)

Example 62 with JTextComponent

use of javax.swing.text.JTextComponent in project freeplane by freeplane.

the class UITools method isEditingText.

public static boolean isEditingText() {
    final Component focusOwner = FocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    final boolean isTextComponentFocused = focusOwner instanceof JEditorPane;
    return isTextComponentFocused && focusOwner.isShowing() && ((JTextComponent) focusOwner).isEditable();
}
Also used : JEditorPane(javax.swing.JEditorPane) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent)

Example 63 with JTextComponent

use of javax.swing.text.JTextComponent in project freeplane by freeplane.

the class FilterConditionEditor method focusInputField.

public void focusInputField(final boolean selectAll) {
    if (values.isEnabled()) {
        values.requestFocus();
        final Component editorComponent = values.getEditor().getEditorComponent();
        if (selectAll && editorComponent instanceof JTextComponent) {
            ((JTextComponent) editorComponent).selectAll();
        }
        return;
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent) JComponent(javax.swing.JComponent) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent)

Example 64 with JTextComponent

use of javax.swing.text.JTextComponent in project freeplane by freeplane.

the class NodeSelector method createTimer.

public void createTimer(final MouseEvent e) {
    if (controlRegionForDelayedSelection != null && controlRegionForDelayedSelection.contains(e.getPoint())) {
        return;
    }
    if (!isInside(e))
        return;
    stopTimerForDelayedSelection();
    Window focusedWindow = FocusManager.getCurrentManager().getFocusedWindow();
    if (focusedWindow == null) {
        return;
    }
    if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() instanceof JTextComponent) {
        return;
    }
    /* Region to check for in the sequel. */
    controlRegionForDelayedSelection = getControlRegion(e.getPoint());
    final String selectionMethod = ResourceController.getResourceController().getProperty(SELECTION_METHOD);
    if (selectionMethod.equals(SELECTION_METHOD_BY_CLICK)) {
        return;
    }
    if (selectionMethod.equals(SELECTION_METHOD_DIRECT)) {
        new TimeDelayedSelection(e).run();
        return;
    }
    final int timeForDelayedSelection = ResourceController.getResourceController().getIntProperty(TIME_FOR_DELAYED_SELECTION, 0);
    timerForDelayedSelection = SysUtils.createTimer(getClass().getSimpleName());
    timerForDelayedSelection.schedule(new TimeDelayedSelection(e), timeForDelayedSelection);
}
Also used : Window(java.awt.Window) JTextComponent(javax.swing.text.JTextComponent)

Example 65 with JTextComponent

use of javax.swing.text.JTextComponent in project basicv2 by EgonOlsen71.

the class BlockCaret method paint.

public void paint(Graphics g) {
    if (isVisible()) {
        try {
            JTextComponent component = getComponent();
            Rectangle r = component.getUI().modelToView(component, getDot());
            Color c = g.getColor();
            g.setColor(component.getBackground());
            g.setXORMode(component.getCaretColor());
            r.setBounds(r.x, r.y, g.getFontMetrics().charWidth('w'), g.getFontMetrics().getHeight());
            g.fillRect(r.x, r.y, r.width, r.height);
            g.setPaintMode();
            g.setColor(c);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
}
Also used : Color(java.awt.Color) Rectangle(java.awt.Rectangle) JTextComponent(javax.swing.text.JTextComponent) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

JTextComponent (javax.swing.text.JTextComponent)181 Component (java.awt.Component)28 JComponent (javax.swing.JComponent)16 BadLocationException (javax.swing.text.BadLocationException)13 NotNull (org.jetbrains.annotations.NotNull)13 DocumentEvent (javax.swing.event.DocumentEvent)11 DocumentAdapter (com.intellij.ui.DocumentAdapter)8 Caret (javax.swing.text.Caret)8 Document (javax.swing.text.Document)8 Point (java.awt.Point)7 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)7 ArrayList (java.util.ArrayList)7 ComboBoxEditor (javax.swing.ComboBoxEditor)7 FocusEvent (java.awt.event.FocusEvent)6 Color (java.awt.Color)5 KeyEvent (java.awt.event.KeyEvent)5 MouseEvent (java.awt.event.MouseEvent)5 JButton (javax.swing.JButton)5 JComboBox (javax.swing.JComboBox)5