📄 component.java
字号:
flags |= IS_MOUSE_AWARE; } /** * Removes the specified listener from the component. This is harmless if * the listener was not previously registered. * * @param listener the listener to remove * @see MouseEvent * @see #addMouseMotionListener(MouseMotionListener) * @see #getMouseMotionListeners() * @since 1.1 */ public synchronized void removeMouseMotionListener(MouseMotionListener listener) { mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, listener); // TODO is this still needed? checkMouseAware(); } /** * Returns an array of all specified listeners registered on this component. * * @return an array of listeners * @see #addMouseMotionListener(MouseMotionListener) * @see #removeMouseMotionListener(MouseMotionListener) * @since 1.4 */ public synchronized MouseMotionListener[] getMouseMotionListeners() { return (MouseMotionListener[]) AWTEventMulticaster.getListeners(mouseMotionListener, MouseMotionListener.class); } /** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. * * @param listener the new listener to add * @see MouseEvent * @see MouseWheelEvent * @see #removeMouseWheelListener(MouseWheelListener) * @see #getMouseWheelListeners() * @since 1.4 */ public synchronized void addMouseWheelListener(MouseWheelListener listener) { mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener, listener); if (mouseWheelListener != null) enableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK); } /** * Removes the specified listener from the component. This is harmless if * the listener was not previously registered. * * @param listener the listener to remove * @see MouseEvent * @see MouseWheelEvent * @see #addMouseWheelListener(MouseWheelListener) * @see #getMouseWheelListeners() * @since 1.4 */ public synchronized void removeMouseWheelListener(MouseWheelListener listener) { mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, listener); } /** * Returns an array of all specified listeners registered on this component. * * @return an array of listeners * @see #addMouseWheelListener(MouseWheelListener) * @see #removeMouseWheelListener(MouseWheelListener) * @since 1.4 */ public synchronized MouseWheelListener[] getMouseWheelListeners() { return (MouseWheelListener[]) AWTEventMulticaster.getListeners(mouseWheelListener, MouseWheelListener.class); } /** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. * * @param listener the new listener to add * @see InputMethodEvent * @see #removeInputMethodListener(InputMethodListener) * @see #getInputMethodListeners() * @see #getInputMethodRequests() * @since 1.2 */ public synchronized void addInputMethodListener(InputMethodListener listener) { inputMethodListener = AWTEventMulticaster.add(inputMethodListener, listener); if (inputMethodListener != null) enableEvents(AWTEvent.INPUT_METHOD_EVENT_MASK); } /** * Removes the specified listener from the component. This is harmless if * the listener was not previously registered. * * @param listener the listener to remove * @see InputMethodEvent * @see #addInputMethodListener(InputMethodListener) * @see #getInputMethodRequests() * @since 1.2 */ public synchronized void removeInputMethodListener(InputMethodListener listener) { inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, listener); } /** * Returns an array of all specified listeners registered on this component. * * @return an array of listeners * @see #addInputMethodListener(InputMethodListener) * @see #removeInputMethodListener(InputMethodListener) * @since 1.4 */ public synchronized InputMethodListener[] getInputMethodListeners() { return (InputMethodListener[]) AWTEventMulticaster.getListeners(inputMethodListener, InputMethodListener.class); } /** * Returns all registered {@link EventListener}s of the given * <code>listenerType</code>. * * @param listenerType the class of listeners to filter (<code>null</code> * not permitted). * * @return An array of registered listeners. * * @throws ClassCastException if <code>listenerType</code> does not implement * the {@link EventListener} interface. * @throws NullPointerException if <code>listenerType</code> is * <code>null</code>. * * @see #getComponentListeners() * @see #getFocusListeners() * @see #getHierarchyListeners() * @see #getHierarchyBoundsListeners() * @see #getKeyListeners() * @see #getMouseListeners() * @see #getMouseMotionListeners() * @see #getMouseWheelListeners() * @see #getInputMethodListeners() * @see #getPropertyChangeListeners() * @since 1.3 */ public EventListener[] getListeners(Class listenerType) { if (listenerType == ComponentListener.class) return getComponentListeners(); if (listenerType == FocusListener.class) return getFocusListeners(); if (listenerType == HierarchyListener.class) return getHierarchyListeners(); if (listenerType == HierarchyBoundsListener.class) return getHierarchyBoundsListeners(); if (listenerType == KeyListener.class) return getKeyListeners(); if (listenerType == MouseListener.class) return getMouseListeners(); if (listenerType == MouseMotionListener.class) return getMouseMotionListeners(); if (listenerType == MouseWheelListener.class) return getMouseWheelListeners(); if (listenerType == InputMethodListener.class) return getInputMethodListeners(); if (listenerType == PropertyChangeListener.class) return getPropertyChangeListeners(); return (EventListener[]) Array.newInstance(listenerType, 0); }public void addNotify () { if ( (flags & IS_ADD_NOTIFIED) == 0 ) { flags |= IS_ADD_NOTIFIED; ClassProperties props = getClassProperties(); if ( props.isNativeLike ){ flags |= IS_NATIVE_LIKE; } if ( parent != null ) { // Note that this only works in case the parent is addNotified // *before* its childs. (we can't use isNativeLike to filter this out // unless we turn BarMenus into isNativeLike, which is bad) if ( (((parent.flags & IS_OLD_EVENT) != 0) || props.useOldEvents) ){ flags |= (IS_OLD_EVENT | IS_MOUSE_AWARE); } if (parent.isLightweight()) new HeavyweightInLightweightListener(parent); } else { // Window if ( props.useOldEvents ) flags |= (IS_OLD_EVENT | IS_MOUSE_AWARE); } if ( popup != null ) { popup.parent = this; popup.owner = this; popup.addNotify(); } }}public Rectangle bounds () { // DUP - we have to return fresh objects because (1) there are apps out there // modifying the return values (causing trouble for concurrent access to bounds), // and (2) because some apps (like Swing) temporarily store return values, relying // on its constness (e.g. for InternalFrame dragging) return new Rectangle( x, y, width, height);}public int checkImage (Image image, ImageObserver obs) { return (image.checkImage( -1, -1, obs, false));}public int checkImage (Image image, int width, int height, ImageObserver obs) { return (image.checkImage( width, height, obs, false));}void checkMouseAware () { if ( ((eventMask & AWTEvent.DISABLED_MASK) == 0) && ((mouseListener != null) || (mouseMotionListener != null) || (eventMask & (AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK)) != 0 || (flags & IS_OLD_EVENT) != 0 )) { flags |= IS_MOUSE_AWARE; } else { flags &= ~IS_MOUSE_AWARE; }}void cleanUpNative () { // nothing native, all lightweight}public boolean contains ( Point pt ) { return contains( pt.x, pt.y);}public boolean contains(int x, int y) { return (inside(x, y));}public Image createImage ( ImageProducer producer ) { return new Image( producer);}public Image createImage ( int width, int height ) { return new Image( width, height);}// TODO this is only a stubpublic VolatileImage createVolatileImage ( int width, int height ) { return null;}void createNative () { // nothing native, all lightweight}/** * @deprecated */public void deliverEvent(Event evt) { postEvent(evt);}void destroyNative () { // nothing native, all lightweight}/** * @deprecated, use setEnabled() */public void disable() { setEnabled(false);}public void disableEvents ( long disableMask ) { eventMask &= ~disableMask; checkMouseAware();}final public void dispatchEvent ( AWTEvent evt ) { // this is NOT our main entry point for Component event processing // (processEvent() is). Because this is a 'final' method, it can't be overloaded // by user classes. Well, almost, because the JDK obviously calls a // hidden dispatchEventImpl() from it, turning this into a "somewhat" final // method. Anyway, this (still?) can be considered as undocumented, // non-portable, and we ignore it for now (regarding the main entry point) dispatchEventImpl( evt);}/*** Implementation of dispatchEvent. Allows trusted package classes * to dispatch additional events first. This implementation first * translates <code>e</code> to an AWT 1.0 event and sends the * result to {@link #postEvent}. If the AWT 1.0 event is not * handled, and events of type <code>e</code> are enabled for this * component, e is passed on to {@link #processEvent}. * * @param e the event to dispatch */void dispatchEventImpl(AWTEvent e){ // This boolean tells us not to process focus events when the focus // opposite component is the same as the focus component. // Retarget focus events before dispatching it to the KeyboardFocusManager // in order to handle lightweight components properly. boolean dispatched = false; if (! e.isFocusManagerEvent) { e = KeyboardFocusManager.retargetFocusEvent(e); dispatched = KeyboardFocusManager.getCurrentKeyboardFocusManager() .dispatchEvent(e); } if (! dispatched) { if (eventTypeEnabled (e.id)) { if (e.id != PaintEvent.PAINT && e.id != PaintEvent.UPDATE) processEvent(e); } // here we differ from classpath since we have no peers e.dispatch(); }}/*** Tells whether or not an event type is enabled. */boolean eventTypeEnabled (int type){ if (type > AWTEvent.RESERVED_ID_MAX) return true; switch (type) { case HierarchyEvent.HIERARCHY_CHANGED: return (hierarchyListener != null || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0); case HierarchyEvent.ANCESTOR_MOVED: case HierarchyEvent.ANCESTOR_RESIZED: return (hierarchyBoundsListener != null || (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0); case ComponentEvent.COMPONENT_HIDDEN: case ComponentEvent.COMPONENT_MOVED: case ComponentEvent.COMPONENT_RESIZED: case ComponentEvent.COMPONENT_SHOWN: return (componentListener != null || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0); case KeyEvent.KEY_PRESSED: case KeyEvent.KEY_RELEASED: case KeyEvent.KEY_TYPED: return (keyListener != null || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0); case MouseEvent.MOUSE_CLICKED: case MouseEvent.MOUSE_ENTERED: case MouseEvent.MOUSE_EXITED: case MouseEvent.MOUSE_PRESSED: case MouseEvent.MOUSE_RELEASED: return (mouseListener != null || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0); case MouseEvent.MOUSE_MOVED: case MouseEvent.MOUSE_DRAGGED: return (mouseMotionListener != null || (eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0); case MouseEvent.MOUSE_WHEEL: return (mouseWheelListener != null || (eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0); case FocusEvent.FOCUS_GAINED: case FocusEvent.FOCUS_LOST: return (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0); case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: case InputMethodEvent.CARET_POSITION_CHANGED: return (inputMethodListener != null || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0); case PaintEvent.PAINT: case PaintEvent.UPDATE: return (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0; default: return false; }}public void doLayout () { layout();}void dump ( String prefix ) { System.out.print( prefix); System.out.println( this);}/** * @deprecated, use setEnabled() */public void enable() { setEnabled(true);}/** * @deprecated, use setEnabled() */public void enable( boolean isEnabled) { setEnabled(isEnabled);}public void enableEvents ( long enableMask ) { eventMask |= enableMask; checkMouseAware();}public float getAlignmentX() { return CENTER_ALIGNMENT;}public float getAlignmentY() { return CENTER_ALIGNMENT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -