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

The following examples show how to use java.awt.event.FocusEvent#isTemporary() . 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: TreeTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void processFocusEvent(FocusEvent fe) {
    super.processFocusEvent(fe);

    //Remove the editor here if the new focus owner is not
    //known to the table & the focus event is not temporary
    if ((fe.getID() == FocusEvent.FOCUS_LOST) && !fe.isTemporary() && !inRemoveRequest && !inEditRequest) {
        boolean stopEditing = ((fe.getOppositeComponent() != getParent()) &&
            !isKnownComponent(fe.getOppositeComponent()) && (fe.getOppositeComponent() != null));

        if (stopEditing) {
            removeEditor();
        }
    }

    //The UI will only repaint the lead selection, but we need to
    //paint all selected rows for the color to change when focus
    //is lost/gained
    if (!inRemoveRequest && !inEditRequest) {
        repaintSelection(fe.getID() == FocusEvent.FOCUS_GAINED);
    }
}
 
Example 2
Source File: BaseTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void focusLost(FocusEvent fe) {
    if ((dragListener != null) && dragListener.isDragging()) {
        dragListener.abortDrag();
    }

    PropUtils.log(BaseTable.class, fe);

    //Ignore temporary focus changes, so sloppy focus middle mouse button
    //cut/paste can work
    if (fe.isTemporary()) {
        return;
    }

    Component opposite = fe.getOppositeComponent();

    if (!isKnownComponent(opposite)) {
        doFocusLost(opposite);
    }
}
 
Example 3
Source File: UIUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void focusGained(FocusEvent e) {
    if (e.isTemporary()) {
        return;
    }
    Component cmp = e.getComponent();
    if(cmp instanceof JComponent) {
        JViewport vp = getViewport(container);
        if(vp == null) {
            return;
        }
        Rectangle vr = vp.getViewRect();
        Point p = SwingUtilities.convertPoint(cmp.getParent(), cmp.getLocation(), container);
        final Rectangle r = new Rectangle(p, cmp.getSize());
        if(vr.intersects(r)) {
            return; 
        }
        container.scrollRectToVisible(r);
    }
}
 
Example 4
Source File: EditorUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Construct extended UI for the use with a text component */
public EditorUI() {
    focusL = new FocusAdapter() {
                 public @Override void focusGained(FocusEvent evt) {
                     /* Fix of #25475 - copyAction's enabled flag
                      * must be updated on focus change
                      */
                     stateChanged(null);
                     if (component!=null){
                        BaseTextUI ui = (BaseTextUI)component.getUI();
                        if (ui!=null) ui.refresh();
                     }
                 }

                 @Override
                 public void focusLost(FocusEvent e) {
                     // see #222935, update actions before menu activates
                     if (e.isTemporary()) {
                         doStateChange(true);
                     }
                 }
             };

    getToolTipSupport();
}
 
Example 5
Source File: FocusDebuggerAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void eventDispatched(AWTEvent event) {
  if (event instanceof FocusEvent) {
    FocusEvent focusEvent = (FocusEvent)event;
    Component fromComponent = focusEvent.getComponent();
    Component oppositeComponent = focusEvent.getOppositeComponent();

    paintFocusBorders(true);

    switch (event.getID()) {
      case FocusEvent.FOCUS_GAINED:
        myCurrent = fromComponent;
        myPrevious = oppositeComponent;
        myTemporary = focusEvent.isTemporary();
        break;
      case FocusEvent.FOCUS_LOST:
        myTemporary = focusEvent.isTemporary();
      default:
        break;
    }
  }
}
 
Example 6
Source File: PropertyMemberUIWrapper.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void focusLost(FocusEvent e) {
    //save the value
    if (!e.isTemporary()) {
        try {
            if (getValueFromUIComponent().equals(getMemberValue())) {
                return;
            }
            setMemberValueWithCheck(getValueFromUIComponent());
            if (callback != null) {
                callback.doCallBack(null, paramDescriptor, null, attributeName);
            }
        } catch (PropertyAttributeException ex) {
            if (callback != null) {
                callback.doCallBack(ex, paramDescriptor, null, attributeName);
            }
            UIComponent.requestFocusInWindow();
        }
    }
}
 
Example 7
Source File: AutoCompletionDocumentListener.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void focusLost(FocusEvent e) {
	hasFocus = false;
	autoSave.runNow();
	if (e.isTemporary()) {
		comboBoxInput.setCaretPosition(comboBoxInput.getCaretPosition());
	}
}
 
Example 8
Source File: ListTableView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void focusLost(FocusEvent evt) {
    if (evt.isTemporary()) {
        return;
    }

    int selectedRow = list.getSelectedIndex();
    table.getSelectionModel().setAnchorSelectionIndex(selectedRow);
    table.getColumnModel().getSelectionModel().setAnchorSelectionIndex(0);
}
 
Example 9
Source File: FocusWatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
public final void focusGained(final FocusEvent e){
  final Component component = e.getComponent();
  if(e.isTemporary()||!component.isShowing()){
    return;
  }
  setFocusedComponentImpl(component, e);
  setNearestFocusableComponent(component.getParent());
}
 
Example 10
Source File: DeferredCharacterComboBoxModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void focusLost(FocusEvent e)
{
	// Temporary focus lost means something like the drop-down has
	// got focus
	if (e.isTemporary())
	{
		return;
	}

	SwingUtilities.invokeLater(() -> commitSelectedItem(selectedItem));
}
 
Example 11
Source File: FlatCaret.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
@Override
public void focusLost( FocusEvent e ) {
	wasTemporaryLost = e.isTemporary();
	super.focusLost( e );
}
 
Example 12
Source File: CausedFocusEvent.java    From openjdk-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 13
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);
}
 
Example 14
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 15
Source File: CausedFocusEvent.java    From jdk8u-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 16
Source File: CausedFocusEvent.java    From jdk8u-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 17
Source File: CausedFocusEvent.java    From openjdk-jdk8u 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 jdk8u60 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 jdk8u_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 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);
}