List of usage examples for com.vaadin.ui Button addClickListener
public Registration addClickListener(ClickListener listener)
From source file:com.cavisson.gui.dashboard.components.controls.CommonParts.java
License:Apache License
Panel loadingIndicators() { Panel p = new Panel("Loading Indicator"); final VerticalLayout content = new VerticalLayout(); p.setContent(content);/*w w w . ja va 2s .c o m*/ content.setSpacing(true); content.setMargin(true); content.addComponent(new Label("You can test the loading indicator by pressing the buttons.")); CssLayout group = new CssLayout(); group.setCaption("Show the loading indicator for"); group.addStyleName("v-component-group"); content.addComponent(group); Button loading = new Button("0.8"); loading.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { Thread.sleep(800); } catch (InterruptedException e) { } } }); group.addComponent(loading); Button delay = new Button("3"); delay.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { Thread.sleep(3000); } catch (InterruptedException e) { } } }); group.addComponent(delay); Button wait = new Button("15"); wait.addClickListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { Thread.sleep(15000); } catch (InterruptedException e) { } } }); wait.addStyleName("last"); group.addComponent(wait); Label label = new Label(" seconds", ContentMode.HTML); label.setSizeUndefined(); group.addComponent(label); Label spinnerDesc = new Label( "The theme also provides a mixin that you can use to include a spinner anywhere in your application. The button below reveals a Label with a custom style name, for which the spinner mixin is added."); spinnerDesc.addStyleName("small"); spinnerDesc.setCaption("Spinner"); content.addComponent(spinnerDesc); if (!ValoThemeUI.isTestMode()) { final Label spinner = new Label(); spinner.addStyleName("spinner"); Button showSpinnerButton = new Button("Show spinner", new ClickListener() { @Override public void buttonClick(final ClickEvent event) { content.replaceComponent(event.getComponent(), spinner); } }); content.addComponent(showSpinnerButton); } return p; }
From source file:com.cavisson.gui.dashboard.components.controls.Dragging.java
License:Apache License
private List<Component> createComponents() { final List<Component> components = new ArrayList<Component>(); final Label label = new Label("This is a long text block that will wrap."); label.setWidth("120px"); components.add(label);//from w ww .jav a 2s. co m final Embedded image = new Embedded("", new ThemeResource("../runo/icons/64/document.png")); components.add(image); final CssLayout documentLayout = new CssLayout(); documentLayout.setWidth("19px"); for (int i = 0; i < 5; ++i) { final Embedded e = new Embedded(null, new ThemeResource("../runo/icons/16/document.png")); e.setHeight("16px"); e.setWidth("16px"); documentLayout.addComponent(e); } components.add(documentLayout); final VerticalLayout buttonLayout = new VerticalLayout(); final Button button = new Button("Button"); button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { Notification.show("Button clicked"); } }); buttonLayout.addComponent(button); buttonLayout.setComponentAlignment(button, Alignment.MIDDLE_CENTER); components.add(buttonLayout); return components; }
From source file:com.cerebro.gorgone.landingpage.SignInWindow.java
private Button createCancelButton() { Button cancel = new Button("Annulla"); cancel.addClickListener((Button.ClickEvent event) -> { this.close(); });/*from www . j a v a 2 s. c o m*/ return cancel; }
From source file:com.cerebro.gorgone.landingpage.SignInWindow.java
private Component setFirstStep() { VerticalLayout firstStep = new VerticalLayout(); firstStep.setMargin(true);//from w w w. j a v a 2 s. c om // Body HorizontalLayout body = new HorizontalLayout(); FormLayout datiIniziali = new FormLayout(); TextField nomePG = new TextField("Nome del Personaggio"); nomePG.setRequired(true); TextField cognomePG = new TextField("Cognome del Personaggio"); cognomePG.setRequired(true); OptionGroup sessoPG = new OptionGroup("Sesso del Personaggio"); sessoPG.setRequired(true); sessoPG.addItems("Maschio", "Femmina"); ComboBox razzaPG = new ComboBox("Razza"); razzaPG.setRequired(true); Slider age = new Slider("Et"); age.setImmediate(true); age.setWidth("200px"); age.setVisible(false); HorizontalLayout ageDescription = new HorizontalLayout(); ageDescription.setHeight("250px"); Label ageText = new Label("Valore dell'et: "); Label ageValue = new Label(age.getValue().toString()); Label periodoVita = new Label(""); ageDescription.addComponents(ageText, ageValue, periodoVita); age.addValueChangeListener((Property.ValueChangeEvent event) -> { System.out.println("Valore: " + age.getValue().toString()); ageValue.setValue(age.getValue().toString()); Double value = (100 * (age.getValue()) / (age.getMax())); if (value < 14) { periodoVita.setValue("Bambino"); } else if (value > 14 && value < 24) { periodoVita.setValue("Adolescenza"); } else if (value > 24 && value < 73) { periodoVita.setValue("Et adulta"); } else if (value > 73) { periodoVita.setValue("Et anziana"); } }); ageDescription.addComponents(ageText, ageValue, periodoVita); ageDescription.setVisible(false); datiIniziali.addComponents(nomePG, cognomePG, sessoPG, razzaPG, age, ageDescription); Panel descrizioneRazza = new Panel(); CssLayout descrizioneRazzaContent = new CssLayout(); descrizioneRazza.setWidth("400px"); descrizioneRazza.setHeight("500px"); descrizioneRazza.setContent(descrizioneRazzaContent); // Dettagli di popolazione e comportamento ComboBox TableQuery tq_races = new TableQuery(DatabaseTables.RACES_TABLE, connPool); tq_races.setVersionColumn(DatabaseTables.RACES_VERSION); SQLContainer container_races = null; try { container_races = new SQLContainer(tq_races); } catch (Exception ex) { logger.error(ex.getMessage()); } razzaPG.setContainerDataSource(container_races); razzaPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); razzaPG.setItemCaptionPropertyId(DatabaseTables.RACES_NAME); razzaPG.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { if (razzaPG.getValue() != null) { logger.info("Razza selezionata: " + razzaPG.getValue()); age.setVisible(true); ageDescription.setVisible(true); descrizioneRazzaContent.removeAllComponents(); Item item = razzaPG.getContainerDataSource().getItem(razzaPG.getValue()); race = (String) item.getItemProperty(DatabaseTables.RACES_NAME).getValue(); Label nameRace = new Label(race); FileResource imageSrc = new FileResource( new File(MyUI.basePath + item.getItemProperty(DatabaseTables.RACES_IMAGE).getValue())); Image imageRace = new Image(null, imageSrc); imageRace.setWidth("200px"); Label descriptionRace = new Label( (String) item.getItemProperty(DatabaseTables.RACES_DESCRIPTION).getValue(), ContentMode.HTML); min_age = (int) item.getItemProperty(DatabaseTables.RACES_MIN_AGE).getValue(); max_age = (int) item.getItemProperty(DatabaseTables.RACES_MAX_AGE).getValue(); age.setMin(min_age); age.setMax(max_age); strenght = (int) item.getItemProperty(DatabaseTables.RACES_STRENGHT).getValue(); resistance = (int) item.getItemProperty(DatabaseTables.RACES_RESISTANCE).getValue(); agility = (int) item.getItemProperty(DatabaseTables.RACES_AGILITY).getValue(); intelligence = (int) item.getItemProperty(DatabaseTables.RACES_INTELLIGENCE).getValue(); wisdom = (int) item.getItemProperty(DatabaseTables.RACES_WISDOM).getValue(); charm = (int) item.getItemProperty(DatabaseTables.RACES_CHARM).getValue(); Label min_ageL = new Label("Et minima: " + min_age); Label max_ageL = new Label("Et masima " + max_age); // Panel levels = new Panel(); // VerticalLayout levelsContent = new VerticalLayout(); // levels.setContent(levelsContent); // Label strenghtL = new Label("Forza: " + strenght); // levelsContent.addComponents(strenghtL); String levelTable = "<table><tr><td>Forza</td><td>Resistenza</td><td>Agilit</td><td>Intelligenza</td>" + "<td>Saggezza</td><td>Carisma</td></tr><tr>" + "<td>" + strenght + "</td>" + "<td>" + resistance + "</td>" + "<td>" + agility + "</td>" + "<td>" + intelligence + "</td>" + "<td>" + wisdom + "</td>" + "<td>" + charm + "</td>" + "</tr></table>"; Label levels = new Label(levelTable, ContentMode.HTML); descrizioneRazzaContent.addComponents(nameRace, imageRace, descriptionRace, min_ageL, max_ageL, levels); } } }); body.addComponents(datiIniziali, descrizioneRazza); CssLayout footer = new CssLayout(); Button next = new Button("Avanti ->"); next.addClickListener((Button.ClickEvent event) -> { user.setNomePG(nomePG.getValue()); user.setCognomePG(cognomePG.getValue()); user.setSessoPG(sessoPG.getValue().toString()); user.setRazzaPG(race); user.setEtaPG(age.getValue().toString()); user.setForzaPG(strenght); user.setResistenzaPG(resistance); user.setAgilitaPG(agility); user.setIntelligenzaPG(intelligence); user.setSaggezzaPG(wisdom); user.setCarismaPG(charm); this.setContent(setSecondStep()); }); footer.addComponents(next, createCancelButton()); firstStep.addComponents(setHeader("2/4"), body, footer); return firstStep; }
From source file:com.cerebro.gorgone.landingpage.SignInWindow.java
private Component setSecondStep() { VerticalLayout secondStep = new VerticalLayout(); HorizontalLayout body = new HorizontalLayout(); Panel sx = new Panel(); VerticalLayout sxContent = new VerticalLayout(); sx.setContent(sxContent);/*from ww w . j a v a2s . co m*/ Label welcome = null; if (user.getSessoPG().equals("Maschio")) { welcome = new Label("Benvenuto: " + user.getNomePG() + "!"); } else if (user.getSessoPG().equals("Femmina")) { welcome = new Label("Benvenuta: " + user.getNomePG() + "!"); } ComboBox carrieraPG = new ComboBox("Scegli la tua carriera:"); carrieraPG.isRequired(); Panel careerDescription = new Panel(); CssLayout careerDescrContent = new CssLayout(); careerDescription.setContent(careerDescrContent); sxContent.addComponents(welcome, carrieraPG, careerDescription); // Dettagli di popolazione e comportamento ComboBox TableQuery tq_career = new TableQuery(DatabaseTables.CAREER_TABLE, connPool); tq_career.setVersionColumn(DatabaseTables.CAREER_VERSION); SQLContainer container_career = null; try { container_career = new SQLContainer(tq_career); } catch (Exception ex) { logger.error(ex.getMessage()); } carrieraPG.setContainerDataSource(container_career); carrieraPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); carrieraPG.setItemCaptionPropertyId(DatabaseTables.CAREER_NAME); carrieraPG.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { if (carrieraPG.getValue() != null) { logger.info("Carriera: " + carrieraPG.getValue().toString()); careerDescrContent.removeAllComponents(); Item item = (Item) carrieraPG.getContainerDataSource().getItem(carrieraPG.getValue()); career = (String) item.getItemProperty(DatabaseTables.CAREER_NAME).getValue(); Label careerName = new Label(career); FileResource imageSrc = new FileResource( new File(MyUI.basePath + item.getItemProperty(DatabaseTables.CAREER_IMAGE).getValue())); Image imageCareer = new Image(null, imageSrc); imageCareer.setWidth("200px"); Label careerDescription = new Label(item.getItemProperty(DatabaseTables.CAREER_DESCRIPTION), ContentMode.HTML); strenght_car = (int) item.getItemProperty(DatabaseTables.CAREER_STRENGTH).getValue(); resistance_car = (int) item.getItemProperty(DatabaseTables.CAREER_RESISTANCE).getValue(); agility_car = (int) item.getItemProperty(DatabaseTables.CAREER_AGILITY).getValue(); intelligence_car = (int) item.getItemProperty(DatabaseTables.CAREER_INTELLIGENCE).getValue(); wisdom_car = (int) item.getItemProperty(DatabaseTables.CAREER_WISDOM).getValue(); charm_car = (int) item.getItemProperty(DatabaseTables.CAREER_CHARM).getValue(); String modsTable = "<table><tr><td>Forza</td><td>Resistenza</td><td>Agilit</td><td>Intelligenza</td>" + "<td>Saggezza</td><td>Carisma</td></tr><tr>" + "<td>" + strenght_car + "</td>" + "<td>" + resistance_car + "</td>" + "<td>" + agility_car + "</td>" + "<td>" + intelligence_car + "</td>" + "<td>" + wisdom_car + "</td>" + "<td>" + charm_car + "</td>" + "</tr></table>"; Label mods = new Label(modsTable, ContentMode.HTML); careerDescrContent.addComponents(careerName, imageCareer, careerDescription, mods); } } }); Panel dx = new Panel(); VerticalLayout dxContent = new VerticalLayout(); dx.setContent(dxContent); ComboBox orientamentoPG = new ComboBox("Scegli il tuo orientamento:"); orientamentoPG.isRequired(); Panel orientamentoDescription = new Panel(); CssLayout orientamentoDescrContent = new CssLayout(); orientamentoDescription.setContent(orientamentoDescrContent); dxContent.addComponents(orientamentoPG, orientamentoDescription); // Dettagli di popolazione e comportamento ComboBox TableQuery tq_orientamento = new TableQuery(DatabaseTables.MORALCODE_TABLE, connPool); tq_orientamento.setVersionColumn(DatabaseTables.MORALCODE_VERSION); SQLContainer container_orientamento = null; try { container_orientamento = new SQLContainer(tq_orientamento); } catch (Exception ex) { logger.error(ex.getMessage()); } orientamentoPG.setContainerDataSource(container_orientamento); orientamentoPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); orientamentoPG.setItemCaptionPropertyId(DatabaseTables.MORALCODE_TENDENCY); orientamentoPG.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { if (orientamentoPG.getValue() != null) { logger.info("Orientamento: " + orientamentoPG.getValue().toString()); orientamentoDescrContent.removeAllComponents(); Item item = (Item) orientamentoPG.getContainerDataSource().getItem(orientamentoPG.getValue()); moralCode = (String) item.getItemProperty(DatabaseTables.MORALCODE_TENDENCY).getValue(); Label orientamentoName = new Label(moralCode); FileResource imageSrc = new FileResource(new File( MyUI.basePath + item.getItemProperty(DatabaseTables.MORALCODE_IMAGE).getValue())); Image imageTendency = new Image(null, imageSrc); imageTendency.setWidth("200px"); Label orientamentoDescription = new Label( item.getItemProperty(DatabaseTables.MORALCODE_DESCRIPTION), ContentMode.HTML); orientamentoDescrContent.addComponents(orientamentoName, imageTendency, orientamentoDescription); } } }); body.addComponents(sx, dx); CssLayout footer = new CssLayout(); Button next = new Button("Avanti ->"); next.addClickListener((Button.ClickEvent event) -> { user.setCarrieraPG(career); // Gestire modificatori user.setForzaPG(user.getForzaPG() + strenght_car); user.setResistenzaPG(user.getResistenzaPG() + resistance_car); user.setAgilitaPG(user.getAgilitaPG() + agility_car); user.setIntelligenzaPG(user.getIntelligenzaPG() + intelligence_car); user.setSaggezzaPG(user.getSaggezzaPG() + wisdom_car); user.setCarismaPG(user.getCarismaPG() + charm_car); user.setOrientamentoPG(moralCode); this.setContent(setThirdStep()); }); footer.addComponents(next, createCancelButton()); secondStep.addComponents(setHeader("3/4"), body, footer); return secondStep; }
From source file:com.cerebro.gorgone.landingpage.SignInWindow.java
private Component setThirdStep() { VerticalLayout thirdStep = new VerticalLayout(); CssLayout body = new CssLayout(); Label title = null;//from w w w .ja v a 2s .c om if (user.getSessoPG().equals("Maschio")) { title = new Label("Caro " + user.getNomeUtente() + " stai per registrare il seguente personaggio: "); } else if (user.getSessoPG().equals("Femmina")) { title = new Label("Cara " + user.getNomeUtente() + " stai per registrare il seguente personaggio: "); } Label nomePG = new Label("Nome: " + user.getNomePG()); Label cognomePG = new Label("Cognome: " + user.getCognomePG()); Label sessoPG = new Label("Sesso: " + user.getSessoPG()); Label etaPG = new Label("Et: " + user.getEtaPG()); Label razzaPG = new Label("Razza: " + user.getRazzaPG()); Label carrieraPG = new Label("Carriera: " + user.getCarrieraPG()); Label orientamentoPG = new Label("Orientamento: " + user.getOrientamentoPG()); String valuesTable = "<table><tr><td>Forza</td><td>Resistenza</td><td>Agilit</td><td>Intelligenza</td>" + "<td>Saggezza</td><td>Carisma</td></tr><tr>" + "<td>" + user.getForzaPG() + "</td>" + "<td>" + user.getResistenzaPG() + "</td>" + "<td>" + user.getAgilitaPG() + "</td>" + "<td>" + user.getIntelligenzaPG() + "</td>" + "<td>" + user.getSaggezzaPG() + "</td>" + "<td>" + user.getCarismaPG() + "</td>" + "</tr></table>"; Label values = new Label(valuesTable, ContentMode.HTML); Label alert = new Label("Premendo il tasto di iscrizione ti verr inviata una mail di conferma " + "all'indirizzo che hai inserito all'inizio. Se non lo confermi non potrai giocare!"); // Aggiungere le condizioni d'uso body.addComponents(title, nomePG, cognomePG, sessoPG, etaPG, razzaPG, carrieraPG, orientamentoPG, values, alert); CssLayout footer = new CssLayout(); Button signIn = new Button("Iscriviti"); signIn.addClickListener((Button.ClickEvent event) -> { logger.info("Iscrizione in corso"); // Creazione del codice String confCode = RandomStringUtils.random(10, true, true); user.setCodiceConferma(confCode); // Salvataggio dei dati nel database user.signInNewUser(); // Invio della mail // SendConfEmail sendConfEmail = new SendConfEmail(user.getEmail(), confCode); // SendConfMailjet sendConf = new SendConfMailjet(user.getEmail(), confCode); // Chiusura della finestra this.close(); }); footer.addComponents(signIn, createCancelButton()); thirdStep.addComponents(setHeader("4/4"), body, footer); return thirdStep; }
From source file:com.cerebro.provevaadin.ChatOffGame.java
public ChatOffGame() { Panel messagesPanel = new Panel(); messagesPanel.setSizeFull();//from ww w.ja va 2 s . c o m messagesPanel.setContent(messages); this.addComponent(messagesPanel); this.setExpandRatio(messagesPanel, 1.0f); HorizontalLayout sendBar = new HorizontalLayout(); sendBar.setWidth("100%"); final TextField input = new TextField(); input.setWidth("100%"); sendBar.addComponent(input); sendBar.setExpandRatio(input, 1.0f); Button send = new Button("Send"); send.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); send.addClickListener((Button.ClickEvent event) -> { BroadcasterOffGame.broadcast(input.getValue(), FROM); input.setValue(""); }); sendBar.addComponent(send); this.addComponent(sendBar); BroadcasterOffGame.register(this); }
From source file:com.cerebro.provevaadin.ChatOnGame.java
public ChatOnGame(User user) { if (user.getUltimoLuogoPG() != null) { logger.info("Luogo: " + user.getUltimoLuogoPG()); } else {//from w w w . j av a 2 s. c o m logger.info("Nessun luogo selezionato"); } Panel messagesPanel = new Panel(); messagesPanel.setSizeFull(); messagesPanel.setContent(messages); this.addComponent(messagesPanel); this.setExpandRatio(messagesPanel, 1.0f); HorizontalLayout sendBar = new HorizontalLayout(); sendBar.setWidth("100%"); final TextField input = new TextField(); input.setWidth("100%"); sendBar.addComponent(input); sendBar.setExpandRatio(input, 1.0f); Button send = new Button("Send"); send.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); send.addClickListener((Button.ClickEvent event) -> { logger.info("Invio del messaggio al server"); BroadcasterOnGame.broadcast(input.getValue(), FROM); input.setValue(""); }); sendBar.addComponent(send); this.addComponent(sendBar); BroadcasterOnGame.register(this); }
From source file:com.cerebro.provevaadin.database.Configurazione.java
public Configurazione() { System.out.println("Componente per la personalizzazione"); this.setMargin(true); TextField db_host = new TextField("Database Host Name"); db_host.isRequired();// ww w . ja v a 2 s . c o m TextField db_port = new TextField("Database Port"); db_port.isRequired(); TextField db_user = new TextField("Username"); db_user.isRequired(); PasswordField db_pwd = new PasswordField("Password"); db_pwd.isRequired(); PasswordField pwd_conf = new PasswordField("Conferma Password"); pwd_conf.setImmediate(true); Properties props = new Properties(); InputStream config = VaadinServlet.getCurrent().getServletContext() .getResourceAsStream("/WEB-INF/config.properties"); if (config != null) { System.out.println("Carico file di configurazione"); try { props.load(config); } catch (IOException ex) { Logger.getLogger(MySQLServer.class.getName()).log(Level.SEVERE, null, ex); } } db_host.setValue(props.getProperty("db_host")); db_user.setValue(props.getProperty("db_user")); Button salva = new Button("Salva"); salva.addClickListener((Button.ClickEvent event) -> { System.out.println("Salvo i parametri"); if (db_host.isValid() && db_port.isValid() && db_user.isValid() && db_pwd.isValid() && pwd_conf.getValue().equals(db_pwd.getValue())) { String dbHost = "jdbc:mysql://" + db_host.getValue() + ":" + db_port.getValue() + "/grizzly?useSSL=false&serverTimezone=UTC"; props.setProperty("db_host", dbHost); props.setProperty("db_user", db_user.getValue()); props.setProperty("db_pwd", db_pwd.getValue()); String webInfPath = VaadinServlet.getCurrent().getServletConfig().getServletContext() .getRealPath("WEB-INF"); File f = new File(webInfPath + "/config.properties"); try { OutputStream o = new FileOutputStream(f); try { props.store(o, "Prova"); } catch (IOException ex) { Logger.getLogger(Configurazione.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(Configurazione.class.getName()).log(Level.SEVERE, null, ex); } Notification.show("Parametri salvati"); } else { Notification.show("Ricontrolla i parametri"); } }); Button test = new Button("Test per i parametri salvati"); test.addClickListener((Button.ClickEvent event) -> { System.out.println("Testo i parametri"); MySQLServer mysql = new MySQLServer(); JDBCConnectionPool conn = mysql.getJDBCConnPool(); if (!mysql.testJDBCConnPool(conn)) { Notification.show("Errore nella connessione al database"); } else { Notification.show("Connessione avvenuta con successo"); } }); this.addComponents(db_host, db_port, db_user, db_pwd, pwd_conf, salva, test); }
From source file:com.cerebro.provevaadin.FirstTime.java
public FirstTime() { this.setMargin(true); TabSheet tabsheet = new TabSheet(); this.addComponent(tabsheet); tabsheet.addTab(new Configurazione(), "Database MySQL"); tabsheet.addTab(new ConfigurazioneSMTP(), "Server SMTP"); Button logout = new Button("Esci"); this.addComponent(logout); logout.addClickListener((Button.ClickEvent e) -> { // logger.info("Esco dall'applicazione"); // logger.info("Pulsante: " + e.toString()); SecurityUtils.getSubject().logout(); UI.getCurrent().getSession().close(); UI.getCurrent().getPage().setLocation(""); });/* w w w .j a va2 s .com*/ this.addComponent(logout); }