Example usage for com.vaadin.ui Slider getMax

List of usage examples for com.vaadin.ui Slider getMax

Introduction

In this page you can find the example usage for com.vaadin.ui Slider getMax.

Prototype

public double getMax() 

Source Link

Document

Gets the maximum slider value.

Usage

From source file:com.cerebro.gorgone.landingpage.SignInWindow.java

private Component setFirstStep() {
    VerticalLayout firstStep = new VerticalLayout();
    firstStep.setMargin(true);//from   w  ww.ja  v a2s  .c o m
    // 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.provevaadin.SignIn.java

private VerticalLayout setSecondStep() {
    VerticalLayout secondStep = new VerticalLayout();
    CssLayout header = new CssLayout();
    Label title = new Label("Benvenuto " + u.getNomeUtente() + "!");
    Label istructions = new Label("Crea il tuo personaggio");
    Label step = new Label("2/*");
    header.addComponents(title, istructions, step);
    VerticalLayout body = new VerticalLayout();
    Label ageIstruction = new Label("Indica l'et del tuo personaggio in anni");
    // Cambiare i parametri in base alla razza
    Slider age = new Slider(1, 150);
    age.setImmediate(true);/*from ww w  .j a  v  a 2  s. c o m*/
    age.setSizeFull();
    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");
        }
    });
    body.addComponents(ageIstruction, age, ageDescription);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        u.setEtaPG(age.getValue().toString());
        this.setContent(setThirdStep());
    });
    footer.addComponents(next, createCancelButton());

    secondStep.addComponents(header, body, footer);
    return secondStep;
}