home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / Samples / ActiveXBeans / JBrowser / JBrowser.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  22.7 KB  |  826 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. // JBrowser.java
  3. // This is a java application which hosts the WebBrowser control (IE4.0)
  4. // and provides similar UI.
  5. //
  6. // (C) Copyright 1998 by Microsoft Corporation. All rights reserved
  7. //////////////////////////////////////////////////////////////////////////
  8.  
  9. // AFC
  10. import com.ms.ui.*;
  11. import com.ms.ui.event.*;
  12. import com.ms.fx.*;
  13.  
  14. // the IE ActiveX control
  15. import com.ms.ie.*;
  16.  
  17. // for hosting ActiveX Controls
  18. import com.ms.activeX.*;
  19. import com.ms.com.Variant;
  20.  
  21. // standard Java
  22. import java.awt.*;
  23. import java.awt.event.*;
  24.  
  25. //
  26. //
  27. // JBrowser
  28. //
  29. //
  30. class JBrowser extends Frame implements IUIActionListener, ActiveXControlListener, WebBrowserEventListener
  31. {
  32.     UIBandBox bandBox = new UIBandBox();                                                    // this contains all the bands.
  33.     UIBand mainMenuBand = new UIBand();                                                        // the main menu band
  34.     UIMenuList fileMenuList = new UIMenuList();                                                // the list of items in the file menu
  35.     UIMenuButton fileMenu = new UIMenuButton("File", 0, fileMenuList);                        // the "File" menu
  36.     UIMenuItem openItem = new UIMenuItem("Open");                                            // the open item in the file menu
  37.     UIMenuItem exitItem = new UIMenuItem("Exit");                                            // the exit item in the file menu
  38.     UIMenuList goMenuList = new UIMenuList();                                                // the list of items in the go menu
  39.     UIMenuButton goMenu = new UIMenuButton("Go", 0, goMenuList);                            // the "Go" menu
  40.     UIMenuItem backItem = new UIMenuItem("Back");                                            // the back item in the go menu
  41.     UIMenuItem forwardItem = new UIMenuItem("Forward");                                        // the forward item in the go menu
  42.     UIMenuItem homeItem = new UIMenuItem("Home");                                            // the home item in the go menu
  43.     UIMenuItem searchItem = new UIMenuItem("Search");                                        // the search item in the go menu
  44.     UIMenuList helpMenuList = new UIMenuList();                                                // the list of items in the help menu
  45.     UIMenuButton helpMenu = new UIMenuButton("Help", 0, helpMenuList);                        // the "Help" menu
  46.     UIMenuItem tutorialItem = new UIMenuItem("Web Tutorial");                                // the Web Tutorial item in the help menu
  47.     UIMenuItem aboutItem = new UIMenuItem("About Java Browser");                            // the About ... item in the help menu.
  48.     UIBand buttonsBand = new UIBand();                                                        // the band of buttons
  49.     UIPushButton backButton;                                                                // go back to the last page button
  50.     UIPushButton forwardButton;                                                                // fo forward to the next page button
  51.     UIPushButton stopButton;                                                                // stop current transfer
  52.     UIPushButton refreshButton;                                                                // refresh current page button
  53.     UIPushButton homeButton;                                                                // go to the home page
  54.     UIPushButton searchButton;                                                                // go to the search page
  55.     UIBand addressBand = new UIBand("Address ");                                            // the band of addresses
  56.     EditBox address = new EditBox();                                                        // the edit box for entering the text
  57.     UIBand linksBand = new UIBand("Links");                                                    // the band of links
  58.     UIPushButton bestOfWebButton;                                                            // the "Best of the Web" button
  59.     UIPushButton microsoftJavaButton;                                                        // the microsoft Java page
  60.     UIPushButton microsoftButton;                                                            // the "microsoft" page
  61.     UIDrawText status = new UIDrawText("Status");                                            // to display the status text
  62.     ProgressBar progress = new ProgressBar(300,20,100,0);                                    // to display the progress of the download
  63.     StatusBar statusBar = new StatusBar(302,22);                                            // the status bar which displays progres and the status text
  64.     WebBrowser browser = new WebBrowser();                                                    // the web browser object
  65.     Thread animationThread;                                                                    // The thread which controls the animation of the image
  66.     JAnim animatedImage;                                                                    // the animated image object
  67.     UIPushButton animatedButton;                                                            // The button which has the animated image
  68.     public Font dialogFont;                                                                    // the font to use in dialog boxes
  69.  
  70.     /**
  71.      * The main method which creates a JBrowser object.
  72.      * @param    String[]    The command line parameters
  73.      */
  74.     public static void main(String[] args)
  75.     {
  76.         new JBrowser();
  77.     }
  78.  
  79.     /**
  80.      * Null constructor for JBrowser object. It creates the following
  81.      * <ol>
  82.      * <li>Main Menu
  83.      *    <ul>
  84.      *    <li>File
  85.      *        <ul>
  86.      *        <li>Open</li>
  87.      *        <li>Exit</li>
  88.      *        </ul>
  89.      *    </li>
  90.      *    <li>Go
  91.      *        <ul>
  92.      *        <li>Back</li>
  93.      *        <li>Forward</li>
  94.      *        <li>Home Page</li>
  95.      *        <li>Search The Web</li>
  96.      *        </ul>
  97.      *    </li>
  98.      *    <li>Help
  99.      *        <ul>
  100.      *        <li>Web Tutorial</li>
  101.      *        <li>About JBrowser</li>
  102.      *        </ul>
  103.      *    </li>
  104.      * </li>
  105.      * <li>An animated button
  106.      * </li>
  107.      * <li>Tool Bar with following icons
  108.      *    <ul>
  109.      *    <li>Back</li>
  110.      *    <li>Forward</li>
  111.      *    <li>Stop</li>
  112.      *    <li>Refresh</li>
  113.      *    <li>Home</li>
  114.      *    <li>Search</li>    
  115.      *    </ul>
  116.      * </li>
  117.      * <li>Creates a bar with the following
  118.      *    <ul>
  119.      *    <li>An Address edit box</li>
  120.      *    <li>A links bar with the following
  121.      *        <ul>
  122.      *        <li>Best of the web</li>
  123.      *        <li>Microsoft Java</li>
  124.      *        <li>Microsoft</li>
  125.      *        <li>Yahoo</li>
  126.      *        </ul>
  127.      *    </li>
  128.      *    </ul>
  129.      * </li>
  130.      * <li>Creates a status bar which has the following
  131.      *    <ul>
  132.      *        <li>A text label which prints the status text</li>
  133.      *        <li>A progress bar which shows the progress of the current operation</li>
  134.      *    </ul>
  135.      * </li>
  136.      * </ol>
  137.      * 
  138.      */
  139.  
  140.     public JBrowser()
  141.     {
  142.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  143.         // Add event hooks to the JBrowser
  144.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  145.         addWindowListener(new JBrowserWindow());
  146.         bandBox.addActionListener(this);
  147.         browser.addWebBrowserEventListener(this);
  148.         browser.addActiveXControlListener(this);
  149.  
  150.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  151.         // Add the main menu band
  152.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  153.         
  154.         // give the band box a new layout manager.
  155.         bandBox.setLayout( new UIBarLayout(0,0) );
  156.  
  157.         // add the file menu 
  158.         fileMenuList.add(openItem);
  159.         fileMenuList.add(exitItem);
  160.         mainMenuBand.add(fileMenu);
  161.                 
  162.         // add the go menu
  163.         goMenuList.add(backItem);
  164.         goMenuList.add(forwardItem);
  165.         goMenuList.add(homeItem);
  166.         goMenuList.add(searchItem);
  167.         mainMenuBand.add(goMenu);
  168.  
  169.         // the forward and the back item will be enabled by browser events
  170.         backItem.setEnabled(false);
  171.         forwardItem.setEnabled(false);
  172.  
  173.         // add the help menu
  174.         helpMenuList.add(tutorialItem);
  175.         helpMenuList.add(aboutItem);
  176.         mainMenuBand.add(helpMenu);
  177.  
  178.         mainMenuBand.setEdge(IFxGraphicsConstants.BDR_RAISED);
  179.         
  180.         bandBox.add(mainMenuBand);
  181.  
  182.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  183.         // create and add an animated image
  184.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  185.         animatedImage = new JAnim( getToolkit().getImage("images/e.gif") , 46, 4 ) ;
  186.         animatedButton = new UIPushButton(animatedImage);
  187.         bandBox.add( animatedButton);
  188.  
  189.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  190.         // Add the buttons band
  191.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  192.         
  193.         // back button
  194.         backButton = createButton("images/previous.gif", "images/previous_g.gif", "Back", UIItem.ABOVE);
  195.         buttonsBand.add(backButton);
  196.  
  197.         // forward button
  198.         forwardButton = createButton("images/next.gif", "images/next_g.gif", "Forward", UIItem.ABOVE);
  199.         buttonsBand.add(forwardButton);
  200.  
  201.         // the forward and back buttons will be enabled by browser events
  202.         backButton.setEnabled(false);
  203.         forwardButton.setEnabled(false);
  204.  
  205.         // stop button
  206.         stopButton = createButton("images/stop.gif", "images/stop_g.gif", "Stop", UIItem.ABOVE);
  207.         buttonsBand.add(stopButton);
  208.  
  209.         //stop button will be enabled by a download begin event
  210.         stopButton.setEnabled(false);
  211.  
  212.         // refresh button
  213.         refreshButton = createButton("images/refresh.gif", "images/refresh_g.gif", "Refresh", UIItem.ABOVE);
  214.         buttonsBand.add(refreshButton);
  215.  
  216.         // home button
  217.         homeButton = createButton("images/home.gif", "images/home_g.gif", "Home", UIItem.ABOVE);
  218.         buttonsBand.add(homeButton);
  219.  
  220.         // search button
  221.         searchButton = createButton("images/search.gif", "images/search_g.gif", "Search", UIItem.ABOVE);
  222.         buttonsBand.add(searchButton);
  223.  
  224.         buttonsBand.setEdge(IFxGraphicsConstants.BDR_RAISED);
  225.         buttonsBand.setStyle(UIBand.BREAK);
  226.  
  227.         bandBox.add(buttonsBand);
  228.         
  229.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  230.         // Add the address band
  231.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  232.  
  233.         // a panel for hosting the editbox
  234.         UIPanel addressPanel = new UIPanel();
  235.         addressPanel.setBackground(FxColor.white);
  236.         addressPanel.setEdge(IFxGraphicsConstants.BDR_SUNKEN);
  237.         addressPanel.add(address, "center");
  238.         addressBand.add(addressPanel);
  239.  
  240.         addressBand.setEdge(IFxGraphicsConstants.BDR_RAISED);
  241.         addressBand.setStyle(UIBand.BREAK);
  242.         bandBox.add(addressBand);
  243.         
  244.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  245.         // Add the links band
  246.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
  247.         bestOfWebButton = createButton("images/favorite_small.gif", "images/favorite_small_g.gif", "Best of the Web", UIItem.ONLEFT);
  248.         linksBand.add(bestOfWebButton);
  249.  
  250.         microsoftButton = createButton("images/favorite_small.gif", "images/favorite_small_g.gif", "Microsoft", UIItem.ONLEFT);
  251.         linksBand.add(microsoftButton);
  252.  
  253.         microsoftJavaButton = createButton("images/favorite_small.gif", "images/favorite_small_g.gif", "Microsoft Java", UIItem.ONLEFT);
  254.         linksBand.add(microsoftJavaButton);
  255.  
  256.         linksBand.setEdge(IFxGraphicsConstants.BDR_RAISED);
  257.         linksBand.setStyle(UIBand.DRAGBREAK);
  258.  
  259.         bandBox.add(linksBand);
  260.  
  261.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  262.         // Add the band box
  263.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  264.         setLayout(new BorderLayout() );
  265.         
  266.         setBackground(FxColor.lightGray);
  267.  
  268.         bandBox.setEdge(IFxGraphicsConstants.BDR_SUNKEN);
  269.         add("North", new AwtUIHost(bandBox) );
  270.  
  271.  
  272.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  273.         // Add the ActiveX WebBrowser control
  274.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  275.         add("Center", browser);
  276.  
  277.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  278.         // Add the status bar with status text and the progress bar in it.
  279.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  280.  
  281.         // this panel will host the status text and the progress bar
  282.         statusBar.setEdge(IFxGraphicsConstants.BDR_RAISED);
  283.         statusBar.setLayout( new UIBorderLayout() );
  284.  
  285.         // the status text
  286.         statusBar.add(status, "center");
  287.  
  288.         // the progress bar
  289.         statusBar.add(progress, "east");
  290.  
  291.         add("South", new AwtUIHost(statusBar) );
  292.  
  293.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  294.         // Show the JBrowser
  295.         // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  296.         setBounds(150,100,900,800);
  297.         setTitle("JBrowser");
  298.         setVisible(true);
  299.         dialogFont = new Font("TimesRoman", Font.BOLD, 18) ;
  300.     }
  301.  
  302.  
  303.     /**
  304.      * This class creates a push button with the specified hot and normal images and
  305.      * a text to be displayed with the image. The button is hot-tracked
  306.      * 
  307.      * @param String    The name of the normal image
  308.      * @param String    The name of the hot image
  309.      * @param String    The text to be displayed with image
  310.      * @param int        The location of the image with respect to the text
  311.      */
  312.     UIPushButton createButton( String normal, String hot, String text, int where)
  313.     {
  314.         Image           gifnormal       = null;         // button in normal state
  315.         Image           gifhot          = null;         // button in hot state
  316.         MediaTracker    tracker;                        // to wait for the images to be loaded
  317.         UIPushButton    button;                         // button to be returned
  318.  
  319.         // create a media tracker
  320.         tracker = new MediaTracker(this);
  321.  
  322.         // load the normal image
  323.         if (normal != null)
  324.         {
  325.             // load the normal image
  326.             gifnormal = getToolkit().getImage(normal);
  327.  
  328.             // track the image neing loaded
  329.             tracker.addImage(gifnormal, 0);
  330.         }
  331.  
  332.        if (hot != null)
  333.         {
  334.                // load the hot-tracked image
  335.             gifhot = getToolkit().getImage(hot);
  336.  
  337.             // listen on this image being loaded
  338.             tracker.addImage(gifhot, 0);
  339.         }
  340.  
  341.         // create the button
  342.         button = new UIPushButton(new UIItem(gifnormal, text, UIItem.HOTTRACK, where), 0);
  343.         //button = new UIPushButton( new UIStateItem(gifnormal, gifHot, text, UIStateItem.CENTERED, where), 0);
  344.  
  345.         // wait for all the images to be loaded
  346.         try 
  347.         {
  348.             tracker.waitForAll();
  349.         } 
  350.         catch (InterruptedException e) 
  351.         {
  352.         }
  353.  
  354.         return button;
  355.     }
  356.  
  357.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  358.     // Perform the browser actions
  359.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  360.  
  361.     /**
  362.      * This shows a dialog box describing the browser in response to the about
  363.      * item in the help menu
  364.      */
  365.     public void about()
  366.     {
  367.         UIMessageBox aboutMsg = new UIMessageBox(new UIFrame(),"About JBrowser", "This is a web-browser written in Java which uses the ActiveX control IE4.0",
  368.             UIMessageBox.INFORMATION, UIButtonBar.OK    );
  369.  
  370.         aboutMsg.setFont(dialogFont);
  371.         aboutMsg.doModal();
  372.     }
  373.  
  374.     /**
  375.      * This navigates the browser object to a specified URL
  376.      *
  377.      * @param    String    The URL to go to.
  378.      */
  379.     public void navigate(String url)
  380.     {
  381.         browser.Navigate(url, null, null, null, null);
  382.     }
  383.  
  384.     /**
  385.      * This method displays a dialog box which takes a user specified URL
  386.      * as input and navigates to that URL.
  387.      */
  388.     public void open()
  389.     {
  390.         new JBrowserOpen(this);
  391.     }
  392.       
  393.     /**
  394.      * This closes the browser application
  395.      */
  396.     public void exit()
  397.     {
  398.         browser.removeWebBrowserEventListener(this);
  399.         browser.removeActiveXControlListener(this);
  400.         System.exit(0);
  401.     }
  402.  
  403.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  404.     // Event handlers for the browser
  405.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  406.  
  407.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  408.     // Interface IUIActionListener requires the following method
  409.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  410.  
  411.     /**
  412.      * This procedure receives action events which occurred in the browser like keyclicks
  413.      * on buttons or menuitems. It then calls the appropriate function to handle the event.
  414.      *
  415.      * @param    UIActionEvent    The event which occurred
  416.      */
  417.     public void actionPerformed(UIActionEvent evt)
  418.     {        
  419.         Object target = evt.getActionItem();
  420.  
  421.         // ignore UIBand events
  422.         if( evt.getSource() instanceof UIBand)
  423.             return;
  424.  
  425.         if(target == address)
  426.         {
  427.             navigate( address.getValueText() );
  428.         }
  429.  
  430.         else if(target == aboutItem)
  431.         {
  432.             about();
  433.         }
  434.  
  435.         else if(target == backItem || target == backButton )
  436.         {
  437.             browser.GoBack();
  438.         }
  439.  
  440.         else if( target == exitItem )
  441.         {
  442.             exit();
  443.         }
  444.  
  445.         else if( target == forwardItem || target == forwardButton)
  446.         {
  447.             browser.GoForward();
  448.         }
  449.  
  450.         else if (target == homeItem || target == homeButton)
  451.         {
  452.             browser.GoHome();
  453.         }
  454.  
  455.         else if( target == microsoftButton)
  456.         {
  457.             navigate("http://www.microsoft.com");
  458.         }
  459.  
  460.         else if(target == microsoftJavaButton)
  461.         {
  462.             navigate("http://www.microsoft.com/java");
  463.         }
  464.  
  465.         else if(target == openItem)
  466.         {
  467.             open();
  468.         }
  469.         
  470.         else if(target == refreshButton)
  471.         {
  472.             browser.Refresh();
  473.         }
  474.         
  475.         else if(target == searchItem || target == searchButton)
  476.         {
  477.             browser.GoSearch();
  478.         }
  479.         
  480.         else if(target == stopButton)
  481.         {
  482.             browser.Stop();
  483.         }
  484.  
  485.         else if(target == tutorialItem)
  486.         {
  487.             navigate("http://www.microsoft.com/magazine/guides/internet/default.asp?");
  488.         }
  489.  
  490.         else if(target == bestOfWebButton)
  491.         {
  492.             navigate("http://home.microsoft.com/exploring/exploring.asp");
  493.         }
  494.  
  495.         else if(target == animatedButton)
  496.         {
  497.             navigate("http://www.microsoft.com/ie/default.asp");
  498.         }
  499.     }
  500.  
  501.  
  502.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  503.     // Interface ActiveXControlListener requires the following method
  504.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  505.  
  506.  
  507.     /**
  508.      * This procedure receives events from the activeX controls after they have been created
  509.      * The browser control is made to start up from the home page.
  510.      *
  511.      * @param    Object    The control which was created
  512.      */
  513.     public void controlCreated(Object target)
  514.     {
  515.         if(target == browser)
  516.         {
  517.             browser.GoHome();
  518.         }
  519.     }
  520.  
  521.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  522.     // Interface WebBrowserEventListener requires the following methods
  523.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  524.  
  525.     /**
  526.      * This method is invoked when the text in the status bar has to be changed
  527.      *
  528.      * @param    String    The new text
  529.      */
  530.     public void StatusTextChange(String text)
  531.     {
  532.         status.setValueText(text);
  533.     }
  534.  
  535.     /**
  536.      * This is invoked when the progress bar's position is to be changed
  537.      *
  538.      * @param    int    The position
  539.      * @param    int    The maximum position
  540.      */
  541.     public void ProgressChange(int pos, int range)
  542.     {
  543.         // UIProgress doesn't like a range of 0 ;-)
  544.         if(range <= 0)
  545.             progress.setRange(100);
  546.         else
  547.             progress.setRange(range);
  548.  
  549.         // the position is set to -1 when the download has finished
  550.         if(pos < 0)
  551.             progress.setPos(0);
  552.         else
  553.             progress.setPos(pos);
  554.     }
  555.  
  556.     /**
  557.      * The title of the page being displayed
  558.      *
  559.      * @param    String    The new title
  560.      */
  561.     public void TitleChange(String text)
  562.     {
  563.         setTitle(text);
  564.     }
  565.  
  566.     /**
  567.      * This method is invoked when the Browser object has finished loading a document
  568.      *
  569.      * @param    Object    The web-browser frame in which this document was loaded
  570.      * @param    Variant    The URL of the loaded document
  571.      */
  572.     public void DocumentComplete(Object pDisp, Variant URL)
  573.     {
  574.         address.setValueText( URL.getString() );
  575.     }
  576.  
  577.     /**
  578.      * This method is invoked when the enabled state of a command changes
  579.      * for example when the forward command or the back command is no longer
  580.      * enabled
  581.      *
  582.      * @param    int        The identifier of the command that changed
  583.      * @param    boolean    Whether the command is enabled (=>true) or disabled
  584.      */
  585.     public void CommandStateChange(int Command, boolean Enable)
  586.     {
  587.         switch(Command)
  588.         {
  589.         case CommandStateChangeConstants.CSC_NAVIGATEFORWARD:
  590.             forwardButton.setEnabled(Enable);
  591.             forwardItem.setEnabled(Enable);
  592.             break;
  593.  
  594.         case CommandStateChangeConstants.CSC_NAVIGATEBACK:
  595.             backButton.setEnabled(Enable);
  596.             backItem.setEnabled(Enable);
  597.             break;
  598.         }
  599.     }
  600.  
  601.     /**
  602.      * This method is called when the browser begins downloading
  603.      */
  604.     public void DownloadBegin()
  605.     {
  606.         // start a new thread for the animated image
  607.         animationThread = new Thread( animatedImage, "Animated Image");
  608.         animationThread.start();
  609.  
  610.         stopButton.setEnabled(true);
  611.         progress.setVisible(true);
  612.     }
  613.  
  614.     /**
  615.      * This method is called when the browser ends downloading
  616.      */
  617.     public void DownloadComplete()
  618.     {
  619.         // stop the animated image thread.
  620.         animationThread.stop();
  621.         animatedImage.reset();
  622.  
  623.         stopButton.setEnabled(false);
  624.         progress.setVisible(false);
  625.     }
  626.  
  627.  
  628.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  629.     // The following methods of interface WebBrowserEventListener
  630.     // are not implemented
  631.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  632.     public void PropertyChange(String szProperty)
  633.     {
  634.     }
  635.  
  636.     public void BeforeNavigate2(Object pDisp, Variant URL, Variant Flags, Variant TargetFrameName, Variant PostData, Variant Headers, boolean[] Cancel)
  637.     {
  638.     }
  639.  
  640.     public void NewWindow2(Object[] ppDisp, boolean[] Cancel)
  641.     {
  642.     }
  643.     
  644.     public void NavigateComplete2(Object pDisp, Variant URL)
  645.     {
  646.     }
  647.  
  648.     public void OnQuit()
  649.     {
  650.     }
  651.     
  652.     public void OnVisible(boolean Visible)
  653.     {
  654.     }
  655.     
  656.     public void OnToolBar(boolean ToolBar)
  657.     {
  658.     }
  659.     
  660.     public void OnMenuBar(boolean MenuBar)
  661.     {
  662.     }
  663.     
  664.     public void OnStatusBar(boolean StatusBar)
  665.     {
  666.     }
  667.     
  668.     public void OnFullScreen(boolean FullScreen)
  669.     {
  670.     }
  671.     
  672.     public void OnTheaterMode(boolean TheaterMode)
  673.     {
  674.     }
  675.  
  676.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  677.     // Interface WindowListener requires the following inner class
  678.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  679.  
  680.     /**
  681.      * This adapter class handles window events like when a user clicks on the 
  682.      * close window button it closes the browser.
  683.      */
  684.     class JBrowserWindow extends WindowAdapter
  685.     {
  686.         /**
  687.          * Handles the event generated when the window is being closed
  688.          *
  689.          * @param    WindowEvent    The window event generated
  690.          */
  691.         public void windowClosing(WindowEvent event)
  692.         {
  693.             exit();
  694.         }
  695.  
  696.  
  697.     }
  698. }
  699.  
  700. /**
  701.  * The progress bar extends the AFC's UIProgress and specifies a size for the same
  702.  */
  703. class ProgressBar extends UIProgress
  704. {
  705.     private int width;                    // The width of the progress bar
  706.     private int height;                    // The height of the progress bar
  707.  
  708.     /**
  709.      * This constructor specifies the width and the height of the progress bar.
  710.      *
  711.      * @param    int    width
  712.      * @param    int    height
  713.      * @param    int    range -- The maximum range of the progress bar
  714.      * @param    int    pos   -- The current position of the progress bar
  715.      */
  716.     public ProgressBar(int width, int height, int range, int pos)
  717.     {
  718.         // tell UIProgress what the range and the pos is
  719.         super(range, pos);
  720.  
  721.         this.width = width;
  722.         this.height = height;
  723.     }
  724.  
  725.     /**
  726.      * The preferred size of this progress bar
  727.      *
  728.      * @return    Dimension    The preferred dimension
  729.      */
  730.     public Dimension getPreferredSize()
  731.     {
  732.         return new Dimension(width, height);
  733.     }
  734.  
  735.     /**
  736.      * The minimum size of this progress bar
  737.      *
  738.      * @return    Dimension    The minimum size
  739.      */
  740.     public Dimension getMinimumSize()
  741.     {
  742.         return new Dimension(width, height);
  743.     }
  744. }
  745.  
  746. /**
  747.  * The status bar is simply a UIPanel with a minimum size. This prevents it
  748.  * from totally disappearing when it has nothing on it.
  749.  */
  750. class StatusBar extends UIPanel
  751. {
  752.     private int width;                    // The width of the status bar
  753.     private int height;                    // The height of the status bar
  754.  
  755.     /**
  756.      * This constructor specifies the width and the height of the status bar.
  757.      *
  758.      * @param    int    width
  759.      * @param    int    height
  760.      */
  761.     public StatusBar(int width, int height)
  762.     {
  763.         this.width = width;
  764.         this.height = height;
  765.     }
  766.  
  767.     /**
  768.      * The preferred size of this progress bar
  769.      *
  770.      * @return    Dimension    The preferred dimension
  771.      */
  772.     public Dimension getPreferredSize()
  773.     {
  774.         return new Dimension(width, height);
  775.     }
  776.  
  777.     /**
  778.      * The minimum size of this progress bar
  779.      *
  780.      * @return    Dimension    The minimum size
  781.      */
  782.     public Dimension getMinimumSize()
  783.     {
  784.         return new Dimension(width, height);
  785.     }
  786. }
  787.  
  788.  
  789. /**
  790.  * This is an edit-box for entering the address to navigate to in the
  791.  * browser.
  792.  */
  793. class EditBox extends UIEdit
  794. {
  795.  
  796.     /**
  797.      * This creates a single line edit box
  798.      */
  799.     public EditBox()
  800.     {
  801.         setSingleLine(true);
  802.         setBackground(FxColor.white);
  803.     }
  804.  
  805.     /**
  806.      * The preferred size of this edit
  807.      *
  808.      * @return    Dimension    The preferred dimension
  809.      */
  810.     
  811.     public Dimension getPreferredSize()
  812.     {
  813.         return new Dimension(700, 16);
  814.     }
  815.  
  816.     /**
  817.      * The minimum size of this edit box
  818.      *
  819.      * @return    Dimension    The minimum size
  820.      */
  821.     public Dimension getMinimumSize()
  822.     {
  823.         return new Dimension(700, 16);
  824.     }
  825. }
  826.