Hands-on Google Web Toolkit 
by Ed Burnette and Adam Houghton

Listing 1:

<html>
    <head>
        <title>GWTFlow</title>
        <link rel="stylesheet" type="text/css" href="GWTFlow.css" />
    </head>
    <body>
    <div id="header">
        <div id="logo">
            <a class="blind" href="GWTFlow.html">GWTFlow</a>
        </div>
        <p>
            <a class="tblind" href="about.html">About</a> &nbsp;&nbsp; 
            <a class="tblind" href="contact.html">Contact</a>
        </p>
    </div>
    <div id="footer">
        <p>Copyright 2007 Adam Houghton</p>
    </div>
    </body>
</html>


Listing 2:

<html>
    <head>
        <title>GWTFlow</title>
        <link rel="stylesheet" type="text/css" href="GWTFlow.css" />
        <!-- Inject GWT code by including compiled JavaScript file -->
        <script language='javascript' src='org.gwtflow.GWTFlow.nocache.js'></script>
        <!-- JavaScript we'll later need for effects -->
        <script type="text/javascript" src="script/prototype.js"></script>
        <script type="text/javascript" src="script/effects.js"></script>
    </head>
    <body>
    <!-- IFrame for GWT history support -->
    <iframe src="javascript:''" id="__gwt_historyFrame"
            style="width:0;height:0;border:0"></iframe>
    <div id="header">
        <div id="logo">
            <a class="blind" href="GWTFlow.html">GWTFlow</a>
        </div>
        <p>
            <a class="tblind" href="about.html">About</a> &nbsp;&nbsp; 
            <a class="tblind" href="contact.html">Contact</a>
        </p>
    </div>
    <!-- GWTFlow will put its content in this div -->
    <div id="main"></div>
    <div id="footer">
        <p>Copyright 2007 Adam Houghton</p>
    </div>
    </body>
</html>


Listing 3:

    private void calcPositions(int imageIdx, int centerX, int centerY, 
            int[][] whxy, boolean drawImages, boolean animLoad) { 
        if (imageIdx < 0 || imageIdx >= images.length) { 
            return;
        }
        int distFromCenter = Math.abs(selIdx - imageIdx);
        int maxWidth = getMaxWidth(distFromCenter);
        int maxHeight = getMaxHeight(distFromCenter);

        int[] wh = scaleImage(dtos[imageIdx].width, dtos[imageIdx].height, 
                maxWidth, maxHeight);
        int xDiff = (int)(maxWidth*.75);
        if (imageIdx < selIdx) { 
            centerX -= xDiff;
        } 
        else if (imageIdx > selIdx) {
            centerX += xDiff;
        }
        if (drawImages) { 
            images[imageIdx].setWidth(wh[0] + "px");
            images[imageIdx].setHeight(wh[1] + "px");
        }
        int[] xy = positionImage(wh[0], wh[1], centerX, centerY);

        // Recursive calls to calculate positions to the left/right
        if (imageIdx <= selIdx) { 
            calcPositions(imageIdx - 1, centerX, centerY, whxy, drawImages, animLoad);
        } 
        if (imageIdx >= selIdx) { 
            calcPositions(imageIdx + 1, centerX, centerY, whxy, drawImages, animLoad);
        }
        whxy[imageIdx] = new int[] { wh[0], wh[1], xy[0], xy[1] } ;
    
        if (drawImages) {
            // If first time we load, we'll use the Scriptaculous grow effect
            // for any images that are in the viewport
            if (animLoad && inViewport(xy[0], images[imageIdx].getWidth())) { 
                images[imageIdx].setVisible(false);
                
                images[imageIdx].addLoadListener(new LoadListener() {
                    public void onError(Widget sender) {
                    }
                    public void onLoad(Widget sender) {
                        Effect.grow(sender, new EffectOption[] { 
                                new EffectOption("duration", LOAD_DURATION)});
                    }
                });            
            }
            // Adding image to the panel - last added are on top, so we add from
            // the outside in.
            this.add(images[imageIdx], xy[0], xy[1]);
        }
    }


Listing 4:

    private void animateMove(Widget widget, int left, int top, double dur) 
    {
        Effect.move(widget, new EffectOption[] { new EffectOption("mode", "absolute"),
            new EffectOption("x", left), new EffectOption("y", top), 
            new EffectOption("duration", dur)} );
    }



Listing 5:

    public AlbumDTO[] getFlickrAlbums(String username) throws IOException,
            SAXException, FlickrException 
    {
        Flickr flickr = FlickrUtil.getInstance(); // Access Flickr using API key
        PeopleInterface people = flickr.getPeopleInterface();
        User user = people.findByUsername(username);
        PhotosetsInterface photoSets = flickr.getPhotosetsInterface();
        Collection sets = photoSets.getList(user.getId()).getPhotosets();
        AlbumDTO[] albums = new AlbumDTO[sets.size()];
        Iterator iter = sets.iterator();
        for (int i = 0; i < albums.length; i++) {
            Photoset set = (Photoset) iter.next();
            albums[i] = new AlbumDTO(); // Custom POJO w/Album metadata
            albums[i].id = set.getId();
            albums[i].name = set.getTitle();
            albums[i].description = set.getDescription();
            albums[i].imageCount = set.getPhotoCount();
            albums[i].smallSquareUrl = set.getPrimaryPhoto().getSmallSquareUrl();
        }
        return albums;
    }





3


