Advertisement
Guest User

Untitled

a guest
May 17th, 2018
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 4.37 KB | None | 0 0
  1. package hello
  2.  
  3. import scalafx.application.JFXApp
  4. import scalafx.application.JFXApp.PrimaryStage
  5. import scalafx.geometry.Insets
  6. import scalafx.scene.Scene
  7. import scalafx.scene.control.Button
  8. import scalafx.scene.effect.DropShadow
  9. import scalafx.scene.layout.HBox
  10. import scalafx.scene.paint.Color._
  11. import scalafx.scene.paint.{LinearGradient, Stops}
  12. import scalafx.scene.text.Text
  13. import scalafx.application.JFXApp
  14. import scalafx.application.JFXApp.PrimaryStage
  15. import scalafx.collections.ObservableBuffer
  16. import scalafx.geometry.Orientation
  17. import scalafx.scene.control.{ChoiceBox, ComboBox, Label, ListCell, ListView, RadioButton}
  18. import scalafx.scene.input.MouseEvent
  19. import scalafx.scene.{Cursor, Scene}
  20. import scalafx.scene.paint.Color
  21. import scalafx.Includes._
  22. import scalafx.beans.property.DoubleProperty
  23. import scalafx.event.ActionEvent
  24. //to download files
  25. import sys.process._
  26. import java.net.URL
  27. import java.io.File
  28. import scala.language.postfixOps
  29.  
  30. //to use scrapper
  31. import net.ruippeixotog.scalascraper.browser.JsoupBrowser
  32. import net.ruippeixotog.scalascraper.model._
  33. import net.ruippeixotog.scalascraper.dsl.DSL._
  34. import net.ruippeixotog.scalascraper.dsl.DSL.Extract._
  35. import net.ruippeixotog.scalascraper.dsl.DSL.Parse._
  36.  
  37. object Html {
  38.   def fileDownloaderMusic(url: String, filename: String) = {
  39.     new URL(url) #> new File(filename) !!
  40.   }
  41.  
  42.   def fileDownloaderHtml(url: String, filename: String) = {
  43.     new URL(url) #> new File(filename) !!
  44.   }
  45. }
  46.  
  47.  
  48. object Scraper {
  49.   def test() = {
  50.     val browser = JsoupBrowser()
  51. //    val doc = browser.parseFile("./example.html")
  52. //    val doc2 = browser.get("http://example.com")
  53. //    print(doc)
  54. //    val header = doc >> text("#header")
  55. //    print("\nheader :\n" + header)
  56. //    val items = doc >> elementList("#menu span")
  57. ////    val items = doc >> text("#menu")
  58. //    print("\nitems: " + items)
  59.     val doc = browser.parseFile("./jedynka.html")
  60. //    val doc2 = browser.get("http://example.com")
  61. //    print(doc)
  62.     val header = doc >> text("#ajax-wrap-body")
  63.     print("\nheader :\n" + header)
  64. //    val items = doc >> elementList("#menu span")
  65. //    val items = doc >> text("#menu")
  66. //    print("\nitems: " + items)
  67.  
  68.  
  69.   }
  70. }
  71.  
  72. object Hello extends JFXApp {
  73.  
  74.   val Wed_songs: List[String] = List("Hello", "World", "Enjoy","a","b","c","d","e","f")
  75.   val Pon_songs: List[String] = List("POniedzialek", "fajny", "jest","o")
  76.   val Wt_songs: List[String] = List("Wtorek", "zamknij", "rozporek","lol")
  77.   var selected_song = 2 //??
  78.   var selected_day = 2
  79.  
  80.   stage = new PrimaryStage {
  81.     title = "ListViewExample"
  82.     scene = new Scene(800,600) {
  83.       val label = new Label("Feedback")
  84.       label.layoutX = 20
  85.       label.layoutY = 20
  86.  
  87.       var listView_songs = new ListView(List("Maryla","Jozin z Bazin"))
  88.       listView_songs.layoutX = 500
  89.       listView_songs.layoutY = 50
  90.       fill = LightBlue
  91.  
  92.       val button_play = new Button("Play")
  93.       button_play.layoutX = 20
  94.       button_play.layoutY = 300
  95.  
  96.       val comboBox_day = new ComboBox(List("Pon","Wt","Sr"))
  97.       comboBox_day.layoutX = 20
  98.       comboBox_day.layoutY = 50
  99.  
  100.       val button_select_day = new Button("Select Day")
  101.       button_select_day.layoutX = 100
  102.       button_select_day.layoutY = 50
  103.  
  104.       button_select_day.onAction = (e: ActionEvent) =>{
  105.         val action = comboBox_day.selectionModel.apply.getSelectedItem
  106.         listView_songs.items = new ObservableBuffer[String]()
  107.         if("Sr" == action){
  108.           for(i <- Wed_songs) {
  109.             listView_songs.items.apply += i
  110.           }
  111.         }
  112.         else if("Pon" == action){
  113.           for(i <- Pon_songs) {
  114.             listView_songs.items.apply += i
  115.           }
  116.         }else if("Wt" == action){
  117.           for(i <- Wt_songs) {
  118.             listView_songs.items.apply += i
  119.           }
  120.         }
  121.         else {
  122.           println(comboBox_day.selectionModel.apply.getSelectedItem.getClass)
  123.           println(comboBox_day.selectionModel.apply.getSelectedItem)
  124.           listView_songs.items.apply += comboBox_day.selectionModel.apply.getSelectedItem
  125.         }
  126.       }
  127.  
  128.       button_play.onAction = (e: ActionEvent) => {
  129.         val selected = listView_songs.selectionModel.apply.getSelectedItems
  130.         println("GRA:"+selected)
  131.  
  132.       }
  133.  
  134.       content = List(label,comboBox_day,listView_songs,button_play,button_select_day)
  135.  
  136.     }
  137.   }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement