Java Code Examples for java.awt.event.FocusEvent#getID()

The following examples show how to use java.awt.event.FocusEvent#getID() . 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: KeyboardFocusManager.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
Example 2
Source File: KeyboardFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
Example 3
Source File: KeyboardFocusManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
Example 4
Source File: KeyboardFocusManager.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
Example 5
Source File: KeyboardFocusManager.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
Example 6
Source File: KeyboardFocusManager.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
Example 7
Source File: ChildFocusWatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void eventDispatched(final AWTEvent event) {
  if (event instanceof FocusEvent) {
    final FocusEvent fe = (FocusEvent)event;
    final Component component = fe.getComponent();
    if (component == null) return;
    if (!SwingUtilities.isDescendingFrom(component, myParent)) return;

    if (fe.getID() == FocusEvent.FOCUS_GAINED) {
      onFocusGained(fe);
    } else if (fe.getID() == FocusEvent.FOCUS_LAST) {
      onFocusLost(fe);
    }
  }
}
 
Example 8
Source File: LWTextFieldPeer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restoring native behavior. We should sets the selection range to zero,
 * when component lost its focus.
 *
 * @param e the focus event
 */
@Override
void handleJavaFocusEvent(final FocusEvent e) {
    if (e.getID() == FocusEvent.FOCUS_LOST) {
        // In order to de-select the selection
        setCaretPosition(0);
    }
    super.handleJavaFocusEvent(e);
}
 
Example 9
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addSnapToGridField(JToolBar buttonBar, Insets margin) {

		gridSpacing = new JTextField("1000000 m") {
			@Override
			protected void processFocusEvent(FocusEvent fe) {
				if (fe.getID() == FocusEvent.FOCUS_LOST) {
					GUIFrame.this.setSnapGridSpacing(this.getText().trim());
				}
				else if (fe.getID() == FocusEvent.FOCUS_GAINED) {
					gridSpacing.selectAll();
				}
				super.processFocusEvent( fe );
			}
		};

		gridSpacing.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				GUIFrame.this.setSnapGridSpacing(gridSpacing.getText().trim());
				controlStartResume.requestFocusInWindow();
			}
		});

		gridSpacing.setMaximumSize(gridSpacing.getPreferredSize());
		int hght = snapToGrid.getPreferredSize().height;
		gridSpacing.setPreferredSize(new Dimension(gridSpacing.getPreferredSize().width, hght));

		gridSpacing.setHorizontalAlignment(JTextField.RIGHT);
		gridSpacing.setToolTipText(formatToolTip("Snap Grid Spacing",
				"Distance between adjacent grid points, e.g. 0.1 m, 10 km, etc."));

		gridSpacing.setEnabled(snapToGrid.isSelected());

		buttonBar.add(gridSpacing);
	}
 
Example 10
Source File: LWTextFieldPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restoring native behavior. We should sets the selection range to zero,
 * when component lost its focus.
 *
 * @param e the focus event
 */
@Override
void handleJavaFocusEvent(final FocusEvent e) {
    if (e.getID() == FocusEvent.FOCUS_LOST) {
        // In order to de-select the selection
        setCaretPosition(0);
    }
    super.handleJavaFocusEvent(e);
}
 
Example 11
Source File: LWTextFieldPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restoring native behavior. We should sets the selection range to zero,
 * when component lost its focus.
 *
 * @param e the focus event
 */
@Override
void handleJavaFocusEvent(final FocusEvent e) {
    if (e.getID() == FocusEvent.FOCUS_LOST) {
        // In order to de-select the selection
        setCaretPosition(0);
    }
    super.handleJavaFocusEvent(e);
}
 
Example 12
Source File: LWTextFieldPeer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restoring native behavior. We should sets the selection range to zero,
 * when component lost its focus.
 *
 * @param e the focus event
 */
@Override
void handleJavaFocusEvent(final FocusEvent e) {
    if (e.getID() == FocusEvent.FOCUS_LOST) {
        // In order to de-select the selection
        setCaretPosition(0);
    }
    super.handleJavaFocusEvent(e);
}
 
Example 13
Source File: LWTextFieldPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restoring native behavior. We should sets the selection range to zero,
 * when component lost its focus.
 *
 * @param e the focus event
 */
@Override
void handleJavaFocusEvent(final FocusEvent e) {
    if (e.getID() == FocusEvent.FOCUS_LOST) {
        // In order to de-select the selection
        setCaretPosition(0);
    }
    super.handleJavaFocusEvent(e);
}
 
Example 14
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addTextHeightField(JToolBar buttonBar, Insets margin) {

		textHeight = new JTextField("1000000 m") {
			@Override
			protected void processFocusEvent(FocusEvent fe) {
				if (fe.getID() == FocusEvent.FOCUS_LOST) {
					GUIFrame.this.setTextHeight(this.getText().trim());
				}
				super.processFocusEvent( fe );
			}
		};

		textHeight.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				GUIFrame.this.setTextHeight(textHeight.getText().trim());
				controlStartResume.requestFocusInWindow();
			}
		});

		textHeight.setMaximumSize(textHeight.getPreferredSize());
		textHeight.setPreferredSize(new Dimension(textHeight.getPreferredSize().width,
				fileSave.getPreferredSize().height));

		textHeight.setHorizontalAlignment(JTextField.RIGHT);
		textHeight.setToolTipText(formatToolTip("Text Height",
				"Sets the height of the text, e.g. 0.1 m, 200 cm, etc."));

		buttonBar.add(textHeight);
	}
 
Example 15
Source File: LWTextFieldPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restoring native behavior. We should sets the selection range to zero,
 * when component lost its focus.
 *
 * @param e the focus event
 */
@Override
void handleJavaFocusEvent(final FocusEvent e) {
    if (e.getID() == FocusEvent.FOCUS_LOST) {
        // In order to de-select the selection
        setCaretPosition(0);
    }
    super.handleJavaFocusEvent(e);
}
 
Example 16
Source File: BaseTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Overridden to remove the editor on focus lost */
public void processFocusEvent(FocusEvent fe) {
    super.processFocusEvent(fe);

    if (PropUtils.isLoggable(BaseTable.class)) {
        PropUtils.log(BaseTable.class, "processFocusEvent - "); //NOI18N
        PropUtils.log(BaseTable.class, fe);
    }

    if (!isAncestorOf(fe.getOppositeComponent()) || (fe.getOppositeComponent() == null)) {
        if (isEditing() && (fe.getID() == FocusEvent.FOCUS_LOST)) {
            if (PropUtils.isLoggable(BaseTable.class)) {
                PropUtils.log(
                    BaseTable.class, "ProcessFocusEvent got focus lost to unknown component, removing editor"
                ); //NOI18N
            }

            focusLostCancel();
        }
    }

    if (!inEditorRemoveRequest() && !inEditRequest()) { //XXX inEditRequest probably shouldn't be here

        if ((fe.getOppositeComponent() == null) && (fe.getID() == FocusEvent.FOCUS_LOST)) {
            //ignore the strange focus to null stuff NetBeans does
            return;
        }

        paintSelectionRow();
    } else {
        paintSelectionRow();
    }
}
 
Example 17
Source File: CausedFocusEvent.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retargets the original focus event to the new target.  If the
 * original focus event is CausedFocusEvent, it remains such and
 * cause is copied.  Otherwise, new CausedFocusEvent is created,
 * with cause as RETARGETED.
 * @return retargeted event, or null if e is null
 */
public static FocusEvent retarget(FocusEvent e, Component newSource) {
    if (e == null) return null;

    return new CausedFocusEvent(newSource, e.getID(), e.isTemporary(), e.getOppositeComponent(),
                                (e instanceof CausedFocusEvent) ? ((CausedFocusEvent)e).getCause() : Cause.RETARGETED);
}
 
Example 18
Source File: CausedFocusEvent.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retargets the original focus event to the new target.  If the
 * original focus event is CausedFocusEvent, it remains such and
 * cause is copied.  Otherwise, new CausedFocusEvent is created,
 * with cause as RETARGETED.
 * @return retargeted event, or null if e is null
 */
public static FocusEvent retarget(FocusEvent e, Component newSource) {
    if (e == null) return null;

    return new CausedFocusEvent(newSource, e.getID(), e.isTemporary(), e.getOppositeComponent(),
                                (e instanceof CausedFocusEvent) ? ((CausedFocusEvent)e).getCause() : Cause.RETARGETED);
}
 
Example 19
Source File: CausedFocusEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retargets the original focus event to the new target.  If the
 * original focus event is CausedFocusEvent, it remains such and
 * cause is copied.  Otherwise, new CausedFocusEvent is created,
 * with cause as RETARGETED.
 * @return retargeted event, or null if e is null
 */
public static FocusEvent retarget(FocusEvent e, Component newSource) {
    if (e == null) return null;

    return new CausedFocusEvent(newSource, e.getID(), e.isTemporary(), e.getOppositeComponent(),
                                (e instanceof CausedFocusEvent) ? ((CausedFocusEvent)e).getCause() : Cause.RETARGETED);
}
 
Example 20
Source File: CausedFocusEvent.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retargets the original focus event to the new target.  If the
 * original focus event is CausedFocusEvent, it remains such and
 * cause is copied.  Otherwise, new CausedFocusEvent is created,
 * with cause as RETARGETED.
 * @return retargeted event, or null if e is null
 */
public static FocusEvent retarget(FocusEvent e, Component newSource) {
    if (e == null) return null;

    return new CausedFocusEvent(newSource, e.getID(), e.isTemporary(), e.getOppositeComponent(),
                                (e instanceof CausedFocusEvent) ? ((CausedFocusEvent)e).getCause() : Cause.RETARGETED);
}