-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainInterface_Controller.java
More file actions
822 lines (666 loc) · 24.4 KB
/
Copy pathMainInterface_Controller.java
File metadata and controls
822 lines (666 loc) · 24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
package application;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
//This project import
import Dijkstra.DijkstraCreateController;
import GestionGraph.EdgeCreation;
import TabuSearchTSP.TabuSearchCreateController;
import VertexGestion.VertexCreate_Controller;
import bfs.BFSCreateController;
import branchAndBound.LittleCreateController;
import dfs.DFSCreateController;
import error.ErrorInterfaceController;
import graph.Edge;
import graph.Graph;
import graph.Vertex;
import graphCreation.CompleteGraphController;
import graphCreation.RandomGraphController;
import parameter.LoadInterfaceController;
import parameter.SaveAsController;
import parameter.Setting;
//JavaFx import
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.ImageCursor;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.control.MenuBar;
import javafx.scene.control.TitledPane;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import mst.MSTCreateController;
/**
* Main interface class
* @author Neil Farmer
*
*/
public class MainInterface_Controller extends Application {
//Settings of the app
public Setting setting = new Setting();
//Link to this (for event handler)
public MainInterface_Controller me = this;
//To create edge after click on two vertex
public EdgeCreation ec = new EdgeCreation(this);
//true if oriented else false
public boolean isOriented = false;
//The element that have been selected by the user
// 0 : None, 1 : Vertex, 2 : Edge
public int userElementSelected = 0;
//Default radius of vertex
protected int radiusOfVertex = 5;
@FXML
private Button BFSButton;
@FXML
private Button PrimMSTButton;
//Borderpane where element are
@FXML
private BorderPane Window;
//AnchorPane in center
@FXML
private AnchorPane BehindOverlay;
//Button to open the left menu (for algorihtm)
@FXML
private Button MenuButtonLeft;
//Main pane (where the graph is display)
@FXML
public Pane Overlay;
@FXML
private TitledPane EdgeRightMenu;
//The top bar
@FXML
private MenuBar MenuTopBar;
//Button to hide the left menu (when it is open)
@FXML
private Button BackLeftSideMenu;
//The anchorpane where the left menu is
@FXML
private AnchorPane LeftSideMenu;
//The graph section of the left menu
@FXML
private TitledPane GraphLeftMenu;
//The algorithm section of the left menu
@FXML
private TitledPane AlgorithmLeftMenu;
@FXML
private TitledPane GraphParameterLeftMenu;
//Color picker for the default color of the vertex
@FXML
private ColorPicker ColorPickerObject;
//Selection of oriented or non oriented graph
@FXML
public ComboBox<String> TypeGraph;
//Group of button for the action of the user (non selected, edge, vertex)
@FXML
private ToggleGroup UserAction;
//Creation of edge selected button
@FXML
private ToggleButton EdgeToggle;
//Mouse selected button (to move, delete, update vertex or edge)
@FXML
private ToggleButton NoneToggle;
//Creation of Vertex selected button
@FXML
private ToggleButton VertexToggle;
//Button to save the graph
@FXML
private Button SaveButton;
//Button to delete the graph
@FXML
private Button DeleteButton;
//Button to apply dijkstra on the graph
@FXML
private Button DijkstraButton;
//Button to create a new complete graph
@FXML
private Button CompleteGraph;
//Button to create a new random graph
@FXML
private Button RandomGraph;
//Button to applytabu search for tsp
@FXML
private Button TabuSearchTSPButton;
//Button tp apply branch and bound
@FXML
private Button BranchAndBoundButton;
@FXML
private Button DFSButton;
@FXML
private Button LoadButton;
@FXML
void PressLoad(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/parameter/LoadInterface.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
LoadInterfaceController sac = fxmlLoader.<LoadInterfaceController>getController();
sac.init_interface(this);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Load graph");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//To create DFS
@FXML
void PressDFS(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/dfs/DFSCreate.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
DFSCreateController dcc = fxmlLoader.<DFSCreateController>getController();
dcc.initInterface(Graph.getListVertex(this.Overlay), Graph.getListEdge(this.Overlay), this.isOriented);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("DFS");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//To create BFS
@FXML
void PressBFSButton(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/bfs/BFSCreate.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
BFSCreateController bcc = fxmlLoader.<BFSCreateController>getController();
bcc.initInterface(Graph.getListVertex(this.Overlay), Graph.getListEdge(this.Overlay), this.isOriented);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("BFS");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Run the branch and bound Algorithm
* @param event Click of the user
*/
@FXML
void PressBranchAndBound(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/branchAndBound/LittleCreate.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
LittleCreateController lcc = fxmlLoader.<LittleCreateController>getController();
lcc.init_interface(this.Overlay, this.isOriented);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Branch and Bound : Little Algorithm");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Run prim algorithm
* @param event Click of the user
*/
@FXML
void PressPrimMSTButton(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/mst/MSTCreate.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
MSTCreateController tscc = fxmlLoader.<MSTCreateController>getController();
tscc.initInterface(Graph.getListVertex(this.Overlay), Graph.getListEdge(this.Overlay));
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Prim Algorithm");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Run the tabu search
* @param event Click of the user
*/
@FXML
void PressTabuSearchTSPButton(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/TabuSearchTSP/TabuSearchCreate.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
TabuSearchCreateController tscc = fxmlLoader.<TabuSearchCreateController>getController();
tscc.init_interface(this);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Tabu search for Travelling Salesman Problem");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Create a complete graph
* @param event Click of the user
*/
@FXML
void PressCompleteGraph(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/graphCreation/CompleteGraph.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
CompleteGraphController rgc = fxmlLoader.<CompleteGraphController>getController();
rgc.init_interface(this);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Create a new complete graph");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Create a random graph
* @param event Click of the user
*/
@FXML
void PressRandomGraph(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/graphCreation/RandomGraph.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
RandomGraphController rgc = fxmlLoader.<RandomGraphController>getController();
rgc.init_interface(this);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Create a new random graph");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Run dijkstra algorithm
* @param event Click of the user
*/
@FXML
void ApplyDijkstra(ActionEvent event) {
//Call the interface to solve
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/Dijkstra/DijkstraCreate.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
DijkstraCreateController dcc = fxmlLoader.<DijkstraCreateController>getController();
dcc.initInterface(Graph.getListVertex(Overlay), Graph.getListEdge(Overlay), this.isOriented);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Dijkstra's algorithm : Creation");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Save the graph
* @param event Click of the user
*/
@FXML
void PressSaveButton(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/parameter/SaveAs.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
SaveAsController sac = fxmlLoader.<SaveAsController>getController();
sac.init_interface(this);
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Save as ...");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
void PressDeleteButton(ActionEvent event) {
this.Overlay.getChildren().clear();
}
//Default mode, where object can move
@FXML
void PressNoneToggle(ActionEvent event) {
//Force to select a mode (by default the mode "none")
if(!NoneToggle.isSelected()) {
NoneToggle.setSelected(true);
return;
}
//for each edge put the control visible if they exist
List<Edge> edgeList = Graph.getListEdge(this.Overlay);
for(Edge e:edgeList) {
e.setControlVisible(true);
}
//Indicate what element have been selected
this.userElementSelected = 0;
//Change cursor
this.Overlay.setCursor(javafx.scene.Cursor.DEFAULT);
//Clear the creation of edge
this.ec.empty();
}
//Mode to create vertex
@FXML
void PressVertexToggle(ActionEvent event) {
//Force to select a mode (by default the mode "none")
if(!VertexToggle.isSelected()) {
NoneToggle.setSelected(true);
this.userElementSelected = 0;
//for each edge put the control visible if they exist
List<Edge> edgeList = Graph.getListEdge(this.Overlay);
for(Edge e:edgeList) {
e.setControlVisible(true);
}
return;
}
this.userElementSelected = 1;
//for each edge put the control non-visible if they exist
List<Edge> edgeList = Graph.getListEdge(this.Overlay);
for(Edge e:edgeList) {
e.setControlVisible(false);
}
//Change the cursor to a custom one
String ToIcon = "\\ressources\\Cursor\\CursorEditVertexEdge.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
Image image = new Image(TotalPath);
Overlay.setCursor(new ImageCursor(image, 32, 32));
this.ec.empty();
}
//mode to create an edge
@FXML
void PressEdgeToggle(ActionEvent event) {
//Force to select a mode (by default the mode "none")
if(!EdgeToggle.isSelected()) {
NoneToggle.setSelected(true);
this.userElementSelected = 0;
List<Edge> edgeList = Graph.getListEdge(this.Overlay);
for(Edge e:edgeList) {
e.setControlVisible(true);
}
return;
}
this.userElementSelected = 2;
List<Edge> edgeList = Graph.getListEdge(this.Overlay);
for(Edge e:edgeList) {
e.setControlVisible(false);
}
//Change the cursor to a custom one
String ToIcon = "\\ressources\\Cursor\\CursorEditVertexEdge.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
Image image = new Image(TotalPath);
Overlay.setCursor(new ImageCursor(image, 32, 32));
}
Predicate<Node> GetEdge = node -> node.getClass().equals(Edge.class);
//Change the type of graph (Oriented or Non-oriented)
@FXML
void ActionTypeGraph(ActionEvent event) {
boolean type;
//Check if the graph has changed type
if (TypeGraph.getValue() == "Non-oriented graph") {
type = false;
} else {
type = true;
}
//if none changed do nothing else ...
if (type == this.isOriented) {
return;
}else if(!type){
//Get list of vertex
List<Vertex> v1 = Graph.getListVertex(this.Overlay);
List<Vertex> v2 = Graph.getListVertex(this.Overlay);
//Check if there's no more than 1 edge between 2 vertex
for(Vertex vertex1:v1) {
v2.remove(vertex1);
for(Vertex vertex2:v2) {
ArrayList<Edge> EdgeList = new ArrayList<Edge>(vertex1.linkToMe);
ArrayList<Edge> EdgeListVertex2 = new ArrayList<Edge>(vertex2.linkToMe);
EdgeList.retainAll(EdgeListVertex2);
if(EdgeList.size() == 2) {
//Error if user try to change type from non-oriented to oriented and 2 edge connect 2 vertex
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/error/ErrorInterface.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
ErrorInterfaceController eic = fxmlLoader.<ErrorInterfaceController>getController();
eic.initInterface("Some vertex have more than one edge ! They can't be converted in non-oriented edge");
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Error !");
String ToIcon = "\\ressources\\Icon\\ErrorIcon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
TypeGraph.setValue("Oriented graph");
return;
}
}
}
}
//Change type of graph
this.isOriented = type;
//Put the button for the MST disable
this.PrimMSTButton.setDisable(this.isOriented);
//Update each edge
//Get the list of edge
List<Edge> result = new ArrayList<Edge>();
result = Graph.getListEdge(this.Overlay);
//update them
for (Edge e : result) {
e.setOriented(type);
}
}
/**
* Hide the left menu
* @param event Click of the user
*/
@FXML
void PressBackLeftSideMenu(ActionEvent event) {
LeftSideMenu_Visible(false);
}
/**
* Show the left menu
* @param event Click of the user
*/
@FXML
void PressMenuButtonLeft(ActionEvent event) {
LeftSideMenu_Visible(true);
}
//Show/Hide the left side menu
private void LeftSideMenu_Visible(boolean visible) {
LeftSideMenu.setVisible(visible);
LeftSideMenu.setManaged(visible);
MenuButtonLeft.setVisible(!visible);
MenuButtonLeft.setManaged(!visible);
}
/**
* Init the pae where the graph will be display
*/
private void init_Overlay() {
Overlay.addEventFilter(MouseEvent.MOUSE_CLICKED, CreateNewVertex);
}
/**
* Init the colorPicker
*/
private void init_ColorPickerObject() {
ColorPickerObject.setValue(setting.getColorVertexDefault());
}
/**
* Init the type of the graph
*/
private void init_TypeGraph() {
this.TypeGraph.getItems().addAll("Non-oriented graph", "Oriented graph");
this.TypeGraph.setValue("Non-oriented graph");
}
/**
* Init the button on the bottom of the interface
*/
private void init_buttonUserAction() {
//Path to icon
String ToIconNone = "\\ressources\\Icon\\NoneIcon.png";
String ToIconVertex = "\\ressources\\Icon\\VertexIcon.png";
String ToIconEdge = "\\ressources\\Icon\\EdgeIcon.png";
String ToIconSave = "\\ressources\\Icon\\SaveIcon.png";
String ToIconDelete = "\\ressources\\Icon\\DeleteIcon.png";
String ToIconLoad = "\\ressources\\Icon\\LoadIcon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPathNone = "file:" + curentAbsoluteDirectory.toString() + ToIconNone;
String TotalPathVertex = "file:" + curentAbsoluteDirectory.toString() + ToIconVertex;
String TotalPathEdge = "file:" + curentAbsoluteDirectory.toString() + ToIconEdge;
String TotalPathSave = "file:" + curentAbsoluteDirectory.toString() + ToIconSave;
String TotalPathDelete = "file:" + curentAbsoluteDirectory.toString() + ToIconDelete;
String TotalPathLoad = "file:" + curentAbsoluteDirectory.toString() + ToIconLoad;
ImageView imageNone = new ImageView(new Image(TotalPathNone));
ImageView imageVertex = new ImageView(new Image(TotalPathVertex));
ImageView imageEdge = new ImageView(new Image(TotalPathEdge));
ImageView imageSave = new ImageView(new Image(TotalPathSave));
ImageView imageDelete = new ImageView(new Image(TotalPathDelete));
ImageView imageLoad = new ImageView(new Image(TotalPathLoad));
//Set the icon size
imageNone.setFitHeight(15);
imageNone.setFitWidth(15);
imageVertex.setFitHeight(15);
imageVertex.setFitWidth(15);
imageEdge.setFitHeight(15);
imageEdge.setFitWidth(15);
imageSave.setFitHeight(15);
imageSave.setFitWidth(15);
imageDelete.setFitHeight(15);
imageDelete.setFitWidth(15);
imageLoad.setFitHeight(15);
imageLoad.setFitWidth(15);
//put the icon on button
this.NoneToggle.setGraphic(imageNone);
this.VertexToggle.setGraphic(imageVertex);
this.EdgeToggle.setGraphic(imageEdge);
this.SaveButton.setGraphic(imageSave);
this.DeleteButton.setGraphic(imageDelete);
this.LoadButton.setGraphic(imageLoad);
this.NoneToggle.setTooltip(new Tooltip("None : You will be able to move vertex, delete element, ..."));
this.VertexToggle.setTooltip(new Tooltip("Vertex"));
this.EdgeToggle.setTooltip(new Tooltip("Edge"));
this.SaveButton.setTooltip(new Tooltip("Save the graph"));
this.DeleteButton.setTooltip(new Tooltip("Delete the graph"));
this.LoadButton.setTooltip(new Tooltip("Load a graph"));
}
//Function call on start
@FXML
public void initialize() {
LeftSideMenu_Visible(false);
init_Overlay();
init_ColorPickerObject();
init_TypeGraph();
init_buttonUserAction();
}
@Override
public void start(Stage arg0) {
}
//When user click on pane
EventHandler<MouseEvent> CreateNewVertex = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
//Check if the user want to create a new Vertex
if (me.userElementSelected == 1) {
//Launch interface to create a new vertex
try {
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/VertexGestion/VertexCreation.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
VertexCreate_Controller vc = fxmlLoader.<VertexCreate_Controller>getController();
vc.init_interface((int) event.getX(), (int) event.getY(), me, ColorPickerObject.getValue());
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("New vertex");
String ToIcon = "\\ressources\\Icon\\GraphApp_icon.png";
Path currentRelativePath = Paths.get("");
Path curentAbsoluteDirectory = currentRelativePath.toAbsolutePath();
String TotalPath = "file:" + curentAbsoluteDirectory.toString() + ToIcon;
stage.getIcons().add(new Image(TotalPath));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
}