Skip to content

Commit 05017a1

Browse files
committed
Added the Popup window and cleaned the code for GUI.java
1 parent ebc063d commit 05017a1

File tree

1 file changed

+96
-35
lines changed

1 file changed

+96
-35
lines changed

src/main/java/GUI.java

Lines changed: 96 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,88 +15,152 @@
1515
import javafx.geometry.Pos;
1616
import javafx.scene.layout.HBox;
1717
import javafx.scene.paint.Color;
18+
import javafx.stage.Modality;
1819
import javafx.stage.Stage;
1920

2021
public class GUI extends Application {
2122

22-
TextField SearchTextField;
23-
TextField UrlTextField;
24-
TextField PagesTextField;
23+
Label labelExpl, labelUrlPopup, labelPagePopup, labelSearchPopup;
24+
TextField SearchTextField, SearchTextFieldPopup, UrlTextField, PagesTextField;
2525
TextArea resultText;
26+
Button btn, btnCrawler, btnCrawlerPopup, btnPopupClose;
27+
28+
// Primary & Secondary(popup):
29+
GridPane pane, paneCenter, paneCenterPopup;
30+
HBox hbox, hboxPopup;
31+
BorderPane border, borderPopup;
32+
Scene scene, scenePopup;
33+
Stage Stage, newStage;
2634

2735
@Override
2836
public void start(Stage primaryStage) {
2937
//Objects
3038
SearchTextField = new TextField();
39+
40+
SearchTextFieldPopup = new TextField();
3141

32-
Label labelExpl = new Label("Input Search word: ");
42+
labelExpl = new Label("Input Search word: ");
3343
labelExpl.setTextFill(Color.web("#0076a3"));
34-
44+
45+
labelUrlPopup = new Label("Input URL: ");
46+
labelUrlPopup.setTextFill(Color.web("#0076a3"));
47+
48+
labelPagePopup = new Label("Sub-pages to crawl: ");
49+
labelPagePopup.setTextFill(Color.web("#0076a3"));
50+
51+
labelSearchPopup = new Label("Input Search word: ");
52+
labelSearchPopup.setTextFill(Color.web("#0076a3"));
53+
3554
resultText = new TextArea();
3655
resultText.setText("Search Results: \n");
3756
resultText.setPrefWidth(450);
3857

39-
Button btn = new Button("Search");
58+
UrlTextField = new TextField("http://www.");
59+
60+
PagesTextField = new TextField();
61+
62+
btn = new Button("Search");
4063
btn.setPrefWidth(170);
64+
btn.setOnAction(new SearchHandler<ActionEvent>(SearchTextField, resultText));
4165

42-
Button btnCrawler = new Button("Crawler");
43-
UrlTextField = new TextField("url");
44-
PagesTextField = new TextField("# of pages");
66+
btnCrawler = new Button("Crawler");
4567
btnCrawler.setPrefWidth(170);
46-
47-
48-
btnCrawler.setOnAction(new SearchHandler<ActionEvent>(SearchTextField, resultText, UrlTextField, PagesTextField));
49-
50-
btn.setOnAction(new SearchHandler<ActionEvent>(SearchTextField, resultText));
51-
52-
68+
btnCrawler.setOnAction(e-> ButtonClicked(e));
69+
70+
btnCrawlerPopup = new Button("Search & Crawl");
71+
btnCrawlerPopup.setPrefWidth(170);
72+
btnCrawlerPopup.setOnAction(e-> ButtonClicked(e));
73+
74+
btnPopupClose = new Button("Close window");
75+
btnPopupClose.setPrefWidth(170);
76+
btnPopupClose.setOnAction(e-> ButtonClicked(e));
77+
5378
//GridPane (grid - top)
5479
GridPane pane = new GridPane();
5580
pane.setAlignment(Pos.BOTTOM_LEFT);
5681
pane.setHgap(5);
5782
pane.setVgap(5);
58-
pane.setPadding(new Insets(5, 10, 10, 45));
59-
pane.setBorder(Border.EMPTY);
60-
83+
pane.setPadding(new Insets(5, 0, 0, 45));
84+
pane.setBorder(Border.EMPTY);
6185
//Add all elements to pane (into grid)
6286
//GridLayout(int rows, int columns, int horizontalGap, int verticalGap)
6387
pane.add(labelExpl,0,0,2,1);
6488
pane.add(SearchTextField,0,1,2,2);
6589

6690
//GridPane (grid - center)
6791
GridPane paneCenter = new GridPane();
68-
pane.setAlignment(Pos.BOTTOM_LEFT);
69-
pane.setHgap(10);
70-
pane.setVgap(10);
71-
pane.setPadding(new Insets(5, 10, 10, 45));
72-
pane.setBorder(Border.EMPTY);
73-
92+
paneCenter.setAlignment(Pos.BOTTOM_LEFT);
93+
paneCenter.setHgap(10);
94+
paneCenter.setVgap(10);
95+
paneCenter.setPadding(new Insets(0, 0, 0, 45));
96+
paneCenter.setBorder(Border.EMPTY);
7497
//Add all elements to pane (into grid)
7598
//GridLayout(int rows, int columns, int horizontalGap, int verticalGap)
76-
pane.add(resultText,0,3,4,4);
99+
paneCenter.add(resultText,0,1,4,4);
100+
101+
GridPane paneCenterPopup = new GridPane();
102+
paneCenterPopup.setAlignment(Pos.BOTTOM_LEFT);
103+
paneCenterPopup.setHgap(10);
104+
paneCenterPopup.setVgap(10);
105+
paneCenterPopup.setPadding(new Insets(5, 10, 10, 15));
106+
paneCenterPopup.setBorder(Border.EMPTY);
107+
paneCenterPopup.add(labelSearchPopup, 0, 0);
108+
paneCenterPopup.add(SearchTextFieldPopup, 1, 0);
109+
paneCenterPopup.add(labelUrlPopup, 0, 1);
110+
paneCenterPopup.add(UrlTextField, 1, 1);
111+
paneCenterPopup.add(labelPagePopup, 0, 2);
112+
paneCenterPopup.add(PagesTextField, 1, 2);
77113

78114
//HBox
79115
HBox hbox = new HBox();
80116
hbox.setPadding(new Insets(5, 10, 10, 45));
81-
hbox.setSpacing(10);
82-
hbox.getChildren().addAll(btn, btnCrawler, UrlTextField, PagesTextField);
83-
117+
hbox.setSpacing(110);
118+
hbox.getChildren().addAll(btn, btnCrawler);
119+
120+
HBox hboxPopup = new HBox();
121+
hboxPopup.setPadding(new Insets(5, 10, 10, 5));
122+
hboxPopup.setSpacing(5);
123+
hboxPopup.getChildren().addAll(btnCrawlerPopup, btnPopupClose);
84124

85125
//BorderPane (border)
86126
BorderPane border = new BorderPane();
87127
border.setBottom(hbox); //add hbox to border from method
88128
border.setTop(pane); //add grid to border from method
89129
border.setCenter(paneCenter);
130+
131+
BorderPane borderPopup = new BorderPane();
132+
borderPopup.setBottom(hboxPopup); //add hbox to border from method
133+
borderPopup.setCenter(paneCenterPopup);
90134

91135
//Scene: (contains border)
92-
Scene scene = new Scene(border, 600, 300);
136+
Scene scene = new Scene(border, 550, 300);
137+
Scene scenePopup = new Scene(borderPopup, 350, 170);
93138

94139
//Stage:
95-
primaryStage.setTitle("JavaSearchEngine");
140+
primaryStage = new Stage();
141+
primaryStage.setTitle("Java Search Engine");
96142
primaryStage.setScene(scene); // Show Scene
97143
primaryStage.show();
98-
}
144+
145+
newStage = new Stage();
146+
newStage.setScene(scenePopup);
147+
//tell stage it is meannt to pop-up (Modal)
148+
newStage.initModality(Modality.APPLICATION_MODAL);
149+
newStage.setTitle("Crawler window");
150+
}
99151

152+
private void ButtonClicked(ActionEvent e) {
153+
if (e.getSource() == btnCrawler) {
154+
newStage.showAndWait(); //internal java function
155+
}
156+
if (e.getSource() == btnCrawlerPopup) {
157+
btnCrawlerPopup.setOnAction(new SearchHandler<ActionEvent>(SearchTextFieldPopup, resultText, UrlTextField, PagesTextField));
158+
}
159+
if (e.getSource() == btnPopupClose) {
160+
newStage.close();
161+
}
162+
}
163+
100164
public static void main (String[] args) throws IOException {
101165
LinkedHashMap hashMap = Setup.initialise(args[0]);
102166

@@ -105,6 +169,3 @@ public static void main (String[] args) throws IOException {
105169
}
106170
}
107171
}
108-
109-
110-

0 commit comments

Comments
 (0)