Advertisement
rsvaco

Untitled

May 25th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package entregable2;
  7.  
  8. import java.net.URL;
  9. import java.lang.Number;
  10. import java.sql.JDBCType;
  11. import java.util.LinkedList;
  12. import java.util.ResourceBundle;
  13. import javafx.collections.FXCollections;
  14. import javafx.collections.ObservableList;
  15. import javafx.fxml.FXML;
  16. import javafx.fxml.Initializable;
  17. import javafx.scene.chart.LineChart;
  18. import javafx.scene.chart.XYChart;
  19. import javafx.scene.control.Slider;
  20.  
  21. /**
  22. * FXML Controller class
  23. *
  24. * @author arsamrei
  25. */
  26. public class FXMLStack3Controller implements Initializable {
  27. private static final int SEGUNDOSPORMINUTO = 10; // para pruebas
  28.  
  29. private static XYChart.Series seriesTWD;
  30. private static XYChart.Series seriesTWS;
  31.  
  32. @FXML
  33. private LineChart<String, Number> lineChartTWD;
  34. @FXML
  35. private LineChart<String, Number> lineChartTWS;
  36. @FXML
  37. private static Slider sliderSeleccion;
  38. private static int segundosTWD;
  39. private static int segundosTWS;
  40. private static int max;
  41.  
  42.  
  43. /**
  44. * Initializes the controller class.
  45. */
  46. @Override
  47. public void initialize(URL url, ResourceBundle rb) {
  48. //max = SEGUNDOSPORMINUTO;
  49. segundosTWD = 0;
  50. segundosTWS = 0;
  51. seriesTWD = new XYChart.Series();
  52. seriesTWS = new XYChart.Series();
  53.  
  54. lineChartTWD.setCreateSymbols(false);
  55. lineChartTWS.setCreateSymbols(false);
  56. lineChartTWD.setLegendVisible(false);
  57. lineChartTWS.setLegendVisible(false);
  58.  
  59.  
  60. lineChartTWD.getData().add(seriesTWD);
  61. lineChartTWS.getData().add(seriesTWS);
  62.  
  63. sliderSeleccion.valueProperty().addListener((obs, oldValue, newValue) -> {
  64. max = (int) sliderSeleccion.getValue() * SEGUNDOSPORMINUTO;
  65. while(seriesTWD.getData().size() > max) {
  66. seriesTWD.getData().remove(0, seriesTWD.getData().size() - max);
  67. }
  68. while(seriesTWS.getData().size() > max) {
  69. seriesTWS.getData().remove(0, seriesTWS.getData().size() - max);
  70. }
  71. });
  72. }
  73.  
  74. public static void addTWD(Number x) {
  75. seriesTWD.getData().add(new XYChart.Data("" + segundosTWD++, x));
  76. //se asegura de que no se supere el maximo al insertar
  77. while(seriesTWD.getData().size() > max) {
  78. seriesTWD.getData().remove(0, seriesTWD.getData().size() - max);
  79. }
  80. }
  81.  
  82. public static void addTWS(Number x) {
  83. seriesTWS.getData().add(new XYChart.Data("" + segundosTWS++, x));
  84. //se asegura de que no se supere el maximo al insertar
  85. while(seriesTWS.getData().size() > max) {
  86. seriesTWS.getData().remove(0, seriesTWS.getData().size() - max);
  87. }
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement