Package org.gwtoolbox.sample.mail.client.ui

Source Code of org.gwtoolbox.sample.mail.client.ui.Contacts$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.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.*;
import org.gwtoolbox.sample.mail.client.Contact;
import org.gwtoolbox.sample.mail.client.Name;
import org.gwtoolbox.widget.client.active.ActiveLabel;

import java.util.Date;

/**
* @author Bram Smeets
*/
public class Contacts extends Composite {

    private static final DateTimeFormat birthDateFormatter = DateTimeFormat.getFormat("dd-MM-yyyy");

    /**
     * An image bundle for this widget and an example of the use of @gwt.resource.
     */
    public interface Images extends ImageBundle {
        /** @gwt.resource default_photo.jpg */
        AbstractImagePrototype defaultPhoto();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/225px-Benoit_Mandelbrot_mg_1804.jpg */
        AbstractImagePrototype photoMandelbrot();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/220px-Albert_Einstein_Head.jpg */
        AbstractImagePrototype photoEinstein();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/200px-Descartes.jpg */
        AbstractImagePrototype photoDescartes();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/220px-Bob_Saget.jpg */
        AbstractImagePrototype photoSaget();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/300px-Beethoven.jpg */
        AbstractImagePrototype photoBeethoven();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/300px-Feynman-book-cover-pic.jpg */
        AbstractImagePrototype photoFeynman();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/220px-Alan_Turing.jpg */
        AbstractImagePrototype photoTuring();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/200px-JohnvonNeumann-LosAlamos.jpg */
        AbstractImagePrototype photoNeumann();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/225px-Benoit_Mandelbrot_mg_1804_thumb.jpg */
        AbstractImagePrototype thumbMandelbrot();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/220px-Albert_Einstein_Head_thumb.jpg */
        AbstractImagePrototype thumbEinstein();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/200px-Descartes_thumb.jpg */
        AbstractImagePrototype thumbDescartes();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/220px-Bob_Saget_thumb.jpg */
        AbstractImagePrototype thumbSaget();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/300px-Beethoven_thumb.jpg */
        AbstractImagePrototype thumbBeethoven();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/300px-Feynman-book-cover-pic_thumb.jpg */
        AbstractImagePrototype thumbFeynman();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/220px-Alan_Turing_thumb.jpg */
        AbstractImagePrototype thumbTuring();

        /** @gwt.resource org/gwtoolbox/sample/mail/images/200px-JohnvonNeumann-LosAlamos_thumb.jpg */
        AbstractImagePrototype thumbNeumann();
    }

    private Contact[] contacts;

    private FlexTable table = new FlexTable();
    private final Images images;

    public Contacts(Images images) {
        SimplePanel outer = new SimplePanel();
        outer.setWidget(table);

        this.images = images;

        createAllContacts();

        // Add all the contacts to the list.
        for (int i = 0; i < contacts.length; ++i) {
          addContact(i, contacts[i]);
        }

        initWidget(new ScrollPanel(outer));
        setStyleName("mail-Contacts");
    }

    private void createAllContacts() {
        contacts = new Contact[] {
            createContact("Benoit", null, "Mandelbrot", "benoit@example.com", false, birthDateFormatter.parse("20-11-1924"), images.photoMandelbrot(), images.thumbMandelbrot()),
            createContact("Albert", null, "Einstein", "albert@example.com", true, birthDateFormatter.parse("14-03-1879"), images.photoEinstein(), images.thumbEinstein()),
            createContact("Rene", null, "Descartes", "rene@example.com", false, birthDateFormatter.parse("31-03-1596"), images.photoDescartes(), images.thumbDescartes()),
            createContact("Bob", null, "Saget", "bob@example.com", false, birthDateFormatter.parse("17-05-1956"), images.photoSaget(), images.thumbSaget()),
            createContact("Ludwig", "von", "Beethoven", "ludwig@example.com", false, birthDateFormatter.parse("17-12-1770"), images.photoBeethoven(), images.thumbBeethoven()),
            createContact("Richard", null, "Feynman", "richard@example.com", false, birthDateFormatter.parse("11-05-1918"), images.photoFeynman(), images.thumbFeynman()),
            createContact("Alan", null, "Turing", "alan@example.com", false, birthDateFormatter.parse("23-06-1912"), images.photoTuring(), images.thumbTuring()),
            createContact("John", "von", "Neumann", "john@example.com", false, birthDateFormatter.parse("28-12-1903"), images.photoNeumann(), images.thumbNeumann())
        };
    }

    private Contact createContact(String firstName, String middleName, String lastName, String email,
                                  boolean privateContact, Date birthDate,
                                  AbstractImagePrototype image, AbstractImagePrototype thumb) {
        Contact contact = (Contact) GWT.create(Contact.class);
        Name name = (Name) GWT.create(Name.class);
        name.setFirstName(firstName);
        name.setMiddleName(middleName);
        name.setLastName(lastName);
        contact.setName(name);
        contact.setEmail(email);
        contact.setPrivateContact(privateContact);
        contact.setBirthDate(birthDate);
        contact.setImage(image.createImage());
        contact.setThumb(thumb.createImage());
        return contact;
    }

    private void addContact(int row, final Contact contact) {
        ClickListener listener = new ClickListener() {
            public void onClick(Widget sender) {
                ContactDialog dialog = new ContactDialog(contact);
                dialog.show();
                dialog.center();
            }
        };

        Image thumb = contact.getThumb();
        thumb.addClickListener(listener);
        DOM.setStyleAttribute(thumb.getElement(), "cursor", "pointer");
        table.setWidget(row, 0, thumb);
        table.getCellFormatter().setAlignment(row, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);

        ActiveLabel label = new ActiveLabel(contact, "name");
        label.addClickListener(listener);
        DOM.setStyleAttribute(label.getElement(), "cursor", "pointer");
        table.setWidget(row, 1, label);
        table.getCellFormatter().setAlignment(row, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_MIDDLE);
    }

}
TOP

Related Classes of org.gwtoolbox.sample.mail.client.ui.Contacts$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.