Example usage for com.vaadin.ui Label setContentMode

List of usage examples for com.vaadin.ui Label setContentMode

Introduction

In this page you can find the example usage for com.vaadin.ui Label setContentMode.

Prototype

public void setContentMode(ContentMode contentMode) 

Source Link

Document

Sets the content mode of the label.

Usage

From source file:com.foc.helpBook.HelpUI.java

License:Apache License

@Override
public FocCentralPanel newWindow() {
    FocCentralPanel focCentralPanel = new FocCentralPanel();
    focCentralPanel.fill();/*from  ww  w .  j  av a  2  s  .  co  m*/

    Label labelHelpContent = new Label();
    labelHelpContent.setContentMode(ContentMode.HTML);

    String htmlContent = (String) FocWebApplication.getFocWebSession_Static().getParameter("HELP_CONTENT");
    labelHelpContent.setValue(htmlContent);
    VerticalLayout mainLayout = new VerticalLayout();

    mainLayout.setSizeFull();

    HorizontalLayout navigationLayout = new HorizontalLayout();
    navigationLayout.setWidth("95%");

    navigationLayout.addComponent(getPreviousPageButton());
    navigationLayout.setComponentAlignment(getPreviousPageButton(), Alignment.BOTTOM_LEFT);

    navigationLayout.addComponent(getNextPageButton());
    navigationLayout.setComponentAlignment(getNextPageButton(), Alignment.BOTTOM_RIGHT);

    mainLayout.addComponent(labelHelpContent);

    mainLayout.addComponent(navigationLayout);
    mainLayout.setComponentAlignment(navigationLayout, Alignment.BOTTOM_CENTER);

    focCentralPanel.addComponent(mainLayout);
    return focCentralPanel;
}

From source file:com.foc.vaadin.gui.FocCustomComponent.java

License:Apache License

private Label addLabel(String value, String style, int left, int top, int width, int heigth,
        ContentMode contentMode) {//from   w w  w.  ja  va  2 s.c o  m
    Label lbl = null;
    if (mainLayout != null) {
        lbl = new Label(value);
        lbl.setContentMode(contentMode);
        lbl.addStyleName(style);
        lbl.setWidth(width + "px");
        lbl.setHeight(heigth + "78px");
        mainLayout.addComponent(lbl, "top:" + top + ".0px;left:" + left + ".0px;");
    }
    return lbl;
}

From source file:com.haulmont.cuba.web.log.LogWindow.java

License:Apache License

private void initUI() {
    ClientConfig clientConfig = AppBeans.<Configuration>get(Configuration.NAME).getConfig(ClientConfig.class);

    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);

    com.vaadin.event.ShortcutAction closeShortcutAction = new com.vaadin.event.ShortcutAction(
            "closeShortcutAction", closeCombination.getKey().getCode(),
            KeyCombination.Modifier.codes(closeCombination.getModifiers()));

    addActionHandler(new com.vaadin.event.Action.Handler() {
        @Override//  ww w.  j ava 2s.  c  om
        public com.vaadin.event.Action[] getActions(Object target, Object sender) {
            return new com.vaadin.event.Action[] { closeShortcutAction };
        }

        @Override
        public void handleAction(com.vaadin.event.Action action, Object sender, Object target) {
            if (Objects.equals(action, closeShortcutAction)) {
                close();
            }
        }
    });

    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setSizeFull();
    setContent(layout);

    Panel scrollablePanel = new Panel();
    scrollablePanel.setSizeFull();
    VerticalLayout scrollContent = new VerticalLayout();
    scrollContent.setSizeUndefined();
    scrollablePanel.setContent(scrollContent);

    final Label label = new Label();
    label.setContentMode(ContentMode.HTML);
    label.setValue(writeLog());
    label.setSizeUndefined();
    label.setStyleName("c-log-content");

    ((Layout) scrollablePanel.getContent()).addComponent(label);

    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setWidth("100%");
    topLayout.setHeightUndefined();

    Messages messages = AppBeans.get(Messages.NAME);
    Button refreshBtn = new CubaButton(messages.getMessage(getClass(), "logWindow.refreshBtn"),
            (Button.ClickListener) event -> label.setValue(writeLog()));

    topLayout.addComponent(refreshBtn);

    layout.addComponent(topLayout);
    layout.addComponent(scrollablePanel);

    layout.setExpandRatio(scrollablePanel, 1.0f);
}

From source file:com.haulmont.cuba.web.LoginWindow.java

License:Apache License

protected HorizontalLayout createTitleLayout() {
    HorizontalLayout titleLayout = new HorizontalLayout();
    titleLayout.setStyleName("cuba-login-title");
    titleLayout.setSpacing(true);//from   w w  w  .  j  a  va 2 s . c om

    Image logoImage = getLogoImage();
    if (logoImage != null) {
        logoImage.setStyleName("cuba-login-icon");
        titleLayout.addComponent(logoImage);
        titleLayout.setComponentAlignment(logoImage, Alignment.MIDDLE_LEFT);
    }

    String welcomeMsg = messages.getMainMessage("loginWindow.welcomeLabel", resolvedLocale);
    Label label = new Label(welcomeMsg.replace("\n", "<br/>"));
    label.setContentMode(ContentMode.HTML);
    label.setWidthUndefined();
    label.setStyleName("cuba-login-caption");

    if (!StringUtils.isBlank(label.getValue())) {
        titleLayout.addComponent(label);
        titleLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    }
    return titleLayout;
}

From source file:com.haulmont.cuba.web.sys.WindowBreadCrumbs.java

License:Apache License

public void update() {
    AppUI ui = AppUI.getCurrent();//from  ww  w  . j a  v a  2s.c o  m
    boolean isTestMode = ui.isTestMode();

    linksLayout.removeAllComponents();
    btn2win.clear();
    for (Iterator<Window> it = windows.iterator(); it.hasNext();) {
        Window window = it.next();
        Button button = new CubaButton(StringUtils.trimToEmpty(window.getCaption()), new BtnClickListener());
        button.setSizeUndefined();
        button.setStyleName(BaseTheme.BUTTON_LINK);
        button.setTabIndex(-1);

        if (isTestMode) {
            button.setCubaId("breadCrubms_Button_" + window.getId());
            button.setId(ui.getTestIdManager().getTestId("breadCrubms_Button_" + window.getId()));
        }

        btn2win.put(button, window);

        if (it.hasNext()) {
            linksLayout.addComponent(button);

            Label separatorLab = new Label("&nbsp;&gt;&nbsp;");
            separatorLab.setStyleName("c-breadcrumbs-separator");
            separatorLab.setSizeUndefined();
            separatorLab.setContentMode(ContentMode.HTML);
            linksLayout.addComponent(separatorLab);
        } else {
            Label captionLabel = new Label(window.getCaption());
            captionLabel.setStyleName("c-breadcrumbs-win-caption");
            captionLabel.setSizeUndefined();
            linksLayout.addComponent(captionLabel);

            this.label = captionLabel;
        }
    }
}

From source file:com.haulmont.cuba.web.WebWindowManager.java

License:Apache License

@Override
public void showMessageDialog(String title, String message, MessageType messageType) {
    backgroundWorker.checkUIAccess();//from   w w  w . jav a  2s  . co  m

    final com.vaadin.ui.Window vWindow = new CubaWindow(title);

    if (ui.isTestMode()) {
        vWindow.setCubaId("messageDialog");
        vWindow.setId(ui.getTestIdManager().getTestId("messageDialog"));
    }

    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);

    vWindow.addAction(new ShortcutListener("Esc", closeCombination.getKey().getCode(),
            KeyCombination.Modifier.codes(closeCombination.getModifiers())) {
        @Override
        public void handleAction(Object sender, Object target) {
            vWindow.close();
        }
    });

    vWindow.addAction(new ShortcutListener("Enter", ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            vWindow.close();
        }
    });

    VerticalLayout layout = new VerticalLayout();
    layout.setStyleName("c-app-message-dialog");
    layout.setSpacing(true);
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        layout.setWidthUndefined();
    }
    vWindow.setContent(layout);

    Label messageLab = new CubaLabel();
    messageLab.setValue(message);
    if (MessageType.isHTML(messageType)) {
        messageLab.setContentMode(ContentMode.HTML);
    } else {
        messageLab.setContentMode(ContentMode.TEXT);
    }
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        messageLab.setWidthUndefined();
    }
    layout.addComponent(messageLab);

    DialogAction action = new DialogAction(Type.OK);
    Button button = WebComponentsHelper.createButton();

    button.setCaption(action.getCaption());
    button.setIcon(WebComponentsHelper.getIcon(action.getIcon()));
    button.addStyleName(WebButton.ICON_STYLE);
    button.addClickListener(event -> vWindow.close());

    button.focus();

    layout.addComponent(button);

    layout.setComponentAlignment(button, Alignment.BOTTOM_RIGHT);

    float width;
    SizeUnit unit;
    DialogParams dialogParams = getDialogParams();
    if (messageType.getWidth() != null) {
        width = messageType.getWidth();
        unit = messageType.getWidthUnit();
    } else if (dialogParams.getWidth() != null) {
        width = dialogParams.getWidth();
        unit = dialogParams.getWidthUnit();
    } else {
        SizeWithUnit size = SizeWithUnit
                .parseStringSize(app.getThemeConstants().get("cuba.web.WebWindowManager.messageDialog.width"));
        width = size.getSize();
        unit = size.getUnit();
    }

    vWindow.setWidth(width, unit != null ? WebWrapperUtils.toVaadinUnit(unit) : Unit.PIXELS);
    vWindow.setResizable(false);

    boolean modal = true;
    if (!hasModalWindow()) {
        if (messageType.getModal() != null) {
            modal = messageType.getModal();
        } else if (dialogParams.getModal() != null) {
            modal = dialogParams.getModal();
        }
    }
    vWindow.setModal(modal);

    boolean closeOnClickOutside = false;
    if (vWindow.isModal()) {
        if (messageType.getCloseOnClickOutside() != null) {
            closeOnClickOutside = messageType.getCloseOnClickOutside();
        }
    }
    ((CubaWindow) vWindow).setCloseOnClickOutside(closeOnClickOutside);

    if (messageType.getMaximized() != null) {
        if (messageType.getMaximized()) {
            vWindow.setWindowMode(WindowMode.MAXIMIZED);
        } else {
            vWindow.setWindowMode(WindowMode.NORMAL);
        }
    }

    dialogParams.reset();

    ui.addWindow(vWindow);
    vWindow.center();
    vWindow.focus();
}

From source file:com.haulmont.cuba.web.WebWindowManager.java

License:Apache License

@Override
public void showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
    backgroundWorker.checkUIAccess();/*from   w  ww  .j  av a  2s. c  o m*/

    final com.vaadin.ui.Window window = new CubaWindow(title);

    if (ui.isTestMode()) {
        window.setCubaId("optionDialog");
        window.setId(ui.getTestIdManager().getTestId("optionDialog"));
    }
    window.setClosable(false);

    Label messageLab = new CubaLabel();
    messageLab.setValue(message);
    if (MessageType.isHTML(messageType)) {
        messageLab.setContentMode(ContentMode.HTML);
    } else {
        messageLab.setContentMode(ContentMode.TEXT);
    }
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        messageLab.setWidthUndefined();
    }

    float width;
    SizeUnit unit;
    if (messageType.getWidth() != null) {
        width = messageType.getWidth();
        unit = messageType.getWidthUnit();
    } else if (getDialogParams().getWidth() != null) {
        width = getDialogParams().getWidth();
        unit = getDialogParams().getWidthUnit();
    } else {
        SizeWithUnit size = SizeWithUnit
                .parseStringSize(app.getThemeConstants().get("cuba.web.WebWindowManager.optionDialog.width"));
        width = size.getSize();
        unit = size.getUnit();
    }

    if (messageType.getModal() != null) {
        log.warn("MessageType.modal is not supported for showOptionDialog");
    }

    getDialogParams().reset();

    window.setWidth(width, unit != null ? WebWrapperUtils.toVaadinUnit(unit) : Unit.PIXELS);
    window.setResizable(false);
    window.setModal(true);

    boolean closeOnClickOutside = false;
    if (window.isModal()) {
        if (messageType.getCloseOnClickOutside() != null) {
            closeOnClickOutside = messageType.getCloseOnClickOutside();
        }
    }
    ((CubaWindow) window).setCloseOnClickOutside(closeOnClickOutside);

    if (messageType.getMaximized() != null) {
        if (messageType.getMaximized()) {
            window.setWindowMode(WindowMode.MAXIMIZED);
        } else {
            window.setWindowMode(WindowMode.NORMAL);
        }
    }

    VerticalLayout layout = new VerticalLayout();
    layout.setStyleName("c-app-option-dialog");
    layout.setSpacing(true);
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        layout.setWidthUndefined();
    }
    window.setContent(layout);

    HorizontalLayout buttonsContainer = new HorizontalLayout();
    buttonsContainer.setSpacing(true);

    boolean hasPrimaryAction = false;
    Map<Action, Button> buttonMap = new HashMap<>();
    for (Action action : actions) {
        Button button = WebComponentsHelper.createButton();
        button.setCaption(action.getCaption());
        button.addClickListener(event -> {
            try {
                action.actionPerform(null);
            } finally {
                ui.removeWindow(window);
            }
        });

        if (StringUtils.isNotEmpty(action.getIcon())) {
            button.setIcon(WebComponentsHelper.getIcon(action.getIcon()));
            button.addStyleName(WebButton.ICON_STYLE);
        }

        if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) {
            button.addStyleName("c-primary-action");
            button.focus();

            hasPrimaryAction = true;
        }

        if (ui.isTestMode()) {
            button.setCubaId("optionDialog_" + action.getId());
            button.setId(ui.getTestIdManager().getTestId("optionDialog_" + action.getId()));
        }

        buttonsContainer.addComponent(button);
        buttonMap.put(action, button);
    }

    assignDialogShortcuts(buttonMap);

    if (!hasPrimaryAction && actions.length > 0) {
        ((Button) buttonsContainer.getComponent(0)).focus();
    }

    layout.addComponent(messageLab);
    layout.addComponent(buttonsContainer);

    layout.setExpandRatio(messageLab, 1);
    layout.setComponentAlignment(buttonsContainer, Alignment.BOTTOM_RIGHT);

    ui.addWindow(window);
    window.center();
}

From source file:com.hazelcast.examples.Tutorial.java

License:Open Source License

private final void prepareSourceCode() {
    String source = "/" + getClass().getName().replaceAll("\\.", "/") + ".java";
    try {/* w ww .j  a  va 2  s . c  o  m*/
        String code = StringUtils.replaceEach(IOUtils.toString(getClass().getResourceAsStream(source)),
                new String[] { "&", "<", ">", "\"", "'", "/" },
                new String[] { "&amp;", "&lt;", "&gt;", "&quot;", "&#x27;", "&#x2F;" });
        Label c = new Label("<pre class='prettyprint'>" + code + "</pre>");
        c.setContentMode(ContentMode.HTML);
        c.setSizeUndefined();
        addSelectedTabChangeListener(e -> JavaScript.eval("setTimeout(function(){prettyPrint();},300);"));
        sourceCode.add(c);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.hazelcast.examples.tutorials.impl.Utils.java

License:Open Source License

public static Label toLabel(Object value) {
    Label label = new Label(toString(value));
    label.setContentMode(ContentMode.PREFORMATTED);
    return label;
}

From source file:com.hrms.main.AboutHRIS.java

public AboutHRIS() {
    setCaption("About HRIS");
    setWidth("300px");

    VerticalLayout vlayout = new VerticalLayout();
    vlayout.setSpacing(true);/*  w  w  w  .j a  v  a2s  . c  om*/
    vlayout.setMargin(true);

    Label version = new Label("Version: <b>1.5</b>");
    version.setContentMode(Label.CONTENT_XHTML);
    vlayout.addComponent(version);

    Label title = new Label("Title: <b>Human Resource Information System</b>");
    title.setContentMode(Label.CONTENT_XHTML);
    vlayout.addComponent(title);

    Label developer = new Label("Developed By: <b>Engr. Godfrey D. Beray</b>");
    developer.setContentMode(Label.CONTENT_XHTML);
    vlayout.addComponent(developer);

    Label framework = new Label("Framework: <b>VAADIN - Sept2012</b>");
    framework.setContentMode(Label.CONTENT_XHTML);
    vlayout.addComponent(framework);

    addComponent(vlayout);
}