Advertisement
Guest User

editor

a guest
Apr 16th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.54 KB | None | 0 0
  1. /*
  2.  *numagrandeviagem.blogspot.com
  3.  */
  4. package fxgmapserios;
  5.  
  6. import java.io.BufferedReader;
  7. import java.io.File;
  8. import java.io.FileNotFoundException;
  9. import java.io.FileReader;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javafx.application.Application;
  15. import javafx.event.ActionEvent;
  16. import javafx.event.EventHandler;
  17. import javafx.scene.Group;
  18. import javafx.scene.Scene;
  19. import javafx.scene.control.Button;
  20. import javafx.scene.control.Menu;
  21. import javafx.scene.control.MenuBar;
  22. import javafx.scene.control.MenuItem;
  23. import javafx.scene.control.TextArea;
  24. import javafx.scene.control.TextField;
  25. import javafx.scene.input.KeyEvent;
  26. import javafx.scene.layout.StackPane;
  27. import javafx.scene.paint.Color;
  28. import javafx.scene.text.Text;
  29. import javafx.scene.web.WebEngine;
  30. import javafx.scene.web.WebView;
  31. import javafx.stage.FileChooser;
  32. import javafx.stage.Stage;
  33.  
  34. /**
  35.  * kmab :s
  36.  */
  37. public class FXGMAPSERIOS extends Application {
  38.  
  39.     public final File fle = new File("C:\\tempOne\\saves\\GMapOne" + "." + "html");
  40.     public FileWriter flw = null;
  41.     public final TextArea ta = new TextArea();
  42.     public MenuItem MnSave = new MenuItem("Salvar");
  43.     public MenuItem MnSaveNew = new MenuItem("SalvarComo");
  44.     public MenuItem MnOpen = new MenuItem("Open");
  45.     public MenuItem MnClear = new MenuItem("APAGAR");
  46.     public Menu menuTurns = new Menu("Turns");
  47.     public MenuItem MiturnOn = new MenuItem("Turn ON");
  48.     public MenuItem MiturnOff = new MenuItem("Turn OFF");
  49.  
  50.     public TextArea taOCP = new TextArea("");
  51.     public WebView wbv;
  52.     public WebEngine wbe;
  53.  
  54.     public void confir() {
  55.         if (new File("C:\\TempOne").exists()) {
  56.             System.out.print("pasta c:\\tempOne esite");
  57.  
  58.         } else {
  59.             new File("c:\\tempOne\\myScript").mkdirs();
  60.             new File("c:\\tempOne\\saves").mkdirs();
  61.             new File("c:\\tempOne\\javascripts").mkdirs();
  62.             System.err.println("ok pastas nessessarias criadas");
  63.         }
  64.  
  65.     }
  66.  
  67.     public void Dispar() {
  68.         try {
  69.             flw = new FileWriter(fle);
  70.             flw.write(ta.getText());
  71.             flw.close();
  72.             int ix = 1;
  73.             ix++;
  74.             System.out.println("salvo+" + ix + " " + fle.getPath());
  75.  
  76.         } catch (IOException ex) {
  77.     Logger.getLogger(FXGMAPSERIOS.class.getName()).log(Level.SEVERE, null, ex);
  78.         }
  79. } ;
  80.    
  81.    /**/ @Override /**/
  82.     public void start(Stage x) {
  83.         confir();
  84.         final Stage stage = new Stage();
  85.         Button btn = new Button();
  86.         btn.setText("Say 'Hello World'");
  87.         final Menu menu1 = new Menu("File");
  88.         final Menu menu2 = new Menu("Options");
  89.         final MenuBar menuBar = new MenuBar();
  90.         menuBar.prefWidthProperty().bind(stage.widthProperty());
  91.         menuBar.getMenus().addAll(menu1, menu2, menuTurns);
  92.  
  93.         //EPOSCRIPT inicar para a pagina os script
  94.         final MenuItem MnScriptGo = new MenuItem("EPOScript");
  95.  
  96.         wbv = new WebView();
  97.         wbe = wbv.getEngine();
  98.         final Button bt = new Button("ATUALIZAR");
  99.  
  100.         menu1.getItems().addAll(MnSave, MnSaveNew, MnOpen);
  101.         menu2.getItems().addAll(MnClear, MnScriptGo);
  102.         menuTurns.getItems().addAll(MiturnOn, MiturnOff);
  103.         ta.setText(
  104.         "<html>\n"
  105.         + "<body>\n"
  106.         + "<h1>\n"
  107.         + "<script src=\"file:\\\\\\c:\\\\TempOne\\\\myScript\\\\myScript.js\"></script>\n"
  108.         + "</h1>\n"
  109.         + "<p id=\"oumen\">repare que o button esta abaixo \n"
  110.         + "<br>e o script esta a cima do codigo</p>\n"
  111.         + "<button type=\"button\" onclick=\"myFunction()\">click</button>\n"
  112.         + "</body>\n"
  113.         + "</html>"
  114.         );
  115.  
  116.         btn.setOnAction(new EventHandler<ActionEvent>() {
  117.             @Override
  118.             public void handle(ActionEvent event) {
  119.  
  120.                 System.out.println("inicializar");
  121.                 Group gp = new Group();
  122.                 Scene scenex = new Scene(gp, 450, 350, Color.SILVER);
  123.                 bt.layoutYProperty().bind(stage.heightProperty().subtract(55));
  124.                 wbv.setLayoutX(6);
  125.                 wbv.setLayoutY(175);
  126.                 wbv.prefHeightProperty().bind(scenex.heightProperty().subtract(10));
  127.                 wbv.prefWidthProperty().bind(scenex.widthProperty().subtract(10));
  128.                 stage.setScene(scenex);
  129.  
  130.                 gp.getChildren().addAll(menuBar, ta, wbv, bt);
  131.                 ta.prefWidthProperty().bind(scenex.widthProperty().subtract(10));
  132.                 ta.setLayoutX(6);
  133.                 ta.setLayoutY(25);
  134.                 //eposcript scriptGo
  135.                 MnScriptGo.setOnAction(new EventHandler<ActionEvent>() {
  136.                     @Override
  137.                     public void handle(ActionEvent t) {
  138.                         //000000000000 PrXmo
  139.                         Stage stageOCP = new Stage();
  140.                         stageOCP.setTitle("OCP SCRIPT");
  141.                         Group gpOCP = new Group();
  142.                         Scene sceneOcep = new Scene(gpOCP, 440, 267, Color.SILVER);
  143.                         stageOCP.setScene(sceneOcep);
  144.                         Button btOCP = new Button("ACTIONSCRIPT");
  145.  
  146.                         gpOCP.getChildren().addAll(taOCP, btOCP);
  147.                         taOCP.setLayoutX(15);
  148.                         taOCP.setLayoutY(35);
  149.                         btOCP.setLayoutX(309);
  150.                         btOCP.setLayoutY(180);
  151.                         taOCP.setText(
  152.                                 "function myFunction()\n"
  153.                                 + "{\n"
  154.                                 + "  document.writeln(\"funcao\")\n"
  155.                                 + "  alert.confirm(\"confirm funçao\");\n"
  156.                                 + "}"
  157.                                 + "");
  158.  
  159.                         btOCP.setOnAction(new EventHandler<ActionEvent>() {
  160.                             @Override
  161.                             public void handle(ActionEvent t) {
  162.                                 System.out.println(taOCP.getText());
  163.                                 FileWriter filew;
  164.                                 File file = new File("c:\\TempOne\\myScript\\myScript.js");
  165.                                 try {
  166.                                     filew = new FileWriter(file);
  167.                                     filew.write(taOCP.getText());
  168.                                     filew.close();
  169.                                     wbe.reload();
  170.                                 } catch (IOException ex) {
  171.                                     Logger.getLogger(FXGMAPSERIOS.class.getName()).log(Level.SEVERE, null, ex);
  172.                                 }
  173.                             }
  174.                         });
  175.  
  176.                         stageOCP.showAndWait();
  177.                     }
  178.                 });
  179.  
  180.                 MnClear.setOnAction(new EventHandler<ActionEvent>() {
  181.                     @Override
  182.                     public void handle(ActionEvent t) {
  183.                         ta.setText(
  184.             "<html>\n<HEAD>\n<BODY><h1>content:Clear<//h1>\n<BODY>\n<HEAD>\n<html>");
  185.  
  186.                     }
  187.                 });
  188.                 MnSave.setOnAction(new EventHandler<ActionEvent>() {
  189.                     @Override
  190.                     public void handle(ActionEvent t) {
  191.                         try {
  192.                             Dispar();
  193.                         } catch (Exception e) {
  194.                             e.printStackTrace();
  195.                         }
  196.                         ta.setText(
  197.                  "<html>\n<HEAD>\n<BODY><h1>content:Save<//h1>\n<BODY>\n<HEAD>\n<html>");
  198.                     }
  199.                 });
  200.                 MnSaveNew.setOnAction(new EventHandler<ActionEvent>() {
  201.                     @Override
  202.                     public void handle(ActionEvent t) {
  203.                         Stage stageSAVED = new Stage();
  204.                         stageSAVED.setTitle("Salvar Como...");
  205.                         Group gpx = new Group();
  206.                         Scene sceneSAVED = new Scene(gpx, 270, 100, Color.BLACK);
  207.                         stageSAVED.setScene(sceneSAVED);
  208.  
  209.                         Text txSaved = new Text("Nome do Arquivo\n        "
  210.                                 + "( SaveText.html or SAVEText.js )");
  211.                         txSaved.setFill(Color.WHITE);
  212.                         final TextField tfSavedName = new TextField();
  213.                         tfSavedName.setPromptText("SaveText.html or SAVEText.js");
  214.                         Button btSAVED = new Button("SAVE");
  215.                         gpx.getChildren().addAll(txSaved, tfSavedName, btSAVED);
  216.  
  217.            btSAVED.setOnAction(new EventHandler<ActionEvent>() {
  218.                             @Override
  219.                             public void handle(ActionEvent t) {
  220.                                 //saved archiv
  221.               final File LETIciafile = new File("c:\\tempOne\\myScript\\" + tfSavedName.getText());
  222.  
  223.                                 final FileWriter myflw;
  224.                                 try {
  225.                                     myflw = new FileWriter(LETIciafile);
  226.                                     myflw.write(ta.getText());
  227.                                     myflw.close();
  228.                                     int ixx = 1;
  229.              /*---*/ System.out.println("salvo como+" + ixx + " " + LETIciafile.getPath());
  230.                                     ++ixx;
  231.                                     //Platform.exit();
  232.                                 } catch (IOException ex) {
  233.                  Logger.getLogger(FXGMAPSERIOS.class.getName()).log(Level.SEVERE, null, ex);
  234.                                 }
  235.                             }
  236.                         });
  237.                         txSaved.setLayoutX(0x10);
  238.                         txSaved.setLayoutY(0x18);
  239.                         tfSavedName.setLayoutX(10 + 50);
  240.                         tfSavedName.setLayoutY(45);
  241.                         btSAVED.setLayoutX(7 + 76 + 55 + 3);
  242.                         btSAVED.setLayoutY(65);
  243.                         stageSAVED.showAndWait();
  244.  
  245.                     }
  246.                 });
  247.                 MnOpen.setOnAction(new EventHandler<ActionEvent>() {
  248.                     @Override
  249.                     public void handle(ActionEvent t) {
  250.                         FileChooser fc = new FileChooser();
  251.                         fc.setTitle("Diretorio ~~");
  252.  
  253.                         fc.getExtensionFilters().add(
  254.                                 new FileChooser.ExtensionFilter("File HTMl", "*.html"));
  255.                         File opendialogFChoise = fc.showOpenDialog(stage);
  256.  
  257.                         File escs = new File(opendialogFChoise.getAbsolutePath());
  258.  
  259.                         FileReader archiv;
  260.                         try {
  261.                             archiv = new FileReader(escs.getAbsoluteFile());
  262.                             BufferedReader bfr = new BufferedReader(archiv);
  263.                             String linha;
  264.                             try {
  265.                                 linha = bfr.readLine();
  266.                                 while (linha != null) {
  267.                                     System.out.println("" + linha);
  268.  
  269.                                     ta.setText("\n" + bfr.readLine() + "\n");
  270.                                     linha = bfr.readLine();
  271.                                 }
  272.                                 archiv.read();
  273.                                 archiv.close();
  274.                             } catch (IOException ex) {
  275.            Logger.getLogger(FXGMAPSERIOS.class.getName()).log(Level.SEVERE, null, ex);
  276.                             }
  277.                         } catch (FileNotFoundException ex) {
  278.           Logger.getLogger(FXGMAPSERIOS.class.getName()).log(Level.SEVERE, null, ex);
  279.                         }
  280.  
  281.                     }
  282.  
  283.                 });
  284.  
  285.                 bt.setOnAction(new EventHandler<ActionEvent>() {
  286.                     @Override
  287.                     public void handle(ActionEvent t) {
  288.                         Dispar();
  289.           wbe.load("file:\\\\C:\\tempOne\\saves\\GMapOne" + "." + "html");
  290.                     }
  291.                 });
  292.  
  293.                 MiturnOff.setDisable(true);
  294.                 MiturnOn.setOnAction(new EventHandler<ActionEvent>() {
  295.                     @Override
  296.                     public void handle(ActionEvent t) {
  297.                         MiturnOn.setDisable(true);
  298.                         MiturnOff.setDisable(false);
  299.                         ta.setOnKeyPressed(new EventHandler<KeyEvent>() {
  300.                             @Override
  301.                             public void handle(KeyEvent t) {
  302.                                 Dispar();
  303.           wbe.load("file:\\\\C:\\\\tempOne\\saves\\GMapOne" + ".html");
  304.                             }
  305.                         });
  306.                     }
  307.                 });
  308.                 MiturnOff.setOnAction(new EventHandler<ActionEvent>() {
  309.                     @Override
  310.                     public void handle(ActionEvent t) {
  311.                         MiturnOff.setDisable(true);
  312.                         MiturnOn.setDisable(false);
  313.                         ta.setOnKeyPressed(null);
  314.                     }
  315.                 });
  316.             }
  317.         });
  318.  
  319.         StackPane root = new StackPane();
  320.         root.getChildren().add(btn);
  321.         Scene scenex = new Scene(root, 300, 250);
  322.  
  323.         stage.setTitle("load!");
  324.         stage.setScene(scenex);
  325.         stage.show();
  326.     }
  327.  
  328.     public static void main(String[] args) {
  329.         launch(args);
  330.     }
  331.  
  332. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement