Skip to content

Instantly share code, notes, and snippets.

@RCura
Created January 18, 2013 15:51
Show Gist options
  • Save RCura/4565513 to your computer and use it in GitHub Desktop.
Save RCura/4565513 to your computer and use it in GitHub Desktop.
JavaFX et typage
package fr.geocite.myprojet
import javafx.event.ActionEvent
import javafx.event.EventHandler
import javafx.scene.{control, Group, Scene}
import javafx.scene.control._
import javafx.scene.effect.Lighting
import javafx.scene.paint.Color
import javafx.scene.text.Text
import javafx.stage.Stage
import javafx.application.Application
import javafx.scene.shape.Rectangle
import javafx.collections.FXCollections
import util.Random
import javafx.scene.chart.{XYChart, NumberAxis, LineChart}
import javafx.fxml.{FXMLLoader, FXML}
import java.io.FileReader
import au.com.bytecode.opencsv.CSVReader
import ch.epfl.lamp.compiler.msil.emit
import javafx.scene.input.MouseEvent
import com.sun.deploy.config.Config
/**
* Created with IntelliJ IDEA.
* User: robin
* Date: 08/01/13
* Time: 10:31
* To change this template use File | Settings | File Templates.
*/
class Launcher extends Application{
def start(primaryStage:Stage ) {
val root : Group = new Group()
val scene_run : Scene = new Scene(root,1024,800,Color.WHITESMOKE)
primaryStage.setScene(scene_run)
primaryStage.setTitle("Fenetre Principale")
/*
primaryStage.setMaxHeight(400)
primaryStage.setMaxWidth(800)
primaryStage.setMinHeight(400)
primaryStage.setMinWidth(800)
*/
// LINECHART SETTINGS
val xAxis = new NumberAxis()
xAxis.setLabel("Temps")
xAxis.setForceZeroInRange(false)
val yAxis = new NumberAxis()
yAxis.setLabel("Population")
yAxis.setForceZeroInRange(false)
val linechart:LineChart[Number,Number] = new LineChart(xAxis, yAxis)
linechart.setTitle("Évolution des villes")
linechart.setLayoutX(0)
linechart.setLayoutY(0)
linechart.setPrefWidth(1000)
linechart.setPrefHeight(750)
linechart.setAnimated(false)
def displayData(NumCities:Int = 5 ){
linechart.getData().retainAll()
// DATA ADD
val reader = new CSVReader(new FileReader("/home/robin/AUpop1954-2006_base.csv"))
val headers = reader.readNext().toList
for(lines <- 0 to (NumCities - 1)){
val currentCity = reader.readNext().toList
val currentName = currentCity(1)
val currentCitySerie:XYChart.Series[Number,Number] = new XYChart.Series()
currentCitySerie.setName(currentName)
for (i <- 3 to 9){
val tps = headers(i).toInt
val pop = currentCity(i).toInt
val currentCityPops:XYChart.Data[Number,Number] = new XYChart.Data(tps,pop)
currentCitySerie.getData().add(currentCityPops)
}
// DATA TO LINECHART
linechart.getData().add(currentCitySerie)
}
}
displayData()
// BOUTON QUITTER
val button_Quit : Button = new Button("Quitter")
button_Quit.getAlignment
button_Quit.setLayoutX(930)
button_Quit.setLayoutY(770)
button_Quit.setStyle("-fx-font-size: 18;")
button_Quit.setDefaultButton(true)
button_Quit.setOnAction(new EventHandler[ActionEvent]() {
override def handle(t:ActionEvent) {
primaryStage.close()
}
})
val label_sliderValue = new Label(5.toString())
label_sliderValue.setLayoutX(150)
label_sliderValue.setLayoutY(760)
val slider_numVilles : Slider = new Slider()
slider_numVilles.setLayoutX(0)
slider_numVilles.setLayoutY(760)
slider_numVilles.setMin(1)
slider_numVilles.setMax(50)
slider_numVilles.setValue(5)
slider_numVilles.setMajorTickUnit(10)
slider_numVilles.setMinorTickCount(5)
slider_numVilles.setShowTickLabels(true)
slider_numVilles.setSnapToTicks(true)
slider_numVilles.setOnMouseClicked(new EventHandler[MouseEvent] {
override def handle(p1: MouseEvent) {
label_sliderValue.setText(slider_numVilles.getValue().ceil.toString())
val s = System.currentTimeMillis()
displayData(slider_numVilles.getValue().ceil.toInt)
println(System.currentTimeMillis() - s)
}
})
val label_slider = new Label("Nombre de villes à afficher")
label_slider.setLayoutX(0)
label_slider.setLayoutY(745)
root.getChildren().addAll(button_Quit, linechart, slider_numVilles, label_slider, label_sliderValue)
primaryStage.show()
}
}
object Launcher extends App {
override def main(args: Array[String]) {
Application.launch(classOf[Launcher], args: _*)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment