Example usage for com.google.gwt.user.client.ui HorizontalPanel add

List of usage examples for com.google.gwt.user.client.ui HorizontalPanel add

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui HorizontalPanel add.

Prototype

@Override
    public void add(Widget w) 

Source Link

Usage

From source file:com.google.gerrit.client.changes.TopicScreen.java

License:Apache License

private void addComments(final TopicDetail detail) {
    comments.clear();//from  w w w .  j  a v a2s .  c  o  m

    final AccountInfoCache accts = detail.getAccounts();
    final List<TopicMessage> msgList = detail.getMessages();

    HorizontalPanel title = new HorizontalPanel();
    title.setWidth("100%");
    // TODO Do we need a new string constant?
    title.add(new Label(Util.C.changeScreenComments()));
    if (msgList.size() > 1) {
        title.add(messagesMenuBar());
    }
    title.setStyleName(Gerrit.RESOURCES.css().blockHeader());
    comments.add(title);

    final long AGE = 7 * 24 * 60 * 60 * 1000L;
    final Timestamp aged = new Timestamp(System.currentTimeMillis() - AGE);

    for (int i = 0; i < msgList.size(); i++) {
        final TopicMessage msg = msgList.get(i);

        final AccountInfo author;
        if (msg.getAuthor() != null) {
            author = accts.get(msg.getAuthor());
        } else {
            final Account gerrit = new Account(null);
            gerrit.setFullName(Util.C.messageNoAuthor());
            author = new AccountInfo(gerrit);
        }

        boolean isRecent;
        if (i == msgList.size() - 1) {
            isRecent = true;
        } else {
            // TODO Instead of opening messages by strict age, do it by "unread"?
            isRecent = msg.getWrittenOn().after(aged);
        }

        final CommentPanel cp = new CommentPanel(author, msg.getWrittenOn(), msg.getMessage());
        cp.setRecent(isRecent);
        cp.addStyleName(Gerrit.RESOURCES.css().commentPanelBorder());
        if (i == msgList.size() - 1) {
            cp.addStyleName(Gerrit.RESOURCES.css().commentPanelLast());
            cp.setOpen(true);
        }
        comments.add(cp);
    }

    comments.setVisible(msgList.size() > 0);
}

From source file:com.google.gerrit.client.ui.MenuScreen.java

License:Apache License

@Override
protected void onInitUI() {
    super.onInitUI();

    HorizontalPanel hp = new HorizontalPanel();
    hp.add(menu);
    hp.add(body);//  www. j  a  v a 2s  .  c  o m
    super.add(hp);
}

From source file:com.google.gwt.examples.ImageExample.java

License:Apache License

public void onModuleLoad() {
    // Create an image, not yet referencing a URL. We make it final so that we
    // can manipulate the image object within the ClickHandlers for the buttons.
    final Image image = new Image();

    // Hook up an error handler, so that we can be informed if the image fails
    // to load./*from w ww. ja  v a  2s  .c  o  m*/
    image.addErrorHandler(new ErrorHandler() {
        public void onError(ErrorEvent event) {
            lbl.setText("An error occurred while loading.");
        }
    });

    // Point the image at a real URL.
    image.setUrl("http://www.google.com/images/logo.gif");

    // When the user clicks this button, we want to clip the image.
    btn.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            image.setVisibleRect(70, 0, 47, 110);
        }
    });
    btn.setWidth("120px");

    // When the user clicks this button, we want to restore the image to its
    // unclipped state.
    btn2.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            image.setUrl("http://www.google.com/images/logo.gif");
        }
    });
    btn2.setWidth("120px");

    // Add the image, label, and clip/restore buttons to the root panel.
    VerticalPanel panel = new VerticalPanel();
    panel.add(lbl);
    panel.add(image);

    HorizontalPanel buttonPanel = new HorizontalPanel();
    buttonPanel.add(btn);
    buttonPanel.add(btn2);

    panel.add(buttonPanel);

    RootPanel.get().add(panel);
}

From source file:com.google.gwt.gadgets.sample.gadgetrpc.client.GadgetRPC.java

License:Apache License

@Override
protected void init(GadgetRPC.Preferences preferences) {

    gadgetService = GWT.create(GadgetService.class);
    ServiceDefTarget serviceDef = (ServiceDefTarget) gadgetService;
    String rpcUrl = serviceDef.getServiceEntryPoint();

    // Uses Gadgets container as proxy for GWT RPC requests
    GadgetsGwtRpc.redirectThroughProxy(serviceDef);

    // Build the user interface.
    VerticalPanel vp = new VerticalPanel();
    vp.setWidth("100%");

    vp.add(new Label("RPC to: " + rpcUrl));

    HorizontalPanel startedHp = new HorizontalPanel();
    startedHp.add(new Label("Server Start Time: "));
    startedHp.add(serverStartedText);// w w w. j  a  va 2  s.  com
    vp.add(startedHp);

    HorizontalPanel currentHp = new HorizontalPanel();
    currentHp.add(new Label("Server Current Time: "));
    currentHp.add(serverCurrentText);
    vp.add(currentHp);

    Button doRPCButton = new Button("Call RPC Method");
    vp.add(doRPCButton);

    vp.add(exceptionInfo);

    RootPanel.get().add(vp);

    // Setup a button listener to invoke the RPC.
    doRPCButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            gadgetService.getServerInfo(rpcCallback);
        }
    });
}

From source file:com.google.gwt.gdata.sample.hellogdata.client.HelloGData.java

License:Apache License

/**
 * Invoked when GData has loaded. Build the UI and display the default demo.
 *///from   w w  w . j  a va  2  s .  c  o m
public void onGDataLoad() {
    if (User.getStatus() == AuthSubStatus.LOGGING_IN) {
        /*
         * AuthSub causes a refresh of the browser, so if status is LOGGING_IN
         * don't render anything. An empty page refresh is friendlier.
         */
        return;
    }

    DecoratorPanel decorator = new DecoratorPanel();
    decorator.add(outerPanel);

    RootPanel.get().setStylePrimaryName("hm-body");
    RootPanel.get().add(new HTML("<img src='logo-small.png' alt='gwt logo' "
            + "align='absmiddle'><span class='hm-title'>Google GData API Library " + "for GWT Demo</span>"));
    RootPanel.get().add(decorator);

    innerPanel.setStylePrimaryName("hm-innerpanel");
    innerPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    innerPanel.setSpacing(10);

    outerPanel.setStylePrimaryName("hm-outerpanel");
    outerPanel.insertRow(0);
    outerPanel.insertRow(0);
    outerPanel.insertRow(0);
    outerPanel.insertRow(0);

    outerPanel.addCell(0);
    outerPanel.addCell(1);
    outerPanel.addCell(2);
    outerPanel.addCell(3);

    outerPanel.setWidget(0, 0,
            new HTML("This GData-enabled application was built using the GData " + "API Library for GWT, "
                    + "<a href=\"http://code.google.com/p/gwt-gdata/\">"
                    + "http://code.google.com/p/gwt-gdata/</a>. "
                    + "The drop down list below allows you to select a scenario that "
                    + "demonstrates a particular capability of the GData support."));

    outerPanel.setWidget(1, 0, innerPanel);

    HorizontalPanel horizPanel = new HorizontalPanel();
    list.setStylePrimaryName("hm-demolistbox");
    list.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            GDataDemoInfo info = list.getGDataDemoSelection();
            if (info == null) {
                showInfo();
            } else {
                show(info);
            }
        }
    });
    description.setStylePrimaryName("hm-description");
    innerPanel.clear();
    innerPanel.add(horizPanel);
    innerPanel.add(description);
    horizPanel.add(new Label("Select Demo: "));
    horizPanel.add(list);
    loadGDataDemos();
    showInfo();
}

From source file:com.google.gwt.gears.sample.database.client.DatabaseDemo.java

License:Apache License

public void onModuleLoad() {
    VerticalPanel outerPanel = new VerticalPanel();
    outerPanel.setSpacing(10);//from   ww w.j a v a  2  s .c o  m
    outerPanel.getElement().getStyle().setPropertyPx("margin", 15);

    HorizontalPanel textAndButtonsPanel = new HorizontalPanel();
    textAndButtonsPanel.add(new Label("Enter a Phrase: "));
    textAndButtonsPanel.add(input);
    textAndButtonsPanel.add(addButton);
    textAndButtonsPanel.add(clearButton);
    outerPanel.add(textAndButtonsPanel);
    outerPanel.add(new Label("Last 3 Entries:"));
    outerPanel.add(dataTable);

    for (int i = 0; i <= NUM_SAVED_ROWS; ++i) {
        dataTable.insertRow(i);
        for (int j = 0; j < NUM_DATA_TABLE_COLUMNS; j++) {
            dataTable.addCell(i);
        }
    }
    dataTable.setWidget(0, 0, new HTML("<b>Id</b>"));
    dataTable.setWidget(0, 1, new HTML("<b>Phrase</b>"));
    dataTable.setWidget(0, 2, new HTML("<b>Timestamp</b>"));

    // Create the database if it doesn't exist.
    try {
        db = Factory.getInstance().createDatabase();
        db.open("database-demo");
        db.execute(
                "CREATE TABLE IF NOT EXISTS Phrases (Id INTEGER PRIMARY KEY AUTOINCREMENT, Phrase VARCHAR(255), Timestamp INTEGER)");
    } catch (DatabaseException e) {
        RootPanel.get("demo").add(new HTML(
                "Error opening or creating database: <font color=\"red\">" + e.toString() + "</font>"));
        // Fatal error.  Do not build the interface.
        return;
    }

    input.addKeyboardListener(new KeyboardListenerAdapter() {
        @Override
        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KeyboardListener.KEY_ENTER) {
                insertPhrase();
            }
        }
    });

    addButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            insertPhrase();
        }
    });

    clearButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            clearPhrases();
            displayRecentPhrases();
        }
    });

    RootPanel.get("demo").add(outerPanel);
    displayRecentPhrases();
}

From source file:com.google.gwt.gears.sample.databasedemo.client.DatabaseDemo.java

License:Apache License

public void onModuleLoad() {
    VerticalPanel outerPanel = new VerticalPanel();
    outerPanel.setSpacing(10);//from  w  w  w. j av a 2  s  .  c  om
    outerPanel.getElement().getStyle().setPropertyPx("margin", 15);

    HorizontalPanel textAndButtonsPanel = new HorizontalPanel();
    textAndButtonsPanel.add(new Label("Enter a Phrase: "));
    textAndButtonsPanel.add(input);
    textAndButtonsPanel.add(addButton);
    textAndButtonsPanel.add(clearButton);
    outerPanel.add(textAndButtonsPanel);
    outerPanel.add(new Label("Last 3 Entries:"));
    outerPanel.add(dataTable);

    for (int i = 0; i <= NUM_SAVED_ROWS; ++i) {
        dataTable.insertRow(i);
        for (int j = 0; j < NUM_DATA_TABLE_COLUMNS; j++) {
            dataTable.addCell(i);
        }
    }
    dataTable.setWidget(0, 0, new HTML("<b>Id</b>"));
    dataTable.setWidget(0, 1, new HTML("<b>Phrase</b>"));
    dataTable.setWidget(0, 2, new HTML("<b>Timestamp</b>"));

    // Create the database if it doesn't exist.
    try {
        db = Factory.getInstance().createDatabase();
        db.open("database-demo");
        db.execute(
                "CREATE TABLE IF NOT EXISTS Phrases (Id INTEGER PRIMARY KEY AUTOINCREMENT, Phrase VARCHAR(255), Timestamp INTEGER)");
    } catch (DatabaseException e) {
        RootPanel.get("demo").add(new HTML(
                "Error opening or creating database: <font color=\"red\">" + e.toString() + "</font>"));
        // Fatal error. Do not build the interface.
        return;
    }

    input.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                insertPhrase();
            }
        }
    });

    addButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            insertPhrase();
        }
    });

    clearButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            clearPhrases();
            displayRecentPhrases();
        }
    });

    RootPanel.get("demo").add(outerPanel);
    displayRecentPhrases();
}

From source file:com.google.gwt.gears.sample.gwtnote.client.ui.RichTextWidget.java

License:Apache License

/**
 * Creates a new widget. This class needs access to certain fields and methods
 * on the application enclosing it./*  www.java 2  s . c om*/
 * 
 * @param parent the host application
 */
public RichTextWidget(final GWTNote parent) {
    super();

    VerticalPanel top = new VerticalPanel();
    top.setWidth("100%");
    HorizontalPanel header = new HorizontalPanel();
    top.add(header);
    header.setWidth("100%");

    header.add(new Label("GWT GearsNote"));

    header.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    status = new Label("Ready");
    header.add(status);

    this.bodyWidget = new RichTextArea();
    bodyWidget.addKeyboardListener(new KeyboardListenerAdapter() {
        @Override
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            String newText = bodyWidget.getText();
            if (((newText == null) && (curText != null)) || ((newText != null) && !newText.equals(curText))) {
                curText = newText;
            }
        }
    });

    HorizontalPanel controls = new HorizontalPanel();
    RichTextToolbar tb = new RichTextToolbar(this.bodyWidget);
    name = new TextBox();
    name.setText("default");
    name.setEnabled(false);
    nameEdit = new PushButton("Edit");
    nameEdit.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            String curName = name.getText();
            boolean doNotify = !oldName.equals(curName);
            if (!nameEditable) { // if becoming editable, store off current value
                oldName = curName;
            }
            if (nameEditable && (curName == null || "".equals(curName))) {
                // if becoming un-editable, check to make sure it's valid
                Window.alert("The note name cannot be blank. Please try again.");
                nameEdit.setText(oldName);
                return;
            }
            // if all else is good, just flip the state
            nameEditable = !nameEditable;
            name.setEnabled(nameEditable);
            nameEdit.getUpFace().setText((nameEditable ? "Confirm" : "Edit"));
            if (doNotify) {
                notifyNameListeners();
            }
        }
    });
    nameEdit.addStyleName("edit-button");

    options = new ListBox();
    controls.add(tb);
    options.addItem("default");
    options.setSelectedIndex(0);
    options.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            String newName = options.getItemText(options.getSelectedIndex());
            name.setText(newName);
            notifyNameListeners();
        }
    });
    HorizontalPanel tmp = new HorizontalPanel();
    tmp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    tmp.add(new Label("Note name:"));
    tmp.add(name);
    tmp.add(nameEdit);
    tmp.add(options);
    controls.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    controls.setWidth("100%");
    controls.add(tmp);
    top.add(controls);

    top.add(bodyWidget);
    this.bodyWidget.setWidth("100%");
    top.setCellHeight(bodyWidget, ((int) (Window.getClientHeight() * .75)) + "px");
    this.bodyWidget.setHeight("100%");

    initWidget(top);
}

From source file:com.google.gwt.gears.sample.managedresourcestore.client.ManagedResourceStoreDemo.java

License:Apache License

public void onModuleLoad() {
    HorizontalPanel hpanel = new HorizontalPanel();
    hpanel.setSpacing(10);//from w  w  w .jav  a2s. c o  m
    RootPanel.get("demo").add(hpanel);

    hpanel.add(createManagedResourceStoreButton);

    // See if we're already running from a ManagedResourceStore
    try {
        LocalServer server = Factory.getInstance().createLocalServer();

        // This check to see if the host page can be served locally
        if (server.canServeLocally(Window.Location.getPath())) {
            createManagedResourceStoreButton.setText("Refresh Manifest");

            // Give the user an opportunity to delete the MRS
            hpanel.add(removeManagedResourceStoreButton);
        }
    } catch (GearsException e) {
        // Gears probably isn't available (e.g. hosted mode)
    }

    createManagedResourceStoreButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            statusLabel.setText("Starting update");
            createManagedResourceStore();
        }
    });

    removeManagedResourceStoreButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            try {
                LocalServer server = Factory.getInstance().createLocalServer();
                ManagedResourceStore store = Offline.getManagedResourceStore();
                server.removeManagedStore(store.getName());
                statusLabel.setText("Removed ManagedResourceStore.  Press Refresh to see Online version.");
                createManagedResourceStoreButton.setEnabled(false);
                removeManagedResourceStoreButton.setEnabled(false);
            } catch (GearsException e) {
                statusLabel.setText(e.getMessage());
            }
        }
    });

    hpanel.add(statusLabel);
}

From source file:com.google.gwt.gears.sample.managedresourcestoredemo.client.ManagedResourceStoreDemo.java

License:Apache License

public void onModuleLoad() {
    HorizontalPanel hpanel = new HorizontalPanel();
    hpanel.setSpacing(10);//from w  ww .j  ava  2 s  . com
    RootPanel.get("demo").add(hpanel);

    hpanel.add(createManagedResourceStoreButton);

    // See if we're already running from a ManagedResourceStore
    try {
        LocalServer server = Factory.getInstance().createLocalServer();

        // This check to see if the host page can be served locally
        if (server.canServeLocally(Window.Location.getPath())) {
            createManagedResourceStoreButton.setText("Refresh Manifest");

            // Give the user an opportunity to delete the MRS
            hpanel.add(removeManagedResourceStoreButton);
        }
    } catch (GearsException e) {
        // Gears probably isn't available (e.g. hosted mode)
    }

    createManagedResourceStoreButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            statusLabel.setText("Starting update");
            createManagedResourceStore();
        }
    });

    removeManagedResourceStoreButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            try {
                LocalServer server = Factory.getInstance().createLocalServer();
                ManagedResourceStore store = Offline.getManagedResourceStore();
                server.removeManagedStore(store.getName());
                statusLabel.setText("Removed ManagedResourceStore.  Press Refresh to see Online version.");
                createManagedResourceStoreButton.setEnabled(false);
                removeManagedResourceStoreButton.setEnabled(false);
            } catch (GearsException e) {
                statusLabel.setText(e.getMessage());
            }
        }
    });

    hpanel.add(statusLabel);
}