Example usage for com.vaadin.ui HorizontalLayout setWidth

List of usage examples for com.vaadin.ui HorizontalLayout setWidth

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout setWidth.

Prototype

@Override
    public void setWidth(String width) 

Source Link

Usage

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

License:Apache License

/**
 * Update the layout. This method is either called internally when scrolling
 * or/* ww w  . j a  v  a 2 s .  c  om*/
 */
public final void update() {
    //remove all components (old result page and navigation)
    removeAllComponents();

    //add current results
    renderPage();

    //build pagination
    int pages = overallEntries / entriesPerPage;
    if (overallEntries % entriesPerPage > 0) {
        pages++;
    }

    final int overallPages = pages;
    HorizontalLayout navigation = new HorizontalLayout();
    //add "JumpToFirstPage" button
    final NativeButton first = new NativeButton();
    first.setIcon(firstIcon);
    if (firstIcon == null) {
        first.setCaption("<<");
    }
    first.setDescription("First Page");
    first.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = 0;
            update();
        }
    });
    //add "PreviousPage" button
    final NativeButton prev = new NativeButton();
    prev.setIcon(prevIcon);
    if (prevIcon == null) {
        prev.setCaption("<");
    }
    prev.setDescription("Previous Page");
    prev.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage > 0) {
                currentPage--;
                update();
            }
        }
    });
    //add "NextPage" button
    final NativeButton next = new NativeButton();
    next.setIcon(nextIcon);
    if (nextIcon == null) {
        next.setCaption(">");
    }
    next.setDescription("Next Page");
    next.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage + 1 < overallPages) {
                currentPage++;
                update();
            }
        }
    });
    //add "JumpToLastPage" button
    final NativeButton last = new NativeButton();
    last.setIcon(endIcon);
    if (endIcon == null) {
        next.setCaption(">>");
    }
    last.setDescription("Last Page");
    last.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = overallPages - 1;
            update();
        }
    });

    //enable/disable buttons depending on the current page
    if (overallPages == 0) {
        first.setEnabled(false);
        prev.setEnabled(false);
        next.setEnabled(false);
        last.setEnabled(false);
    } else {
        first.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        prev.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        next.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
        last.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
    }

    //at first, put the page size selection box into the navigation
    final ComboBox entriesPerPageBox = new ComboBox();
    entriesPerPageBox.setItemCaptionPropertyId("name");
    entriesPerPageBox.addContainerProperty("name", String.class, null);
    entriesPerPageBox.addItem(5);
    entriesPerPageBox.getContainerProperty(5, "name").setValue("5 Entries / Page");
    entriesPerPageBox.addItem(10);
    entriesPerPageBox.getContainerProperty(10, "name").setValue("10 Entries / Page");
    entriesPerPageBox.addItem(15);
    entriesPerPageBox.getContainerProperty(15, "name").setValue("15 Entries / Page");
    entriesPerPageBox.addItem(20);
    entriesPerPageBox.getContainerProperty(20, "name").setValue("20 Entries / Page");

    entriesPerPageBox.setValue(entriesPerPage);
    entriesPerPageBox.setNullSelectionAllowed(false);
    entriesPerPageBox.setImmediate(true);

    entriesPerPageBox.addListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            entriesPerPage = (Integer) entriesPerPageBox.getValue();
            update();
        }
    });

    navigation.addComponent(entriesPerPageBox);

    //filler labels are added to the beginning and to the end to keep the navigation in the middle
    Label leftFiller = new Label();
    leftFiller.setWidth("25px");
    navigation.addComponent(leftFiller);
    navigation.addComponent(first);
    navigation.addComponent(prev);

    //Show max. 10 pages at once for performance and layout reasons.
    //If there are more than 10 pages, "move" the to show 10 pages based on the current page.
    int start = currentPage - 5;
    start = (start < 0) ? 0 : start;
    int end = start + 10;
    end = (end > pages) ? pages : end;

    if (end - start < 10 && pages > 10) {
        start = end - 10;
    }

    if (overallPages == 0) {
        Label noEntryLabel = new Label("<i>No entries</i>", Label.CONTENT_XHTML);
        //noEntryLabel.setWidth("80px");
        noEntryLabel.setSizeUndefined();
        navigation.addComponent(noEntryLabel);
        navigation.setComponentAlignment(noEntryLabel, Alignment.MIDDLE_CENTER);
    }
    //build the actual page entries
    for (int i = start; i < end; i++) {
        if (i == currentPage) {
            //the current page is marked with a special style
            Label pageLink = new Label("<b>" + Integer.toString(i + 1) + "</b>", Label.CONTENT_XHTML);
            pageLink.setStyleName("currentpage");
            pageLink.setWidth("15px");
            navigation.addComponent(pageLink);
            navigation.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        } else {
            //otherwise normal links are added, click-events are handled via LayoutClickListener 
            Link pageLink = new Link(Integer.toString(i + 1), null);
            navigation.addComponent(pageLink);
            navigation.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        }
    }
    //add right navigation buttons
    navigation.addComponent(next);
    navigation.addComponent(last);
    //...and fill the remaining space 
    Label rightFiller = new Label();
    navigation.addComponent(rightFiller);
    //  navigation.setExpandRatio(leftFiller, 1.0f);
    navigation.setExpandRatio(rightFiller, 1.0f);
    navigation.setSpacing(true);

    //put everything ot the middle
    navigation.setComponentAlignment(first, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(prev, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(next, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(last, Alignment.MIDDLE_CENTER);

    //add layout click listener to be able to navigate by clicking the single pages
    navigation.addListener(new LayoutEvents.LayoutClickListener() {
        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent event) {

            // Get the child component which was clicked
            Component child = event.getChildComponent();

            if (child == null) {
                // Not over any child component
            } else {
                // Over a child component
                if (child instanceof Link) {
                    // Over a valid child element
                    currentPage = Integer.parseInt(((Link) child).getCaption()) - 1;
                    update();
                }
            }
        }
    });

    //finalize
    navigation.setWidth("100%");
    navigation.setHeight("25px");

    //add navigation and align it right below the result page
    addComponent(page);
    setExpandRatio(page, 1f);
    if (overallEntries > 0) {
        addComponent(navigation);
        setComponentAlignment(navigation, Alignment.BOTTOM_CENTER);
        setExpandRatio(navigation, .05f);
    }
    requestRepaint();
}

From source file:edu.kit.dama.ui.components.ConfirmationWindow7.java

License:Apache License

/**
 * Builds a customized subwindow <b>ConfirmationWindow</b> that allows the
 * user to confirm his previously requested action.
 *
 * @param pTitle The title of the window.
 * @param pMessage The message shown in the window.
 * @param pOptionType The type of the window (OK or YES_NO) which defines the
 * visible buttons./*from ww w .j a  v a  2  s . c o m*/
 * @param pMessageType The message type (INFORMATION, WARNING, ERROR) which
 * determines the icon. If pMessageType is null, no icon will be shown.
 * @param pListener The listener which receives the result if a button was
 * pressed or the window was closed.
 *
 */
ConfirmationWindow7(String pTitle, String pMessage, OPTION_TYPE pOptionType, MESSAGE_TYPE pMessageType,
        IConfirmationWindowListener7 pListener) {
    this.listener = pListener;
    //basic setup

    //set caption depending on type
    String caption = pTitle;
    if (caption == null) {
        if (pMessageType != null) {
            switch (pMessageType) {
            case QUESTION:
                caption = DEFAULT_TITLE;
                break;
            case INFORMATION:
                caption = "Information";
                break;
            case WARNING:
                caption = "Warning";
                break;
            case ERROR:
                caption = "Error";
                break;
            }
        } else {
            //no type provided...use default title
            caption = DEFAULT_TITLE;
        }
    }

    setCaption(caption);
    setModal(true);
    center();

    // Build line of buttons depending on pOptionType
    HorizontalLayout buttonLine = new HorizontalLayout();
    buttonLine.setSpacing(true);
    buttonLine.setWidth("100%");
    //add spacer
    Label spacer = new Label();
    buttonLine.addComponent(spacer);
    //add buttons
    if (OPTION_TYPE.YES_NO_OPTION.equals(pOptionType)) {
        buttonLine.addComponent(buildYesButton("Yes"));
        buttonLine.addComponent(buildNoButton());
        buttonLine.setComponentAlignment(yesButton, Alignment.MIDDLE_RIGHT);
        buttonLine.setComponentAlignment(noButton, Alignment.MIDDLE_RIGHT);
        //Assign ENTER to the YES button
        yesButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
        //Assign ESC to the NO button
        noButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    } else {
        buttonLine.addComponent(buildYesButton("OK"));
        buttonLine.setComponentAlignment(yesButton, Alignment.MIDDLE_RIGHT);
        //Assign ENTER to the OK button
        yesButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
        //Assign ESC to close the dialog
        setCloseShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    }

    buttonLine.setExpandRatio(spacer, 1.0f);

    //determine the icon depending on pMessageType
    ThemeResource icon = null;

    if (pMessageType != null) {
        switch (pMessageType) {
        case QUESTION:
            icon = new ThemeResource("img/24x24/question.png");
            break;
        case INFORMATION:
            icon = new ThemeResource("img/24x24/information.png");
            break;
        case WARNING:
            icon = new ThemeResource("img/24x24/warning.png");
            break;
        case ERROR:
            icon = new ThemeResource("img/24x24/forbidden.png");
            break;
        }
    }
    Component iconComponent = new Label();
    if (icon != null) {
        //icon was set, overwrite icon component
        iconComponent = new Image(null, icon);
    }

    //build the message label
    Label message = new Label(pMessage, ContentMode.HTML);
    message.setSizeUndefined();
    //build the main layout
    GridLayout mainLayout = new UIUtils7.GridLayoutBuilder(2, 2)
            .addComponent(iconComponent, Alignment.TOP_LEFT, 0, 0, 1, 1).addComponent(message, 1, 0, 1, 1)
            .addComponent(buttonLine, 0, 1, 2, 1).getLayout();
    mainLayout.setMargin(true);
    mainLayout.setSpacing(true);
    mainLayout.setColumnExpandRatio(0, .05f);
    mainLayout.setColumnExpandRatio(1, 1f);
    mainLayout.setRowExpandRatio(0, 1f);
    mainLayout.setRowExpandRatio(1, .05f);
    setContent(mainLayout);

    //add the close listener
    addCloseListener(new CloseListener() {
        @Override
        public void windowClose(CloseEvent e) {
            fireCloseEvents(RESULT.CANCEL);
        }
    });
}

From source file:edu.kit.dama.ui.repo.components.PaginationPanel.java

License:Apache License

/**
 * Build the navigation layout including the appropriate buttons to navigate
 * through the pagination pages./*from ww  w .java  2 s  .  c  o  m*/
 *
 * @return The navigation layout component.
 */
private HorizontalLayout buildNavigationComponent() {
    HorizontalLayout result = new HorizontalLayout();
    //add "JumpToFirstPage" button
    final NativeButton first = new NativeButton();
    first.setIcon(new ThemeResource("img/16x16/beginning.png"));
    first.setDescription("First Page");
    first.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = 0;
            updatePage();
        }
    });
    //add "PreviousPage" button
    final NativeButton prev = new NativeButton();
    prev.setIcon(new ThemeResource("img/16x16/prev.png"));
    prev.setDescription("Previous Page");
    prev.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage > 0) {
                currentPage--;
                updatePage();
            }
        }
    });
    //add "NextPage" button
    final NativeButton next = new NativeButton();
    next.setDescription("Next Page");
    next.setIcon(new ThemeResource("img/16x16/next.png"));
    next.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage + 1 < overallPages) {
                currentPage++;
                updatePage();
            }
        }
    });
    //add "JumpToLastPage" button
    final NativeButton last = new NativeButton();
    last.setDescription("Last Page");
    last.setIcon(new ThemeResource("img/16x16/end.png"));
    last.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = overallPages - 1;
            updatePage();
        }
    });

    //enable/disable buttons depending on the current page
    if (overallPages == 0) {
        first.setEnabled(false);
        prev.setEnabled(false);
        next.setEnabled(false);
        last.setEnabled(false);
    } else {
        first.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        prev.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        next.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
        last.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
    }

    Label leftFiller = new Label();
    result.addComponent(leftFiller);
    result.setExpandRatio(leftFiller, 1.0f);
    result.addComponent(first);
    result.addComponent(prev);
    int start = currentPage - 5;
    start = (start < 0) ? 0 : start;
    int end = start + 10;
    end = (end > overallPages) ? overallPages : end;

    if (end - start < 10 && overallPages > 10) {
        start = end - 10;
    }

    if (overallPages == 0) {
        Label noEntryLabel = new Label("<i>No entries</i>", ContentMode.HTML);
        //noEntryLabel.setWidth("80px");
        noEntryLabel.setSizeUndefined();
        result.addComponent(noEntryLabel);
        result.setComponentAlignment(noEntryLabel, Alignment.MIDDLE_CENTER);
    }
    //build the actual page entries
    for (int i = start; i < end; i++) {
        if (i == currentPage) {
            //the current page is marked with a special style
            Label pageLink = new Label("<b>" + Integer.toString(i + 1) + "</b>", ContentMode.HTML);
            pageLink.setStyleName("currentpage");
            pageLink.setWidth("15px");
            result.addComponent(pageLink);
            result.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        } else {
            //otherwise normal links are added, click-events are handled via LayoutClickListener 
            Link pageLink = new Link(Integer.toString(i + 1), null);
            result.addComponent(pageLink);
            result.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        }
    }
    //add right navigation buttons
    result.addComponent(next);
    result.addComponent(last);
    //...and fill the remaining space 
    Label rightFiller = new Label();
    result.addComponent(rightFiller);
    result.setExpandRatio(rightFiller, 1.0f);
    result.setSpacing(true);

    //put everything ot the middle
    result.setComponentAlignment(first, Alignment.MIDDLE_CENTER);
    result.setComponentAlignment(prev, Alignment.MIDDLE_CENTER);
    result.setComponentAlignment(next, Alignment.MIDDLE_CENTER);
    result.setComponentAlignment(last, Alignment.MIDDLE_CENTER);

    //add layout click listener to be able to navigate by clicking the single pages
    result.addLayoutClickListener(new LayoutEvents.LayoutClickListener() {
        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent event) {

            // Get the child component which was clicked
            Component child = event.getChildComponent();

            if (child == null) {
                // Not over any child component
            } else // Over a child component
            {
                if (child instanceof Link) {
                }
            }
        }
    });

    //finalize
    result.setWidth("100%");
    result.setHeight("25px");
    return result;
}

From source file:edu.kit.dama.ui.simon.panel.SimonMainPanel.java

License:Apache License

/**
 * Build the overview tab including the list of all categories and der
 * overall status./*w  w w . j  av a 2s  .  c o  m*/
 *
 * @param pCategories A list of all categories.
 *
 * @return The tab component.
 */
private Component buildOverviewTab(String[] pCategories) {
    AbsoluteLayout abLay = new AbsoluteLayout();
    UIUtils7.GridLayoutBuilder layoutBuilder = new UIUtils7.GridLayoutBuilder(4, pCategories.length + 1);

    updateButton = new Button("Update Status");
    updateButton.addClickListener(this);
    Embedded logo = new Embedded(null, new ThemeResource("img/simon.png"));
    abLay.addComponent(logo, "top:30px;left:30px;");

    Label simonSaysLabel = new Label("", ContentMode.HTML);
    simonSaysLabel.setHeight("150px");
    setSimonSaysContent(simonSaysLabel, "Everything is fine.");
    abLay.addComponent(simonSaysLabel, "top:30px;left:250px;");

    int row = 0;
    for (String category : pCategories) {
        HorizontalLayout rowLayout = new HorizontalLayout();
        Label name = new Label(category);
        name.setWidth("200px");
        name.setHeight("24px");
        List<AbstractProbe> probes = probesByCategory.get(category);
        Collections.sort(probes, new Comparator<AbstractProbe>() {
            @Override
            public int compare(AbstractProbe o1, AbstractProbe o2) {
                return o1.getCurrentStatus().compareTo(o2.getCurrentStatus());
            }
        });

        int failed = 0;
        int unknown = 0;
        int unavailable = 0;
        int charactersPerProbe = 100;
        if (probes.size() > 0) {
            charactersPerProbe = (int) Math.rint((700.0 / probes.size()) / 8.0);
        }

        for (AbstractProbe probe : probes) {
            Label probeLabel = new Label(StringUtils.abbreviate(probe.getName(), charactersPerProbe));
            probeLabel.setHeight("24px");
            switch (probe.getCurrentStatus()) {
            case UNKNOWN:
                probeLabel.setDescription(probe.getName() + ": UNKNOWN");
                probeLabel.addStyleName("probe-unknown");
                unknown++;
                break;
            case UPDATING:
                probeLabel.setDescription(probe.getName() + ": UPDATING");
                probeLabel.addStyleName("probe-updating");
                break;
            case UNAVAILABLE:
                probeLabel.setDescription(probe.getName() + ": UNAVAILABLE");
                probeLabel.addStyleName("probe-unavailable");
                unavailable++;
                break;
            case FAILED:
                probeLabel.setDescription(probe.getName() + ": FAILED");
                probeLabel.addStyleName("probe-failed");
                failed++;
                break;
            default:
                probeLabel.setDescription(probe.getName() + ": SUCCESS");
                probeLabel.addStyleName("probe-success");
            }

            probeLabel.addStyleName("probe");
            rowLayout.addComponent(probeLabel);
        }

        if (failed != 0) {
            setSimonSaysContent(simonSaysLabel, "There are errors!");
        } else {
            if (unknown != 0) {
                setSimonSaysContent(simonSaysLabel, "There are unknown states. Please select 'Update Status'.");
            } else {
                if (unavailable != 0) {
                    setSimonSaysContent(simonSaysLabel,
                            "Some probes are unavailable. Please check their configuration.");
                }
            }
        }

        rowLayout.setWidth("700px");
        layoutBuilder.addComponent(name, Alignment.TOP_LEFT, 0, row, 1, 1).addComponent(rowLayout,
                Alignment.TOP_LEFT, 1, row, 3, 1);
        row++;
    }

    layoutBuilder.addComponent(updateButton, Alignment.BOTTOM_RIGHT, 3, row, 1, 1);

    GridLayout tabLayout = layoutBuilder.getLayout();
    tabLayout.setSpacing(true);
    tabLayout.setMargin(true);
    Panel p = new Panel();
    p.setContent(tabLayout);
    p.setWidth("1024px");
    p.setHeight("400px");
    abLay.addComponent(p, "top:160px;left:30px;");
    abLay.setSizeFull();
    return abLay;
}

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

License:Open Source License

private Component makeHL(String s, int num) {
    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);//from  w  w w  . j a va 2  s .c o m
    Label lab;
    hl.addComponent(lab = new HtmlLabel(s));
    hl.setExpandRatio(lab, 1.0f);
    Label countTf = new HtmlLabel();
    countTf.setWidth("50px");
    countTf.setValue("&nbsp;" + num);
    countTf.addStyleName("m-greyborder");
    countTf.addStyleName("m-textalignright");
    hl.addComponent(countTf);
    hl.setComponentAlignment(countTf, Alignment.TOP_RIGHT);
    hl.setWidth("100%");
    return hl;
}

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

License:Open Source License

public void handleDumpEmailsTL() {
    final TextField tf;

    final Window dialog = new Window("Filter Player Email Dump");
    dialog.setModal(true);//www .  ja  v  a  2  s .com

    VerticalLayout layout = new VerticalLayout();
    dialog.setContent(layout);
    layout.setMargin(true);
    layout.setSpacing(true);

    final OptionGroup radios = new OptionGroup(null, Arrays.asList(opts));
    layout.addComponent(radios);

    layout.addComponent(tf = new MTextField().withWidth("50%"));
    tf.setCaption("value");

    Label lab;

    layout.addComponent(lab = new Label());
    lab.setHeight("10px");

    radios.setNullSelectionAllowed(false); // user can not 'unselect'
    radios.select(allp); // select this by default
    radios.setImmediate(false); // don't send the change to the server at once
    radios.setMultiSelect(false);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    @SuppressWarnings("serial")
    Button cancelButt = new Button("Cancel", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();
        }
    });

    @SuppressWarnings("serial")
    Button addButt = new Button("Dump", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Float val = null;
            String valS = "";
            boolean parseError = false;
            try {
                val = Float.parseFloat(tf.getValue());
                valS = formatter.valueToString(val);
            } catch (Exception ex) {
                parseError = true;
            }

            HSess.init();
            Object sel = radios.getValue();
            Criteria crit = null;
            String windowTitle = "";
            boolean isExpl = true;
            if (sel == allp) {
                crit = HSess.get().createCriteria(User.class);
                windowTitle = new String("All users");
                isExpl = true;
                if (parseError) {
                    Notification.show("Value ignored", Notification.Type.WARNING_MESSAGE);
                    System.out.println("Tried to show a Notification");
                }
            } else if (sel == grex) {
                crit = getExplorationGreaterThanTL(val);
                windowTitle = "Users with exploration points greater than " + valS;
                isExpl = true;
            } else if (sel == lsex) {
                crit = getExplorationLessThanTL(val);
                windowTitle = "Users with exploration points less than " + valS;
                isExpl = true;
            } else if (sel == grim) {
                crit = getImplementationGreaterThanTL(val);
                windowTitle = "Users with implementation points greater than " + valS;
                isExpl = false;
            } else if (sel == lsim) {
                crit = getImplementationLessThanTL(val);
                windowTitle = "Users with implementation points less than " + valS;
                isExpl = false;
            }

            if (crit != null) {
                @SuppressWarnings("unchecked")
                List<User> lis = (List<User>) crit.list();
                StringBuilder sb = new StringBuilder();
                handleEmailListNoHeader(lis, sb, isExpl);

                String title = windowTitle + " - " + UUID.randomUUID();
                BrowserWindowOpener.openWithInnerHTML(sb.toString(), title, "_blank");
            } else {
                Notification.show("Invalid value", Notification.Type.ERROR_MESSAGE);
                HSess.close();
                return;
            }

            dialog.close();
            HSess.close();
        }
    });

    hl.addComponent(cancelButt);
    hl.addComponent(addButt);
    hl.setComponentAlignment(cancelButt, Alignment.MIDDLE_RIGHT);
    hl.setExpandRatio(cancelButt, 1.0f);

    layout.addComponent(hl);

    hl.setWidth("100%");

    layout.addComponent(lab = new Label());
    layout.setExpandRatio(lab, 1.0f);

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

From source file:edu.nps.moves.mmowgli.components.CardSummary.java

License:Open Source License

@SuppressWarnings("serial")
public void initGui(Session sess) {
    setHeight(heightStr);/*from  ww  w .ja v  a2s. com*/
    setWidth(widthStr);
    addStyleName("m-cursor-pointer"); // pointer when over me, because I'm clickable

    if (bckgrndResource != null) {
        backImg = new Embedded(null, bckgrndResource);
        addComponent(backImg, "top:0px;left:0px");
    }

    if (!isFactCard) {
        String hdrTxt = card.getCardType().getSummaryHeader();
        header.setDescription(hdrTxt);
        if (hdrTxt != null && hdrTxt.length() > 0) {
            //if(hdrTxt.length()>=15) {
            //   hdrTxt = hdrTxt.substring(0, 15).trim()+"...";
            // }
            header.setValue(hdrTxt);
            header.setWidth(headerWidthStr);
            header.setHeight(headerHeightStr);
            addComponent(header, headerPositionStr);
            header.addStyleName(headerStyleStr);
            header.addStyleName(textColorStyleStr);
            header.addStyleName("m-cursor-pointer");
        }

        if (starGreyResource != null && starRedResource != null) {
            Set<Card> favs = me.getFavoriteCards();
            if (favs != null && favs.contains(card)) {
                star.setIcon(starRedResource);
            } else {
                star.setIcon(starGreyResource);
            }
            addComponent(star, starPositionStr);
            if (!mockupOnly)
                star.addClickListener(new StarClick());
            star.addStyleName("borderless");
            star.setDescription("Mark or unmark as a favorite of yours");
        }
    }
    idLab.setWidth(idLabWidthStr);
    idLab.setHeight(idLabHeightStr);
    idLab.setValue("" + card.getId());
    idLab.addStyleName(idLabStyleStr);
    idLab.addStyleName("m-text-align-right");
    addComponent(idLab, idLabPositionStr);

    content.setWidth(contentWidthStr);
    content.setHeight(contentHeightStr);
    addComponent(content, contentPositionStr);
    content.addStyleName(contentStyle);
    if (card.isHidden())
        content.addStyleName(hiddenStyle); // red "HIDDEN" text background

    content.setValue(formatText(card.getText()));
    content.addStyleName("m-cursor-pointer");
    content.setDescription(card.getText());

    if (!isFactCard) {
        /* We shouldn't have to be setting widths on the components within this horizontal layout.  The
         * fact that we do is, I think, related to the absolutelayout parent.  Get rid of that and we might
         * be able to yank the .setwidth, setheight stuff.
         */
        HorizontalLayout hLay = new HorizontalLayout();
        hLay.setMargin(false);
        hLay.setHeight(userHeightStr);
        hLay.setWidth(userDateWidthStr);
        addComponent(hLay, userDatePositionStr);

        user.setValue(card.getAuthorName()); //.getAuthor().getUserName());
        hLay.addComponent(user);
        user.setWidth(userWidthStr);
        user.setHeight(userHeightStr);
        user.addStyleName(userStyle);
        user.addStyleName("m-cursor-pointer");

        Label sp;
        hLay.addComponent(sp = new Label());
        sp.setWidth("1px");
        hLay.setExpandRatio(sp, 1.0f);

        dateLab.setValue(dateFormatter.format(card.getCreationDate()));
        hLay.addComponent(dateLab);
        dateLab.setHeight(userHeightStr);
        dateLab.setWidth(null); //dateWidthStr);
        dateLab.addStyleName(userStyle);
    }

    if (card.getCreatedInMove().getId() != Move.getCurrentMove(sess).getId()) {
        Label lab = new Label(card.getCreatedInMove().getName());
        lab.addStyleName(moveStyleStr);
        lab.setWidth(moveWidthStr);
        lab.setHeight(moveHeightStr);
        addComponent(lab, movePositionStr);
    }

    // Listen for layout click events
    if (!mockupOnly)
        this.addLayoutClickListener(new LayoutClickListener() {
            @MmowgliCodeEntry
            @HibernateOpened
            @HibernateRead
            public void layoutClick(LayoutClickEvent event) {
                HSess.init();
                Component c = event.getChildComponent();
                Card card = Card.getTL(cardId);
                if (c == star) {
                    //Let the starlistener below handle it
                } else if (c == user) {
                    AppEvent evt = new AppEvent(CARDAUTHORCLICK, CardSummary.this, card.getAuthor().getId());
                    Mmowgli2UI.getGlobals().getController().miscEventTL(evt);
                } else { //if (c == content) {
                    AppEvent evt = new AppEvent(CARDCLICK, CardSummary.this, card.getId());
                    Mmowgli2UI.getGlobals().getController().miscEventTL(evt);
                }
                HSess.close();
            }
        });
}

From source file:edu.nps.moves.mmowgli.components.Footer.java

License:Open Source License

@Override
public void initGui() {
    setWidth(FOOTER_W);/* www .  j  av  a 2  s .c  o  m*/
    setHeight("130px"); //room for fouo butt//FOOTER_H);
    AbsoluteLayout mainAbsLay = new AbsoluteLayout(); // offset it from master

    mainAbsLay.setWidth(FOOTER_W);
    mainAbsLay.setHeight(FOOTER_H);
    addComponent(mainAbsLay, FOOTER_OFFSET_POS);

    MediaLocator medLoc = ((Mmowgli2UI) UI.getCurrent()).getMediaLocator();
    Embedded back = new Embedded(null, medLoc.getFooterBackground());
    mainAbsLay.addComponent(back, "top:0px;left:0px");

    HorizontalLayout outerHorLay = new HorizontalLayout();
    addComponent(outerHorLay, "top:45px;left:0px");
    outerHorLay.setWidth(FOOTER_W);
    HorizontalLayout innerHorLay = new HorizontalLayout();
    innerHorLay.setSpacing(true);
    outerHorLay.addComponent(innerHorLay);
    outerHorLay.setComponentAlignment(innerHorLay, Alignment.MIDDLE_CENTER);

    Label sp;
    innerHorLay.addComponent(aboutButt);
    innerHorLay.addComponent(pingPushLab = new HtmlLabel());
    pingPushLab.setWidth("7px");
    innerHorLay.addComponent(creditsButt);
    innerHorLay.addComponent(sp = new Label());
    sp.setWidth("7px");
    innerHorLay.addComponent(faqsButt);
    innerHorLay.addComponent(sp = new Label());
    sp.setWidth("7px");
    innerHorLay.addComponent(fixesButt);
    innerHorLay.addComponent(sp = new Label());
    sp.setWidth("7px");
    innerHorLay.addComponent(glossaryButt);
    innerHorLay.addComponent(sp = new Label());
    sp.setWidth("7px");
    innerHorLay.addComponent(reportsButt);
    innerHorLay.addComponent(sp = new Label());
    sp.setWidth("7px");
    innerHorLay.addComponent(termsButt);
    innerHorLay.addComponent(sp = new Label());
    sp.setWidth("7px");
    innerHorLay.addComponent(troubleButt);
    troubleButt.addStyleName("m-red-text");
    innerHorLay.addComponent(sp = new Label());
    sp.setWidth("7px");
    innerHorLay.addComponent(twitterButt);
    innerHorLay.addComponent(sp = new Label());
    sp.setWidth("7px");
    innerHorLay.addComponent(videosButt);

    GameLinks gl = GameLinks.getTL();
    if (gl.getFixesLink().toLowerCase().contains("armyscitech")
            || gl.getGlossaryLink().toLowerCase().contains("armyscitech")) {
        ; // This is a hack, but I don't want to pollute the db with a bogus boolean...this is a special case just for these folks.
    } else {
        HorizontalLayout hl = new HorizontalLayout();
        Label lab = null;
        hl.addComponent(lab = new HtmlLabel("Build " + MMOWGLI_BUILD_ID));
        lab.addStyleName("m-footer-servername"); //small text
        lab.setDescription(Mmowgli2UI.getGlobals().getVaadinSessionCookie());
        hl.addComponent(lab = new HtmlLabel("&nbsp;&nbsp;Vaadin " + VAADIN_BUILD_VERSION));
        lab.addStyleName("m-footer-servername"); //small text
        hl.addComponent(lab = new HtmlLabel("&nbsp;&nbsp;" + AppMaster.instance().getServerName()));
        lab.addStyleName("m-footer-servername"); //small text
        hl.setSizeUndefined();
        mainAbsLay.addComponent(hl, "bottom:3px;right:15px;");
    }

    fouoLink = Footer.buildFouoNoticeTL();
    addComponent(fouoLink, "top:92px;left:365px");
    fouoLink.setVisible(Game.getTL().isShowFouo());
}

From source file:edu.nps.moves.mmowgli.components.Header.java

License:Open Source License

@SuppressWarnings("serial")
@Override//from w w w . j a  v  a 2 s.  com
public void initGui() {
    setWidth(HEADER_W);
    setHeight(HEADER_H);
    Game g = Game.getTL();
    GameLinks gl = GameLinks.getTL();

    Embedded embedded = new Embedded(null, mediaLoc.getHeaderBackground());
    addComponent(embedded, "top:0px;left:0px");

    if (g.isActionPlansEnabled()) {
        embedded = new Embedded(null, mediaLoc.getImage("scoretext200w50h.png"));
        addComponent(embedded, "top:52px;left:63px");
        addComponent(explorPtsLab, "top:55px;left:260px");
        addComponent(implPtsLab, "top:79px;left:247px");
    } else {
        embedded = new Embedded(null, mediaLoc.getImage("scoretextoneline200w50h.png"));
        addComponent(embedded, "top:52px;left:73px");
        addComponent(explorPtsLab, "top:65px;left:205px");
    }

    Resource res = mediaLoc.getHeaderBanner(g);
    if (res != null) {
        embedded = new Embedded(null, res);
        addComponent(embedded, pos_banner);
    }
    HorizontalLayout buttHL = new HorizontalLayout();
    buttHL.setSpacing(false);
    buttHL.setMargin(false);
    buttHL.setWidth("291px");
    buttHL.setHeight("45px");
    addComponent(buttHL, "top:1px;left:687px");

    Label lab;
    boolean armyHack = gl.getFixesLink().toLowerCase().contains("armyscitech")
            || gl.getGlossaryLink().toLowerCase().contains("armyscitech");
    if (armyHack)
        buttonChars = buttonChars - 3 + 9; // Replace "Map" with "Resources
    buttHL.addComponent(lab = new Label());
    lab.setWidth("1px");
    buttHL.setExpandRatio(lab, 0.5f);
    buttHL.addComponent(leaderBoardButt);
    buttHL.setComponentAlignment(leaderBoardButt, Alignment.MIDDLE_CENTER);
    addDivider(buttHL, buttonChars);

    // Hack
    if (armyHack) { //Hack
        Link resourceLink = makeSmallLink("Resources", "", "http://futures.armyscitech.com/resources/");
        buttHL.addComponent(resourceLink);
        buttHL.setComponentAlignment(resourceLink, Alignment.MIDDLE_CENTER);
    } else {
        buttHL.addComponent(mapButt);
        buttHL.setComponentAlignment(mapButt, Alignment.MIDDLE_CENTER);
    }
    addDivider(buttHL, buttonChars);
    buttHL.addComponent(liveBlogButt);
    buttHL.setComponentAlignment(liveBlogButt, Alignment.MIDDLE_CENTER);
    addDivider(buttHL, buttonChars);
    buttHL.addComponent(learnMoreButt);
    buttHL.setComponentAlignment(learnMoreButt, Alignment.MIDDLE_CENTER);

    buttHL.addComponent(lab = new Label());
    lab.setWidth("1px");
    buttHL.setExpandRatio(lab, 0.5f);

    addComponent(playIdeaButt, pos_playIdeaButt);

    if (g.isActionPlansEnabled()) {
        addComponent(takeActionButt, pos_takeActionButt);
        toggleTakeActionButt(true); // everbody can click it me.isGameMaster());
    } else if (armyHack) {
        embedded = new Embedded(null, mediaLoc.getImage("armylogoxpntbg80w80h.png"));
        addComponent(embedded, "top:54px;left:864px");
    }

    Serializable uid = Mmowgli2UI.getGlobals().getUserID();
    refreshUser(uid, HSess.get()); // assume in vaadin transaction here

    avatar.setWidth(HEADER_AVATAR_W);
    avatar.setHeight(HEADER_AVATAR_H);
    avatar.setDescription(user_profile_tt);
    avatar.addClickListener(new MouseEvents.ClickListener() {
        @Override
        public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
            userNameButt.buttonClick(new ClickEvent(userNameButt));
        }
    });
    userNameButt.setDescription(user_profile_tt);
    addComponent(userNameButt, HEADER_USERNAME_POS);
    addComponent(avatar, "top:13px;left:6px"); //HEADER_AVATAR_POS);

    searchField.setWidth("240px");
    //  searchField.setHeight("18px");    // this causes a text _area_ to be used, giving me two lines, default height is good, style removes borders
    searchField.setInputPrompt("Search");
    searchField.setImmediate(true);
    searchField.setTextChangeEventMode(TextChangeEventMode.LAZY);
    searchField.setTextChangeTimeout(5000); // ms
    searchField.addStyleName("m-header-searchfield");
    searchField.addValueChangeListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            HSess.init();
            handleSearchClickTL();
            HSess.close();
            /*
            searchButt.focus();  // make the white go away
            String s = event.getProperty().getValue().toString();
            if (s.length() > 0) {
              MmowgliController controller = Mmowgli2UI.getGlobals().getController();
              controller.handleEvent(SEARCHCLICK, s, searchField);
            } */
        }
    });
    searchButt.enableAction(false); // want a local listener
    searchButt.addClickListener(new ClickListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void buttonClick(ClickEvent event) {
            HSess.init();
            handleSearchClickTL();
            HSess.close();
        }
    });
    addComponent(searchField, "top:107px;left:74px"); //"top:110px;left:74px");
    addComponent(signOutButt, "top:25px;left:250px"); //"top:18px;left:250px");
    addComponent(searchButt, "top:105px;left:30px"); //"top:100px;left:180px");

    MessageUrl mu = MessageUrl.getLastTL();
    if (mu != null)
        decorateBlogHeadlinesLink(mu);
    addBlogHeadlinesLink("top:147px;left:20px");

    String headline = blogHeadlinesLink.getCaption();
    if (headline != null && headline.length() > 0) {
        // Add Window.Notification relaying the same info as the BlogHeadLinesLink
        Notification note = new Notification("Today's News", "<br/>" + headline,
                Notification.Type.WARNING_MESSAGE, true);
        note.setPosition(Position.TOP_CENTER);
        note.setDelayMsec(5 * 1000);
        // Yellow is more an attention getter
        note.setStyleName("m-blue");
        note.show(Page.getCurrent());
    }

    addComponent(callToActionButt, "top:0px;left:333px");
    /* The css has a height, width and even a background, but stupid IE will only properly size the button if an image is
     * used.  Therefore we use an a transparent png of the proper size */
    MediaLocator medLoc = Mmowgli2UI.getGlobals().getMediaLocator();
    callToActionButt.setIcon(medLoc.getEmpty353w135h());

    Move move = g.getCurrentMove();
    if (g.isShowHeaderBranding()) {
        Media brand = g.getHeaderBranding();
        if (brand != null) {
            Embedded bremb = new Embedded(null, mediaLoc.locate(brand));
            addComponent(bremb, "top:0px;left:333px");
        } else {
            brandingLab.setHeight("30px");
            setBrandingLabelText(move, g);
            addComponent(brandingLab, "top:0px;left:333px"); //HEADER_MOVETITLE_POS);  //"top:151px;left:476px";      
        }
    }
    if (move.isShowMoveBranding()) {
        moveNumLab.setValue(move.getName());
        addComponent(moveNumLab, "top:103px;left:333px");
    }
    /*    if(user != null && (user.isAdministrator() || user.isGameMaster() || user.isDesigner() )) { // has a menu
          //  fouoLink.addStyleName("m-absolutePositioning");
            addComponent(fouoLink,"top:-10px;left:400px");
        }
        else
          addComponent(fouoLink,"top:0px;left:400px");
                
        fouoLink.setVisible(g.isShowFouo());
        */
}

From source file:edu.nps.moves.mmowgli.components.Leaderboard.java

License:Open Source License

public void initGuiTL() {
    setSizeUndefined();/*from w w  w.j a v a2 s .c om*/
    setWidth(APPLICATION_SCREEN_WIDTH);
    setSpacing(false);

    MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals();
    Label sp;

    HorizontalLayout titleHL = new HorizontalLayout();
    addComponent(titleHL);
    titleHL.setMargin(new MarginInfo(false, true, false, true)); //sides only
    titleHL.setWidth("100%");

    Component c;
    titleHL.addComponent(c = globs.getMediaLocator().getLeaderboardTitle());
    titleHL.setComponentAlignment(c, Alignment.MIDDLE_LEFT);
    titleHL.setExpandRatio(c, .5f);

    maybeShowMoveSelector(titleHL);

    tips.setStyleName(BaseTheme.BUTTON_LINK);
    tips.addStyleName("m-link-button");
    titleHL.addComponent(tips);
    titleHL.setComponentAlignment(tips, Alignment.MIDDLE_RIGHT);
    titleHL.setExpandRatio(tips, 0.5f);

    tableVLayout = new VerticalLayout();
    tableVLayout.setSizeUndefined();
    tableVLayout.setWidth(APPLICATION_SCREEN_WIDTH);
    tableVLayout.setSpacing(true);
    tableVLayout.setMargin(true);
    tableVLayout.addStyleName("m-whitepage-header");

    addComponent(tableVLayout);

    tableVLayout.addComponent(sp = new Label());
    sp.setHeight("20px"); // to fit top of background

    tableVLayout.addComponent(table = createTableTL());
    tableVLayout.setComponentAlignment(table, Alignment.TOP_CENTER);
    table.setValue(globs.getUserID());
    tableVLayout.setExpandRatio(table, 1.0f);

    /* I can't get this to properly refresh, todo
    refreshButt = new Button("Refresh");
    mainVLayout.addComponent(refreshButt);
    mainVLayout.setComponentAlignment(refreshButt, Alignment.TOP_CENTER);
            
    refreshButt.addListener(new RefreshListener());
    refreshButt.setEnabled(false);
    */
}