Example usage for com.vaadin.ui VerticalLayout setComponentAlignment

List of usage examples for com.vaadin.ui VerticalLayout setComponentAlignment

Introduction

In this page you can find the example usage for com.vaadin.ui VerticalLayout setComponentAlignment.

Prototype

@Override
    public void setComponentAlignment(Component childComponent, Alignment alignment) 

Source Link

Usage

From source file:edu.kit.dama.ui.admin.ProfileView.java

License:Apache License

/**
 * Build the main layout./*w  ww .  j av a 2  s.  com*/
 */
private void buildMainLayout() {
    //information area
    screenName = new Label();
    screenName.setCaption("Screen Name:");
    screenName.setStyleName("form");
    firstName = new Label();
    firstName.setCaption("First Name:");
    firstName.setStyleName("form");
    lastName = new Label();
    lastName.setCaption("Last Name:");
    lastName.setStyleName("form");
    email = new Label();
    email.setCaption("Email:");
    email.setStyleName("form");
    FormLayout userInformationForm = new FormLayout(screenName, firstName, lastName, email);
    userInformationForm.setStyleName("form");
    userInformationForm.setCaption("User Information");
    tokenDialog = new ServiceAccessTokenDialog();
    //Credentials
    //table with serviceId, key, secret for logged in userId
    //---mainLogin and webdav are special (username = email), others can be configured in AuthenticatorFactory
    //---support for adding/regenerating new tokens (support for random secrets)
    //---support for blocking?
    //---'show secrets' button
    credentialTable = new Table("Credentials");
    credentialTable.setSelectable(true);
    credentialTable.setMultiSelect(false);
    credentialTable.addContainerProperty("ServiceId", String.class, null);
    credentialTable.addContainerProperty("Key", String.class, null);
    credentialTable.addContainerProperty("Secret", String.class, null);
    credentialTable.addStyleName("myboldcaption");
    credentialTable.setSizeFull();

    Button addCredential = new Button();
    addCredential.setIcon(new ThemeResource(IconContainer.ADD));
    Button modifyCredential = new Button();
    modifyCredential.setIcon(new ThemeResource(IconContainer.EDIT));
    Button removeCredential = new Button();
    removeCredential.setIcon(new ThemeResource(IconContainer.DELETE));
    Button reloadCredentialTable = new Button();
    reloadCredentialTable.setIcon(new ThemeResource(IconContainer.REFRESH));
    reloadCredentialTable.addClickListener(((event) -> {
        reload();
    }));

    CheckBox showPasswords = new CheckBox("Show Secrets");
    showPasswords.addValueChangeListener((Property.ValueChangeEvent event) -> {
        showSecrets(showPasswords.getValue());
    });

    removeCredential.addClickListener((event) -> {
        Long selection = (Long) credentialTable.getValue();
        if (selection != null) {
            ConfirmationWindow7.showConfirmation("Delete Credential",
                    "If you delete the selected credential, you won't be able to access the associated service any longer.<br/> "
                            + "Do you wish to proceed?",
                    ConfirmationWindow7.OPTION_TYPE.YES_NO_OPTION, ConfirmationWindow7.MESSAGE_TYPE.WARNING,
                    (ConfirmationWindow7.RESULT pResult) -> {
                        switch (pResult) {
                        case YES:
                            removeCredential(selection);
                            break;
                        default:
                            //do nothing
                        }
                    });
        }

    });

    modifyCredential.addClickListener((event) -> {
        Long selection = (Long) credentialTable.getValue();
        if (selection != null) {
            updateCredential(selection);
        }
    });

    addCredential.addClickListener((event) -> {
        createCredential();
    });

    VerticalLayout buttonLayout = new VerticalLayout(addCredential, modifyCredential, removeCredential,
            reloadCredentialTable);

    buttonLayout.setComponentAlignment(modifyCredential, Alignment.TOP_LEFT);
    buttonLayout.setComponentAlignment(removeCredential, Alignment.TOP_LEFT);
    buttonLayout.setComponentAlignment(reloadCredentialTable, Alignment.TOP_LEFT);
    buttonLayout.setMargin(true);

    UIUtils7.GridLayoutBuilder builder = new UIUtils7.GridLayoutBuilder(2, 3);

    builder.fillRow(userInformationForm, 0, 0, 1);
    builder.addComponent(credentialTable, 0, 1).addComponent(buttonLayout, 1, 1);
    builder.fillRow(showPasswords, 0, 2, 1);
    mainLayout = builder.getLayout();

    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);
    mainLayout.setRowExpandRatio(1, 1.0f);
    mainLayout.setColumnExpandRatio(0, .9f);
    mainLayout.setColumnExpandRatio(1, .1f);
    mainLayout.setSizeFull();
    reload();
}

From source file:edu.kit.dama.ui.admin.schedule.SchedulerBasePropertiesLayout.java

License:Apache License

/**
 * Default constructor.//from w w  w  . j a  v  a 2  s  . co m
 */
public SchedulerBasePropertiesLayout() {
    super();
    LOGGER.debug("Building " + DEBUG_ID_PREFIX + " ...");

    setId(DEBUG_ID_PREFIX.substring(0, DEBUG_ID_PREFIX.length() - 1));

    setSizeFull();
    setMargin(true);
    setSpacing(true);

    setColumns(3);
    setRows(3);
    //first row
    addComponent(getIdField(), 0, 0);
    addComponent(getGroupField(), 1, 0);
    addComponent(getNameField(), 2, 0);

    //second row
    addComponent(getDescriptionArea(), 0, 1, 2, 1);
    Button addTriggerButton = new Button();
    addTriggerButton.setDescription("Add a new trigger.");
    addTriggerButton.setIcon(new ThemeResource(IconContainer.ADD));
    addTriggerButton.addClickListener((Button.ClickEvent event) -> {
        addTrigger();
    });

    Button removeTriggerButton = new Button();
    removeTriggerButton.setDescription("Remove the selected trigger.");
    removeTriggerButton.setIcon(new ThemeResource(IconContainer.DELETE));
    removeTriggerButton.addClickListener((Button.ClickEvent event) -> {
        removeTrigger();
    });

    Button refreshTriggerButton = new Button();
    refreshTriggerButton.setDescription("Refresh the list of triggers.");
    refreshTriggerButton.setIcon(new ThemeResource(IconContainer.REFRESH));
    refreshTriggerButton.addClickListener((Button.ClickEvent event) -> {
        reloadTriggers();
    });

    VerticalLayout buttonLayout = new VerticalLayout(addTriggerButton, refreshTriggerButton,
            removeTriggerButton);
    buttonLayout.setComponentAlignment(addTriggerButton, Alignment.TOP_RIGHT);
    buttonLayout.setComponentAlignment(removeTriggerButton, Alignment.TOP_RIGHT);
    buttonLayout.setMargin(true);

    GridLayout triggerLayout = new UIUtils7.GridLayoutBuilder(2, 2).addComponent(getTriggerTable(), 0, 0, 1, 2)
            .addComponent(buttonLayout, 1, 0, 1, 2).getLayout();
    triggerLayout.setSizeFull();
    triggerLayout.setMargin(false);
    triggerLayout.setColumnExpandRatio(0, .95f);
    triggerLayout.setColumnExpandRatio(1, .05f);
    triggerLayout.setRowExpandRatio(0, .9f);
    triggerLayout.setRowExpandRatio(1, .05f);
    triggerLayout.setRowExpandRatio(2, .05f);

    //third row
    addComponent(triggerLayout, 0, 2, 2, 2);
    addTriggerComponent = new AddTriggerComponent(this);

    setRowExpandRatio(1, .3f);
    setRowExpandRatio(2, .6f);
}

From source file:edu.kit.dama.ui.admin.wizard.FirstStartWizard.java

License:Apache License

private void buildMainLayout() {
    stepLayout = new VerticalLayout();

    back.setEnabled(false);/*w  w  w  .  j  av  a  2 s .  c  om*/
    stepLayout.addComponent(stepList[currentStep]);
    stepLayout.setComponentAlignment(stepList[currentStep], Alignment.TOP_RIGHT);
    stepLayout.setSpacing(false);
    stepLayout.setMargin(false);
    stepLayout.setWidth("100%");
    stepLayout.setHeight("500px");

    final VerticalLayout stepLabels = new VerticalLayout();
    for (WizardStep step : stepList) {
        Label stepLabel = new Label(step.getStepName());
        stepLabel.setWidth("250px");
        stepLabels.addComponent(stepLabel);
        stepLabels.setComponentAlignment(stepLabel, Alignment.TOP_LEFT);
    }

    //make introduction label bold
    stepLabels.getComponent(0).addStyleName("myboldcaption");

    Label spacer = new Label();
    stepLabels.addComponent(spacer);
    stepLabels.setExpandRatio(spacer, 1.0f);
    stepLabels.setWidth("275px");
    stepLabels.setHeight("550px");
    stepLabels.setSpacing(true);

    UIUtils7.GridLayoutBuilder builder = new UIUtils7.GridLayoutBuilder(2, 2);

    HorizontalLayout buttonLayout = new HorizontalLayout(back, next);
    buttonLayout.setSizeFull();
    buttonLayout.setComponentAlignment(back, Alignment.BOTTOM_RIGHT);
    buttonLayout.setComponentAlignment(next, Alignment.BOTTOM_RIGHT);
    buttonLayout.setExpandRatio(back, 1.0f);

    next.addClickListener((event) -> {
        if ("Go To Login".equals(next.getCaption())) {
            Page.getCurrent().reload();
        } else if ("Finish".equals(next.getCaption())) {
            //do finish
            WizardPersistHelper helper = new WizardPersistHelper();
            if (helper.persist(properties)) {
                UIUtils7.showInformation("Success",
                        "All information have been successfully stored into the database. For details, please refer to the log output above.\n"
                                + "You may now dismiss this message and click 'Go To Login' in order to access the login page.\n"
                                + "From there you can to login using your administrator account or create a personalized user account.",
                        3000);
                back.setVisible(false);
                next.setCaption("Go To Login");
            } else {
                UIUtils7.showError("Failed to store collected information in database.\n"
                        + "Please refer to the log output above.");
            }
            ((WizardSummary) stepList[currentStep]).setSummary(helper.getMessages());
        } else {
            if (currentStep + 1 <= stepList.length - 1) {
                if (stepList[currentStep].validate()) {
                    stepList[currentStep].collectProperties(properties);
                    currentStep++;
                    stepLayout.replaceComponent(stepList[currentStep - 1], stepList[currentStep]);
                    Label currentLabel = (Label) stepLabels.getComponent(currentStep);
                    Label prevLabel = (Label) stepLabels.getComponent(currentStep - 1);
                    currentLabel.addStyleName("myboldcaption");
                    prevLabel.removeStyleName("myboldcaption");

                    if (stepList[currentStep] instanceof WizardSummary) {
                        StringBuilder summary = new StringBuilder();
                        for (WizardStep step : stepList) {
                            summary.append(step.getSummary()).append("\n");
                        }
                        ((WizardSummary) stepList[currentStep]).setSummary(summary.toString());
                    }
                }
            }

            if (currentStep == stepList.length - 1) {
                //finish
                next.setCaption("Finish");
            } else {
                next.setCaption("Next");
            }

            back.setEnabled(true);
        }
    });

    back.addClickListener((event) -> {
        if (currentStep - 1 >= 0) {
            stepList[currentStep].collectProperties(properties);
            currentStep--;
            stepLayout.replaceComponent(stepList[currentStep + 1], stepList[currentStep]);
            Label currentLabel = (Label) stepLabels.getComponent(currentStep);
            Label prevLabel = (Label) stepLabels.getComponent(currentStep + 1);
            currentLabel.addStyleName("myboldcaption");
            prevLabel.removeStyleName("myboldcaption");
        }
        next.setEnabled(true);
        back.setEnabled(currentStep > 0);
        next.setCaption("Next");
    });

    builder.addComponent(stepLabels, Alignment.TOP_LEFT, 0, 0, 1, 2);
    builder.addComponent(stepLayout, Alignment.TOP_LEFT, 1, 0, 1, 1);
    builder.addComponent(buttonLayout, Alignment.BOTTOM_LEFT, 1, 1, 1, 1);

    mainLayout = builder.getLayout();
    mainLayout.setMargin(true);
    mainLayout.setSizeFull();

    // mainLayout.setColumnExpandRatio(0, .3f);
    mainLayout.setColumnExpandRatio(1, 1f);
    mainLayout.setRowExpandRatio(0, .95f);
    mainLayout.setRowExpandRatio(1, .05f);
}

From source file:edu.kit.dama.ui.commons.util.PaginationLayout.java

License:Apache License

/**
 * Fill the pagination listing based on a specific query to obtain valid
 * objects.// ww  w .j av  a  2  s  .c om
 */
private void renderPage() {
    //obtain the objects of this page (5 entries per page are shown)
    int start = currentPage * entriesPerPage;
    //initialize page panel and layout
    page = new Panel();
    page.setCaption(caption);
    page.setImmediate(true);
    page.setIcon(icon);
    VerticalLayout pageLayout = new VerticalLayout();
    pageLayout.setMargin(true);
    pageLayout.setImmediate(true);
    pageLayout.setSizeUndefined();
    page.setSizeFull();
    List<C> entries;

    if (overallEntries > 0) {
        AbstractComponent header = callback.renderHeader();
        if (header != null) {
            pageLayout.addComponent(header);
            pageLayout.setComponentAlignment(header, Alignment.TOP_LEFT);
        }
        entries = callback.getEntries(this, start);
        //add all objects of this page
        int objectIdx = 1;
        for (C entry : entries) {
            AbstractComponent renderedEntry = callback.renderEntry(entry, start + objectIdx);

            pageLayout.addComponent(renderedEntry);
            pageLayout.setComponentAlignment(renderedEntry, Alignment.TOP_CENTER);
            Label spacer = new Label("<hr/>", Label.CONTENT_XHTML);
            spacer.setHeight("3px");
            spacer.setWidth("100%");
            pageLayout.addComponent(spacer);
            pageLayout.setComponentAlignment(spacer, Alignment.TOP_CENTER);
            objectIdx++;
        }

        //if there are less than 'entriesPerPage' entries, add a 'filler' to keep the actual items on top of the layout
        if (objectIdx < entriesPerPage) {
            Label filler = new Label();
            pageLayout.addComponent(filler);
            pageLayout.setExpandRatio(filler, 1.0f);
        }
    } else {
        //nothing visible
        Label filler = new Label("No entries available");
        pageLayout.addComponent(filler);
        pageLayout.setExpandRatio(filler, 1.0f);
    }

    page.setContent(pageLayout);
}

From source file:edu.kit.dama.ui.commons.util.UIUtils7.java

License:Apache License

public static void openResourceSubWindow(File sourceFile) {
    boolean fileAccessible = sourceFile != null && sourceFile.exists() && sourceFile.canRead();

    // Set subwindow for displaying file resource
    final Window window = new Window(fileAccessible ? sourceFile.getName() : "Information");
    window.center();/*ww  w .  j a v a  2 s  .co m*/
    // Set window layout
    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setSizeFull();

    if (fileAccessible) {
        // Set resource that has to be embedded
        final Embedded resource = new Embedded(null, new FileResource(sourceFile));
        if ("application/octet-stream".equals(resource.getMimeType())) {
            window.setWidth("570px");
            window.setHeight("150px");
            windowLayout.setMargin(true);

            Label attentionNote = new Label(
                    "A file preview is not possible as the file type is not supported by your browser.");
            attentionNote.setContentMode(ContentMode.HTML);
            Link fileURL = new Link("Click here for downloading the file.", new FileResource(sourceFile));

            windowLayout.addComponent(attentionNote);
            windowLayout.addComponent(fileURL);
            windowLayout.setComponentAlignment(attentionNote, Alignment.MIDDLE_CENTER);
            windowLayout.setComponentAlignment(fileURL, Alignment.MIDDLE_CENTER);
        } else {
            window.setResizable(true);
            window.setWidth("800px");
            window.setHeight("500px");
            final Image image = new Image(null, new FileResource(sourceFile));
            image.setSizeFull();
            windowLayout.addComponent(image);
        }
    } else {
        //file is not accessible
        window.setWidth("570px");
        window.setHeight("150px");
        windowLayout.setMargin(true);
        Label attentionNote = new Label("Provided file cannot be accessed.");
        attentionNote.setContentMode(ContentMode.HTML);
        windowLayout.addComponent(attentionNote);
        windowLayout.setComponentAlignment(attentionNote, Alignment.MIDDLE_CENTER);
    }

    window.setContent(windowLayout);
    UI.getCurrent().addWindow(window);
}

From source file:edu.kit.dama.ui.repo.MyVaadinUI.java

License:Apache License

/**
 * Build the search view and execute the provided query immediately.
 *
 * @param pQuery The query to execute or null if an empty view should be
 * shown./*w ww  . j  a v a 2s.  c om*/
 */
private void buildSearchView(String pQuery) {
    loginButton.setWidth("70px");
    loginButton.setStyleName(BaseTheme.BUTTON_LINK);
    logoutButton.setWidth("70px");
    logoutButton.setStyleName(BaseTheme.BUTTON_LINK);
    adminButton.setWidth("70px");
    adminButton.setStyleName(BaseTheme.BUTTON_LINK);

    logoutButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            loggedInUser = UserData.NO_USER;
            refreshMainLayout();
        }
    });

    adminButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Page.getCurrent()
                    .open(DataManagerSettings.getSingleton().getStringProperty(
                            DataManagerSettings.GENERAL_BASE_URL_ID, "http://localhost:8889/BaReDemo")
                            + "/admin", "_blank");
        }
    });

    searchField = UIUtils7.factoryTextField(null, "Search for...");
    searchField.setWidth("920px");
    searchField.setHeight("60px");
    searchField.addStyleName("searchField");

    paginationPanel = new PaginationPanel(this);
    paginationPanel.setSizeFull();
    paginationPanel.setAllEntries(new LinkedList<DigitalObjectId>());

    searchProvider = new FulltextElasticSearchProvider(
            DataManagerSettings.getSingleton()
                    .getStringProperty(DataManagerSettings.ELASTIC_SEARCH_DEFAULT_CLUSTER_ID, "KITDataManager"),
            DataManagerSettings.getSingleton()
                    .getStringProperty(DataManagerSettings.ELASTIC_SEARCH_DEFAULT_HOST_ID, "localhost"),
            DataManagerSettings.getSingleton().getStringProperty(
                    DataManagerSettings.ELASTIC_SEARCH_DEFAULT_INDEX_ID,
                    ElasticsearchHelper.ELASTICSEARCH_TYPE),
            ElasticsearchHelper.ELASTICSEARCH_TYPE);
    NativeButton goButton = new NativeButton();
    goButton.setIcon(new ThemeResource("img/24x24/search.png"));
    goButton.setWidth("60px");
    goButton.setHeight("60px");
    goButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            doSearch();
        }
    });
    goButton.setClickShortcut(KeyCode.ENTER);

    setupLoginForm();
    loginForm.setWidth("320px");
    loginForm.setHeight("150px");
    final PopupView loginPopup = new PopupView(null, loginForm);
    loginPopup.setHideOnMouseOut(false);
    loginButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            //mainLayout.replaceComponent(searchLayout, loginForm);
            loginPopup.setPopupVisible(true);
        }
    });

    Label filler = new Label();
    memberLayout = new HorizontalLayout(filler, adminButton, loginButton, loginPopup);
    memberLayout.setComponentAlignment(loginButton, Alignment.TOP_RIGHT);
    memberLayout.setComponentAlignment(adminButton, Alignment.TOP_RIGHT);
    memberLayout.setComponentAlignment(loginPopup, Alignment.TOP_RIGHT);

    memberLayout.setExpandRatio(filler, 1.0f);
    memberLayout.setMargin(false);
    memberLayout.setSpacing(false);
    memberLayout.setWidth("100%");
    memberLayout.setHeight("30px");

    Label spacer = new Label("<hr/>", ContentMode.HTML);
    spacer.setHeight("20px");

    searchLayout = new UIUtils7.GridLayoutBuilder(3, 4)
            .addComponent(searchField, Alignment.TOP_LEFT, 0, 0, 2, 1)
            .addComponent(goButton, Alignment.TOP_RIGHT, 2, 0, 1, 1).fillRow(spacer, 0, 1, 1)
            .addComponent(paginationPanel, Alignment.MIDDLE_CENTER, 0, 2, 3, 2).getLayout();
    searchLayout.addStyleName("paper");
    searchLayout.setSpacing(true);
    searchLayout.setMargin(true);
    paginationPanel.setWidth("980px");
    //wrapper
    Label icon8Link = new Label("<a href=\"http://icons8.com\">Icons by icon8.com</a>", ContentMode.HTML);
    mainLayout = new VerticalLayout(memberLayout, searchLayout, icon8Link);
    mainLayout.setComponentAlignment(memberLayout, Alignment.TOP_CENTER);
    mainLayout.setComponentAlignment(searchLayout, Alignment.TOP_CENTER);
    mainLayout.setComponentAlignment(icon8Link, Alignment.BOTTOM_RIGHT);
    mainLayout.setExpandRatio(memberLayout, .05f);
    mainLayout.setExpandRatio(searchLayout, .93f);
    mainLayout.setExpandRatio(icon8Link, .02f);

    VerticalLayout fullscreen = new VerticalLayout(mainLayout);
    fullscreen.setComponentAlignment(mainLayout, Alignment.TOP_CENTER);
    fullscreen.setSizeFull();
    setContent(fullscreen);

    mainLayout.setWidth("1024px");
    mainLayout.setHeight("768px");

    if (pQuery != null) {
        searchField.setValue(pQuery);
        doSearch();
    }
}

From source file:edu.nps.moves.mmowgli.AbstractMmowgliController.java

License:Open Source License

@SuppressWarnings("serial")
private void handleAdminMessage(Game g) {
    final Window dialog = new Window("Important!");
    VerticalLayout vl = new VerticalLayout();
    dialog.setContent(vl);/*from   www .  j  av  a  2  s  . c om*/
    vl.setSizeUndefined();
    vl.setMargin(true);
    vl.setSpacing(true);

    vl.addComponent(new HtmlLabel(g.getAdminLoginMessage()));

    HorizontalLayout buttHL = new HorizontalLayout();
    buttHL.setSpacing(true);
    final CheckBox cb;
    buttHL.addComponent(cb = new CheckBox("Show this message again on the next administrator login"));
    cb.setValue(true);
    Button closeButt;
    buttHL.addComponent(closeButt = new Button("Close"));
    closeButt.addClickListener(new ClickListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void buttonClick(ClickEvent event) {
            if (Boolean.parseBoolean(cb.getValue().toString()))
                ; // do nothing
            else {
                HSess.init();
                Game.getTL().setAdminLoginMessage(null);
                Game.updateTL();
                HSess.close();
            }
            UI.getCurrent().removeWindow(dialog);
        }
    });

    vl.addComponent(buttHL);
    vl.setComponentAlignment(buttHL, Alignment.MIDDLE_RIGHT);

    UI.getCurrent().addWindow(dialog);
    dialog.center();
}

From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper.java

License:Open Source License

void handleShowActiveUsersPerServer(MenuBar mbar) {
    Object[][] oa = Mmowgli2UI.getGlobals().getSessionCountByServer();

    Window svrCountWin = new Window("Display Active Users Per Server");
    svrCountWin.setModal(true);/*from w w  w .  j a v  a  2s .c  om*/
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth("99%");
    svrCountWin.setContent(layout);

    GridLayout gl = new GridLayout(2, Math.max(1, oa.length));
    gl.setSpacing(true);
    gl.addStyleName("m-greyborder");
    for (Object[] row : oa) {
        Label lab = new Label();
        lab.setSizeUndefined();
        lab.setValue(row[0].toString());
        gl.addComponent(lab);
        gl.setComponentAlignment(lab, Alignment.MIDDLE_RIGHT);

        gl.addComponent(new Label(row[1].toString()));
    }
    layout.addComponent(gl);
    layout.setComponentAlignment(gl, Alignment.MIDDLE_CENTER);

    svrCountWin.setWidth("250px");
    UI.getCurrent().addWindow(svrCountWin);
    svrCountWin.center();
}

From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper.java

License:Open Source License

private void _postGameEvent(String title, final GameEvent.EventType typ, String buttName, boolean doWarning,
        MenuBar mbar) {//from   www  . j ava  2 s  .  c om
    // Create the window...
    final Window bcastWindow = new Window(title);
    bcastWindow.setModal(true);

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth("99%");
    bcastWindow.setContent(layout);
    layout.addComponent(new Label("Compose message (255 char limit):"));
    final TextArea ta = new TextArea();
    ta.setRows(5);
    ta.setWidth("99%");
    layout.addComponent(ta);

    HorizontalLayout buttHl = new HorizontalLayout();
    final Button bcancelButt = new Button("Cancel");
    buttHl.addComponent(bcancelButt);
    Button bokButt = new Button(buttName);
    bokButt.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttHl.addComponent(bokButt);
    layout.addComponent(buttHl);
    layout.setComponentAlignment(buttHl, Alignment.TOP_RIGHT);

    if (doWarning)
        layout.addComponent(new Label("Use with great deliberation!"));

    bcastWindow.setWidth("320px");
    UI.getCurrent().addWindow(bcastWindow);
    bcastWindow.setPositionX(0);
    bcastWindow.setPositionY(0);

    ta.focus();

    @SuppressWarnings("serial")
    ClickListener lis = new ClickListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void buttonClick(ClickEvent event) {
            if (event.getButton() == bcancelButt)
                ; // nothin
            else {
                // This check is now done in GameEvent.java, but should ideally prompt the user.
                String msg = ta.getValue().toString().trim();
                if (msg.length() > 0) {
                    HSess.init();
                    if (msg.length() > 255) // clamp to 255 to avoid db exception
                        msg = msg.substring(0, 254);
                    User u = Mmowgli2UI.getGlobals().getUserTL();
                    if (typ == GameEvent.EventType.GAMEMASTERNOTE)
                        GameEventLogger.logGameMasterCommentTL(msg, u);
                    else
                        GameEventLogger.logGameMasterBroadcastTL(typ, msg, u);
                    HSess.close();
                }
            }

            bcastWindow.close();
        }
    };
    bcancelButt.addClickListener(lis);
    bokButt.addClickListener(lis);
}

From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper.java

License:Open Source License

public void handleLoginLimitActionTL() {
    // Create the window...
    final Window loginWin = new Window("Change Session Login Limit");
    loginWin.setModal(true);//  w ww  .j  a v  a  2  s  . c  om

    VerticalLayout layout = new VerticalLayout();
    loginWin.setContent(layout);
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth("99%");
    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    hl.addComponent(new Label("Max users to be logged in"));
    final TextField utf = new TextField();
    utf.setColumns(10);

    final int oldVal = Game.getTL().getMaxUsersOnline();
    utf.setValue("" + oldVal);
    hl.addComponent(utf);

    layout.addComponent(hl);

    HorizontalLayout buttHl = new HorizontalLayout();
    // LLListener llis = new LLListener(loginWin);
    final Button cancelButt = new Button("Cancel");
    buttHl.addComponent(cancelButt);
    final Button okButt = new Button("Save");
    buttHl.addComponent(okButt);
    layout.addComponent(buttHl);
    layout.setComponentAlignment(buttHl, Alignment.TOP_RIGHT);

    layout.addComponent(new Label("Use with great deliberation!"));

    loginWin.setWidth("320px");
    UI.getCurrent().addWindow(loginWin);
    loginWin.center();

    @SuppressWarnings("serial")
    ClickListener llis = new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (event.getButton() == cancelButt) {
            } else if (event.getButton() == okButt) {
                HSess.init();
                try {
                    int i = Integer.parseInt(utf.getValue().toString());
                    Game g = Game.getTL();
                    g.setMaxUsersOnline(i);
                    Game.updateTL();
                    GameEventLogger.logLoginLimitChangeTL(oldVal, i);
                } catch (Throwable t) {
                    Notification.show("Error", "Invalid integer", Notification.Type.ERROR_MESSAGE);
                    HSess.close();
                    return;
                }
                HSess.close();
            }
            loginWin.close();
        }
    };
    cancelButt.addClickListener(llis);
    okButt.addClickListener(llis);
}