Package org.gwtoolbox.sample.mail.client

Source Code of org.gwtoolbox.sample.mail.client.ContentPanel$Images

/*
* Copyright (c) 2006-2007 The original author(s).
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package org.gwtoolbox.sample.mail.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.WindowResizeListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import org.gwtoolbox.sample.mail.client.ui.MailDetail;
import org.gwtoolbox.sample.mail.client.ui.MailList;
import org.gwtoolbox.sample.mail.client.ui.Shortcuts;
import org.gwtoolbox.sample.mail.client.ui.TopPanel;

/**
* @author Bram Smeets
*/
public class ContentPanel extends Composite implements WindowResizeListener {

    private static ContentPanel singleton;

    /**
     * Instantiate an application-level image bundle. This object will provide
     * programmatic access to all the images needed by widgets.
     */
    private static final Images images = (Images) GWT.create(Images.class);

    /**
     * An aggragate image bundle that pulls together all the images for this
     * application into a single bundle.
     */
    public interface Images extends Shortcuts.Images, TopPanel.Images {
    }

    /**
     * Gets the singleton Mail instance.
     */
    public static ContentPanel get() {
        return singleton;
    }

    /**
     * Displays the specified item.
     *
     * @param item
     */
    public void displayItem(MailItem item) {
        mailDetail.setItem(item);
    }

    private TopPanel topPanel = new TopPanel(images);
    private VerticalPanel rightPanel = new VerticalPanel();
    private MailList mailList;
    private MailDetail mailDetail = new MailDetail();
    private Shortcuts shortcuts = new Shortcuts(images);

    public ContentPanel() {
        singleton = this;
       
        topPanel.setWidth("100%");

        // MailList uses Mail.get() in its constructor, so initialize it after
        // 'singleton'.
        mailList = new MailList();
        mailList.setWidth("100%");

        // Create the right panel, containing the email list & details.
        rightPanel.add(mailList);
        rightPanel.add(mailDetail);
        mailList.setWidth("100%");
        mailDetail.setWidth("100%");

        // Create a dock panel that will contain the menu bar at the top,
        // the shortcuts to the left, and the mail list & details taking the rest.
        DockPanel outer = new DockPanel();
        outer.add(topPanel, DockPanel.NORTH);
        outer.add(shortcuts, DockPanel.WEST);
        outer.add(rightPanel, DockPanel.CENTER);
        outer.setWidth("100%");

        outer.setSpacing(4);
        outer.setCellWidth(rightPanel, "100%");

        // Hook the window resize event, so that we can adjust the UI.
        Window.addWindowResizeListener(this);

        // Get rid of scrollbars, and clear out the window's built-in margin,
        // because we want to take advantage of the entire client area.
        Window.enableScrolling(false);
        Window.setMargin("0px");

        // Finally, add the outer panel to the RootPanel, so that it will be
        // displayed.
        initWidget(outer);

        // Call the window resized handler to get the initial sizes setup. Doing
        // this in a deferred command causes it to occur after all widgets' sizes
        // have been computed by the browser.
        DeferredCommand.addCommand(new Command() {
            public void execute() {
                onWindowResized(Window.getClientWidth(), Window.getClientHeight());
            }
        });

        onWindowResized(Window.getClientWidth(), Window.getClientHeight());
    }

    public void onWindowResized(int width, int height) {
        // Adjust the shortcut panel and detail area to take up the available room
        // in the window.
        int shortcutHeight = height - shortcuts.getAbsoluteTop() - 8;
        if (shortcutHeight < 1) {
            shortcutHeight = 1;
        }
        shortcuts.setHeight("" + shortcutHeight);

        // Give the mail detail widget a chance to resize itself as well.
        mailDetail.adjustSize(width, height);
    }
}
TOP

Related Classes of org.gwtoolbox.sample.mail.client.ContentPanel$Images

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.