Exemple #1
0
    // implemented for ActionListener event handling
    public void actionPerformed(ActionEvent e) {
      String actionCmd = e.getActionCommand();
      Stack locStack = parentBrowserFrame.locationStack;
      Stack fwdStack = parentBrowserFrame.forwardStack;

      if (actionCmd.equals(homeCmd)) // event from home button
      {
        fwdStack.removeAllElements();
        parentBrowserFrame.setBrowserLocation(mainBrowserURL);
      } else if (actionCmd.equals(backCmd)) // event from back button
      {
        if (!locStack.isEmpty()) {
          String myLocale = (String) (locStack.pop());

          // push current location on forward stack
          fwdStack.push(location);
          getForwardButton().setEnabled(true);

          // do *not* cache the last location in the stack
          parentBrowserFrame.setBrowserLocation(myLocale, false);
        }
      } else if (actionCmd.equals(forwardCmd)) // event from forward button
      {
        if (!fwdStack.isEmpty()) {
          // remove location from forward stack
          String newLoc = (String) (fwdStack.pop());

          // DO add the current location to the back stack
          parentBrowserFrame.setBrowserLocation(newLoc);
        }
      } else if (actionCmd.equals(comboCmd)) // event from URL combo box!
      {
        if (e.getSource() instanceof JComboBox) // just to be sure
        {
          JComboBox thisBox = (JComboBox) e.getSource();

          String newLoc = thisBox.getSelectedItem().toString();
          if (newLoc != null && !newLoc.equals("")) // ignore empty selections
          {
            if (thisBox.getSelectedIndex() == -1) {
              thisBox.insertItemAt(newLoc, 0);
            }
            fwdStack.removeAllElements();
            parentBrowserFrame.setBrowserLocation(newLoc);
          }
        }
      }

      // disable the back button if we find the location stack is empty
      if (locStack.isEmpty()) {
        getBackButton().setEnabled(false);
      }

      // disable forward button if forward stack is empty
      if (fwdStack.isEmpty()) {
        getForwardButton().setEnabled(false);
      }
    }
 public void setRootNode(NodeImpl node) {
   if (!(node instanceof HTMLElementImpl)) {
     throw new IllegalArgumentException("node=" + node);
   }
   HTMLElementImpl element = (HTMLElementImpl) node;
   HtmlRendererContext context = element.getHtmlRendererContext();
   this.htmlContext = context;
   if (context != null) {
     String rows = element.getAttribute("rows");
     String cols = element.getAttribute("cols");
     HtmlLength[] rowLengths = this.getLengths(rows);
     HtmlLength[] colLengths = this.getLengths(cols);
     this.rowHtmlLengths = rowLengths;
     this.colHtmlLengths = colLengths;
     HTMLElementImpl[] subframes = this.getSubFrames(element);
     Component[] frameComponents = new Component[subframes.length];
     this.frameComponents = frameComponents;
     for (int i = 0; i < subframes.length; i++) {
       HTMLElementImpl frameElement = subframes[i];
       if (frameElement != null && "FRAMESET".equalsIgnoreCase(frameElement.getTagName())) {
         FrameSetPanel fsp = new FrameSetPanel();
         fsp.setRootNode(frameElement);
         frameComponents[i] = fsp;
       } else {
         BrowserFrame frame = context.createBrowserFrame();
         if (frameElement != null) {
           String src = frameElement.getAttribute("src");
           if (src != null) {
             java.net.URL url;
             try {
               url = frameElement.getFullURL(src);
               if (url != null) {
                 frame.loadURL(url);
               }
             } catch (MalformedURLException mfu) {
               // ignore
             }
           }
         }
         frameComponents[i] = frame.getComponent();
       }
     }
   }
 }