Example usage for com.vaadin.server ExternalResource ExternalResource

List of usage examples for com.vaadin.server ExternalResource ExternalResource

Introduction

In this page you can find the example usage for com.vaadin.server ExternalResource ExternalResource.

Prototype

public ExternalResource(String sourceURL) 

Source Link

Document

Creates a new download component for downloading directly from given URL.

Usage

From source file:edu.nps.moves.mmowgli.utility.MediaLocator.java

License:Open Source License

public Resource locateUserImage(String url) {
    try {//from   w  ww . j a  v  a 2  s  .  c o  m
        return new ExternalResource(new URL(getUserImagesUrl(), url));
    } catch (MalformedURLException e) {
        System.err.println("Program error in MediaLocator.locateUserImage(): " + e.getLocalizedMessage());
        return null;
    }
}

From source file:edu.nps.moves.mmowgli.utility.Res.java

License:Open Source License

public Embedded getExternalImage(String url) {
    ExternalResource exR = new ExternalResource(url);
    Embedded emb = new Embedded();
    emb.setSource(exR);/*from   ww  w  .  ja v  a 2s .  co  m*/
    return emb;
}

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

License:Apache License

@Override
protected void init(VaadinRequest request) {

    final VerticalLayout wrapper = new VerticalLayout();
    wrapper.setSizeFull();// ww  w  .ja v  a 2s  .  co m
    setContent(wrapper);

    // Show it in the middle of the screen
    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setSizeUndefined();
    wrapper.addComponent(layout);
    wrapper.setComponentAlignment(layout, Alignment.MIDDLE_CENTER);

    final Label themeName = new Label();
    themeName.setCaption("Current Theme:");
    themeName.addStyleName("h1");
    layout.addComponent(themeName);

    Label waring = new Label("<strong>Attention:</strong><br />\nChanging the theme may take a few seconds!");
    waring.setContentMode(ContentMode.HTML);
    layout.addComponent(waring);

    getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() {

        @Override
        public void uriFragmentChanged(UriFragmentChangedEvent event) {
            String fragment = event.getUriFragment().replace("!", "");
            if (fragment.isEmpty()) {
                fragment = defaultTheme;
            }
            loadTheme(fragment);
        }
    });

    themeSelect.setSizeFull();
    themeSelect.setNullSelectionAllowed(false);
    themeSelect.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            String fragment = "!" + themeSelect.getValue();
            getPage().setUriFragment(fragment);
        }
    });
    layout.addComponent(themeSelect);
    layout.setComponentAlignment(themeSelect, Alignment.BOTTOM_CENTER);

    final CheckBox useIcon = new CheckBox("Use icons");
    useIcon.setValue(false);
    layout.addComponent(useIcon);

    final HorizontalLayout comparsionLayout = new HorizontalLayout();
    comparsionLayout.setSpacing(true);
    layout.addComponent(comparsionLayout);
    layout.setComponentAlignment(comparsionLayout, Alignment.TOP_CENTER);

    final Button button = new Button("This is a \"normal\" Button", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Notification.show("Hello World!");
        }
    });
    comparsionLayout.addComponent(button);
    comparsionLayout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);

    // Initialize our new UI component
    final ButtonLink buttonLink = new ButtonLink("This is a ButtonLink",
            new ExternalResource("https://vaadin.com"));
    buttonLink.setTargetName("_blank");
    buttonLink.setDescription("Visit vaadin.com in a new tab or window.");
    buttonLink.addStyleName("test-stylename");
    comparsionLayout.addComponent(buttonLink);
    comparsionLayout.setComponentAlignment(buttonLink, Alignment.MIDDLE_LEFT);

    themeName.setPropertyDataSource(themeSelect);

    useIcon.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean b = (Boolean) event.getProperty().getValue();
            if (b) {
                button.setIcon(vaadinIcon, "Vaadin Logo");
                buttonLink.setIcon(vaadinIcon, "Vaadin Logo");
            } else {
                button.setIcon(null);
                buttonLink.setIcon(null);
            }
        }
    });

    String fragment = getPage().getUriFragment();

    loadTheme(
            fragment == null || fragment.replace("!", "").isEmpty() ? defaultTheme : fragment.replace("!", ""));
}

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

License:Apache License

@Override
protected void init(VaadinRequest request) {

    getPage().setTitle(pageTitle);/*from w w  w . j a  v  a2  s . co m*/

    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.aalto.drumbeat.drumbeatUI.DrumbeatinterfaceUI.java

License:Open Source License

@SuppressWarnings("deprecation")
private void createTab_Datasets() {
    VerticalLayout tab_datasets = new VerticalLayout();
    tab_datasets.setCaption("Data sets");
    tabsheet.addTab(tab_datasets);//from  w  w w.  jav a 2  s  . co  m
    tab_datasets.addComponent(datasets_tree);
    Link void_link = new Link("Void description of the data sets",
            new ExternalResource("http://drumbeat.cs.hut.fi/void.ttl"));
    tab_datasets.addComponent(void_link);
    Panel p_model = new Panel("Upload and convert an IFC file");
    p_model.setWidth("900");
    tab_datasets.addComponent(p_model);

    HorizontalLayout hor1 = new HorizontalLayout();
    hor1.setSizeFull(); // Use all available space
    hor1.setMargin(true);
    p_model.setContent(hor1);

    VerticalLayout upload_selections = new VerticalLayout();
    hor1.addComponent(upload_selections);

    upload_selections.addComponent(sites_tree_4upload);
    VerticalLayout upload_panels = new VerticalLayout();
    hor1.addComponent(upload_panels);

    Panel p_model_file = new Panel("Upload a file");
    p_model_file.setWidth("400");
    upload_panels.addComponent(p_model_file);

    Panel p_model_url = new Panel("Upload from a URL");
    p_model_url.setWidth("400");
    upload_panels.addComponent(p_model_url);

    // Create the upload with a caption and set receiver later
    Upload upload = new Upload("Select a file and press Upload", drumbeat_fileReceiver);
    upload.addSucceededListener(drumbeat_fileReceiver);
    upload.addFailedListener(drumbeat_fileReceiver);
    p_model_file.setContent(upload);

    url_textField.setImmediate(true);
    Button button = new Button("Upload from the URL", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            drumbeat_fileReceiver.receiveFileFromURL(url_textField.getValue());
        }
    });

    HorizontalLayout url_upload = new HorizontalLayout();
    url_upload.setSizeUndefined();
    url_upload.addComponent(url_textField);
    url_upload.addComponent(button);
    url_upload.setSpacing(true);
    p_model_url.setContent(url_upload);

    bim_projects_selection.setInvalidAllowed(false);
    bim_projects_selection.setNullSelectionAllowed(false);
    bim_projects_selection.setNewItemsAllowed(false);
    bim_projects_selection.setWidth("400");
    final VerticalLayout project_browser = new VerticalLayout();
    bim_projects_selection.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -5188369735622627751L;

        public void valueChange(ValueChangeEvent event) {
            if (bim_projects_selection.getValue() != null) {
                htmlView_BIMProject(project_browser, bim_projects.get(bim_projects_selection.getValue()));
            }
        }
    });

    tab_datasets.addComponent(bim_projects_selection);
    tab_datasets.addComponent(project_browser);
}

From source file:fi.aalto.drumbeat.drumbeatUI.DrumbeatinterfaceUI.java

License:Open Source License

private void creatTab_Resources() {
    VerticalLayout tab_internaldata = new VerticalLayout();
    tab_internaldata.setCaption("Internal resources");
    tabsheet.addTab(tab_internaldata);//w ww.  j a  v  a 2s  . co  m

    BrowserFrame browser = new BrowserFrame("", new ExternalResource("http://drumbeat.cs.hut.fi/home.html"));
    browser.setWidth("900px");
    browser.setHeight("450px");
    tab_internaldata.addComponent(browser);

    files_table.addContainerProperty("File name", String.class, null);
    listUploaded_IFCFiles();
    tab_internaldata.addComponent(files_table);

    contexts_table.addContainerProperty("Graph", String.class, null);
    contexts_table.addContainerProperty("Size", Long.class, null);
    tab_internaldata.addComponent(contexts_table);
}

From source file:fi.aalto.drumbeat.drumbeatUI.DrumbeatinterfaceUI.java

License:Open Source License

private void htmlView_BIMProject(VerticalLayout layout, long pid) {
    layout.removeAllComponents();// www  .j  a  v a 2  s.  co m
    ExternalResource er = new ExternalResource(DrumbeatConstants.bimsurfer_project_url + pid);
    BrowserFrame bim_browser = new BrowserFrame("", er);
    bim_browser.setWidth("900px");
    bim_browser.setHeight("800px");

    layout.addComponent(bim_browser);

}

From source file:fi.aalto.drumbeat.drumbeatUI.DrumbeatinterfaceUI.java

License:Open Source License

private void htmlView_Project(VerticalLayout layout, String project_name) {
    layout.removeAllComponents();/*from   w w  w.  ja va2 s  .  c om*/
    ExternalResource er = new ExternalResource(DrumbeatConstants.drumbeatview_project_url + project_name);
    BrowserFrame bim_browser = new BrowserFrame("", er);
    bim_browser.setWidth("700px");
    bim_browser.setHeight("650px");

    layout.addComponent(bim_browser);

}

From source file:fi.jasoft.dragdroplayouts.demo.views.DragdropAbsoluteLayoutDemo.java

License:Apache License

@Override
public Component getLayout() {
    // start-source
    final DDAbsoluteLayout layout = new DDAbsoluteLayout();
    layout.setId("layout");
    layout.setSizeFull();//from w  ww .  ja  v  a  2  s .  co  m

    // Enable dragging components
    layout.setDragMode(LayoutDragMode.CLONE);

    // Enable dropping components
    layout.setDropHandler(new DefaultAbsoluteLayoutDropHandler());

    // Add some components
    Label lbl = new Label("This is an Absolute layout, you can freely drag the components around");
    layout.addComponent(lbl);
    Button btn = new Button("Button 1", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Notification.show("Click!");
        }
    });
    btn.setId("button");
    layout.addComponent(btn, "left:50px; top:50px");
    Link link = new Link("A link to Vaadin", new ExternalResource("http://www.vaadin.com"));
    layout.addComponent(link, "left:200px; top:100px");

    // end-source
    return layout;
}

From source file:fi.jasoft.dragdroplayouts.demo.views.DragdropIframeDragging.java

License:Apache License

private void addComponentsToLayout(DDAbsoluteLayout layout, String caption) {

    BrowserFrame frame = new BrowserFrame(caption,
            new ExternalResource("https://platform.twitter.com/widgets/tweet_button.html"));
    frame.setWidth("300px");
    frame.setHeight("300px");

    layout.addComponent(frame, "top:100px;left:50px");

}