/**
   * 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();
  }
Ejemplo n.º 2
0
 /**
  * Sets the navigation entry.
  *
  * @param entry the new navigation entry
  */
 public void setNavigationEntry(NavigationEntry entry) {
   if (entry != null) {
     if (this.window.getTopFrame() == entry.getNavigatorFrame()) {
       URL url = entry.getUrl();
       this.addressField.setUrl(url);
       this.clearState();
       this.actionPool.updateEnabling();
     }
   } else {
     this.clearState();
     this.addressField.setUrl(null);
     this.actionPool.updateEnabling();
   }
 }
Ejemplo n.º 3
0
 /** Populate forward more. */
 public void populateForwardMore() {
   NavigationEntry[] entries = this.window.getForwardNavigationEntries();
   JMenu forwardMoreMenu = this.forwardMoreMenu;
   forwardMoreMenu.removeAll();
   for (NavigationEntry entry : entries) {
     String method = entry.getMethod();
     if ("GET".equals(method)) {
       String title = entry.getTitle();
       URL url = entry.getUrl();
       String text = (title == null) || (title.length() == 0) ? url.toExternalForm() : title;
       Action action = this.actionPool.createGoToAction(entry);
       JMenuItem menuItem = menuItem(text, action);
       menuItem.setToolTipText(url.toExternalForm());
       forwardMoreMenu.add(menuItem);
     }
   }
 }
Ejemplo n.º 4
0
 private void updateLinks() {
   JComboBox comboBox = this.linksComboBox;
   comboBox.removeAllItems();
   // The content object should be of type HTMLDocumentImpl
   // when we're rendering a HTML page.
   Object contentObject = this.browserPanel.getContentObject();
   // We'll also need the base URL in order to resolve hrefs.
   NavigationEntry navEntry = this.browserPanel.getCurrentNavigationEntry();
   java.net.URL baseURL = navEntry == null ? null : navEntry.getUrl();
   if (baseURL == null) {
     Logger.getLogger(this.getClass().getName())
         .log(Level.WARNING, "updateLinks(): No URL in current entry.");
     return;
   }
   if (contentObject instanceof HTMLDocumentImpl) {
     HTMLDocumentImpl document = (HTMLDocumentImpl) contentObject;
     // Now we'll look through all the anchors in the page
     // and populate the combo box accordingly.
     HTMLCollection anchors = document.getAnchors();
     int length = anchors.getLength();
     for (int i = 0; i < length; i++) {
       HTMLElement anchor = (HTMLElement) anchors.item(i);
       String href = anchor.getAttribute("href");
       if (href != null) {
         java.net.URL itemURL;
         try {
           itemURL = new java.net.URL(baseURL, href);
         } catch (java.net.MalformedURLException mfu) {
           Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "updateLinks()", mfu);
           continue;
         }
         String textContent = anchor.getTextContent();
         if (textContent == null) {
           textContent = "(no link text)";
         } else if (textContent.length() > 60) {
           textContent = textContent.substring(0, 60) + "...";
         }
         LocationItem item = new LocationItem(itemURL, textContent);
         comboBox.addItem(item);
       }
     }
   }
 }