List of usage examples for com.vaadin.ui FormLayout addComponent
@Override public void addComponent(Component c)
From source file:edu.nps.moves.mmowgli.modules.cards.ShowCardCacheCountsDialog.java
License:Open Source License
private ShowCardCacheCountsDialog() { setCaption("Show Card Cache Sizes"); setModal(true);// w w w .j av a 2s. c om setWidth("350px"); FormLayout fl = new FormLayout(); setContent(fl); fl.setMargin(true); fl.setSpacing(true); MCacheManager mgr = MCacheManager.instance(); Object[][] caches = mgr.getCaches(); Label lab; for (int i = 0; i < caches[0].length; i++) { if (!(caches[0][i] instanceof String)) continue; if (!(caches[1][i] instanceof Map)) continue; fl.addComponent(lab = new Label("" + ((Map<?, ?>) caches[1][i]).size())); lab.setCaption(caches[0][i].toString()); } }
From source file:edu.nps.moves.mmowgli.modules.registrationlogin.PasswordResetPopup.java
License:Open Source License
@SuppressWarnings("serial") public PasswordResetPopup(Button.ClickListener listener, String uname) { setCaption("Password Reset"); VerticalLayout vLay = new VerticalLayout(); vLay.setSpacing(true);//w w w .j av a 2 s . co m vLay.setMargin(true); setContent(vLay); vLay.addComponent(new HtmlLabel( "<center>Please fill in your player name and/or email address<br/>to initiate a password reset.</center>")); // Use an actual form widget here for data binding and error display. FormLayout formLay = new FormLayout(); formLay.setSizeUndefined(); formLay.setSpacing(true); formLay.addStyleName("m-login-form"); // to allow styling contents (v-textfield) vLay.addComponent(formLay); vLay.setComponentAlignment(formLay, Alignment.TOP_CENTER); formLay.addComponent(userIDTf = new TextField("Player name:")); userIDTf.addStyleName("m-dialog-textfield"); userIDTf.setWidth("85%"); userIDTf.setTabIndex(100); // Help out a little here userIDTf.setValue(uname == null ? "" : uname); formLay.addComponent(emailTf = new TextField("Email:")); emailTf.addStyleName("m-dialog-textfield"); emailTf.setWidth("85%"); emailTf.setTabIndex(101); HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); hl.setMargin(false); hl.setWidth("100%"); vLay.addComponent(hl); Label lab; hl.addComponent(lab = new Label()); hl.setExpandRatio(lab, 1.0f); Button cancelButt = new Button("Cancel"); hl.addComponent(cancelButt); cancelButt.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { getUI().setScrollTop(0); getUI().removeWindow(PasswordResetPopup.this); } }); cancelButt.setClickShortcut(ShortcutAction.KeyCode.ESCAPE); Button continueButt = new Button("Continue"); hl.addComponent(continueButt); continueButt.addClickListener(PasswordResetPopup.this); continueButt.setClickShortcut(ShortcutAction.KeyCode.ENTER); emailTf.focus(); }
From source file:edu.nps.moves.mmowgli.modules.userprofile.ChangeEmailDialog.java
License:Open Source License
@SuppressWarnings("serial") public ChangeEmailDialog(EmailPacket pkt) { this.packet = pkt; // this.uid=uid; //User user = DBGet.getUser(uid); setCaption("Change Email"); setModal(true);/*from w w w . j a v a 2 s. c o m*/ setWidth("350px"); //setHeight("200px"); VerticalLayout vLay = new VerticalLayout(); setContent(vLay); FormLayout fLay = new FormLayout(); oldEmail = new TextField("Current Email", pkt.original);//user.getEmailAddresses().toString()); //oldPw.setColumns(20); oldEmail.setWidth("99%"); fLay.addComponent(oldEmail); newEmail = new TextField("New Email"); newEmail.setWidth("99%"); fLay.addComponent(newEmail); newEmail2 = new TextField("Confirm Email"); newEmail2.setWidth("99%"); fLay.addComponent(newEmail2); vLay.addComponent(fLay); HorizontalLayout buttLay = new HorizontalLayout(); buttLay.setSpacing(true); vLay.addComponent(buttLay); vLay.setComponentAlignment(buttLay, Alignment.TOP_RIGHT); MediaLocator mLoc = Mmowgli2UI.getGlobals().getMediaLocator(); NativeButton cancelButt = new NativeButton(); mLoc.decorateCancelButton(cancelButt); buttLay.addComponent(cancelButt); buttLay.setComponentAlignment(cancelButt, Alignment.BOTTOM_RIGHT); // Label sp; // buttLay.addComponent(sp = new Label()); // sp.setWidth("30px"); saveButt = new NativeButton(); //app.globs().mediaLocator().decorateSaveButton(saveButt); //"save" mLoc.decorateOkButton(saveButt); //"ok" buttLay.addComponent(saveButt); buttLay.setComponentAlignment(saveButt, Alignment.BOTTOM_RIGHT); // buttLay.addComponent(sp = new Label()); // sp.setWidth("5px"); cancelButt.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { UI.getCurrent().removeWindow(ChangeEmailDialog.this); } }); saveButt.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { String oldTry = oldEmail.getValue().toString(); if (!packet.original.equals(oldTry)) { Notification.show("Error", "This should never show", Notification.Type.ERROR_MESSAGE); return; } String check = newEmail2.getValue().toString(); String newStr = newEmail.getValue().toString(); if (check == null || !newStr.trim().equals(check.trim())) { Notification.show("Error", "Emails do not match", Notification.Type.ERROR_MESSAGE); return; } EmailValidator v = new EmailValidator(""); if (newStr == null || !v.isValid(newStr)) { Notification.show("Error", "Please enter a valid email", Notification.Type.ERROR_MESSAGE); return; } packet.updated = newStr.trim(); if (saveListener != null) saveListener.buttonClick(event); UI.getCurrent().removeWindow(ChangeEmailDialog.this); } }); }
From source file:edu.nps.moves.mmowgli.modules.userprofile.ChangePasswordDialog.java
License:Open Source License
@SuppressWarnings("serial") public ChangePasswordDialog(PasswordPacket pkt) { this.packet = pkt; setCaption("Change Password"); setModal(true);//from ww w . jav a 2 s . co m setWidth("350px"); VerticalLayout vLay = new VerticalLayout(); setContent(vLay); FormLayout fLay = new FormLayout(); oldPw = new PasswordField("Current"); //oldPw.setColumns(20); oldPw.setWidth("99%"); fLay.addComponent(oldPw); newPw = new PasswordField("New"); newPw.setWidth("99%"); fLay.addComponent(newPw); newPw2 = new PasswordField("New again"); newPw2.setWidth("99%"); fLay.addComponent(newPw2); vLay.addComponent(fLay); HorizontalLayout buttLay = new HorizontalLayout(); buttLay.setSpacing(true); vLay.addComponent(buttLay); vLay.setComponentAlignment(buttLay, Alignment.TOP_RIGHT); MediaLocator mLoc = Mmowgli2UI.getGlobals().getMediaLocator(); NativeButton cancelButt = new NativeButton(); mLoc.decorateCancelButton(cancelButt); buttLay.addComponent(cancelButt); buttLay.setComponentAlignment(cancelButt, Alignment.BOTTOM_RIGHT); // Label sp; // buttLay.addComponent(sp = new Label()); // sp.setWidth("30px"); saveButt = new NativeButton(); //app.globs().mediaLocator().decorateSaveButton(saveButt); //"save" mLoc.decorateOkButton(saveButt); //"ok" buttLay.addComponent(saveButt); buttLay.setComponentAlignment(saveButt, Alignment.BOTTOM_RIGHT); // buttLay.addComponent(sp = new Label()); // sp.setWidth("5px"); cancelButt.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { UI.getCurrent().removeWindow(ChangePasswordDialog.this); } }); saveButt.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { String oldTry = oldPw.getValue().toString(); StrongPasswordEncryptor spe = new StrongPasswordEncryptor(); if (!spe.checkPassword(oldTry, packet.original)) { Notification.show("Error", "Existing password incorrect", Notification.Type.ERROR_MESSAGE); return; } String newStr = newPw.getValue().toString(); if (newStr == null || newStr.length() < 6) { Notification.show("Error", "Enter a password of at least six characters", Notification.Type.ERROR_MESSAGE); return; } String check = newPw2.getValue().toString(); if (check == null || !newStr.trim().equals(check.trim())) { Notification.show("Error", "Passwords do not match", Notification.Type.ERROR_MESSAGE); return; } packet.updated = newStr.trim(); if (saveListener != null) saveListener.buttonClick(event); UI.getCurrent().removeWindow(ChangePasswordDialog.this); } }); }
From source file:edu.nps.moves.mmowgli.modules.userprofile.EditAwardTypeDialog.java
License:Open Source License
@SuppressWarnings("serial") private EditAwardTypeDialog(AwardType awt, EditAwardResultListener lis) { Object sessKey = HSess.checkInit(); listener = lis;//from w w w. ja va 2 s. c om awardType = awt; setCaption("Edit Award Type"); setModal(true); setWidth("450px"); VerticalLayout vLay = new VerticalLayout(); setContent(vLay); vLay.setMargin(true); vLay.setSpacing(true); vLay.addStyleName("m-greybackground"); FormLayout formLay; vLay.addComponent(formLay = new FormLayout()); formLay.setSizeFull(); formLay.addComponent( nameTF = new MTextField("Award Title").withFullWidth().withNullRepresentation("required field")); nameTF.setRequired(true); nameTF.setRequiredError("Required field"); nameTF.setSizeFull(); formLay.addComponent( descTF = new MTextField("Description").withFullWidth().withNullRepresentation("required field")); descTF.setRequired(true); descTF.setRequiredError("Required field"); Label sp; formLay.addComponent(hLay55 = new HorizontalLayout()); hLay55.setWidth("100%"); hLay55.setCaption("55x55 pixel icon"); hLay55.setSpacing(true); hLay55.addComponent(lab55 = new HtmlLabel("<i>image name</i>")); hLay55.setComponentAlignment(lab55, Alignment.MIDDLE_CENTER); hLay55.addComponent(butt55 = new NativeButton("Choose 55x55 image")); hLay55.setComponentAlignment(butt55, Alignment.MIDDLE_CENTER); hLay55.addComponent(sp = new Label()); hLay55.setExpandRatio(sp, 1.0f); hLay55.addComponent(image55 = new Image(null)); image55.setWidth("55px"); image55.setHeight("55px"); image55.addStyleName("m-greyborder3"); formLay.addComponent(hLay300 = new HorizontalLayout()); hLay300.setWidth("100%"); hLay300.setCaption("300x300 pixel icon"); hLay300.setSpacing(true); hLay300.addComponent(lab300 = new HtmlLabel("<i>image name</i>")); hLay300.setComponentAlignment(lab300, Alignment.MIDDLE_CENTER); hLay300.addComponent(butt300 = new NativeButton("Choose 300x300 image")); hLay300.setComponentAlignment(butt300, Alignment.MIDDLE_CENTER); hLay300.addComponent(sp = new Label()); hLay300.setExpandRatio(sp, 1.0f); hLay300.addComponent(image300 = new Image(null)); image300.setWidth("55px"); image300.setHeight("55px"); image300.addStyleName("m-greyborder3"); ClickListener chooseIconListener = new ClickListener() { boolean is55 = false; @Override public void buttonClick(ClickEvent event) { is55 = (event.getButton() == butt55); String txt = (is55 ? pix55text : pix300text); InstallImageResultListener lis = new InstallImageResultListener() { @Override public void doneTL(MediaImage mimg) { Media m = null; if (mimg != null) m = mimg.media; if (m != null) { MediaLocator mediaLoc = Mmowgli2UI.getGlobals().getMediaLocator(); String handle = m.getHandle(); if (handle != null && handle.trim().length() <= 0) handle = null; if (is55) { media55 = m; if (handle == null) { m.setHandle("55x55"); Media.updateTL(m); } lab55.setValue(m.getUrl()); image55.setSource(mediaLoc.locate(m)); } else { media300 = m; if (handle == null) { m.setHandle("300x300"); Media.updateTL(m); } lab300.setValue(m.getUrl()); image300.setSource(mediaLoc.locate(m)); } } } }; InstallImageDialog.show(txt, lis, is55 ? pix55filter : pix300filter); } }; butt55.addClickListener(chooseIconListener); butt300.addClickListener(chooseIconListener); HorizontalLayout buttHL = new HorizontalLayout(); vLay.addComponent(buttHL); buttHL.setWidth("100%"); buttHL.addComponent(sp = new Label()); sp.setWidth("1px"); buttHL.setExpandRatio(sp, 1.0f); buttHL.addComponent(new NativeButton("Cancel", new ClickListener() { @Override public void buttonClick(ClickEvent event) { awardType = null; doneHereTL(); } })); buttHL.addComponent(new NativeButton("Close", new ClickListener() { @Override public void buttonClick(ClickEvent event) { String title = nameTF.getValue().trim(); String description = descTF.getValue().trim(); if (title.length() <= 0 || description.length() <= 0 || media300 == null || media55 == null) { Notification.show("All fields must be completed", Notification.Type.ERROR_MESSAGE); return; } HSess.init(); boolean save = false; if (awardType == null) { awardType = new AwardType(); save = true; } awardType.setName(nameTF.getValue().trim()); awardType.setDescription(descTF.getValue().trim()); awardType.setIcon300x300(media300); awardType.setIcon55x55(media55); if (save) HSess.get().save(awardType); else HSess.get().update(awardType); doneHereTL(); HSess.close(); } })); HSess.checkClose(sessKey); }
From source file:edu.nps.moves.security.PasswordResetUI.java
License:Open Source License
private void handleChangeTL(User user) { this.user = user; Game g = Game.getTL();/* ww w . j a v a2s . c o m*/ String brand = g.getCurrentMove().getTitle(); Page.getCurrent().setTitle("Password reset for " + brand + " mmowgli"); HorizontalLayout hLay = new HorizontalLayout(); hLay.setMargin(true); hLay.setWidth("100%"); setContent(hLay); GameLinks gl = GameLinks.getTL(); String blog = gl.getBlogLink(); Label lab; hLay.addComponent(lab = new Label()); hLay.setExpandRatio(lab, 0.5f); VerticalLayout vl = new VerticalLayout(); hLay.addComponent(vl); vl.setWidth(bannerWidthPx); hLay.addComponent(lab = new Label()); hLay.setExpandRatio(lab, 0.5f); vl.addStyleName("m-greyborder"); vl.setMargin(true); vl.setSpacing(true); vl.addComponent(lab = new HtmlLabel("")); lab.addStyleName("m-font-21-bold"); lab.setSizeUndefined(); vl.setComponentAlignment(lab, Alignment.MIDDLE_CENTER); StringBuilder sb = new StringBuilder(); sb.append(thanksHdr1); sb.append(blog); sb.append(thanksHdr2); sb.append(brand); sb.append(thanksHdr3); lab.setValue(sb.toString()); vl.addComponent(lab = new HtmlLabel("")); lab.setHeight("15px"); vl.setComponentAlignment(lab, Alignment.MIDDLE_CENTER); FormLayout fLay = new FormLayout(); fLay.setSizeUndefined(); fLay.addStyleName("m-login-form"); // to allow styling contents (v-textfield) vl.addComponent(fLay); vl.setComponentAlignment(fLay, Alignment.MIDDLE_CENTER); newPw = new PasswordField("New Password"); newPw.setWidth("99%"); fLay.addComponent(newPw); newPw2 = new PasswordField("Again, please"); newPw2.setWidth("99%"); fLay.addComponent(newPw2); HorizontalLayout buttLay = new HorizontalLayout(); buttLay.setSpacing(true); vl.addComponent(buttLay); vl.setComponentAlignment(buttLay, Alignment.TOP_CENTER); NativeButton cancelButt = new NativeButton(); cancelButt.setStyleName("m-cancelButton"); buttLay.addComponent(cancelButt); buttLay.setComponentAlignment(cancelButt, Alignment.BOTTOM_RIGHT); saveButt = new NativeButton(); saveButt.setClickShortcut(ShortcutAction.KeyCode.ENTER); saveButt.setStyleName("m-continueButton"); //m-saveChangesButton"); buttLay.addComponent(saveButt); buttLay.setComponentAlignment(saveButt, Alignment.BOTTOM_RIGHT); cancelButt.addClickListener(this); saveButt.addClickListener(this); }
From source file:eu.hurion.hello.vaadin.shiro.application.HelloScreen.java
License:Apache License
public HelloScreen(final HerokuShiroApplication app) { setSizeFull();/* w w w .j a va 2s .co m*/ final Subject currentUser = SecurityUtils.getSubject(); final Panel welcomePanel = new Panel(); final FormLayout content = new FormLayout(); final Label label = new Label("Logged in as " + currentUser.getPrincipal().toString()); logout = new Button("logout"); logout.addClickListener(new HerokuShiroApplication.LogoutListener(app)); content.addComponent(label); content.addComponent(logout); welcomePanel.setContent(content); welcomePanel.setWidth("400px"); welcomePanel.setHeight("200px"); addComponent(welcomePanel); setComponentAlignment(welcomePanel, Alignment.MIDDLE_CENTER); final HorizontalLayout footer = new HorizontalLayout(); footer.setHeight("50px"); addComponent(footer); final Button adminButton = new Button("For admin only"); adminButton.setEnabled(currentUser.hasRole("admin")); adminButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final Button.ClickEvent event) { Notification.show("you're an admin"); } }); content.addComponent(adminButton); final Button userButton = new Button("For users with permission 1"); userButton.setEnabled(currentUser.isPermitted("permission_1")); userButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final Button.ClickEvent event) { Notification.show("you've got permission 1"); } }); content.addComponent(userButton); }
From source file:eu.hurion.hello.vaadin.shiro.application.LoginScreen.java
License:Apache License
public LoginScreen(final HerokuShiroApplication app) { setSizeFull();//from w w w . j ava 2 s . c om final Panel loginPanel = new Panel("Login"); loginPanel.setWidth("300px"); final FormLayout content = new FormLayout(); content.setSizeFull(); user = new TextField("User"); content.addComponent(user); password = new PasswordField("Password"); content.addComponent(password); final Button loginButton = new Button("Log in"); content.setHeight("150px"); loginButton.addClickListener(new ShiroLoginListener(app)); content.addComponent(loginButton); loginPanel.setContent(content); addComponent(loginPanel); setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER); final HorizontalLayout footer = new HorizontalLayout(); footer.setHeight("50px"); addComponent(footer); }
From source file:eu.maxschuster.vaadin.signaturefield.demo.DemoUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { getPage().setTitle(pageTitle);/*from w ww . java 2s . 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:facs.components.Settings.java
License:Open Source License
private void addNewDevice() { final Window subWindow = new Window("Add Device"); FormLayout form = new FormLayout(); form.setMargin(true);/* w ww . j a v a 2 s .c o m*/ final TextField name = new TextField(); name.setImmediate(true); name.addValidator(new StringLengthValidator("The name must be 1-85 letters long (Was {0}).", 1, 85, true)); name.setCaption("Name of new device"); form.addComponent(name); final TextArea description = new TextArea(); description.setImmediate(true); description.addValidator( new StringLengthValidator("The name must be 1-255 letters long (Was {0}).", 1, 255, true)); description.setCaption("Description"); form.addComponent(description); final OptionGroup restricted = new OptionGroup("Is Device restricted by operators?"); restricted.addItem("yes"); restricted.setMultiSelect(true); form.addComponent(restricted); HorizontalLayout buttons = new HorizontalLayout(); Button save = new Button("save"); buttons.addComponent(save); Button discard = new Button("discard"); discard.setDescription("discarding will abort the process of adding a new device into the databse."); buttons.addComponent(discard); buttons.setSpacing(true); form.addComponent(buttons); subWindow.setContent(form); form.setMargin(true); form.setSpacing(true); buttons.setMargin(true); buttons.setSpacing(true); // Center it in the browser window subWindow.center(); subWindow.setModal(true); subWindow.setWidth("50%"); // Open it in the UI UI.getCurrent().addWindow(subWindow); discard.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = -5808910314649620731L; @Override public void buttonClick(ClickEvent event) { subWindow.close(); } }); save.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = 3748395242651585005L; @Override public void buttonClick(ClickEvent event) { if (name.isValid() && description.isValid()) { Set<String> restr = (Set<String>) restricted.getValue(); int deviceId = DBManager.getDatabaseInstance().addDevice(name.getValue(), description.getValue(), (restr.size() == 1)); DeviceBean bean = new DeviceBean(deviceId, name.getValue(), description.getValue(), (restr.size() == 1)); devicesGrid.addRow(bean); } else { Notification.show("Failed to add device to database."); } } }); // DeviceBean db = new DeviceBean(0, "Device 1","some description1", false); // TODO // add to database /* * boolean added = false;//DBManager.getDatabaseInstance().addDevice(db); //TODO test //add to * grid if(added){ devicesGrid.addRow(db); }else{ //TODO log failed operation * Notification.show("Failed to add device to database.", Type.ERROR_MESSAGE); } */ }