Package java.awt.event

Examples of java.awt.event.FocusEvent


            descendant = heavyweight;
        }

        KeyboardFocusManager manager = getCurrentKeyboardFocusManager(SunToolkit.targetToAppContext(descendant));

        FocusEvent currentFocusOwnerEvent = null;
        FocusEvent newFocusOwnerEvent = null;
        Component currentFocusOwner = manager.getGlobalFocusOwner();

        synchronized (heavyweightRequests) {
            HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
                ((heavyweightRequests.size() > 0)
                 ? heavyweightRequests.getLast() : null);
            if (hwFocusRequest == null &&
                heavyweight == manager.getNativeFocusOwner() &&
                allowSyncFocusRequests)
            {

                if (descendant == currentFocusOwner) {
                    // Redundant request.
                    return true;
                }

                // 'heavyweight' owns the native focus and there are no pending
                // requests. 'heavyweight' must be a Container and
                // 'descendant' must not be the focus owner. Otherwise,
                // we would never have gotten this far.
                manager.enqueueKeyEvents(time, descendant);

                hwFocusRequest =
                    new HeavyweightFocusRequest(heavyweight, descendant,
                                                temporary, CausedFocusEvent.Cause.UNKNOWN);
                heavyweightRequests.add(hwFocusRequest);

                if (currentFocusOwner != null) {
                    currentFocusOwnerEvent =
                        new FocusEvent(currentFocusOwner,
                                       FocusEvent.FOCUS_LOST,
                                       temporary, descendant);
                }
                newFocusOwnerEvent =
                    new FocusEvent(descendant, FocusEvent.FOCUS_GAINED,
                                   temporary, currentFocusOwner);
            }
        }
        boolean result = false;
        final boolean clearing = clearingCurrentLightweightRequests;
View Full Code Here


                    new HeavyweightFocusRequest(heavyweight, descendant,
                                                temporary, cause);
                heavyweightRequests.add(hwFocusRequest);

                if (currentFocusOwner != null) {
                    FocusEvent currentFocusOwnerEvent =
                        new CausedFocusEvent(currentFocusOwner,
                                       FocusEvent.FOCUS_LOST,
                                       temporary, descendant, cause);
                    // Fix 5028014. Rolled out.
                    // SunToolkit.postPriorityEvent(currentFocusOwnerEvent);
                    SunToolkit.postEvent(currentFocusOwner.appContext,
                                         currentFocusOwnerEvent);
                }
                FocusEvent newFocusOwnerEvent =
                    new CausedFocusEvent(descendant, FocusEvent.FOCUS_GAINED,
                                   temporary, currentFocusOwner, cause);
                // Fix 5028014. Rolled out.
                // SunToolkit.postPriorityEvent(newFocusOwnerEvent);
                SunToolkit.postEvent(descendant.appContext, newFocusOwnerEvent);
View Full Code Here

                     */
                     if (!iter.hasNext()) {
                           disableRestoreFocus = false;
                     }

                    FocusEvent currentFocusOwnerEvent = null;
                    if ( currentFocusOwner != null ){ 
                       currentFocusOwnerEvent = new CausedFocusEvent(currentFocusOwner,
                                       FocusEvent.FOCUS_LOST,
                                       lwFocusRequest.temporary,
                                       lwFocusRequest.component, lwFocusRequest.cause);
                    }
                   
                    FocusEvent newFocusOwnerEvent =
                        new CausedFocusEvent(lwFocusRequest.component,
                                       FocusEvent.FOCUS_GAINED,
                                       lwFocusRequest.temporary,
                                       currentFocusOwner == null? lastFocusOwner : currentFocusOwner, lwFocusRequest.cause);

View Full Code Here

             * Fix for 4472032
             */
            if (newFocusOwner != null &&
                event.getID() == FocusEvent.FOCUS_LOST)
            {
                FocusEvent fe = (FocusEvent)event;

                if (manager.getGlobalFocusOwner() == fe.getComponent() &&
                    fe.getOppositeComponent() == newFocusOwner)
                {
                    newFocusOwner = null;
                    return event;
                }
            }
View Full Code Here

                return typeAheadAssertions(newActiveWindow, we);
            }

            case FocusEvent.FOCUS_GAINED: {
                FocusEvent fe = (FocusEvent)e;
                CausedFocusEvent.Cause cause = (fe instanceof CausedFocusEvent) ?
                    ((CausedFocusEvent)fe).getCause() : CausedFocusEvent.Cause.UNKNOWN;
                Component oldFocusOwner = getGlobalFocusOwner();
                Component newFocusOwner = fe.getComponent();
                if (oldFocusOwner == newFocusOwner) {
                    if (focusLog.isLoggable(Level.FINE)){
                        focusLog.log(Level.FINE, "Skipping {0} because focus owner is the same",
                                                 new Object[] {String.valueOf(e)});
        }
                    // We can't just drop the event - there could be
                    // type-ahead markers associated with it.
                    dequeueKeyEvents(-1, newFocusOwner);
                    break;
                }

                // If there exists a current focus owner, then notify it that
                // it has lost focus.
                if (oldFocusOwner != null) {
                    boolean isEventDispatched =
                        sendMessage(oldFocusOwner,
                                    new CausedFocusEvent(oldFocusOwner,
                                                   FocusEvent.FOCUS_LOST,
                                                   fe.isTemporary(),
                                                   newFocusOwner, cause));
                    // Failed to dispatch, clear by ourselfves
                    if (!isEventDispatched) {
                        setGlobalFocusOwner(null);
                        if (!fe.isTemporary()) {
                            setGlobalPermanentFocusOwner(null);
                        }
                    }
                }

                // Because the native windowing system has a different notion
                // of the current focus and activation states, it is possible
                // that a Component outside of the focused Window receives a
                // FOCUS_GAINED event. We synthesize a WINDOW_GAINED_FOCUS
                // event in that case.
                Component newFocusedWindow = newFocusOwner;
                while (newFocusedWindow != null &&
                       !(newFocusedWindow instanceof Window)) {
                    newFocusedWindow = newFocusedWindow.parent;
                }
                Window currentFocusedWindow = getGlobalFocusedWindow();
                if (newFocusedWindow != null &&
                    newFocusedWindow != currentFocusedWindow)
                {
                    sendMessage(newFocusedWindow,
                                new WindowEvent((Window)newFocusedWindow,
                                        WindowEvent.WINDOW_GAINED_FOCUS,
                                                currentFocusedWindow));
                    if (newFocusedWindow != getGlobalFocusedWindow()) {
                        // Focus change was rejected. Will happen if
                        // newFocusedWindow is not a focusable Window.

                        // Need to recover type-ahead, but don't bother
                        // restoring focus. That was done by the
                        // WINDOW_GAINED_FOCUS handler
                        dequeueKeyEvents(-1, newFocusOwner);
                        break;
                    }
                }

                setGlobalFocusOwner(newFocusOwner);

                if (newFocusOwner != getGlobalFocusOwner()) {
                    // Focus change was rejected. Will happen if
                    // newFocusOwner is not focus traversable.
                    dequeueKeyEvents(-1, newFocusOwner);
                    if (! disableRestoreFocus ){
                        restoreFocus(fe, (Window)newFocusedWindow);
                    }
                    break;
                }

                if (!fe.isTemporary()) {
                    setGlobalPermanentFocusOwner(newFocusOwner);

                    if (newFocusOwner != getGlobalPermanentFocusOwner()) {
                        // Focus change was rejected. Unlikely, but possible.
                        dequeueKeyEvents(-1, newFocusOwner);
                        if (! disableRestoreFocus ){
                            restoreFocus(fe, (Window)newFocusedWindow);
                        }
                        break;
                    }
                }

                setNativeFocusOwner(getHeavyweight(newFocusOwner));

                Component realOppositeComponent = this.realOppositeComponent.get();
                if (realOppositeComponent != null &&
                    realOppositeComponent != fe.getOppositeComponent()) {
                    fe = new CausedFocusEvent(newFocusOwner,
                                        FocusEvent.FOCUS_GAINED,
                                        fe.isTemporary(),
                                        realOppositeComponent, cause);
                    ((AWTEvent) fe).isPosted = true;
                }
                return typeAheadAssertions(newFocusOwner, fe);
            }

            case FocusEvent.FOCUS_LOST: {
                FocusEvent fe = (FocusEvent)e;
                Component currentFocusOwner = getGlobalFocusOwner();
                if (currentFocusOwner == null) {
                    if (focusLog.isLoggable(Level.FINE)) {
                        focusLog.log(Level.FINE, "Skipping {0} because focus owner is null",
                                                 new Object[] {String.valueOf(e)});
                    }
                    break;
                }
                // Ignore cases where a Component loses focus to itself.
                // If we make a mistake because of retargeting, then the
                // FOCUS_GAINED handler will correct it.
                if (currentFocusOwner == fe.getOppositeComponent()) {
                    if (focusLog.isLoggable(Level.FINE)) {
                        focusLog.log(Level.FINE, "Skipping {0} because current focus owner is equal to opposite",
                                                 new Object[] {String.valueOf(e)});
                    }
                    break;
                }

                setGlobalFocusOwner(null);

                if (getGlobalFocusOwner() != null) {
                    // Focus change was rejected. Unlikely, but possible.
                    restoreFocus(currentFocusOwner, true);
                    break;
                }

                if (!fe.isTemporary()) {
                    setGlobalPermanentFocusOwner(null);

                    if (getGlobalPermanentFocusOwner() != null) {
                        // Focus change was rejected. Unlikely, but possible.
                        restoreFocus(currentFocusOwner, true);
                        break;
                    }
                } else {
                    Window owningWindow = currentFocusOwner.getContainingWindow();
                    if (owningWindow != null) {
                        owningWindow.setTemporaryLostComponent(currentFocusOwner);
                    }
                }

                setNativeFocusOwner(null);

                fe.setSource(currentFocusOwner);

                realOppositeComponent = (fe.getOppositeComponent() != null)
                    ? new WeakReference<Component>(currentFocusOwner)
                    : NULL_COMPONENT_WR;

                return typeAheadAssertions(currentFocusOwner, fe);
            }
View Full Code Here

            }
            DialogUtility.showDialog(new MS(), "Mine Sweeper", new Dimension(250, 350));
          }
        }else if(event instanceof FocusEvent) {
          if(event.getID() == FocusEvent.FOCUS_GAINED) {
            FocusEvent fEevnt = (FocusEvent)event;
            if(fEevnt.getComponent() instanceof JTextComponent) {
              if(((JTextComponent)fEevnt.getComponent()).isEditable() == false ||
                  ((JTextComponent)fEevnt.getComponent()).isEnabled() == false) {
                return;
              }
              //Not to be deployed ((JTextComponent)fEevnt.getComponent()).selectAll();
            }
          }
View Full Code Here

                        currentOwner = null;
                    }

                    //if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Simulating transfer from " + currentOwner +
                    // " to " + lightweightChild);
                    FocusEvent fg =
                        new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED, false, currentOwner, cause);
                    FocusEvent fl = null;
                    if (currentOwner != null) {
                        fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST, false, lightweightChild, cause);
                    }

                    if (fl != null) {
View Full Code Here

            // when losing focus to some component in other window
            // post temporary event:
            if (!focus && (opposite != null) && !callCB) {
                temporary = (c.getWindowAncestor() != opposite.getWindowAncestor());
            }
            FocusEvent newEvent = new FocusEvent(c, focus ? FocusEvent.FOCUS_GAINED
                    : FocusEvent.FOCUS_LOST, temporary, opposite);
            // remember previous focus owner to be able to post it as opposite
            // later
            // [when opposite component gains focus]
            // but clear it if application loses focus
View Full Code Here

    public boolean dispatchEvent(AWTEvent e) {
        if (e instanceof KeyEvent) {
            KeyEvent ke = (KeyEvent) e;
            return (preProcessKeyEvent(ke) || dispatchKeyEvent(ke));
        } else if (e instanceof FocusEvent) {
            FocusEvent fe = (FocusEvent) e;
            return dispatchFocusEvent(fe);
        } else if (e instanceof WindowEvent) {
            WindowEvent we = (WindowEvent) e;
            return dispatchWindowEvent(we);
        }
View Full Code Here

       
        // Intelligent Input.
        IntelligentInput inputWindow = currentPar.getIntelligentInput(this, this.pars);
        if (inputWindow != null) {
            if (currentPar.getParameterName().equals(eas.statistics.ConstantsStatistics.MASTER_SCHEDULER_PAR_NAME)) {
                this.focusGained(new FocusEvent(this.parFelder[paramListe.getSelectedRow()], FocusEvent.FOCUS_GAINED));
            }
            inputWindow.setVisible(true);

            // If the user did not cancel the input.
            if (inputWindow.getResult() != null) {
                if (currentPar.getParameterName().equals(eas.statistics.ConstantsStatistics.MASTER_SCHEDULER_PAR_NAME)) {
                    // Füge Plugins hinzu (immer auf Feld 3). TODO: Flexibel machen!
                    HashSet<String> plugs = new HashSet<String>();
                    for (String s : this.parFelder[3].getText().split(",")) {
                        if (!s.equals("")) {
                            plugs.add(s);
                        }
                    }
                    for (String s : inputWindow.getPluginsToAdd().split(",")) {
                        if (!s.equals("")) {
                            plugs.add(s);
                        }
                    }
                   
                    this.parFelder[3].setText(plugs.toString().replace("]", "").replace("[", "").replace(" ", ""));
                }
                this.parFelder[paramListe.getSelectedRow()].setText(inputWindow.getResult().toString());
                this.setzeChanged(paramListe.getSelectedRow());
            } else {
              cancelled = true;
            }
           
            if (currentPar.getParameterName().equals(eas.statistics.ConstantsStatistics.MASTER_SCHEDULER_PAR_NAME)
                    || currentPar.getParameterName().equals(eas.statistics.ConstantsStatistics.PLUGINS_PAR_NAME)) {
                this.keyReleased(new KeyEvent(
                        this.parFelder[paramListe.getSelectedRow()],
                        KeyEvent.KEY_RELEASED,
                        System.currentTimeMillis(),
                        0,
                        1,
                        KeyEvent.CHAR_UNDEFINED));
               
                if (cancelled) {
                  cancelledFromIntelligentInput = true;
                }
               
                this.focusLost(new FocusEvent(this.parFelder[paramListe.getSelectedRow()], FocusEvent.FOCUS_LOST));
                cancelledFromIntelligentInput = false;
            }
        }
    }
View Full Code Here

TOP

Related Classes of java.awt.event.FocusEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.