private void wakeupEDT() {
   if (log.isLoggable(PlatformLogger.Level.FINEST)) {
     log.finest("wakeupEDT(): EDT == " + dispatchThread);
   }
   EventQueue eq = dispatchThread.getEventQueue();
   eq.postEvent(new PeerEvent(this, wakingRunnable, PeerEvent.PRIORITY_EVENT));
 }
  public void handleConfigureNotifyEvent(XEvent xev) {
    assert (SunToolkit.isAWTLockHeldByCurrentThread());
    XConfigureEvent xe = xev.get_xconfigure();
    if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) {
      xembedLog.fine(xe.toString());
    }

    // fix for 5063031
    // if we use super.handleConfigureNotifyEvent() we would get wrong
    // size and position because embedded frame really is NOT a decorated one
    checkIfOnNewScreen(
        toGlobal(new Rectangle(xe.get_x(), xe.get_y(), xe.get_width(), xe.get_height())));

    Rectangle oldBounds = getBounds();

    synchronized (getStateLock()) {
      x = xe.get_x();
      y = xe.get_y();
      width = xe.get_width();
      height = xe.get_height();

      dimensions.setClientSize(width, height);
      dimensions.setLocation(x, y);
    }

    if (!getLocation().equals(oldBounds.getLocation())) {
      handleMoved(dimensions);
    }
    reconfigureContentWindow(dimensions);
  }
 // Coordinates are that of the shell
 void setContentBounds(WindowDimensions dims) {
   XToolkit.awtLock();
   try {
     // Bounds of content window are of the same size as bounds of Java window and with
     // location as -(insets)
     Rectangle newBounds = dims.getBounds();
     Insets in = dims.getInsets();
     if (in != null) {
       newBounds.setLocation(-in.left, -in.top);
     }
     if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
       insLog.fine("Setting content bounds {0}, old bounds {1}", newBounds, getBounds());
     }
     // Fix for 5023533:
     // Change in the size of the content window means, well, change of the size
     // Change in the location of the content window means change in insets
     boolean needHandleResize = !(newBounds.equals(getBounds()));
     reshape(newBounds);
     if (needHandleResize) {
       insLog.fine("Sending RESIZED");
       handleResize(newBounds);
     }
   } finally {
     XToolkit.awtUnlock();
   }
   validateSurface();
 }
  private boolean processProxyModeEvent(XEvent ev) {
    if (getProxyModeSourceWindow() == 0) {
      return false;
    }

    if (ev.get_type() != (int) XConstants.ClientMessage) {
      return false;
    }

    if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
      logger.finest("        proxyModeSourceWindow=" + getProxyModeSourceWindow() + " ev=" + ev);
    }

    XClientMessageEvent xclient = ev.get_xclient();

    Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
    while (dragProtocols.hasNext()) {
      XDragSourceProtocol dragProtocol = (XDragSourceProtocol) dragProtocols.next();
      if (dragProtocol.processProxyModeEvent(xclient, getProxyModeSourceWindow())) {
        return true;
      }
    }

    return false;
  }
 public void run() {
   log.fine("Wake up EDT");
   synchronized (getTreeLock()) {
     keepBlockingCT.set(false);
     getTreeLock().notifyAll();
   }
   log.fine("Wake up EDT done");
 }
 public boolean requestWindowFocus(long time, boolean timeProvided) {
   // Should check for active state of host application
   if (embedder != null && embedder.isActive()) {
     xembedLog.fine("Requesting focus from embedding host");
     return embedder.requestFocus();
   } else {
     xembedLog.fine("Requesting focus from X");
     return super.requestWindowFocus(time, timeProvided);
   }
 }
Esempio n. 7
0
 public long getNSWindowPtr() {
   final long nsWindowPtr = ptr;
   if (nsWindowPtr == 0L) {
     if (logger.isLoggable(PlatformLogger.Level.FINE)) {
       logger.fine(
           "NSWindow already disposed?", new Exception("Pointer to native NSWindow is invalid."));
     }
   }
   return nsWindowPtr;
 }
 /** @inheritDoc */
 public boolean exit() {
   if (log.isLoggable(PlatformLogger.Level.FINE)) {
     log.fine(
         "exit(): blockingEDT=" + keepBlockingEDT.get() + ", blockingCT=" + keepBlockingCT.get());
   }
   if (keepBlockingEDT.compareAndSet(true, false)) {
     wakeupEDT();
     return true;
   }
   return false;
 }
Esempio n. 9
0
 public boolean processXEmbedDnDEvent(long ctxt, int eventID) {
   if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
     xembedLog.finest("     Drop target=" + target.getDropTarget());
   }
   if (target.getDropTarget() instanceof XEmbedDropTarget) {
     AppContext appContext = XToolkit.targetToAppContext(getTarget());
     XDropTargetContextPeer peer = XDropTargetContextPeer.getPeer(appContext);
     peer.forwardEventToEmbedded(xembed.handle, ctxt, eventID);
     return true;
   } else {
     return false;
   }
 }
Esempio n. 10
0
 private void updateWindow(boolean repaint) {
   Window w = (Window) target;
   synchronized (getStateLock()) {
     if (isOpaque || !w.isVisible() || (w.getWidth() <= 0) || (w.getHeight() <= 0)) {
       return;
     }
     TranslucentWindowPainter currentPainter = painter;
     if (currentPainter != null) {
       currentPainter.updateWindow(repaint);
     } else if (log.isLoggable(PlatformLogger.Level.FINER)) {
       log.finer("Translucent window painter is null in updateWindow");
     }
   }
 }
Esempio n. 11
0
 @Override
 public void setBackground(Color c) {
   if (log.isLoggable(PlatformLogger.Level.FINE)) {
     log.fine("target=" + target + ", old=" + background + ", new=" + c);
   }
   background = c;
   if (xtext != null) {
     if (xtext.getBackground() != c) {
       xtext.setBackground(c);
     }
     xtext.setSelectedTextColor(c);
   }
   repaintText();
 }
Esempio n. 12
0
 void childResized() {
   if (xembedLog.isLoggable(PlatformLogger.FINER)) {
     Rectangle bounds = getClientBounds();
     xembedLog.finer("Child resized: " + bounds);
     // It is not required to update embedder's size when client size changes
     // However, since there is no any means to get client size it seems to be the
     // only way to provide it. However, it contradicts with Java layout concept -
     // so it is disabled for now.
     //             Rectangle my_bounds = getBounds();
     //             setBounds(my_bounds.x, my_bounds.y, bounds.width, bounds.height, SET_BOUNDS);
   }
   XToolkit.postEvent(
       XToolkit.targetToAppContext(target),
       new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED));
 }
Esempio n. 13
0
 void requestXEmbedFocus() {
   if (isXEmbedActive()) {
     xembedLog.fine("Requesting focus for client");
     postEvent(
         new InvocationEvent(
             target,
             new Runnable() {
               public void run() {
                 target.requestFocus();
               }
             }));
   } else {
     xembedLog.fine("XEmbed is not active - denying request focus");
   }
 }
Esempio n. 14
0
 void focusNext() {
   if (isXEmbedActive()) {
     xembedLog.fine("Requesting focus for the next component after embedder");
     postEvent(
         new InvocationEvent(
             target,
             new Runnable() {
               public void run() {
                 KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(target);
               }
             }));
   } else {
     xembedLog.fine("XEmbed is not active - denying focus next");
   }
 }
Esempio n. 15
0
 public void windowLostFocus(WindowEvent e) {
   applicationActive = false;
   if (isXEmbedActive()) {
     xembedLog.fine("Sending WINDOW_DEACTIVATE");
     xembed.sendMessage(xembed.handle, XEMBED_WINDOW_DEACTIVATE);
   }
 }
Esempio n. 16
0
    public void propertyChange(PropertyChangeEvent e) {
      boolean isDisposed = (Boolean) e.getNewValue();
      if (isDisposed != true) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
          log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED ");
        }
      }
      AppContext appContext = AppContext.getAppContext();
      synchronized (appContext) {
        appContext.remove(ACTIVE_WINDOWS_KEY);
        appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this);

        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        kfm.removePropertyChangeListener("activeWindow", activeWindowListener);
      }
    }
Esempio n. 17
0
 void notifyChildEmbedded() {
   xembed.sendMessage(
       xembed.handle,
       XEMBED_EMBEDDED_NOTIFY,
       getWindow(),
       Math.min(xembed.version, XEMBED_VERSION),
       0);
   if (isApplicationActive()) {
     xembedLog.fine("Sending WINDOW_ACTIVATE during initialization");
     xembed.sendMessage(xembed.handle, XEMBED_WINDOW_ACTIVATE);
     if (hasFocus()) {
       xembedLog.fine("Sending FOCUS_GAINED during initialization");
       xembed.sendMessage(xembed.handle, XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT, 0, 0);
     }
   }
 }
 protected void traverseOutBackward() {
   if (embedder != null && embedder.isActive()) {
     if (embedder.isApplicationActive()) {
       xembedLog.fine("Traversing out Backward");
       embedder.traverseOutBackward();
     }
   }
 }
Esempio n. 19
0
 @Override
 public boolean rejectFocusRequest(FocusEvent.Cause cause) {
   // Cross-app activation requests are not allowed.
   if (cause != FocusEvent.Cause.MOUSE_EVENT
       && !((LWCToolkit) Toolkit.getDefaultToolkit()).isApplicationActive()) {
     focusLogger.fine("the app is inactive, so the request is rejected");
     return true;
   }
   return false;
 }
Esempio n. 20
0
  void initDispatching() {
    if (xembedLog.isLoggable(PlatformLogger.FINE))
      xembedLog.fine("Init embedding for " + Long.toHexString(xembed.handle));
    XToolkit.awtLock();
    try {
      XToolkit.addEventDispatcher(xembed.handle, xembed);
      XlibWrapper.XSelectInput(
          XToolkit.getDisplay(),
          xembed.handle,
          XConstants.StructureNotifyMask | XConstants.PropertyChangeMask);

      XDropTargetRegistry.getRegistry().registerXEmbedClient(getWindow(), xembed.handle);
    } finally {
      XToolkit.awtUnlock();
    }
    xembed.processXEmbedInfo();

    notifyChildEmbedded();
  }
Esempio n. 21
0
  /**
   * *********************************************************** Callbacks from the AWTWindow and
   * AWTView objc classes. ***********************************************************
   */
  private void deliverWindowFocusEvent(boolean gained, CPlatformWindow opposite) {
    // Fix for 7150349: ingore "gained" notifications when the app is inactive.
    if (gained && !((LWCToolkit) Toolkit.getDefaultToolkit()).isApplicationActive()) {
      focusLogger.fine("the app is inactive, so the notification is ignored");
      return;
    }

    LWWindowPeer oppositePeer = (opposite == null) ? null : opposite.getPeer();
    responder.handleWindowFocusEvent(gained, oppositePeer);
  }
Esempio n. 22
0
  /*
   * Requests platform to set native focus on a frame/dialog.
   * In case of a simple window, triggers appropriate java focus change.
   */
  public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
    if (focusLog.isLoggable(PlatformLogger.FINE)) {
      focusLog.fine("requesting native focus to " + this);
    }

    if (!focusAllowedFor()) {
      focusLog.fine("focus is not allowed");
      return false;
    }

    if (platformWindow.rejectFocusRequest(cause)) {
      return false;
    }

    Window currentActive = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();

    Window opposite = LWKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();

    // Make the owner active window.
    if (isSimpleWindow()) {
      LWWindowPeer owner = getOwnerFrameDialog(this);

      // If owner is not natively active, request native
      // activation on it w/o sending events up to java.
      if (owner != null && !owner.platformWindow.isActive()) {
        if (focusLog.isLoggable(PlatformLogger.FINE)) {
          focusLog.fine("requesting native focus to the owner " + owner);
        }
        LWWindowPeer currentActivePeer =
            (currentActive != null ? (LWWindowPeer) currentActive.getPeer() : null);

        // Ensure the opposite is natively active and suppress sending events.
        if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
          if (focusLog.isLoggable(PlatformLogger.FINE)) {
            focusLog.fine("the opposite is " + currentActivePeer);
          }
          currentActivePeer.skipNextFocusChange = true;
        }
        owner.skipNextFocusChange = true;

        owner.platformWindow.requestWindowFocus();
      }

      // DKFM will synthesize all the focus/activation events correctly.
      changeFocusedWindow(true, opposite);
      return true;

      // In case the toplevel is active but not focused, change focus directly,
      // as requesting native focus on it will not have effect.
    } else if (getTarget() == currentActive && !getTarget().hasFocus()) {

      changeFocusedWindow(true, opposite);
      return true;
    }

    return platformWindow.requestWindowFocus();
  }
Esempio n. 23
0
 void endDispatching() {
   xembedLog.fine("End dispatching for " + Long.toHexString(xembed.handle));
   XToolkit.awtLock();
   try {
     XDropTargetRegistry.getRegistry().unregisterXEmbedClient(getWindow(), xembed.handle);
     // We can't deselect input since someone else might be interested in it
     XToolkit.removeEventDispatcher(xembed.handle, xembed);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Esempio n. 24
0
  public void updateGC() {
    int scrn = getScreenImOn();
    if (screenLog.isLoggable(PlatformLogger.Level.FINER)) {
      log.finer("Screen number: " + scrn);
    }

    // get current GD
    Win32GraphicsDevice oldDev = (Win32GraphicsDevice) winGraphicsConfig.getDevice();

    Win32GraphicsDevice newDev;
    GraphicsDevice devs[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    // Occasionally during device addition/removal getScreenImOn can return
    // a non-existing screen number. Use the default device in this case.
    if (scrn >= devs.length) {
      newDev =
          (Win32GraphicsDevice)
              GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    } else {
      newDev = (Win32GraphicsDevice) devs[scrn];
    }

    // Set winGraphicsConfig to the default GC for the monitor this Window
    // is now mostly on.
    winGraphicsConfig = (Win32GraphicsConfig) newDev.getDefaultConfiguration();
    if (screenLog.isLoggable(PlatformLogger.Level.FINE)) {
      if (winGraphicsConfig == null) {
        screenLog.fine("Assertion (winGraphicsConfig != null) failed");
      }
    }

    // if on a different display, take off old GD and put on new GD
    if (oldDev != newDev) {
      oldDev.removeDisplayChangedListener(this);
      newDev.addDisplayChangedListener(this);
    }

    AWTAccessor.getComponentAccessor()
        .setGraphicsConfiguration((Component) target, winGraphicsConfig);
  }
Esempio n. 25
0
  private static void writeLogRecords(PrintStream logps) throws Exception {
    PrintStream err = System.err;
    try {
      System.setErr(logps);

      Object[] params = new Object[] {new Long(1), "string"};
      PlatformLogger plog = PlatformLogger.getLogger("test.log.foo");
      plog.severe("Log message {0} {1}", (Object[]) params);

      // create a java.util.logging.Logger
      // now java.util.logging.Logger should be created for each platform
      // logger
      Logger logger = Logger.getLogger("test.log.bar");
      logger.log(Level.SEVERE, "Log message {0} {1}", params);

      plog.severe("Log message {0} {1}", (Object[]) params);
    } finally {
      logps.flush();
      logps.close();
      System.setErr(err);
    }
  }
Esempio n. 26
0
 void detachChild() {
   if (xembedLog.isLoggable(PlatformLogger.FINE))
     xembedLog.fine("Detaching child " + Long.toHexString(xembed.handle));
   /**
    * XEmbed specification: "The embedder can unmap the client and reparent the client window to
    * the root window. If the client receives an ReparentNotify event, it should check the parent
    * field of the XReparentEvent structure. If this is the root window of the window's screen,
    * then the protocol is finished and there is no further interaction. If it is a window other
    * than the root window, then the protocol continues with the new parent acting as the embedder
    * window."
    */
   XToolkit.awtLock();
   try {
     XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), xembed.handle);
     XlibWrapper.XReparentWindow(
         XToolkit.getDisplay(), xembed.handle, XToolkit.getDefaultRootWindow(), 0, 0);
   } finally {
     XToolkit.awtUnlock();
   }
   endDispatching();
   xembed.handle = 0;
 }
Esempio n. 27
0
 void canvasFocusLost(FocusEvent e) {
   if (isXEmbedActive() && !e.isTemporary()) {
     xembedLog.fine("Forwarding FOCUS_LOST");
     int num = 0;
     if (AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembed.testing"))) {
       Component opp = e.getOppositeComponent();
       try {
         num = Integer.parseInt(opp.getName());
       } catch (NumberFormatException nfe) {
       }
     }
     xembed.sendMessage(xembed.handle, XEMBED_FOCUS_OUT, num, 0, 0);
   }
 }
Esempio n. 28
0
 void forwardKeyEvent(KeyEvent e) {
   xembedLog.fine("Try to forward key event");
   byte[] bdata = getBData(e);
   long data = Native.toData(bdata);
   if (data == 0) {
     return;
   }
   try {
     XKeyEvent ke = new XKeyEvent(data);
     ke.set_window(xembed.handle);
     if (xembedLog.isLoggable(PlatformLogger.FINE))
       xembedLog.fine("Forwarding native key event: " + ke);
     XToolkit.awtLock();
     try {
       XlibWrapper.XSendEvent(
           XToolkit.getDisplay(), xembed.handle, false, XConstants.NoEventMask, data);
     } finally {
       XToolkit.awtUnlock();
     }
   } finally {
     XlibWrapper.unsafe.freeMemory(data);
   }
 }
Esempio n. 29
0
 public void handleClientMessage(XEvent xev) {
   super.handleClientMessage(xev);
   XClientMessageEvent msg = xev.get_xclient();
   if (xembedLog.isLoggable(PlatformLogger.FINER))
     xembedLog.finer("Client message to embedder: " + msg);
   if (msg.get_message_type() == xembed.XEmbed.getAtom()) {
     if (xembedLog.isLoggable(PlatformLogger.FINE))
       xembedLog.fine(xembed.XEmbedMessageToString(msg));
   }
   if (isXEmbedActive()) {
     switch ((int) msg.get_data(1)) {
       case XEMBED_REQUEST_FOCUS:
         requestXEmbedFocus();
         break;
       case XEMBED_FOCUS_NEXT:
         focusNext();
         break;
       case XEMBED_FOCUS_PREV:
         focusPrev();
         break;
       case XEMBED_REGISTER_ACCELERATOR:
         registerAccelerator(msg.get_data(2), msg.get_data(3), msg.get_data(4));
         break;
       case XEMBED_UNREGISTER_ACCELERATOR:
         unregisterAccelerator(msg.get_data(2));
         break;
       case NON_STANDARD_XEMBED_GTK_GRAB_KEY:
         grabKey(msg.get_data(3), msg.get_data(4));
         break;
       case NON_STANDARD_XEMBED_GTK_UNGRAB_KEY:
         ungrabKey(msg.get_data(3), msg.get_data(4));
         break;
     }
   } else {
     xembedLog.finer("But XEmbed is not Active!");
   }
 }
Esempio n. 30
0
    private void init(KeyEvent e) {
      byte[] bdata = getBData(e);
      long data = Native.toData(bdata);
      if (data == 0) {
        return;
      }
      try {
        XToolkit.awtLock();
        try {
          keysym = XWindow.getKeySymForAWTKeyCode(e.getKeyCode());
        } finally {
          XToolkit.awtUnlock();
        }
        XKeyEvent ke = new XKeyEvent(data);

        // We recognize only these masks
        modifiers =
            ke.get_state() & (XConstants.ShiftMask | XConstants.ControlMask | XConstants.LockMask);
        if (xembedLog.isLoggable(PlatformLogger.FINEST))
          xembedLog.finest("Mapped " + e + " to " + this);
      } finally {
        XlibWrapper.unsafe.freeMemory(data);
      }
    }