Search in sources :

Example 1 with Label

use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.

the class InteractionDialog method showPopupDialog.

/**
 * A popup dialog is shown with the context of a component and  its selection, it is disposed seamlessly if the back button is pressed
 * or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
 * dialog has the PopupDialog style by default.
 *
 * @param rect the screen rectangle to which the popup should point
 */
public void showPopupDialog(Rectangle rect) {
    disposed = false;
    if (getUIID().equals("Dialog")) {
        setUIID("PopupDialog");
        if (getTitleComponent().getUIID().equals("DialogTitle")) {
            getTitleComponent().setUIID("PopupDialogTitle");
        }
        getContentPane().setUIID("PopupContentPane");
    }
    Component contentPane = getContentPane();
    Label title = getTitleComponent();
    UIManager manager = getUIManager();
    String dialogTitle = title.getText();
    // preferred size logic of the dialog won't work with large title borders
    if ((dialogTitle != null || dialogTitle.length() == 0) && manager.isThemeConstant("hideEmptyTitleBool", false)) {
        boolean b = getTitle().length() > 0;
        titleArea.setVisible(b);
        getTitleComponent().setVisible(b);
        if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
            getTitleComponent().setPreferredSize(new Dimension(0, 0));
            getTitleComponent().getStyle().setBorder(null);
            titleArea.setPreferredSize(new Dimension(0, 0));
            if (getContentPane().getClientProperty("$ENLARGED_POP") == null) {
                getContentPane().putClientProperty("$ENLARGED_POP", Boolean.TRUE);
                int cpPaddingTop = getContentPane().getStyle().getPaddingTop();
                int titlePT = getTitleComponent().getStyle().getPaddingTop();
                byte[] pu = getContentPane().getStyle().getPaddingUnit();
                if (pu == null) {
                    pu = new byte[4];
                }
                pu[0] = Style.UNIT_TYPE_PIXELS;
                getContentPane().getStyle().setPaddingUnit(pu);
                int pop = Display.getInstance().convertToPixels(manager.getThemeConstant("popupNoTitleAddPaddingInt", 1), false);
                getContentPane().getStyle().setPadding(TOP, pop + cpPaddingTop + titlePT);
            }
        }
    }
    // allows a text area to recalculate its preferred size if embedded within a dialog
    revalidate();
    Style contentPaneStyle = getStyle();
    boolean restoreArrow = false;
    if (manager.isThemeConstant(getUIID() + "ArrowBool", false)) {
        Image t = manager.getThemeImageConstant(getUIID() + "ArrowTopImage");
        Image b = manager.getThemeImageConstant(getUIID() + "ArrowBottomImage");
        Image l = manager.getThemeImageConstant(getUIID() + "ArrowLeftImage");
        Image r = manager.getThemeImageConstant(getUIID() + "ArrowRightImage");
        Border border = contentPaneStyle.getBorder();
        if (border != null) {
            border.setImageBorderSpecialTile(t, b, l, r, rect);
            restoreArrow = true;
        }
    }
    calcPreferredSize();
    int prefHeight = getPreferredH();
    int prefWidth = getPreferredW();
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    Form f = Display.getInstance().getCurrent();
    int availableHeight = getLayeredPane(f).getParent().getHeight();
    int availableWidth = getLayeredPane(f).getParent().getWidth();
    int width = Math.min(availableWidth, prefWidth);
    int x = 0;
    int y = 0;
    boolean showPortrait = Display.getInstance().isPortrait();
    // if we don't have enough space then disregard device orientation
    if (showPortrait) {
        if (availableHeight < (availableWidth - rect.getWidth()) / 2) {
            showPortrait = false;
        }
    } else {
        if (availableHeight / 2 > availableWidth - rect.getWidth()) {
            showPortrait = true;
        }
    }
    if (showPortrait) {
        if (width < availableWidth) {
            int idealX = rect.getX() - width / 2 + rect.getSize().getWidth() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealX > 0) {
                // if the idealX is too far to the right just align to the right
                if (idealX + width > availableWidth) {
                    x = availableWidth - width;
                } else {
                    x = idealX;
                }
            }
        }
        if (rect.getY() < availableHeight / 2) {
            // popup downwards
            y = rect.getY();
            int height = Math.min(prefHeight, availableHeight - y);
            show(y, Math.max(0, availableHeight - height - y), x, Math.max(0, availableWidth - width - x));
        } else {
            // popup upwards
            int height = Math.min(prefHeight, rect.getY() - getLayeredPane(f).getAbsoluteY());
            y = rect.getY() - height - getLayeredPane(f).getAbsoluteY();
            show(y, Math.max(0, getLayeredPane(f).getComponentForm().getHeight() - rect.getY()), x, Math.max(0, availableWidth - width - x));
        }
    } else {
        int height = Math.min(prefHeight, availableHeight);
        if (height < availableHeight) {
            int idealY = rect.getY() - height / 2 + rect.getSize().getHeight() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealY > 0) {
                // if the idealY is too far up just align to the top
                if (idealY + height > availableHeight) {
                    y = availableHeight - height;
                } else {
                    y = idealY;
                }
            }
        }
        if (prefWidth > rect.getX()) {
            // popup right
            x = rect.getX() + rect.getSize().getWidth();
            if (x + prefWidth > availableWidth) {
                x = availableWidth - prefWidth;
            }
            width = Math.min(prefWidth, availableWidth - x);
            show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
        } else {
            // popup left
            width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
            x = rect.getX() - width;
            show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
        }
    }
/*if(restoreArrow) {
            contentPaneStyle.getBorder().clearImageBorderSpecialTile();
        }*/
}
Also used : Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component) Image(com.codename1.ui.Image) Border(com.codename1.ui.plaf.Border)

Example 2 with Label

use of com.vaadin.v7.ui.Label in project charts by vaadin.

the class TListUi method loadTestClasses.

private void loadTestClasses(TListUi aThis) {
    if (testClassess != null) {
        return;
    }
    testClassess = new IndexedContainer();
    testClassess.addContainerProperty("name", String.class, "");
    testClassess.addContainerProperty("description", String.class, "");
    testClassess.addContainerProperty("package", String.class, "");
    listTestClasses(testClassess, "area");
    listTestClasses(testClassess, "columnandbar");
    listTestClasses(testClassess, "combinations");
    listTestClasses(testClassess, "container");
    listTestClasses(testClassess, "dynamic");
    listTestClasses(testClassess, "lineandscatter");
    listTestClasses(testClassess, "other");
    listTestClasses(testClassess, "pie");
    listTestClasses(testClassess, "themes");
    listTestClasses(testClassess, "librarydata");
    listTestClasses(testClassess, "timeline");
    listTestClasses(testClassess, "threed");
    listTestClasses(testClassess, "declarative");
    listTestClasses(testClassess, "dataprovider");
    Table table = new Table("Test cases", testClassess);
    table.addGeneratedColumn("name", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            String name = (String) source.getItem(itemId).getItemProperty(columnId).getValue();
            String pack = (String) source.getItem(itemId).getItemProperty("package").getValue();
            Link link = new Link();
            link.setResource(new ExternalResource("/" + (pack != null ? pack + "/" : "") + name));
            link.setCaption(name);
            link.setTargetName("_new");
            return link;
        }
    });
    table.addGeneratedColumn("description", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            String description = (String) source.getItem(itemId).getItemProperty(columnId).getValue();
            return new Label(description);
        }
    });
    table.setSizeFull();
    table.setColumnExpandRatio("description", 1);
    VerticalLayout verticalLayout = new VerticalLayout();
    TextField filter = new TextField();
    filter.addTextChangeListener(new TextChangeListener() {

        @Override
        public void textChange(TextChangeEvent event) {
            String text = event.getText();
            testClassess.removeAllContainerFilters();
            testClassess.addContainerFilter("name", text, true, false);
        }
    });
    verticalLayout.addComponent(filter);
    filter.focus();
    verticalLayout.addComponent(table);
    setContent(verticalLayout);
}
Also used : Table(com.vaadin.v7.ui.Table) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) Label(com.vaadin.ui.Label) ExternalResource(com.vaadin.server.ExternalResource) TextChangeEvent(com.vaadin.v7.event.FieldEvents.TextChangeEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.v7.ui.TextField) TextChangeListener(com.vaadin.v7.event.FieldEvents.TextChangeListener) Link(com.vaadin.ui.Link)

Example 3 with Label

use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.

the class DefaultLookAndFeel method getPullToRefreshHeight.

/**
 * {@inheritDoc}
 */
public int getPullToRefreshHeight() {
    if (pull == null) {
        BorderLayout bl = new BorderLayout();
        bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
        pull = new Container(bl);
    }
    if (pullDown == null) {
        pullDown = new Label(getUIManager().localize("pull.down", "Pull down do refresh..."));
        pullDown.setUIID("PullToRefresh");
        Image i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
        if (i == null) {
            i = getDefaultRefreshIcon();
        }
        i = i.rotate(180);
        ((Label) pullDown).setIcon(i);
    }
    if (releaseToRefresh == null) {
        releaseToRefresh = new Label(getUIManager().localize("pull.release", "Release to refresh..."));
        releaseToRefresh.setUIID("PullToRefresh");
        Image i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
        if (i == null) {
            i = getDefaultRefreshIcon();
        }
        ((Label) releaseToRefresh).setIcon(i);
    }
    if (updating == null) {
        updating = new Container(new BoxLayout(BoxLayout.X_AXIS));
        ((Container) updating).addComponent(new InfiniteProgress());
        Label l = new Label(getUIManager().localize("pull.refresh", "Updating..."));
        l.setUIID("PullToRefresh");
        ((Container) updating).addComponent(l);
        pull.getUnselectedStyle().setPadding(0, 0, 0, 0);
        pull.getUnselectedStyle().setMargin(0, 0, 0, 0);
        pull.addComponent(BorderLayout.CENTER, updating);
        pull.layoutContainer();
        pull.setHeight(Math.max(pullDown.getPreferredH(), pull.getPreferredH()));
    }
    String s = UIManager.getInstance().getThemeConstant("pullToRefreshHeight", null);
    if (s != null) {
        float f = Util.toFloatValue(s);
        if (f > 0) {
            return Display.getInstance().convertToPixels(f);
        }
    }
    return pull.getHeight();
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) InfiniteProgress(com.codename1.components.InfiniteProgress) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) FontImage(com.codename1.ui.FontImage) Image(com.codename1.ui.Image)

Example 4 with Label

use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.

the class GenericListCellRenderer method findComponentsOfInterest.

private void findComponentsOfInterest(Component cmp, ArrayList dest) {
    if (cmp instanceof Container) {
        Container c = (Container) cmp;
        int count = c.getComponentCount();
        for (int iter = 0; iter < count; iter++) {
            findComponentsOfInterest(c.getComponentAt(iter), dest);
        }
        return;
    }
    // performance optimization for fixed images in lists
    if (cmp.getName() != null) {
        if (cmp instanceof Label) {
            Label l = (Label) cmp;
            if (l.getName().toLowerCase().endsWith("fixed") && l.getIcon() != null) {
                l.getIcon().lock();
            }
            dest.add(cmp);
            return;
        }
        if (cmp instanceof TextArea) {
            dest.add(cmp);
            return;
        }
    }
}
Also used : Container(com.codename1.ui.Container) TextArea(com.codename1.ui.TextArea) Label(com.codename1.ui.Label)

Example 5 with Label

use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.

the class GenericListCellRenderer method setComponentValueWithTickering.

private void setComponentValueWithTickering(Component cmp, Object value, Component l, Component rootRenderer) {
    setComponentValue(cmp, value, l, rootRenderer);
    if (cmp instanceof Label) {
        if (selectionListener) {
            if (l instanceof List) {
                ((List) l).addActionListener(mon);
            }
            parentList = l;
        }
        Label label = (Label) cmp;
        if (label.shouldTickerStart() && Display.getInstance().shouldRenderSelection()) {
            if (!label.isTickerRunning()) {
                parentList = l;
                if (parentList != null) {
                    Form f = parentList.getComponentForm();
                    if (f != null) {
                        f.registerAnimated(mon);
                        label.startTicker(cmp.getUIManager().getLookAndFeel().getTickerSpeed(), true);
                    }
                }
            }
        } else {
            if (label.isTickerRunning()) {
                label.stopTicker();
            }
            label.setTextPosition(0);
        }
    }
}
Also used : Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) List(com.codename1.ui.List) ArrayList(java.util.ArrayList)

Aggregations

Label (com.codename1.ui.Label)129 Form (com.codename1.ui.Form)85 Label (com.vaadin.ui.Label)53 Container (com.codename1.ui.Container)45 Button (com.codename1.ui.Button)41 Label (com.vaadin.v7.ui.Label)41 Button (com.vaadin.ui.Button)32 TextField (com.vaadin.v7.ui.TextField)32 BorderLayout (com.codename1.ui.layouts.BorderLayout)31 ComboBox (com.vaadin.v7.ui.ComboBox)30 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)28 VerticalLayout (com.vaadin.ui.VerticalLayout)26 Captions (de.symeda.sormas.api.i18n.Captions)26 Strings (de.symeda.sormas.api.i18n.Strings)25 Component (com.codename1.ui.Component)23 HorizontalLayout (com.vaadin.ui.HorizontalLayout)23 FacadeProvider (de.symeda.sormas.api.FacadeProvider)23 Window (com.vaadin.ui.Window)22 CssStyles (de.symeda.sormas.ui.utils.CssStyles)22 ValoTheme (com.vaadin.ui.themes.ValoTheme)19