11import  java .io .IOException ;
22
3- import  Infrastructure .Filesystem ;
43import  javafx .application .Application ;
54import  javafx .event .ActionEvent ;
6- import  javafx .event .Event ;
7- import  javafx .event .EventHandler ;
85import  javafx .scene .Scene ;
96import  javafx .scene .control .Button ;
107import  javafx .scene .control .Label ;
2017import  javafx .stage .Stage ;
2118
2219import  java .util .LinkedHashMap ;
23- import  java .util .HashSet ;
2420
25- import  Crawler .Crawler ;
2621
2722public  class  GUI  extends  Application  {
2823
2924 TextField  SearchTextField ;
3025 TextField  UrlTextField ;
3126 TextField  PagesTextField ;
32-  LinkedHashMap  hashMap  = Setup .getInstance ();
3327 TextArea  resultText ;
3428
3529
@@ -53,104 +47,11 @@ public void start(Stage primaryStage) {
5347 PagesTextField  = new  TextField ("# of pages" );
5448 btnCrawler .setPrefWidth (170 );
5549
50+ 
5651 btnCrawler .setOnAction (new  SearchHandler <ActionEvent >(SearchTextField , resultText , UrlTextField , PagesTextField ));
57- // // @Override 
58- // public void handle(ActionEvent event) { 
59- // Filesystem.deleteFile("scrape"); 
60- // 
61- // String url = UrlTextField.getText(); 
62- // int numberOfPages = Integer.parseInt(PagesTextField.getText()); 
63- // 
64- // Crawler crawler = new Crawler(url, numberOfPages); 
65- // crawler.crawl(); 
66- // 
67- // LinkedHashMap hashMap2 = Setup.initialise("files/scrape"); 
68- // 
69- // 
70- // System.out.println("created hashmap"); 
71- // 
72- // String userInput = SearchTextField.getText(); //Collect input from textField 
73- // System.out.println(userInput); 
74- // 
75- // if (userInput.length() == 0) resultText.setText("Please enter a search query"); 
76- // 
77- // else { 
78- // 
79- // long start = System.currentTimeMillis(); // Search time count start 
80- // 
81- // HashSet<String> results = Searcher.search(userInput, hashMap2); 
82- // 
83- // if (results == null) resultText.setText("The search did not find any results for " +userInput); 
84- // 
85- // else { 
86- // resultText.setText("Search Results for " +userInput +": \n"); //Resets the textArea for new results to be shown 
87- // 
88- // int count = 0; 
89- // 
90- // for(String result: results) { 
91- // resultText.appendText(result +"\n"); 
92- // count++; 
93- // } 
94- // 
95- // long end = System.currentTimeMillis(); 
96- // 
97- // float time = (float) ((end - start) / 1000); // Search time total ms 
98- // 
99- // resultText.appendText(results.size() +" results in " + time + " second(s)."); 
100- // } 
101- // 
102- // } 
103- // 
104- // } 
105- // }); 
106- 
107- 
108-  // TODO: Turn these things into lambdas 
109- 
110-  //Add handle to btn (Search:) 
52+ 
11153 btn .setOnAction (new  SearchHandler <ActionEvent >(SearchTextField , resultText ));
112-  // //* // @Override 
113- // public void handle(ActionEvent event) { 
114- // String userInput = SearchTextField.getText(); //Collect input from textField 
115- // 
116- // if (userInput.length() != 0) { // textField does not handle (userInput != null) 
117- // long start = System.currentTimeMillis(); // Search time count start 
118- // 
119- // HashSet<String> results = Searcher.search(userInput, hashMap); 
120- // 
121- // long end = System.currentTimeMillis(); // Search time count end 
122- // 
123- // long time = ((end - start)); // Search time total ms 
124- // 
125- // if (results == null) { 
126- // resultText.setText("The search did not find any results for '" +userInput+ "'"); 
127- // 
128- // HashSet<String> similarWords = SimilarWords.retrieveSimilarWords(hashMap, userInput); 
129- // if (!similarWords.isEmpty()) { // If there are no similar words, don't try to display them 
130- // resultText.appendText("\n ...but, I found these similar words: "); 
131- // for (String similarWord: similarWords) { 
132- // resultText.appendText(similarWord + ", "); 
133- // } 
134- // } 
135- // //Maybe this should more correctly be handled somewhere else, like the searcher? 
136- // //TODO: Handle boolean searches, could be just not do similar words when boolean search. 
137- // } else { 
138- // 
139- // resultText.setText("Search Results for " +userInput +": \n"); //Resets the textArea for new results to be shown 
140- // 
141- // int count = 0; 
142- // 
143- // for(String result: results) { // for-each loop through the result and append 
144- // resultText.appendText(result +"\n"); 
145- // count++; 
146- // } 
147- // resultText.appendText(count +" results in " +time +" milisecond(s)."); 
148- // } 
149- // } else { 
150- // resultText.setText("Please enter a search query"); 
151- // } 
152- // } 
153- // }); 
54+ 
15455
15556 //GridPane (grid - top) 
15657 GridPane  pane  = new  GridPane ();
0 commit comments