public LWWindowPeer(
      Window target,
      PlatformComponent platformComponent,
      PlatformWindow platformWindow,
      PeerType peerType) {
    super(target, platformComponent);
    this.platformWindow = platformWindow;
    this.peerType = peerType;

    Window owner = target.getOwner();
    LWWindowPeer ownerPeer =
        owner == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
    PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;

    // The delegate.initialize() needs a non-null GC on X11.
    GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
    synchronized (getStateLock()) {
      // graphicsConfig should be updated according to the real window
      // bounds when the window is shown, see 4868278
      this.graphicsConfig = gc;
    }

    if (!target.isFontSet()) {
      target.setFont(DEFAULT_FONT);
    }

    if (!target.isBackgroundSet()) {
      target.setBackground(SystemColor.window);
    } else {
      // first we check if user provided alpha for background. This is
      // similar to what Apple's Java do.
      // Since JDK7 we should rely on setOpacity() only.
      // this.opacity = c.getAlpha();
    }

    if (!target.isForegroundSet()) {
      target.setForeground(SystemColor.windowText);
      // we should not call setForeground because it will call a repaint
      // which the peer may not be ready to do yet.
    }

    platformWindow.initialize(target, this, ownerDelegate);

    // Init warning window(for applets)
    SecurityWarningWindow warn = null;
    if (target.getWarningString() != null) {
      // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
      // and TrayIcon balloon windows without a warning window.
      if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) {
        LWToolkit toolkit = (LWToolkit) Toolkit.getDefaultToolkit();
        warn = toolkit.createSecurityWarning(target, this);
      }
    }

    warningWindow = warn;
  }
 /*
  * Retrieves the owner of the peer.
  * Note: this method returns the owner which can be activated, (i.e. the instance
  * of Frame or Dialog may be returned).
  */
 static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
   Window owner = (peer != null ? peer.getTarget().getOwner() : null);
   while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
     owner = owner.getOwner();
   }
   return owner == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
 }
 @Override
 public void blockWindows(List<Window> windows) {
   // TODO: LWX will probably need some collectJavaToplevels to speed this up
   for (Window w : windows) {
     WindowPeer wp = (WindowPeer) AWTAccessor.getComponentAccessor().getPeer(w);
     if (wp != null) {
       wp.setModalBlocked((Dialog) getTarget(), true);
     }
   }
 }
  private void postWindowStateChangedEvent(int newWindowState) {
    if (getTarget() instanceof Frame) {
      AWTAccessor.getFrameAccessor().setExtendedState((Frame) getTarget(), newWindowState);
    }
    WindowEvent stateChangedEvent =
        new WindowEvent(getTarget(), WindowEvent.WINDOW_STATE_CHANGED, windowState, newWindowState);
    postEvent(stateChangedEvent);
    windowState = newWindowState;

    updateSecurityWarningVisibility();
  }
 @Override
 public void repositionSecurityWarning() {
   if (warningWindow != null) {
     AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
     Window target = getTarget();
     int x = compAccessor.getX(target);
     int y = compAccessor.getY(target);
     int width = compAccessor.getWidth(target);
     int height = compAccessor.getHeight(target);
     warningWindow.reposition(x, y, width, height);
   }
 }
  @Override
  public void setModalBlocked(Dialog blocker, boolean blocked) {
    synchronized (getPeerTreeLock()) {
      ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(blocker);
      if (blocked && (peer instanceof LWWindowPeer)) {
        this.blocker = (LWWindowPeer) peer;
      } else {
        this.blocker = null;
      }
    }

    platformWindow.setModalBlocked(blocked);
  }
  /*
   * Called by the delegate when a key is pressed.
   */
  @Override
  public void notifyKeyEvent(
      int id, long when, int modifiers, int keyCode, char keyChar, int keyLocation) {
    LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
    Component focusOwner = kfmPeer.getCurrentFocusOwner();

    if (focusOwner == null) {
      focusOwner = kfmPeer.getCurrentFocusedWindow();
      if (focusOwner == null) {
        focusOwner = this.getTarget();
      }
    }

    KeyEvent keyEvent =
        new KeyEvent(focusOwner, id, when, modifiers, keyCode, keyChar, keyLocation);
    AWTAccessor.getKeyEventAccessor()
        .setExtendedKeyCode(
            keyEvent,
            (keyChar == KeyEvent.CHAR_UNDEFINED)
                ? keyCode
                : ExtendedKeyCodes.getExtendedKeyCodeForChar(keyChar));
    postEvent(keyEvent);
  }
  /*
   * 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.Level.FINE)) {
      focusLog.fine("requesting native focus to " + this);
    }

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

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

    AppContext targetAppContext = AWTAccessor.getComponentAccessor().getAppContext(getTarget());
    KeyboardFocusManager kfm =
        AWTAccessor.getKeyboardFocusManagerAccessor()
            .getCurrentKeyboardFocusManager(targetAppContext);
    Window currentActive = kfm.getActiveWindow();

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

    // Make the owner active window.
    if (isSimpleWindow()) {
      focusLog.fine("This is a Simple Window.");
      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.Level.FINE)) {
          focusLog.fine("requesting native focus to the owner " + owner);
        }
        LWWindowPeer currentActivePeer =
            currentActive == null
                ? null
                : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(currentActive);

        // Ensure the opposite is natively active and suppress sending events.
        if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
          if (focusLog.isLoggable(PlatformLogger.Level.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);
      focusLog.fine("DKFM will synthesize all the focus/activation events correctly");
      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);
      focusLog.fine("toplevel is active but not focused, change focus directly");
      return true;
    }

    focusLog.fine("platformWindow.requestWindowFocus()");
    return platformWindow.requestWindowFocus();
  }