/**
  * Constructs a PlatformWindowContextImpl. It starts out by showing a progress window. Later a new
  * browser window is obtained given the windowId, or created.
  *
  * @param openerFrame the opener frame
  * @param windowId the window id
  * @param properties the properties
  */
 public NavigatorWindowImpl(NavigatorFrame openerFrame, String windowId, Properties properties) {
   this.requestedProperties = properties;
   this.windowId = windowId;
   WindowFactory wf = windowFactory;
   if (wf == null) {
     throw new IllegalStateException("Global WindowFactory is null.");
   }
   AbstractBrowserWindow window = wf.getExistingWindow(windowId);
   FramePanel framePanel = null;
   if (window != null) {
     framePanel = window.getTopFramePanel();
     if (framePanel == null) {
       throw new IllegalStateException(
           "Window with ID " + windowId + " exists but its top frame is null.");
     }
   } else {
     framePanel =
         FramePanelFactorySource.getInstance().getActiveFactory().createFramePanel(windowId);
     framePanel.setOpenerFrame(openerFrame);
   }
   this.framePanel = framePanel;
   // Starts out as progress window.
   // We allow documents to override window properties, but
   // it can also be the case that such methods as alert() are
   // invoked while the document loads.
   if (window != null) {
     this.browserWindow = window;
     this.progressWindow = null;
     this.launched = true;
   } else {
     AbstractBrowserWindow newWindow = wf.createWindow(this.windowId, properties, this);
     this.browserWindow = newWindow;
     JFrame progressWindow = new ProgressWindow();
     this.progressWindow = progressWindow;
     // Pack to use preferred sizes
     progressWindow.pack();
     // Then resize
     progressWindow.setSize(new Dimension(400, progressWindow.getHeight()));
     progressWindow.setLocationByPlatform(true);
     progressWindow.setVisible(true);
     progressWindow.addWindowListener(
         new WindowAdapter() {
           @Override
           public void windowClosed(WindowEvent e) {
             if (!launched) {
               if (logger.isLoggable(Level.INFO)) {
                 logger.info(
                     "NavigatorWindowImpl(): Disposing browserWindow due to progress window getting closed.");
               }
               browserWindow.dispose();
             }
           }
         });
   }
 }
  /**
   * Reset as navigator.
   *
   * @param overridingProperties the overriding properties
   */
  void resetAsNavigator(Properties overridingProperties) {
    // Invoke in GUI thread
    if (this.launched) {
      return;
    }
    this.launched = true;
    if (this.progressWindow != null) {
      if (!progressWindow.isDisplayable()) {
        if (logger.isLoggable(Level.INFO)) {
          logger.info(
              "resetAsNavigator(): Progress window is not displayable, so it must have been closed; cancelling operation.");
        }
        this.browserWindow.dispose();
        return;
      }
      this.progressWindow.dispose();
    }
    AbstractBrowserWindow window = this.browserWindow;
    if (!window.isVisible()) {
      window.setVisible(true);
    }
    window.toFront();

    // Come up with combination properties object
    if (overridingProperties != null) {
      Properties original = this.requestedProperties;
      if (original == null) {
        original = new Properties();
      }
      original.putAll(overridingProperties);
      WindowFactory wf = windowFactory;
      if (wf == null) {
        throw new IllegalStateException("Global WindowFactory is null.");
      }
      wf.overrideProperties(window, original);
    }

    // Initialize title
    if (window instanceof Frame) {
      NavigationEntry currentEntry = this.getCurrentNavigationEntry();
      if (currentEntry != null) {
        String title = currentEntry.getTitle();
        if (title == null) {
          title = Urls.getNoRefForm(currentEntry.getUrl());
        }
        ((Frame) window).setTitle(title);
      }
    }
    // Make visible and bring to front
    if (!window.isVisible()) {
      window.setVisible(true);
    }
    window.toFront();
  }