window.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 969 行 · 第 1/2 页
JAVA
969 行
if (numValid != validList.length) { trimmedList = new Window [numValid]; System.arraycopy (validList, 0, trimmedList, 0, numValid); } else trimmedList = validList; } return trimmedList; } /** * Adds the specified listener to the list of <code>WindowListeners</code> * that will receive events for this window. * * @param listener The <code>WindowListener</code> to add. */ public synchronized void addWindowListener(WindowListener listener) { windowListener = AWTEventMulticaster.add(windowListener, listener); } /** * Removes the specified listener from the list of * <code>WindowListeners</code> that will receive events for this window. * * @param listener The <code>WindowListener</code> to remove. */ public synchronized void removeWindowListener(WindowListener listener) { windowListener = AWTEventMulticaster.remove(windowListener, listener); } /** * Returns an array of all the window listeners registered on this window. * * @since 1.4 */ public synchronized WindowListener[] getWindowListeners() { return (WindowListener[]) AWTEventMulticaster.getListeners(windowListener, WindowListener.class); } /** * Returns an array of all the window focus listeners registered on this * window. * * @since 1.4 */ public synchronized WindowFocusListener[] getWindowFocusListeners() { return (WindowFocusListener[]) AWTEventMulticaster.getListeners(windowFocusListener, WindowFocusListener.class); } /** * Returns an array of all the window state listeners registered on this * window. * * @since 1.4 */ public synchronized WindowStateListener[] getWindowStateListeners() { return (WindowStateListener[]) AWTEventMulticaster.getListeners(windowStateListener, WindowStateListener.class); } /** * Adds the specified listener to this window. */ public void addWindowFocusListener (WindowFocusListener wfl) { windowFocusListener = AWTEventMulticaster.add (windowFocusListener, wfl); } /** * Adds the specified listener to this window. * * @since 1.4 */ public void addWindowStateListener (WindowStateListener wsl) { windowStateListener = AWTEventMulticaster.add (windowStateListener, wsl); } /** * Removes the specified listener from this window. */ public void removeWindowFocusListener (WindowFocusListener wfl) { windowFocusListener = AWTEventMulticaster.remove (windowFocusListener, wfl); } /** * Removes the specified listener from this window. * * @since 1.4 */ public void removeWindowStateListener (WindowStateListener wsl) { windowStateListener = AWTEventMulticaster.remove (windowStateListener, wsl); } /** * Returns an array of all the objects currently registered as FooListeners * upon this Window. FooListeners are registered using the addFooListener * method. * * @exception ClassCastException If listenerType doesn't specify a class or * interface that implements java.util.EventListener. * * @since 1.3 */ public EventListener[] getListeners(Class listenerType) { if (listenerType == WindowListener.class) return getWindowListeners(); return super.getListeners(listenerType); } void dispatchEventImpl(AWTEvent e) { // Make use of event id's in order to avoid multiple instanceof tests. if (e.id <= WindowEvent.WINDOW_LAST && e.id >= WindowEvent.WINDOW_FIRST && (windowListener != null || windowFocusListener != null || windowStateListener != null || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)) processEvent(e); else super.dispatchEventImpl(e); } /** * Processes the specified event for this window. If the event is an * instance of <code>WindowEvent</code>, then * <code>processWindowEvent()</code> is called to process the event, * otherwise the superclass version of this method is invoked. * * @param evt The event to process. */ protected void processEvent(AWTEvent evt) { if (evt instanceof WindowEvent) processWindowEvent((WindowEvent) evt); else super.processEvent(evt); } /** * Dispatches this event to any listeners that are listening for * <code>WindowEvents</code> on this window. This method only gets * invoked if it is enabled via <code>enableEvents()</code> or if * a listener has been added. * * @param evt The event to process. */ protected void processWindowEvent(WindowEvent evt) { int id = evt.getID(); if (id == WindowEvent.WINDOW_GAINED_FOCUS || id == WindowEvent.WINDOW_LOST_FOCUS) processWindowFocusEvent (evt); else if (id == WindowEvent.WINDOW_STATE_CHANGED) processWindowStateEvent (evt); else { if (windowListener != null) { switch (evt.getID()) { case WindowEvent.WINDOW_ACTIVATED: windowListener.windowActivated(evt); break; case WindowEvent.WINDOW_CLOSED: windowListener.windowClosed(evt); break; case WindowEvent.WINDOW_CLOSING: windowListener.windowClosing(evt); break; case WindowEvent.WINDOW_DEACTIVATED: windowListener.windowDeactivated(evt); break; case WindowEvent.WINDOW_DEICONIFIED: windowListener.windowDeiconified(evt); break; case WindowEvent.WINDOW_ICONIFIED: windowListener.windowIconified(evt); break; case WindowEvent.WINDOW_OPENED: windowListener.windowOpened(evt); break; default: break; } } } } /** * Identifies if this window is active. The active window is a Frame or * Dialog that has focus or owns the active window. * * @return true if active, else false. * @since 1.4 */ public boolean isActive() { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); return manager.getActiveWindow() == this; } /** * Identifies if this window is focused. A window is focused if it is the * focus owner or it contains the focus owner. * * @return true if focused, else false. * @since 1.4 */ public boolean isFocused() { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); return manager.getFocusedWindow() == this; } /** * Returns the child window that has focus if this window is active. * This method returns <code>null</code> if this window is not active * or no children have focus. * * @return The component that has focus, or <code>null</code> if no * component has focus. */ public Component getFocusOwner () { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); Window activeWindow = manager.getActiveWindow (); // The currently-focused Component belongs to the active Window. if (activeWindow == this) return manager.getFocusOwner (); else return windowFocusOwner; } /** * Set the focus owner for this window. This method is used to * remember which component was focused when this window lost * top-level focus, so that when it regains top-level focus the same * child component can be refocused. * * @param windowFocusOwner the component in this window that owns * the focus. */ void setFocusOwner (Component windowFocusOwner) { this.windowFocusOwner = windowFocusOwner; } /** * Post a Java 1.0 event to the event queue. * * @param e The event to post. * * @deprecated */ public boolean postEvent(Event e) { return handleEvent (e); } /** * Tests whether or not this window is visible on the screen. * * @return <code>true</code> if this window is visible, <code>false</code> * otherwise. */ public boolean isShowing() { return super.isShowing(); } public void setLocationRelativeTo (Component c) { if (c == null || !c.isShowing ()) { int x = 0; int y = 0; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment (); Point center = ge.getCenterPoint (); x = center.x - (width / 2); y = center.y - (height / 2); setLocation (x, y); } // FIXME: handle case where component is non-null. } /** * @since 1.2 * * @deprecated */ public void applyResourceBundle(ResourceBundle rb) { throw new Error ("Not implemented"); } /** * @since 1.2 * * @deprecated */ public void applyResourceBundle(String rbName) { ResourceBundle rb = ResourceBundle.getBundle(rbName, Locale.getDefault(), ClassLoader.getSystemClassLoader()); if (rb != null) applyResourceBundle(rb); } /** * Gets the AccessibleContext associated with this <code>Window</code>. * The context is created, if necessary. * * @return the associated context */ public AccessibleContext getAccessibleContext() { /* Create the context if this is the first request */ if (accessibleContext == null) accessibleContext = new AccessibleAWTWindow(); return accessibleContext; } /** * Get graphics configuration. The implementation for Window will * not ask any parent containers, since Window is a toplevel * window and not actually embedded in the parent component. */ public GraphicsConfiguration getGraphicsConfiguration() { if (graphicsConfiguration != null) return graphicsConfiguration; if (peer != null) return peer.getGraphicsConfiguration(); return null; } protected void processWindowFocusEvent(WindowEvent event) { if (windowFocusListener != null) { switch (event.getID ()) { case WindowEvent.WINDOW_GAINED_FOCUS: windowFocusListener.windowGainedFocus (event); break; case WindowEvent.WINDOW_LOST_FOCUS: windowFocusListener.windowLostFocus (event); break; default: break; } } } /** * @since 1.4 */ protected void processWindowStateEvent(WindowEvent event) { if (windowStateListener != null && event.getID () == WindowEvent.WINDOW_STATE_CHANGED) windowStateListener.windowStateChanged (event); } /** * Returns whether this <code>Window</code> can get the focus or not. * * @since 1.4 */ public final boolean isFocusableWindow () { if (getFocusableWindowState () == false) return false; if (this instanceof Dialog || this instanceof Frame) return true; // FIXME: Implement more possible cases for returning true. return false; } /** * Returns the value of the focusableWindowState property. * * @since 1.4 */ public boolean getFocusableWindowState () { return focusableWindowState; } /** * Sets the value of the focusableWindowState property. * * @since 1.4 */ public void setFocusableWindowState (boolean focusableWindowState) { this.focusableWindowState = focusableWindowState; } // setBoundsCallback is needed so that when a user moves a window, // the Window's location can be updated without calling the peer's // setBounds method. When a user moves a window the peer window's // location is updated automatically and the windowing system sends // a message back to the application informing it of its updated // dimensions. We must update the AWT Window class with these new // dimensions. But we don't want to call the peer's setBounds // method, because the peer's dimensions have already been updated. // (Under X, having this method prevents Configure event loops when // moving windows: Component.setBounds -> peer.setBounds -> // postConfigureEvent -> Component.setBounds -> ... In some cases // Configure event loops cause windows to jitter back and forth // continuously). void setBoundsCallback (int x, int y, int w, int h) { if (this.x == x && this.y == y && width == w && height == h) return; invalidate(); boolean resized = width != w || height != h; boolean moved = this.x != x || this.y != y; this.x = x; this.y = y; width = w; height = h; if (resized && isShowing ()) { ComponentEvent ce = new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED); getToolkit().getSystemEventQueue().postEvent(ce); } if (moved && isShowing ()) { ComponentEvent ce = new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED); getToolkit().getSystemEventQueue().postEvent(ce); } } /** * Generate a unique name for this window. * * @return A unique name for this window. */ String generateName() { return "win" + getUniqueLong(); } private static synchronized long getUniqueLong() { return next_window_number++; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?