📄 mouseevt.java
字号:
}static synchronized MouseEvt getEvent ( int srcIdx, int id, int button, int x, int y ) { MouseEvt e; Component source = sources[srcIdx]; long when = System.currentTimeMillis(); boolean popupTrigger = (button == 3) && (id == MOUSE_PRESSED); if ( (Toolkit.flags & Toolkit.EXTERNAL_DECO) != 0 ) { Rectangle d = source.deco; x += d.x; y += d.y; } nativeSource = source; nativePos.x = x; nativePos.y = y; if ( cache == null ) { e = new MouseEvt( source, id, when, inputModifier, x, y, 0, popupTrigger); } else { e = cache; cache = (MouseEvt) e.next; e.next = null; e.source = source; e.id = id; e.consumed = false; e.when = when; e.modifiers = inputModifier; e.x = x; e.y = y; e.clickCount = 0; e.isPopupTrigger = popupTrigger; } e.button = button; if ( (Toolkit.flags & Toolkit.NATIVE_DISPATCHER_LOOP) != 0 ) { // this is not used as a direct return value for EventQueue.getNextEvent(), // it has to be Java-queued by the native layer Toolkit.eventQueue.postEvent( e); } return e;}static Component getGrab() { return (grabStack.isEmpty()) ? null : (Component)grabStack.peek();}static void grabMouse ( Component grab ) { // note that grabs currently don't work with Windows being moved // explicitly during the grab (since this requires the xMouseTgt,yMouseTgt // to be recomputed) synchronized ( MouseEvt.class ) { if ( nativeSource == null ) return; Component p; int x = 0, y=0; for ( p=grab; p != null; p = p.parent ){ x += p.x; y += p.y; } xMouseTgt = x - nativeSource.x; yMouseTgt = y - nativeSource.y; AWTEvent.mouseTgt = grab; nativeSource.setNativeCursor( grab.cursor); grabStack.push( grab); mouseGrabbed = true; }}static void moveMouseTgt ( int dx, int dy ) { xMouseTgt += dx; yMouseTgt += dy;}static void postMouseClicked ( Object source, long when, int x, int y, int modifiers, int clickCount, int button ) { MouseEvt e = getEvent( (Component)source, MOUSE_CLICKED, when, modifiers, x, y, clickCount, (button == 3)); e.button = button; AWTEvent.sendEvent( e, false);}protected void recycle () { synchronized ( MouseEvt.class ) { source = null; next = cache; cache = this; }}static void releaseMouse ( Component c ) { Cursor curs = null; Component grab = (Component)grabStack.peek(); synchronized ( MouseEvt.class ) { if ( !mouseGrabbed ) return; while ( grab != c ) { grabStack.pop(); if ( grabStack.isEmpty() ){ AWTEvent.mouseTgt = null; xMouseTgt = yMouseTgt = 0; mouseGrabbed = false; curs = nativeSource.cursor; break; } grab = (Component)grabStack.peek(); xMouseTgt = grab.x - nativeSource.x; yMouseTgt = grab.y - nativeSource.y; AWTEvent.mouseTgt = grab; curs = grab.cursor; } if ( curs != null ) nativeSource.setNativeCursor( curs); }}protected MouseEvent retarget ( Component target, int dx, int dy ) { source = target; x += dx; y += dy; return this;}static void sendMouseEnterEvent ( Component src, int x, int y, boolean sync ) { MouseEvt e = getEvent( src, MouseEvent.MOUSE_ENTERED, System.currentTimeMillis(), 0, x, y, 0, false); if ( sync ) e.dispatch(); else Toolkit.eventQueue.postEvent( e);}void setMouseEvent ( long time, int mods, int xNew, int yNew, int click, boolean popUp ) { when = time; modifiers = mods; x = xNew; y = yNew; clickCount = click; isPopupTrigger = popUp;}protected void setXY ( int xNew, int yNew ) { x = xNew; y = yNew;}static void transferMouse ( MouseEvt e, Component from, int xFrom, int yFrom, Component to, int xTo, int yTo ) { // We have to handle both inter-/intra- toplevel transfers, exits and enters have to // be fully symmetrical (enter A, enter A.B -> exit A.B, exit A). Note that for intra // transfers, the first common parent does not have to be a toplevel container. // We also have to handle non-contiguous mouse moves (e.g. acceleration or wraps), // with exits always using the last known (inside) coordinate of the lastTarget. // Last, not least, we also have to handle 'null' from / to targets (toplevel enter/exits) int i, n, m; int x = xFrom; int y = yFrom; // save event state (we "re-use" it in order to save memory) Object origSource = e.source; int origId = e.id; int origX = e.x; int origY = e.y; // Work out depths of from and to and adjust arrays accordingly. // (we have to inform all non-shared parents, so there is no way // around it) int df = 1; for (Component c = from; c != null; c = c.parent, df++); int dt = 1; for (Component c = to; c != null; c = c.parent, dt++); if (dt > df) { df = dt; } if (df > cFrom.length) { cFrom = new Component[df]; cTo = new Component[df]; } // init the from[], to[] stacks and get the first common parent (if any) for ( n=0, cFrom[0] = from; from != null; from = from.parent ) { cFrom[++n] = from; } for ( m=0, cTo[0] = to; to != null; to = to.parent ) { cTo[++m] = to; } for ( ; cFrom[n] == (to = cTo[m]); n--, m-- ) { cFrom[n] = null; cTo[m] = null; } // send EXITED to all from[] components (inside out) e.id = MouseEvent.MOUSE_EXITED; for ( i=1; i <= n; i++ ) { e.setXY( x, y); from = cFrom[i]; e.source = from; //System.out.println( "mouseExit: " + from.getClass() + ": " + x + ',' + y); from.processMouse( e); x += from.x; y += from.y; } // send ENTERED to all to[] components (outside in, hence we have to adapt x,y first) e.id = MouseEvent.MOUSE_ENTERED; if ( cFrom[n] != cTo[m] ) { for ( i=1, x=xTo, y=yTo; i<=m; i++ ) { x += cTo[i].x; y += cTo[i].y; } } for ( i=m; i > 0; i-- ) { to = cTo[i]; e.source = to; x -= to.x; y -= to.y; e.x = x; e.y = y; //System.out.println( "mouseEnter: " + to.getClass() + ": " + x + ',' + y); to.processMouse( e); } // set cursor if ( to != null ){ to.setCursor( to.cursor); } // clean up stacks (to avoid memory leaks) for ( i=0; i<n; i++ ) { cFrom[i] = null; } for ( i=0; i<m; i++ ) { cTo[i] = null; } // restore state e.source = origSource; e.id = origId; e.x = origX; e.y = origY;}static int updateInputModifier ( int button, boolean pressed ) { if ( pressed ) { switch ( button ) { case 1: inputModifier |= BUTTON1_MASK; break; case 2: inputModifier |= BUTTON2_MASK; break; case 3: inputModifier |= BUTTON3_MASK; } } else { switch ( button ) { case 1: inputModifier &= ~BUTTON1_MASK; break; case 2: inputModifier &= ~BUTTON2_MASK; break; case 3: inputModifier &= ~BUTTON3_MASK; } } return inputModifier;}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -