Advertisement
Guest User

Untitled

a guest
May 20th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.66 KB | None | 0 0
  1. public void load(Stage stage) throws IOException{
  2. try
  3. {
  4. FileChooser chooser = new FileChooser();
  5. chooser.setInitialDirectory(new File("."));
  6. File file = chooser.showOpenDialog(stage);
  7. FileInputStream fstream = new FileInputStream(file);
  8. BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
  9.  
  10.  
  11. for (GBlock block : blockList){
  12. plan1.delete_blok(block.see_matchblock().see_name());
  13. root.getChildren().remove(block);
  14. }
  15.  
  16. for (GWire wire : wireList){
  17. root.getChildren().remove(wire);
  18. }
  19. blockList.clear();
  20. portList.clear();
  21. wireList.clear();
  22. GPort.port_number = 0;
  23. Main.id = 0;
  24.  
  25. String line = null;
  26. while ((line = br.readLine()) != null) {
  27. //System.out.println(line);
  28. String[] split = line.split(" ");
  29. if (split[0].equals("start")){
  30. Port.hodnoty hodny = Port.hodnoty.Metr;
  31. for (Port.hodnoty hod : Port.hodnoty.values()){
  32. if (split[2].equals(hod.toString())){
  33. hodny = hod;
  34. break;
  35. }
  36. }
  37. GBlock_start loaded_block = new GBlock_start(Double.parseDouble(split[3]), Double.parseDouble(split[4]),
  38. Double.parseDouble(split[1]), hodny, Integer.parseInt(split[5]));
  39. loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[6]));
  40. root.getChildren().add(loaded_block);
  41. }
  42. else if(split[0].equals("soucet")){
  43. GBlock_soucet loaded_block = new GBlock_soucet(Double.parseDouble(split[1]),
  44. Double.parseDouble(split[2]), Integer.parseInt(split[3]));
  45. loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
  46. root.getChildren().add(loaded_block);
  47. }
  48. else if(split[0].equals("rozdil")){
  49. GBlock_rozdil loaded_block = new GBlock_rozdil(Double.parseDouble(split[1]),
  50. Double.parseDouble(split[2]), Integer.parseInt(split[3]));
  51. loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
  52. root.getChildren().add(loaded_block);
  53. }
  54. else if(split[0].equals("koule")){
  55. GBlock_koule loaded_block = new GBlock_koule(Double.parseDouble(split[1]),
  56. Double.parseDouble(split[2]), Integer.parseInt(split[3]));
  57. loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
  58. root.getChildren().add(loaded_block);
  59. }
  60. else if(split[0].equals("kvadr")){
  61. GBlock_kvadr loaded_block = new GBlock_kvadr(Double.parseDouble(split[1]),
  62. Double.parseDouble(split[2]), Integer.parseInt(split[3]));
  63. loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
  64. root.getChildren().add(loaded_block);
  65. }
  66. else if(split[0].equals("obdelnik")){
  67. GBlock_obdelnik loaded_block = new GBlock_obdelnik(Double.parseDouble(split[1]),
  68. Double.parseDouble(split[2]), Integer.parseInt(split[3]));
  69. loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
  70. root.getChildren().add(loaded_block);
  71. }
  72. else if(split[0].equals("podil")){
  73. GBlock_podil loaded_block = new GBlock_podil(Double.parseDouble(split[1]),
  74. Double.parseDouble(split[2]), Integer.parseInt(split[3]));
  75. loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
  76. root.getChildren().add(loaded_block);
  77. }
  78. else if(split[0].equals("soucin")){
  79. GBlock_soucin loaded_block = new GBlock_soucin(Double.parseDouble(split[1]),
  80. Double.parseDouble(split[2]), Integer.parseInt(split[3]));
  81. loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
  82. root.getChildren().add(loaded_block);
  83. }
  84. else if(split[0].equals("name")){
  85. scheme_name.setText(split[1]);
  86. }
  87. }
  88. Main.plan1.poradnik_refresh();
  89.  
  90. br.close();
  91. fstream.close();
  92.  
  93.  
  94.  
  95. FileInputStream fstream2 = new FileInputStream(file);
  96. BufferedReader br2 = new BufferedReader(new InputStreamReader(fstream2));
  97. br2 = new BufferedReader(new InputStreamReader(fstream2));
  98. while ((line = br2.readLine()) != null) {
  99. //System.out.println(line);
  100. String[] split = line.split(" ");
  101. if (split[0].equals("wire")) {
  102.  
  103. System.out.println(line);
  104. plan1.add_propoj(split[1], split[3], split[2], split[4]);
  105. GPort tmp1 = null;
  106. GPort tmp2 = null;
  107. //
  108. for (GPort port : portList){
  109. if(port.matching_port.see_nazev().equals(split[3])) {
  110. GBlock block = (GBlock) port.getParent();
  111. Block tmp = plan1.find_block(split[1]);
  112. if (block.see_matchblock().see_name().equals(tmp.see_name())) {
  113. tmp1 = port;
  114. break;
  115. }
  116. }
  117. }
  118. for (GPort port : portList){
  119. if(port.matching_port.see_nazev().equals(split[4])) {
  120. GBlock block = (GBlock) port.getParent();
  121. Block tmp = plan1.find_block(split[2]);
  122. if (block.see_matchblock().see_name().equals(tmp.see_name())) {
  123. tmp2 = port;
  124. break;
  125. }
  126. }
  127. }
  128. //
  129. /*for (GPort gport : Main.portList) {
  130. if (gport.port_id == Integer.parseInt(split[5])) {
  131. tmp1 = gport;
  132. } else if (gport.port_id == Integer.parseInt(split[6])) {
  133. tmp2 = gport;
  134. }
  135. }*/
  136. GWire gwire = new GWire(tmp1, tmp2, plan1.find_wire(split[1] + "-" + split[2]));
  137. root.getChildren().add(gwire);
  138. }
  139. }
  140.  
  141.  
  142.  
  143. }
  144.  
  145. catch(IOException ex)
  146. {
  147. System.out.println("IOException is caught");
  148. }
  149.  
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement