![]()
Step 1 - Basics
Create a file called MyBrowser.java like the following:
import ice.storm.*; import java.awt.*; public class MyBrowser { public static void main(String[] args) { StormBase stormBase = new StormBase(); String location = "http://www.yahoo.com"; if (args.length > 0) { location = args[0]; } stormBase.setViewportCallback(new MyCallback()); stormBase.renderContent(location, null, "MyBrowser"); } } class MyCallback implements ViewportCallback { private StormBase stormBase; public Container createTopLevelContainer(Viewport viewport) { BrowserFrame browserFrame = new BrowserFrame(stormBase, viewport); browserFrame.setVisible(true); return browserFrame.getPanel(); } public void disposeTopLevelContainer(Viewport viewport) { // do nothing. } public void init(StormBase stormBase) { this.stormBase = stormBase; } public void processViewportMessage( Viewport viewport, String messageName, Object addArg, Object value) { // do nothing. } } class BrowserFrame extends Frame { private Panel contentPanel; private StormBase stormBase; BrowserFrame(StormBase stormBase, Viewport viewport) { this.stormBase = stormBase; contentPanel = new Panel(); add(contentPanel, BorderLayout.CENTER); setSize(600, 600); } Panel getPanel() { return contentPanel; } }The Import Statements
The ice.storm package is always required. The java.awt package is necessary for the application GUI.
The Static Main Method
This line creates a StormBase object:
StormBase stormBase = new StormBase( );This takes care of finding the right pilot, keeping track of the history, displaying the content in the AWT component, and so on.
This line provides StormBase with a ViewportCallback:
stormBase.setViewportCallback(new MyCallback( ));The callback object creates new containers and disposes them. It also provides an API for displaying toolkit independent dialogs.
The input arguments are parsed in a simple way and content is displayed with these lines:
String location = "http://www.yahoo.com"; if(args.length > 0) { location=args[0]; } stormBase.renderContent(location,null,"MyBrowser");The content type parameter of the method is unspecified (null).
If no URL is specified when the application is started, the browser displays the Yahoo home page. Provided the callback object is okay, this causes a window to appear and display the appropriate content.
The MyCallback Class
The StormBase object is referenced by means of a private property. The value is set by StormBase with the init method:
public void init(StormBase stormBase) { this.stormBase = stormBase; }The next method implemented is createTopLevelContainer( ).
public Container createTopLevelContainer(Viewport viewport) { BrowserFrame browserFrame = new BrowserFrame(stormBase, viewport); browserFrame.setVisible(true); return browserFrame.getPanel(); }The code creates a new BrowserFrame object, passes it the base and viewport, makes it visible, and returns it to the caller (StormBase).
For simplicity, the rest of the methods are not implemented.
The BrowserFrame Class
This extends the AWT Frame class, which extends the Window class, to be able to keep other lightweight containers, in this case a Panel, within it:
class BrowserFrame extends FrameA reference to the StormBase is kept, as well as to the Panel:
private Panel panel; private StormBase stormbase;The constructor sets the base property. For simplicity, ignore the viewport argument for now. The code also creates a Panel, adds it to itself (the window), and sets the size of the window:
BrowserFrame(StormBase stormBase, Viewport viewport) { this.stormBase = stormBase; contentPanel = new Panel(); add(contentPanel, BorderLayout.CENTER); setSize(600, 600); }This line provides a getter function for the panel property:
Panel getPanel() { return contentPanel; }
|
Copyright 2005. ICEsoft Technologies, Inc. http://www.icesoft.com |