Example usage for javafx.scene.control SpinnerValueFactory SpinnerValueFactory

List of usage examples for javafx.scene.control SpinnerValueFactory SpinnerValueFactory

Introduction

In this page you can find the example usage for javafx.scene.control SpinnerValueFactory SpinnerValueFactory.

Prototype

SpinnerValueFactory

Source Link

Usage

From source file:br.com.OCTur.view.InfograficoController.java

/**
 * Initializes the controller class./* w  w  w .  j  a  va2s.  c om*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    hotel = new HotelDAO().pegarPorEmpresa(Sessao.pessoa.getEmpresa());
    snRelatorio = new SwingNode();
    spContainer.setContent(snRelatorio);
    spAno.setValueFactory(new SpinnerValueFactory<Integer>() {
        @Override
        public void decrement(int steps) {
            setValue(getValue() - steps);
        }

        @Override
        public void increment(int steps) {
            setValue(getValue() + 1);
        }
    });
    spAno.valueProperty().addListener(
            (ObservableValue<? extends Integer> observable, Integer oldValue, Integer newValue) -> {
                try {
                    inicio = DateFormatter.toDate("01/01/" + spAno.getValue());
                    fim = DateFormatter.toDate("01/01/" + (spAno.getValue() + 1));
                    Map<String, Object> parametros = new HashMap<>();
                    parametros.put("hotel", hotel.getEmpresa().getNome());
                    parametros.put("logo",
                            getClass().getResourceAsStream(FxMananger.VIEW + "image/octur-logo.png"));
                    parametros.put("occ", NumberFormatter.duasCasas(new Random().nextDouble() * 100) + "%");
                    parametros.put("mpi", NumberFormatter.duasCasas(new Random().nextDouble() * 100) + "%");
                    parametros.put("rgi", NumberFormatter.duasCasas(new Random().nextDouble() * 100) + "%");
                    parametros.put("ari", NumberFormatter.duasCasas(new Random().nextDouble() * 100) + "%");
                    parametros.put("revpar", NumberFormatter.duasCasas(new Random().nextDouble() * 100));
                    parametros.put("adr", NumberFormatter.duasCasas(new Random().nextDouble() * 100));
                    parametros.put("receitaMensal", receitaMensal());
                    parametros.put("participacao", participacao());
                    parametros.put("classificacaoHotel", classificacaoHotel());

                    parametros.put("mes", hotel.getEmpresa().getNome() + " " + mes);
                    JasperPrint jasperPrint = JasperFillManager.fillReport(
                            getClass().getResourceAsStream(FxMananger.VIEW + "report/infografico.jasper"),
                            parametros, new JREmptyDataSource());
                    JRViewer jRViewer = new JRViewer(jasperPrint);
                    snRelatorio.setContent(jRViewer);
                } catch (JRException e) {
                    System.err.println(e.getMessage());
                }
            });
    spAno.getValueFactory().setValue(Calendar.getInstance().get(Calendar.YEAR));

}