Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void load(Stage stage) throws IOException{
- try
- {
- FileChooser chooser = new FileChooser();
- chooser.setInitialDirectory(new File("."));
- File file = chooser.showOpenDialog(stage);
- FileInputStream fstream = new FileInputStream(file);
- BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
- for (GBlock block : blockList){
- plan1.delete_blok(block.see_matchblock().see_name());
- root.getChildren().remove(block);
- }
- for (GWire wire : wireList){
- root.getChildren().remove(wire);
- }
- blockList.clear();
- portList.clear();
- wireList.clear();
- GPort.port_number = 0;
- Main.id = 0;
- String line = null;
- while ((line = br.readLine()) != null) {
- //System.out.println(line);
- String[] split = line.split(" ");
- if (split[0].equals("start")){
- Port.hodnoty hodny = Port.hodnoty.Metr;
- for (Port.hodnoty hod : Port.hodnoty.values()){
- if (split[2].equals(hod.toString())){
- hodny = hod;
- break;
- }
- }
- GBlock_start loaded_block = new GBlock_start(Double.parseDouble(split[3]), Double.parseDouble(split[4]),
- Double.parseDouble(split[1]), hodny, Integer.parseInt(split[5]));
- loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[6]));
- root.getChildren().add(loaded_block);
- }
- else if(split[0].equals("soucet")){
- GBlock_soucet loaded_block = new GBlock_soucet(Double.parseDouble(split[1]),
- Double.parseDouble(split[2]), Integer.parseInt(split[3]));
- loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
- root.getChildren().add(loaded_block);
- }
- else if(split[0].equals("rozdil")){
- GBlock_rozdil loaded_block = new GBlock_rozdil(Double.parseDouble(split[1]),
- Double.parseDouble(split[2]), Integer.parseInt(split[3]));
- loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
- root.getChildren().add(loaded_block);
- }
- else if(split[0].equals("koule")){
- GBlock_koule loaded_block = new GBlock_koule(Double.parseDouble(split[1]),
- Double.parseDouble(split[2]), Integer.parseInt(split[3]));
- loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
- root.getChildren().add(loaded_block);
- }
- else if(split[0].equals("kvadr")){
- GBlock_kvadr loaded_block = new GBlock_kvadr(Double.parseDouble(split[1]),
- Double.parseDouble(split[2]), Integer.parseInt(split[3]));
- loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
- root.getChildren().add(loaded_block);
- }
- else if(split[0].equals("obdelnik")){
- GBlock_obdelnik loaded_block = new GBlock_obdelnik(Double.parseDouble(split[1]),
- Double.parseDouble(split[2]), Integer.parseInt(split[3]));
- loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
- root.getChildren().add(loaded_block);
- }
- else if(split[0].equals("podil")){
- GBlock_podil loaded_block = new GBlock_podil(Double.parseDouble(split[1]),
- Double.parseDouble(split[2]), Integer.parseInt(split[3]));
- loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
- root.getChildren().add(loaded_block);
- }
- else if(split[0].equals("soucin")){
- GBlock_soucin loaded_block = new GBlock_soucin(Double.parseDouble(split[1]),
- Double.parseDouble(split[2]), Integer.parseInt(split[3]));
- loaded_block.see_matchblock().set_poradi(Integer.parseInt(split[4]));
- root.getChildren().add(loaded_block);
- }
- else if(split[0].equals("name")){
- scheme_name.setText(split[1]);
- }
- }
- Main.plan1.poradnik_refresh();
- br.close();
- fstream.close();
- FileInputStream fstream2 = new FileInputStream(file);
- BufferedReader br2 = new BufferedReader(new InputStreamReader(fstream2));
- br2 = new BufferedReader(new InputStreamReader(fstream2));
- while ((line = br2.readLine()) != null) {
- //System.out.println(line);
- String[] split = line.split(" ");
- if (split[0].equals("wire")) {
- System.out.println(line);
- plan1.add_propoj(split[1], split[3], split[2], split[4]);
- GPort tmp1 = null;
- GPort tmp2 = null;
- //
- for (GPort port : portList){
- if(port.matching_port.see_nazev().equals(split[3])) {
- GBlock block = (GBlock) port.getParent();
- Block tmp = plan1.find_block(split[1]);
- if (block.see_matchblock().see_name().equals(tmp.see_name())) {
- tmp1 = port;
- break;
- }
- }
- }
- for (GPort port : portList){
- if(port.matching_port.see_nazev().equals(split[4])) {
- GBlock block = (GBlock) port.getParent();
- Block tmp = plan1.find_block(split[2]);
- if (block.see_matchblock().see_name().equals(tmp.see_name())) {
- tmp2 = port;
- break;
- }
- }
- }
- //
- /*for (GPort gport : Main.portList) {
- if (gport.port_id == Integer.parseInt(split[5])) {
- tmp1 = gport;
- } else if (gport.port_id == Integer.parseInt(split[6])) {
- tmp2 = gport;
- }
- }*/
- GWire gwire = new GWire(tmp1, tmp2, plan1.find_wire(split[1] + "-" + split[2]));
- root.getChildren().add(gwire);
- }
- }
- }
- catch(IOException ex)
- {
- System.out.println("IOException is caught");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement