예제 #1
0
  public void setOpaque(boolean isOpaque) {
    synchronized (getStateLock()) {
      if (this.isOpaque == isOpaque) {
        return;
      }
    }

    Window target = (Window) getTarget();

    if (!isOpaque) {
      SunToolkit sunToolkit = (SunToolkit) target.getToolkit();
      if (!sunToolkit.isWindowTranslucencySupported()
          || !sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration())) {
        return;
      }
    }

    boolean isVistaOS = Win32GraphicsEnvironment.isVistaOS();

    if (this.isOpaque != isOpaque && !isVistaOS) {
      // non-Vista OS: only replace the surface data if the opacity
      // status changed (see WComponentPeer.isAccelCapable() for more)
      replaceSurfaceDataRecursively(target);
    }

    synchronized (getStateLock()) {
      this.isOpaque = isOpaque;
      setOpaqueImpl(isOpaque);
      if (isOpaque) {
        TranslucentWindowPainter currentPainter = painter;
        if (currentPainter != null) {
          currentPainter.flush();
          painter = null;
        }
      } else {
        painter = TranslucentWindowPainter.createInstance(this);
      }
    }

    if (isVistaOS) {
      // On Vista: setting the window non-opaque makes the window look
      // rectangular, though still catching the mouse clicks within
      // its shape only. To restore the correct visual appearance
      // of the window (i.e. w/ the correct shape) we have to reset
      // the shape.
      Shape shape = target.getShape();
      if (shape != null) {
        target.setShape(shape);
      }
    }

    if (target.isVisible()) {
      updateWindow(true);
    }
  }
예제 #2
0
  // WComponentPeer overrides
  @SuppressWarnings("unchecked")
  protected void disposeImpl() {
    AppContext appContext = SunToolkit.targetToAppContext(target);
    synchronized (appContext) {
      List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY);
      if (l != null) {
        l.remove(this);
      }
    }

    // Remove ourself from the Map of DisplayChangeListeners
    GraphicsConfiguration gc = getGraphicsConfiguration();
    ((Win32GraphicsDevice) gc.getDevice()).removeDisplayChangedListener(this);

    synchronized (getStateLock()) {
      TranslucentWindowPainter currentPainter = painter;
      if (currentPainter != null) {
        currentPainter.flush();
        // don't set the current one to null here; reduces the chances of
        // MT issues (like NPEs)
      }
    }

    super.disposeImpl();
  }
예제 #3
0
 /*
  * Called from native code when we have been dragged onto another screen.
  */
 void draggedToNewScreen() {
   SunToolkit.executeOnEventHandlerThread(
       (Component) target,
       new Runnable() {
         public void run() {
           displayChanged();
         }
       });
 }
예제 #4
0
 public void updateIconImages() {
   java.util.List<Image> imageList = ((Window) target).getIconImages();
   if (imageList == null || imageList.size() == 0) {
     setIconImagesData(null, 0, 0, null, 0, 0);
   } else {
     int w = getSysIconWidth();
     int h = getSysIconHeight();
     int smw = getSysSmIconWidth();
     int smh = getSysSmIconHeight();
     DataBufferInt iconData = SunToolkit.getScaledIconData(imageList, w, h);
     DataBufferInt iconSmData = SunToolkit.getScaledIconData(imageList, smw, smh);
     if (iconData != null && iconSmData != null) {
       setIconImagesData(iconData.getData(), w, h, iconSmData.getData(), smw, smh);
     } else {
       setIconImagesData(null, 0, 0, null, 0, 0);
     }
   }
 }
예제 #5
0
 public void setXEmbedDropTarget() {
   // Register a drop site on the top level.
   Runnable r =
       new Runnable() {
         public void run() {
           target.setDropTarget(new XEmbedDropTarget());
         }
       };
   SunToolkit.executeOnEventHandlerThread(target, r);
 }
예제 #6
0
 static byte[] getBData(KeyEvent e) {
   try {
     if (bdataField == null) {
       bdataField = SunToolkit.getField(java.awt.AWTEvent.class, "bdata");
     }
     return (byte[]) bdataField.get(e);
   } catch (IllegalAccessException ex) {
     return null;
   }
 }
예제 #7
0
 public void removeXEmbedDropTarget() {
   // Unregister a drop site on the top level.
   Runnable r =
       new Runnable() {
         public void run() {
           if (target.getDropTarget() instanceof XEmbedDropTarget) {
             target.setDropTarget(null);
           }
         }
       };
   SunToolkit.executeOnEventHandlerThread(target, r);
 }
예제 #8
0
 public void propertyChange(PropertyChangeEvent e) {
   Window w = (Window) e.getNewValue();
   if (w == null) {
     return;
   }
   AppContext appContext = SunToolkit.targetToAppContext(w);
   synchronized (appContext) {
     WWindowPeer wp = (WWindowPeer) w.getPeer();
     // add/move wp to the end of the list
     List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY);
     if (l != null) {
       l.remove(wp);
       l.add(wp);
     }
   }
 }
예제 #9
0
  /** Returns true if the GraphicsDevice has been changed, false otherwise. */
  public boolean updateGraphicsDevice() {
    GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
    synchronized (getStateLock()) {
      if (graphicsDevice == newGraphicsDevice) {
        return false;
      }
      graphicsDevice = newGraphicsDevice;
    }

    final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();

    if (!setGraphicsConfig(newGC)) return false;

    SunToolkit.executeOnEventHandlerThread(
        getTarget(),
        new Runnable() {
          public void run() {
            AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
          }
        });
    return true;
  }
  /**
   * Disposes of this AppContext, all of its top-level Frames, and all Threads and ThreadGroups
   * contained within it.
   *
   * <p>This method must be called from a Thread which is not contained within this AppContext.
   *
   * @exception IllegalThreadStateException if the current thread is contained within this
   *     AppContext
   * @since JDK1.2
   */
  public void dispose() throws IllegalThreadStateException {
    // Check to be sure that the current Thread isn't in this AppContext
    if (this.threadGroup.parentOf(Thread.currentThread().getThreadGroup())) {
      throw new IllegalThreadStateException(
          "Current Thread is contained within AppContext to be disposed.");
    }

    synchronized (this) {
      if (this.isDisposed) {
        return; // If already disposed, bail.
      }
      this.isDisposed = true;
    }

    // final PropertyChangeSupport changeSupport = this.changeSupport;
    // if (changeSupport != null) {
    //    changeSupport.firePropertyChange(DISPOSED_PROPERTY_NAME, false, true);
    // }

    // First, we post an InvocationEvent to be run on the
    // EventDispatchThread which disposes of all top-level Frames

    final Object notificationLock = new Object();

    /*no mutiple frames in basis
     * Runnable runnable = new Runnable() { public void run() {
     *     Frame [] frames = Frame.getFrames();
     *     for (int i = frames.length - 1; i >= 0; i--) {
     *         frames[i].dispose(); // Dispose of all top-level Frames
     *     }
     *     synchronized(notificationLock) {
     *         notificationLock.notifyAll(); // Notify caller that we're done
     *     }
     * } };
     * synchronized(notificationLock) {
     *     SunToolkit.postEvent(this,
     *         new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
     *     try {
     *         notificationLock.wait(DISPOSAL_TIMEOUT);
     *     } catch (InterruptedException e) { }
     *  }
     */

    // Next, we post another InvocationEvent to the end of the
    // EventQueue.  When it's executed, we know we've executed all
    // events in the queue.

    Runnable runnable =
        new Runnable() {
          public void run() {
            synchronized (notificationLock) {
              notificationLock.notifyAll(); // Notify caller that we're done
            }
          }
        };
    synchronized (notificationLock) {
      SunToolkit.postEvent(this, new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
      try {
        notificationLock.wait(DISPOSAL_TIMEOUT);
      } catch (InterruptedException e) {
      }
    }

    // Next, we interrupt all Threads in the ThreadGroup
    this.threadGroup.interrupt();
    // Note, the EventDispatchThread we've interrupted may dump an
    // InterruptedException to the console here.  This needs to be
    // fixed in the EventDispatchThread, not here.

    // Next, we sleep 10ms at a time, waiting for all of the active
    // Threads in the ThreadGroup to exit.

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (long) THREAD_INTERRUPT_TIMEOUT;
    while ((this.threadGroup.activeCount() > 0) && (System.currentTimeMillis() < endTime)) {
      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {
      }
    }

    // Then, we stop any remaining Threads
    // this.threadGroup.stop();

    // Next, we sleep 10ms at a time, waiting for all of the active
    // Threads in the ThreadGroup to die.

    startTime = System.currentTimeMillis();
    endTime = startTime + (long) THREAD_INTERRUPT_TIMEOUT;
    while ((this.threadGroup.activeCount() > 0) && (System.currentTimeMillis() < endTime)) {
      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {
      }
    }

    // Next, we remove this and all subThreadGroups from threadGroup2appContext
    int numSubGroups = this.threadGroup.activeGroupCount();
    if (numSubGroups > 0) {
      ThreadGroup[] subGroups = new ThreadGroup[numSubGroups];
      numSubGroups = this.threadGroup.enumerate(subGroups);
      for (int subGroup = 0; subGroup < numSubGroups; subGroup++) {
        threadGroup2appContext.remove(subGroups[subGroup]);
      }
    }
    threadGroup2appContext.remove(this.threadGroup);

    MostRecentThreadAppContext recent = mostRecentThreadAppContext;
    if ((recent != null) && (recent.appContext == this)) mostRecentThreadAppContext = null;
    // If the "most recent" points to this, clear it for GC

    // Finally, we destroy the ThreadGroup entirely.
    try {
      this.threadGroup.destroy();
    } catch (IllegalThreadStateException e) {
      // Fired if not all the Threads died, ignore it and proceed
    }

    synchronized (table) {
      this.table.clear(); // Clear out the Hashtable to ease garbage collection
    }

    numAppContexts--;

    mostRecentKeyValue = null;
  }
예제 #11
0
 public boolean supportsXEmbed() {
   return supportsXEmbed && SunToolkit.needsXEmbed();
 }
예제 #12
0
  /**
   * Disposes of this AppContext, all of its top-level Frames, and all Threads and ThreadGroups
   * contained within it.
   *
   * <p>This method must be called from a Thread which is not contained within this AppContext.
   *
   * @exception IllegalThreadStateException if the current thread is contained within this
   *     AppContext
   * @since 1.2
   */
  public void dispose() throws IllegalThreadStateException {
    // Check to be sure that the current Thread isn't in this AppContext
    if (this.threadGroup.parentOf(Thread.currentThread().getThreadGroup())) {
      throw new IllegalThreadStateException(
          "Current Thread is contained within AppContext to be disposed.");
    }

    synchronized (this) {
      if (this.isDisposed) {
        return; // If already disposed, bail.
      }
      this.isDisposed = true;
    }

    final PropertyChangeSupport changeSupport = this.changeSupport;
    if (changeSupport != null) {
      changeSupport.firePropertyChange(DISPOSED_PROPERTY_NAME, false, true);
    }

    // First, we post an InvocationEvent to be run on the
    // EventDispatchThread which disposes of all top-level Frames and TrayIcons

    final Object notificationLock = new Object();

    Runnable runnable =
        new Runnable() {
          public void run() {
            Window[] windowsToDispose = Window.getOwnerlessWindows();
            for (Window w : windowsToDispose) {
              w.dispose();
            }
            AccessController.doPrivileged(
                new PrivilegedAction() {
                  public Object run() {
                    if (!GraphicsEnvironment.isHeadless() && SystemTray.isSupported()) {
                      SystemTray systemTray = SystemTray.getSystemTray();
                      TrayIcon[] trayIconsToDispose = systemTray.getTrayIcons();
                      for (TrayIcon ti : trayIconsToDispose) {
                        systemTray.remove(ti);
                      }
                    }
                    return null;
                  }
                });
            // Alert PropertyChangeListeners that the GUI has been disposed.
            if (changeSupport != null) {
              changeSupport.firePropertyChange(GUI_DISPOSED, false, true);
            }
            synchronized (notificationLock) {
              notificationLock.notifyAll(); // Notify caller that we're done
            }
          }
        };
    synchronized (notificationLock) {
      SunToolkit.postEvent(this, new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
      try {
        notificationLock.wait(DISPOSAL_TIMEOUT);
      } catch (InterruptedException e) {
      }
    }

    // Next, we post another InvocationEvent to the end of the
    // EventQueue.  When it's executed, we know we've executed all
    // events in the queue.

    runnable =
        new Runnable() {
          public void run() {
            synchronized (notificationLock) {
              notificationLock.notifyAll(); // Notify caller that we're done
            }
          }
        };
    synchronized (notificationLock) {
      SunToolkit.postEvent(this, new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
      try {
        notificationLock.wait(DISPOSAL_TIMEOUT);
      } catch (InterruptedException e) {
      }
    }
    /* jnode
            // Next, we interrupt all Threads in the ThreadGroup
            this.threadGroup.interrupt();
                // Note, the EventDispatchThread we've interrupted may dump an
                // InterruptedException to the console here.  This needs to be
                // fixed in the EventDispatchThread, not here.

            // Next, we sleep 10ms at a time, waiting for all of the active
            // Threads in the ThreadGroup to exit.

            long startTime = System.currentTimeMillis();
            long endTime = startTime + (long)THREAD_INTERRUPT_TIMEOUT;
            while ((this.threadGroup.activeCount() > 0) &&
                   (System.currentTimeMillis() < endTime)) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) { }
            }

            // Then, we stop any remaining Threads
            this.threadGroup.stop();

            // Next, we sleep 10ms at a time, waiting for all of the active
            // Threads in the ThreadGroup to die.

            startTime = System.currentTimeMillis();
            endTime = startTime + (long)THREAD_INTERRUPT_TIMEOUT;
            while ((this.threadGroup.activeCount() > 0) &&
                   (System.currentTimeMillis() < endTime)) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) { }
            }
    jnode*/
    // Next, we remove this and all subThreadGroups from threadGroup2appContext
    int numSubGroups = this.threadGroup.activeGroupCount();
    if (numSubGroups > 0) {
      ThreadGroup[] subGroups = new ThreadGroup[numSubGroups];
      numSubGroups = this.threadGroup.enumerate(subGroups);
      for (int subGroup = 0; subGroup < numSubGroups; subGroup++) {
        threadGroup2appContext.remove(subGroups[subGroup]);
      }
    }
    threadGroup2appContext.remove(this.threadGroup);

    MostRecentThreadAppContext recent = mostRecentThreadAppContext;
    if ((recent != null) && (recent.appContext == this)) mostRecentThreadAppContext = null;
    // If the "most recent" points to this, clear it for GC

    // Finally, we destroy the ThreadGroup entirely.
    try {
      // jnode            this.threadGroup.destroy();
    } catch (IllegalThreadStateException e) {
      // Fired if not all the Threads died, ignore it and proceed
    }

    synchronized (table) {
      this.table.clear(); // Clear out the Hashtable to ease garbage collection
    }

    numAppContexts--;

    mostRecentKeyValue = null;
  }