Example usage for com.vaadin.ui Image setSource

List of usage examples for com.vaadin.ui Image setSource

Introduction

In this page you can find the example usage for com.vaadin.ui Image setSource.

Prototype

public void setSource(Resource source) 

Source Link

Document

Sets the object source resource.

Usage

From source file:edu.nps.moves.mmowgli.modules.actionplans.MediaSubWindow.java

License:Open Source License

private Component buildCenter(Resource res) {
    Image img = new Image();
    img.setSource(res);
    return img;
}

From source file:edu.nps.moves.mmowgliMobile.ui.CardRenderer2.java

License:Open Source License

public void setMessage(FullEntryView2 mView, ListEntry message, ListView2 messageList,
        AbstractOrderedLayout layout) {//  w ww . j ava2 s  .co m
    Object key = HSess.checkInit();
    CardListEntry wc = (CardListEntry) message;
    Card c = wc.getCard();
    CardType typ = c.getCardType();

    layout.removeAllComponents();
    layout.setSpacing(true);

    VerticalLayout cardLay = new VerticalLayout();
    cardLay.addStyleName("m-card-render");
    cardLay.setWidth("98%"); //100%");
    cardLay.setSpacing(true);
    layout.addComponent(cardLay);

    HorizontalLayout horl = new HorizontalLayout();
    horl.addStyleName("m-card-header");
    String stl = CardStyler.getCardBaseStyle(typ);
    horl.addStyleName(stl);
    horl.addStyleName(CardStyler.getCardTextColorOverBaseStyle(typ));
    horl.setMargin(true);
    horl.setWidth("100%");

    Label lbl = new Label(typ.getTitle());//c.getText());
    horl.addComponent(lbl);
    lbl = new Label("" + getPojoId(message));
    lbl.addStyleName("m-text-align-right");
    horl.addComponent(lbl);
    cardLay.addComponent(horl);

    horl = new HorizontalLayout();
    horl.setWidth("100%");
    horl.setMargin(true);
    cardLay.addComponent(horl);
    lbl = new Label(c.getText());
    horl.addComponent(lbl);

    horl = new HorizontalLayout();
    horl.addStyleName("m-card-footer");

    horl.setMargin(true);
    horl.setWidth("100%");
    horl.addComponent(lbl = new Label(""));
    lbl.setWidth("5px");

    Image img = new Image();
    img.setSource(mediaLocator.locate(c.getAuthor().getAvatar().getMedia()));
    img.setWidth("30px");
    img.setHeight("30px");
    horl.addComponent(img);

    //    horl.addComponent(lbl=new Label(c.getAuthorName()));
    //    lbl.setWidth("100%");
    //    lbl.addStyleName("m-text-align-center");
    //    horl.setComponentAlignment(lbl, Alignment.MIDDLE_CENTER);
    //    horl.setExpandRatio(lbl, 1.0f);

    Button authButt = new MyButton(c.getAuthorName(), c, mView);
    authButt.setStyleName(BaseTheme.BUTTON_LINK);
    authButt.setWidth("100%");
    horl.addComponent(authButt);
    horl.setComponentAlignment(authButt, Alignment.MIDDLE_CENTER);
    horl.setExpandRatio(authButt, 1.0f);

    horl.addComponent(lbl = new HtmlLabel(formatter.format(message.getTimestamp())));
    lbl.setWidth("115px");
    ;
    lbl.addStyleName("m-text-align-right");
    horl.setComponentAlignment(lbl, Alignment.MIDDLE_CENTER);

    cardLay.addComponent(horl);

    //    lbl = new Hr();   
    //    layout.addComponent(lbl);

    lbl = new Label("Child Cards");
    layout.addComponent(lbl);
    lbl.addStyleName("m-text-center");

    //    lbl = new Hr();
    //    layout.addComponent(lbl);

    horl = new HorizontalLayout();
    horl.setSpacing(true);
    horl.setMargin(true);
    horl.setWidth("100%");
    layout.addComponent(horl);

    horl.addComponent(
            makeChildGroupButton("Expand", (CardListEntry) message, CardType.getExpandTypeTL(), messageList));
    horl.addComponent(
            makeChildGroupButton("Counter", (CardListEntry) message, CardType.getCounterTypeTL(), messageList));
    horl.addComponent(
            makeChildGroupButton("Adapt", (CardListEntry) message, CardType.getAdaptTypeTL(), messageList));
    horl.addComponent(
            makeChildGroupButton("Explore", (CardListEntry) message, CardType.getExploreTypeTL(), messageList));

    HSess.checkClose(key);
}

From source file:edu.nps.moves.mmowgliMobile.ui.UserRenderer2.java

License:Open Source License

public void setMessage(FullEntryView2 mView, ListEntry message, ListView2 messageList,
        AbstractOrderedLayout layout) {//from  w  ww.  j  a va 2 s .c  o m
    // messageList can be null if coming in from ActionPlan
    Object key = HSess.checkInit();
    UserListEntry wu = (UserListEntry) message;
    User u = wu.getUser();
    layout.removeAllComponents();

    HorizontalLayout hlay = new HorizontalLayout();
    layout.addComponent(hlay);
    hlay.addStyleName("m-userview-top");
    hlay.setWidth("100%");
    hlay.setMargin(true);
    hlay.setSpacing(true);

    Image img = new Image();
    img.addStyleName("m-ridgeborder");
    img.setSource(mediaLocator.locate(u.getAvatar().getMedia()));
    img.setWidth("90px");
    img.setHeight("90px");
    hlay.addComponent(img);
    hlay.setComponentAlignment(img, Alignment.MIDDLE_CENTER);

    Label lab;
    hlay.addComponent(lab = new Label());
    lab.setWidth("5px");

    VerticalLayout vlay = new VerticalLayout();
    vlay.setSpacing(true);
    hlay.addComponent(vlay);
    hlay.setComponentAlignment(vlay, Alignment.MIDDLE_LEFT);
    vlay.setWidth("100%");
    hlay.setExpandRatio(vlay, 1.0f);
    HorizontalLayout horl = new HorizontalLayout();
    horl.setSpacing(false);
    vlay.addComponent(horl);
    vlay.setComponentAlignment(horl, Alignment.BOTTOM_LEFT);
    horl.addComponent(lab = new Label("name"));
    lab.addStyleName("m-user-top-label"); //light-text");
    horl.addComponent(lab = new HtmlLabel("  " + u.getUserName()));
    lab.addStyleName("m-user-top-value");
    horl = new HorizontalLayout();
    horl.setSpacing(false);
    vlay.addComponent(horl);
    vlay.setComponentAlignment(horl, Alignment.TOP_LEFT);

    horl.addComponent(lab = new Label("level"));
    lab.addStyleName("m-user-top-label"); //light-text");
    Level lev = u.getLevel();
    if (u.isGameMaster()) {
        Level l = Level.getLevelByOrdinal(Level.GAME_MASTER_ORDINAL, HSess.get());
        if (l != null)
            lev = l;
    }
    horl.addComponent(lab = new HtmlLabel("   " + lev.getDescription()));
    lab.addStyleName("m-user-top-value");

    GridLayout gLay = new GridLayout();
    // gLay.setHeight("155px");  // won't size properly
    gLay.setMargin(true);
    gLay.addStyleName("m-userview-mid");
    gLay.setColumns(2);
    gLay.setRows(11);
    gLay.setSpacing(true);
    gLay.setWidth("100%");
    gLay.setColumnExpandRatio(1, 1.0f);
    layout.addComponent(gLay);

    addRow(gLay, "user ID:", "" + getPojoId(message));
    addRow(gLay, "location:", u.getLocation());
    addRow(gLay, "expertise:", u.getExpertise());
    addRow(gLay, "affiliation:", u.getAffiliation());
    addRow(gLay, "date registered:", formatter.format(u.getRegisterDate()));

    gLay.addComponent(new Hr(), 0, 5, 1, 5);

    Container cntr = new CardsByUserContainer<Card>(u); // expects ThreadLocal session to be setup
    numCards = cntr.size();
    addRow(gLay, "cards played:", "" + numCards);
    cntr = new ActionPlansByUserContainer<Card>(u); // expects ThreadLocal session to be setup
    numAps = cntr.size();
    addRow(gLay, "action plans:", "" + numAps);

    gLay.addComponent(new Hr(), 0, 8, 1, 8);

    addRow(gLay, "exploration points:", "" + u.getBasicScore());
    addRow(gLay, "innovation points:", "" + u.getInnovationScore());

    cardListener = new CardLis(u, mView);
    apListener = new AppLis(u, mView);

    layout.addComponent(makeButtons());

    HSess.checkClose(key);
}

From source file:eu.eco2clouds.portal.component.PictureWindow.java

License:Apache License

private void render() {

    VerticalLayout content = new VerticalLayout();
    content.setSpacing(true);/*from  w  ww . j  a v  a  2 s  .  c  om*/
    content.setMargin(true);
    content.setSizeFull();

    Image image = new Image();
    //image.setSource(new ThemeResource("img/applicationsample.png"));
    image.setSource(new FileResource(
            new File(Configuration.propertiesDir + File.separator + "sample_applicationprofile.png")));
    //image.setHeight("300px");
    content.addComponent(image);

    Button btnClose = new Button("Close");
    btnClose.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {

            close();
        }
    });

    content.addComponent(btnClose);
    content.setExpandRatio(image, 1.0f);
    content.setComponentAlignment(btnClose, Alignment.BOTTOM_CENTER);
    this.setContent(content);

    this.setHeight("450px");
    this.setWidth("900px");

    this.center();
    this.setModal(true);
}

From source file:eu.maxschuster.vaadin.signaturefield.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    getPage().setTitle(pageTitle);/*from www.  j a  v  a  2 s.c  om*/

    final VerticalLayout margin = new VerticalLayout();
    setContent(margin);

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth("658px");
    margin.addComponent(layout);
    margin.setComponentAlignment(layout, Alignment.TOP_CENTER);

    final Label header1 = new Label(pageTitle);
    header1.addStyleName("h1");
    header1.setSizeUndefined();
    layout.addComponent(header1);
    layout.setComponentAlignment(header1, Alignment.TOP_CENTER);

    final TabSheet tabSheet = new TabSheet();
    tabSheet.setWidth("100%");
    layout.addComponent(tabSheet);
    layout.setComponentAlignment(tabSheet, Alignment.TOP_CENTER);

    final Panel signaturePanel = new Panel();
    signaturePanel.addStyleName("signature-panel");
    signaturePanel.setWidth("100%");
    tabSheet.addTab(signaturePanel, "Demo");

    final VerticalLayout signatureLayout = new VerticalLayout();
    signatureLayout.setMargin(true);
    signatureLayout.setSpacing(true);
    signatureLayout.setSizeFull();
    signaturePanel.setContent(signatureLayout);

    final SignatureField signatureField = new SignatureField();
    signatureField.setWidth("100%");
    signatureField.setHeight("318px");
    signatureField.setPenColor(Color.ULTRAMARINE);
    signatureField.setBackgroundColor("white");
    signatureField.setConverter(new StringToDataUrlConverter());
    signatureField.setPropertyDataSource(dataUrlProperty);
    signatureField.setVelocityFilterWeight(0.7);
    signatureLayout.addComponent(signatureField);
    signatureLayout.setComponentAlignment(signatureField, Alignment.MIDDLE_CENTER);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    signatureLayout.addComponent(buttonLayout);

    final Button clearButton = new Button("Clear", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            signatureField.clear();
        }
    });
    buttonLayout.addComponent(clearButton);
    buttonLayout.setComponentAlignment(clearButton, Alignment.MIDDLE_LEFT);

    final Label message = new Label("Sign above");
    message.setSizeUndefined();
    buttonLayout.addComponent(message);
    buttonLayout.setComponentAlignment(message, Alignment.MIDDLE_CENTER);

    final ButtonLink saveButtonLink = new ButtonLink("Save", null);
    saveButtonLink.setTargetName("_blank");
    buttonLayout.addComponent(saveButtonLink);
    buttonLayout.setComponentAlignment(saveButtonLink, Alignment.MIDDLE_RIGHT);

    final Panel optionsPanel = new Panel();
    optionsPanel.setSizeFull();
    tabSheet.addTab(optionsPanel, "Options");

    final FormLayout optionsLayout = new FormLayout();
    optionsLayout.setMargin(true);
    optionsLayout.setSpacing(true);
    optionsPanel.setContent(optionsLayout);

    final ComboBox mimeTypeComboBox = new ComboBox(null, mimeTypeContainer);
    optionsLayout.addComponent(mimeTypeComboBox);
    mimeTypeComboBox.setItemCaptionPropertyId("mimeType");
    mimeTypeComboBox.setNullSelectionAllowed(false);
    mimeTypeComboBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            MimeType mimeType = (MimeType) event.getProperty().getValue();
            signatureField.setMimeType(mimeType);
        }
    });
    mimeTypeComboBox.setValue(MimeType.PNG);
    mimeTypeComboBox.setCaption("Result MIME-Type");

    final CheckBox immediateCheckBox = new CheckBox("immediate", false);
    optionsLayout.addComponent(immediateCheckBox);
    immediateCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean immediate = (Boolean) event.getProperty().getValue();
            signatureField.setImmediate(immediate);
        }
    });

    final CheckBox readOnlyCheckBox = new CheckBox("readOnly", false);
    optionsLayout.addComponent(readOnlyCheckBox);
    readOnlyCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean readOnly = (Boolean) event.getProperty().getValue();
            signatureField.setReadOnly(readOnly);
            mimeTypeComboBox.setReadOnly(readOnly);
            clearButton.setEnabled(!readOnly);
        }
    });

    final CheckBox requiredCheckBox = new CheckBox("required (causes bug that clears field)", false);
    optionsLayout.addComponent(requiredCheckBox);
    requiredCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean required = (Boolean) event.getProperty().getValue();
            signatureField.setRequired(required);
        }
    });

    final CheckBox clearButtonEnabledButton = new CheckBox("clearButtonEnabled", false);
    optionsLayout.addComponent(clearButtonEnabledButton);
    clearButtonEnabledButton.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean clearButtonEnabled = (Boolean) event.getProperty().getValue();
            signatureField.setClearButtonEnabled(clearButtonEnabled);
        }
    });

    final Panel resultPanel = new Panel("Results:");
    resultPanel.setWidth("100%");
    layout.addComponent(resultPanel);

    final VerticalLayout resultLayout = new VerticalLayout();
    resultLayout.setMargin(true);
    resultPanel.setContent(resultLayout);

    final Image stringPreviewImage = new Image("String preview image:");
    stringPreviewImage.setWidth("500px");
    resultLayout.addComponent(stringPreviewImage);

    final Image dataUrlPreviewImage = new Image("DataURL preview image:");
    dataUrlPreviewImage.setWidth("500px");
    resultLayout.addComponent(dataUrlPreviewImage);

    final TextArea textArea = new TextArea("DataURL:");
    textArea.setWidth("100%");
    textArea.setHeight("300px");
    resultLayout.addComponent(textArea);

    final Label emptyLabel = new Label();
    emptyLabel.setCaption("Is Empty:");
    emptyLabel.setValue(String.valueOf(signatureField.isEmpty()));
    resultLayout.addComponent(emptyLabel);

    signatureField.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            String signature = (String) event.getProperty().getValue();
            stringPreviewImage.setSource(signature != null ? new ExternalResource(signature) : null);
            textArea.setValue(signature);
            emptyLabel.setValue(String.valueOf(signatureField.isEmpty()));
        }
    });
    dataUrlProperty.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            try {
                final DataUrl signature = (DataUrl) event.getProperty().getValue();
                dataUrlPreviewImage.setSource(
                        signature != null ? new ExternalResource(serializer.serialize(signature)) : null);
                StreamResource streamResource = null;
                if (signature != null) {
                    StreamSource streamSource = new StreamSource() {

                        @Override
                        public InputStream getStream() {
                            return new ByteArrayInputStream(signature.getData());
                        }
                    };
                    MimeType mimeType = MimeType.valueOfMimeType(signature.getMimeType());
                    String extension = null;

                    switch (mimeType) {
                    case JPEG:
                        extension = "jpg";
                        break;
                    case PNG:
                        extension = "png";
                        break;
                    }

                    streamResource = new StreamResource(streamSource, "signature." + extension);
                    streamResource.setMIMEType(signature.getMimeType());
                    streamResource.setCacheTime(0);
                }
                saveButtonLink.setResource(streamResource);
            } catch (MalformedURLException e) {
                logger.error(e.getMessage(), e);
            }
        }
    });
}

From source file:fi.semantum.strategia.Updates.java

License:Open Source License

private static void updateQueryGrid(final Main main, final FilterState state) {

    main.gridPanelLayout.removeAllComponents();
    main.gridPanelLayout.setMargin(false);

    final List<String> keys = state.reportColumns;
    if (keys.isEmpty()) {
        Label l = new Label("Kysely ei tuottanut yhtn tulosta.");
        l.addStyleName(ValoTheme.LABEL_BOLD);
        l.addStyleName(ValoTheme.LABEL_HUGE);
        main.gridPanelLayout.addComponent(l);
        return;// w ww.  j a va 2s  .c o  m
    }

    final IndexedContainer container = new IndexedContainer();

    for (String key : keys) {
        container.addContainerProperty(key, String.class, "");
    }

    rows: for (Map<String, ReportCell> map : state.report) {
        Object item = container.addItem();
        for (String key : keys)
            if (map.get(key) == null)
                continue rows;

        for (Map.Entry<String, ReportCell> entry : map.entrySet()) {
            @SuppressWarnings("unchecked")
            com.vaadin.data.Property<String> p = container.getContainerProperty(item, entry.getKey());
            p.setValue(entry.getValue().get());
        }

    }

    HorizontalLayout hl = new HorizontalLayout();
    hl.setWidth("100%");

    final TextField filter = new TextField();
    filter.addStyleName(ValoTheme.TEXTFIELD_TINY);
    filter.setInputPrompt("rajaa hakutuloksia - kirjoitetun sanan tulee lyty rivin teksteist");
    filter.setWidth("100%");

    final Image clipboard = new Image();
    clipboard.setSource(new ThemeResource("page_white_excel.png"));
    clipboard.setHeight("24px");
    clipboard.setWidth("24px");

    hl.addComponent(filter);
    hl.setExpandRatio(filter, 1.0f);
    hl.setComponentAlignment(filter, Alignment.BOTTOM_CENTER);
    hl.addComponent(clipboard);
    hl.setComponentAlignment(clipboard, Alignment.BOTTOM_CENTER);
    hl.setExpandRatio(clipboard, 0.0f);

    main.gridPanelLayout.addComponent(hl);
    main.gridPanelLayout.setExpandRatio(hl, 0f);

    filter.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 3033918399018888150L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            container.removeAllContainerFilters();
            container.addContainerFilter(new QueryFilter(filter.getValue(), true, false));
        }
    });

    AbsoluteLayout abs = new AbsoluteLayout();
    abs.setSizeFull();

    final Grid queryGrid = new Grid(container);
    queryGrid.setSelectionMode(SelectionMode.NONE);
    queryGrid.setHeightMode(HeightMode.CSS);
    queryGrid.setHeight("100%");
    queryGrid.setWidth("100%");

    for (String key : keys) {
        Column col = queryGrid.getColumn(key);
        col.setExpandRatio(1);
    }

    abs.addComponent(queryGrid);

    OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() {

        private static final long serialVersionUID = 981769438054780731L;

        File f;
        Date date = new Date();

        @Override
        public InputStream getStream() {

            String uuid = UUID.randomUUID().toString();
            File printing = new File(Main.baseDirectory(), "printing");
            f = new File(printing, uuid + ".xlsx");

            Workbook w = new XSSFWorkbook();
            Sheet sheet = w.createSheet("Sheet1");
            Row header = sheet.createRow(0);
            for (int i = 0; i < keys.size(); i++) {
                Cell cell = header.createCell(i);
                cell.setCellValue(keys.get(i));
            }

            int row = 1;
            rows: for (Map<String, ReportCell> map : state.report) {
                for (String key : keys)
                    if (map.get(key) == null)
                        continue rows;

                Row r = sheet.createRow(row++);
                int column = 0;
                for (int i = 0; i < keys.size(); i++) {
                    Cell cell = r.createCell(column++);
                    ReportCell rc = map.get(keys.get(i));
                    cell.setCellValue(rc.getLong());
                }

            }

            try {
                FileOutputStream s = new FileOutputStream(f);
                w.write(s);
                s.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                return new FileInputStream(f);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

            throw new IllegalStateException();

        }

        @Override
        public void onRequest() {
            // TODO Auto-generated method stub

        }

        @Override
        public long getFileSize() {
            return f.length();
        }

        @Override
        public String getFileName() {
            return "Strategiakartta_" + Utils.dateString(date) + ".xlsx";
        }

    });

    dl.getResource().setCacheTime(0);
    dl.extend(clipboard);

    main.gridPanelLayout.addComponent(abs);
    main.gridPanelLayout.setExpandRatio(abs, 1f);

}

From source file:fi.semantum.strategia.widget.Indicator.java

License:Open Source License

public static void updateIndicators(final Main main, final Base base, boolean canWrite) {

    final Database database = main.getDatabase();

    List<IndicatorDescription> descs = new ArrayList<IndicatorDescription>();
    fillIndicatorDescriptions(main, base, "", descs);

    boolean isMap = base instanceof Strategiakartta;

    if (isMap && (!descs.isEmpty() || canWrite)) {

        HorizontalLayout indiHeader = new HorizontalLayout();
        indiHeader.setSpacing(true);/* w ww . ja  v  a  2s. c o  m*/

        Label header = new Label("Indikaattorit (ennuste)");
        main.propertyCells.add(Utils.excelRow(header.getValue()));
        header.setHeight("32px");
        header.addStyleName(ValoTheme.LABEL_HUGE);
        header.addStyleName(ValoTheme.LABEL_BOLD);
        indiHeader.addComponent(header);
        indiHeader.setComponentAlignment(header, Alignment.BOTTOM_CENTER);

        if (canWrite) {

            final Image editIndicators = new Image(null, new ThemeResource("chart_line_edit.png"));
            editIndicators.setHeight("24px");
            editIndicators.setWidth("24px");
            editIndicators.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Utils.loseFocus(editIndicators);
                    manageIndicators(main, main.getUIState().currentItem);
                }

            });

            indiHeader.addComponent(editIndicators);
            indiHeader.setComponentAlignment(editIndicators, Alignment.BOTTOM_CENTER);

        }

        main.properties.addComponent(indiHeader);
        main.properties.setComponentAlignment(indiHeader, Alignment.MIDDLE_CENTER);

        VerticalLayout indicators = new VerticalLayout();

        boolean showYears = main.getUIState().time.equals(Property.AIKAVALI_KAIKKI);

        Property time = Property.find(database, Property.AIKAVALI);

        int index = 0;
        for (final IndicatorDescription desc : descs) {

            ArrayList<String> excelRow = new ArrayList<String>();

            Indicator indicator = desc.indicator;

            final HorizontalLayout hl = new HorizontalLayout();
            hl.addStyleName((((index++) & 1) == 0) ? "evenProperty" : "oddProperty");
            hl.setSpacing(true);

            Label l = new Label(desc.caption);
            excelRow.add(l.getValue().replace("%nbsp", ""));
            l.setContentMode(ContentMode.HTML);
            l.setWidth("450px");
            l.addStyleName("propertyName");
            l.setData(desc);
            hl.addComponent(l);
            hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT);

            String value = updateIndicatorValue(main, hl, base, indicator, canWrite);
            excelRow.add(value);

            Label unit = new Label(indicator.getUnit());
            unit.setWidth("100px");
            hl.addComponent(unit);
            hl.setComponentAlignment(unit, Alignment.MIDDLE_LEFT);
            excelRow.add(unit.getValue());

            Label comment = new Label(indicator.getValueShortComment());
            comment.setWidth("150px");
            hl.addComponent(comment);
            hl.setComponentAlignment(comment, Alignment.MIDDLE_LEFT);
            excelRow.add(comment.getValue());

            if (showYears) {

                HorizontalLayout hl2 = new HorizontalLayout();
                hl2.setWidth("70px");
                hl2.setHeight("100%");
                hl.addComponent(hl2);
                hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT);

                String years = time.getPropertyValue(indicator);
                if (years == null)
                    years = Property.AIKAVALI_KAIKKI;

                final Label region = new Label(years);
                region.setWidthUndefined();

                excelRow.add(region.getValue());

                hl2.addComponent(region);
                hl2.setComponentAlignment(region, Alignment.MIDDLE_CENTER);

            }

            final Image wiki = new Image();
            wiki.setSource(new ThemeResource("table_edit.png"));
            wiki.setHeight("24px");
            wiki.setWidth("24px");
            wiki.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Wiki.openWiki(main, desc.indicator);
                }

            });

            hl.addComponent(wiki);
            hl.setComponentAlignment(wiki, Alignment.MIDDLE_CENTER);

            indicators.addComponent(hl);
            indicators.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);

            main.propertyCells.add(excelRow);

        }

        indicators.addLayoutClickListener(new LayoutClickListener() {

            private static final long serialVersionUID = 3295743025581923380L;

            private String extractData(Component c) {
                if (c instanceof AbstractComponent) {
                    Object data = ((AbstractComponent) c).getData();
                    if (data instanceof IndicatorDescription) {
                        IndicatorDescription desc = (IndicatorDescription) data;
                        return desc.indicator.getDescription(database);
                    }
                }
                return null;
            }

            @Override
            public void layoutClick(LayoutClickEvent event) {

                String desc = extractData(event.getClickedComponent());
                if (desc == null)
                    return;

                String content = "<div style=\"width: 700px; border: 2px solid; padding: 5px\">";
                content += "<div style=\"text-align: center; white-space:normal; font-size: 36px; padding: 10px\">"
                        + desc + "</div>";
                content += "</div>";

                Notification n = new Notification(content, Notification.Type.HUMANIZED_MESSAGE);
                n.setHtmlContentAllowed(true);
                n.show(Page.getCurrent());

            }

        });

        main.properties.addComponent(indicators);
        main.properties.setComponentAlignment(indicators, Alignment.MIDDLE_CENTER);

    }

}

From source file:fi.semantum.strategia.widget.Meter.java

License:Open Source License

public static void updateMeters(final Main main, boolean canWrite) {

    if (main.getUIState().currentItem instanceof Strategiakartta)
        return;//from   w  ww. ja  v  a2 s  . c  om

    final Database database = main.getDatabase();

    final Base base = main.getUIState().currentItem;

    List<MeterDescription> descs = makeMeterDescriptions(main, base, false);
    if (!descs.isEmpty() || canWrite) {

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

        Label header = new Label("Mittarit");
        main.propertyCells.add(Utils.excelRow(header.getValue()));
        header.setHeight("32px");
        header.addStyleName(ValoTheme.LABEL_HUGE);
        header.addStyleName(ValoTheme.LABEL_BOLD);
        meterHeader.addComponent(header);
        meterHeader.setComponentAlignment(header, Alignment.BOTTOM_CENTER);

        if (canWrite) {

            final Image editMeters = new Image(null, new ThemeResource("chart_bar_edit.png"));
            editMeters.setHeight("24px");
            editMeters.setWidth("24px");
            editMeters.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 2661060702097338722L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Utils.loseFocus(editMeters);
                    manageMeters(main, main.getUIState().currentItem);
                }

            });

            meterHeader.addComponent(editMeters);
            meterHeader.setComponentAlignment(editMeters, Alignment.BOTTOM_CENTER);

        }

        main.properties.addComponent(meterHeader);
        main.properties.setComponentAlignment(meterHeader, Alignment.MIDDLE_CENTER);

        VerticalLayout meters = new VerticalLayout();

        boolean showYears = main.getUIState().time.equals(Property.AIKAVALI_KAIKKI);

        Property time = Property.find(database, Property.AIKAVALI);

        int index = 0;
        for (final MeterDescription desc : descs) {

            ArrayList<String> excelRow = new ArrayList<String>();

            final Meter meter = desc.meter;

            final HorizontalLayout hl = new HorizontalLayout();
            hl.addStyleName((((index++) & 1) == 0) ? "evenProperty" : "oddProperty");
            hl.setSpacing(true);

            Label l = new Label(desc.caption);
            excelRow.add(l.getValue().replace("%nbsp", ""));
            l.setContentMode(ContentMode.HTML);
            l.setWidth("450px");
            l.addStyleName("propertyName");
            l.setData(desc);
            hl.addComponent(l);
            hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT);

            String value = updateMeterValue(main, hl, base, meter, canWrite);
            excelRow.add(value);

            String shortComment = "";
            Indicator indicator = meter.getPossibleIndicator(database);
            if (indicator != null)
                shortComment = indicator.getValueShortComment();
            Label comment = new Label(shortComment);
            comment.setWidth("150px");
            hl.addComponent(comment);
            hl.setComponentAlignment(comment, Alignment.MIDDLE_LEFT);
            excelRow.add(comment.getValue());

            if (showYears) {

                HorizontalLayout hl2 = new HorizontalLayout();
                hl2.setWidth("70px");
                hl2.setHeight("100%");
                hl.addComponent(hl2);
                hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT);

                String years = time.getPropertyValue(meter);
                if (years == null)
                    years = Property.AIKAVALI_KAIKKI;

                final Label region = new Label(years);
                region.setWidthUndefined();

                excelRow.add(region.getValue());

                hl2.addComponent(region);
                hl2.setComponentAlignment(region, Alignment.MIDDLE_CENTER);

            }

            AbsoluteLayout image = new AbsoluteLayout();
            image.setWidth("32px");
            image.setHeight("32px");
            image.addStyleName("meterColor" + index);

            String color = meter.getTrafficColor(database);

            Styles styles = Page.getCurrent().getStyles();
            styles.add(
                    ".fi_semantum_strategia div." + "meterColor" + index + " { background: " + color + "; }");

            hl.addComponent(image);
            hl.setComponentAlignment(image, Alignment.MIDDLE_CENTER);
            hl.setExpandRatio(image, 0.0f);

            meters.addComponent(hl);
            meters.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);

            ThemeResource res = desc.meter.showInMap ? new ThemeResource("zoom.png")
                    : new ThemeResource("zoom_out.png");

            final Image show = new Image();
            show.setSource(res);
            show.setHeight("24px");
            show.setWidth("24px");
            if (canWrite) {
                show.setDescription("Klikkaamalla voit valita, nytetnk mittaria strategiakartassa");
                show.addClickListener(new MouseEvents.ClickListener() {

                    private static final long serialVersionUID = 7156984656942915939L;

                    @Override
                    public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                        desc.meter.setShowInMap(!desc.meter.showInMap);
                        Updates.update(main, true);
                    }

                });
            }

            hl.addComponent(show);
            hl.setComponentAlignment(show, Alignment.MIDDLE_CENTER);

            final Image wiki = new Image();
            wiki.setSource(new ThemeResource("table_edit.png"));
            wiki.setHeight("24px");
            wiki.setWidth("24px");
            wiki.setDescription("Klikkaamalla voit siirty tausta-asiakirjaan");
            wiki.addClickListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 7156984656942915939L;

                @Override
                public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                    Wiki.openWiki(main, desc.meter);
                }

            });

            hl.addComponent(wiki);
            hl.setComponentAlignment(wiki, Alignment.MIDDLE_CENTER);

            if (canWrite) {
                final Button principalButton = new Button();
                if (meter.isPrincipal) {
                    principalButton.setCaption("Poista kokonaisarvio");
                } else {
                    principalButton.setCaption("Aseta kokonaisarvioksi");
                }
                principalButton.setStyleName(ValoTheme.BUTTON_TINY);
                principalButton.addClickListener(new ClickListener() {

                    private static final long serialVersionUID = 8247560202892661226L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        if (meter.isPrincipal) {
                            meter.isPrincipal = false;
                        } else {
                            for (Meter m : base.getMeters(database))
                                m.isPrincipal = false;
                            meter.isPrincipal = true;
                        }
                        Updates.update(main, true);

                    }

                });
                hl.addComponent(principalButton);
                hl.setComponentAlignment(principalButton, Alignment.MIDDLE_CENTER);
            }

            main.propertyCells.add(excelRow);

        }

        meters.addLayoutClickListener(new LayoutClickListener() {

            private static final long serialVersionUID = 3295743025581923380L;

            private String extractData(Component c) {
                if (c instanceof AbstractComponent) {
                    Object data = ((AbstractComponent) c).getData();
                    if (data instanceof MeterDescription) {
                        MeterDescription desc = (MeterDescription) data;
                        return desc.meter.getDescription(database);
                    }
                }
                return null;
            }

            @Override
            public void layoutClick(LayoutClickEvent event) {

                String desc = extractData(event.getClickedComponent());
                if (desc == null)
                    return;

                String content = "<div style=\"width: 700px; border: 2px solid; padding: 5px\">";
                content += "<div style=\"text-align: center; white-space:normal; font-size: 36px; padding: 10px\">"
                        + desc + "</div>";
                content += "</div>";

                Notification n = new Notification(content, Notification.Type.HUMANIZED_MESSAGE);
                n.setHtmlContentAllowed(true);
                n.show(Page.getCurrent());

            }

        });

        main.properties.addComponent(meters);
        main.properties.setComponentAlignment(meters, Alignment.MIDDLE_CENTER);

    }

}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre el dilogo para cambiar la foto//from   ww w  .  j av a  2  s . c  o  m
 *
 *
 */
private void uploadFoto() {
    // Create a sub-window and set the content
    Window subWindow = new Window("My photo");

    subWindow.setWidth("475px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    Label e = new Label();

    Image image = new Image();

    class MyUploader implements Upload.Receiver, Upload.SucceededListener {

        File file;

        public File getFile() {
            return file;
        }

        public OutputStream receiveUpload(String fileName, String mimeType) {
            // Create and return a file output stream

            System.out.println("receiveUpload(" + fileName + "," + mimeType + ")");

            FileOutputStream os = null;
            if (fileName != null && !"".equals(fileName)) {

                long id = fileId++;
                String extension = ".tmp";
                if (fileName == null || "".equals(fileName.trim()))
                    fileName = "" + id + extension;
                if (fileName.lastIndexOf(".") < fileName.length() - 1) {
                    extension = fileName.substring(fileName.lastIndexOf("."));
                    fileName = fileName.substring(0, fileName.lastIndexOf("."));
                }
                File temp = null;
                try {
                    temp = File.createTempFile(fileName, extension);
                    os = new FileOutputStream(file = temp);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return os;
        }

        public void uploadSucceeded(Upload.SucceededEvent event) {
            // Show the uploaded file in the image viewer
            image.setSource(new FileResource(file));
            System.out.println("uploadSucceeded(" + file.getAbsolutePath() + ")");

        }

        public FileLocator getFileLocator() throws IOException {

            String extension = ".tmp";
            String fileName = file.getName();

            if (file.getName() == null || "".equals(file.getName().trim()))
                fileName = "" + getId();
            if (fileName.lastIndexOf(".") < fileName.length() - 1) {
                extension = fileName.substring(fileName.lastIndexOf("."));
                fileName = fileName.substring(0, fileName.lastIndexOf(".")).replaceAll(" ", "_");
            }

            java.io.File temp = (System.getProperty("tmpdir") == null)
                    ? java.io.File.createTempFile(fileName, extension)
                    : new java.io.File(new java.io.File(System.getProperty("tmpdir")), fileName + extension);

            System.out.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir"));
            System.out.println("Temp file : " + temp.getAbsolutePath());

            if (System.getProperty("tmpdir") == null || !temp.exists()) {
                System.out.println("writing temp file to " + temp.getAbsolutePath());
                Files.copy(file, temp);
            } else {
                System.out.println("temp file already exists");
            }

            String baseUrl = System.getProperty("tmpurl");
            URL url = null;
            try {
                if (baseUrl == null) {
                    url = file.toURI().toURL();
                } else
                    url = new URL(baseUrl + "/" + file.getName());
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            return new FileLocator(0, file.getName(), url.toString(), file.getAbsolutePath());
        }
    }
    ;
    MyUploader receiver = new MyUploader();

    Upload upload = new Upload(null, receiver);
    //upload.setImmediateMode(false);
    upload.addSucceededListener(receiver);

    f.addComponent(image);

    f.addComponent(upload);

    f.addComponent(e);

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button ok = new Button("Change it!", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Changing photo...");
            try {
                FileLocator loc = receiver.getFileLocator();

                io.mateu.ui.core.client.app.MateuUI.getBaseService()
                        .updateFoto(getApp().getUserData().getLogin(), loc, new AsyncCallback<Void>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                            }

                            @Override
                            public void onSuccess(Void result) {
                                e.setValue("OK!");
                                getApp().getUserData().setPhoto(loc.getUrl());
                                foto = (getApp().getUserData().getPhoto() != null)
                                        ? new ExternalResource(getApp().getUserData().getPhoto())
                                        : new ClassResource("profile-pic-300px.jpg");
                                subWindow.close();

                                refreshSettings();

                            }
                        });

            } catch (IOException e1) {
                e1.printStackTrace();
                io.mateu.ui.core.client.app.MateuUI.alert("" + e1.getClass().getName() + ":" + e1.getMessage());
            }

        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    upload.focus();
}

From source file:me.uni.emuseo.view.common.helpers.ImagePreviewWindow.java

License:Open Source License

public ImagePreviewWindow(String url) {
    setSizeUndefined();/*from   w  w  w .  j  a va2 s .c o  m*/
    setWidth(400, Unit.PIXELS);
    setHeight(360, Unit.PIXELS);
    windowLayout = new VerticalLayout();

    if (url != null) {
        Image image = new Image();
        image.setSource(new ExternalResource(url));
        image.setSizeFull();
        windowLayout.addComponent(image);
    }

    // buildButtons();
    // windowLayout.addComponent(buttonLayout);
    setContent(windowLayout);
    setModal(true);
}