package com.example.json_web; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import javafx.application.Application; import javafx.concurrent.Worker; import javafx.css.PseudoClass; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.control.cell.TextFieldTreeCell; import javafx.scene.effect.Glow; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.transform.Scale; import javafx.scene.transform.Translate; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import javafx.stage.Stage; import org.json.JSONArray; import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.*; import java.awt.Desktop; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.security.KeyManagementException; import java.security.SecureRandom; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; class Notifier { Timer timer; public Integer seconds; public Notifier(int seconds) { this.seconds = seconds; timer = new Timer(); timer.schedule(new RemindTask(), seconds*1000); // schedule the task } class RemindTask extends TimerTask { public void run() { System.out.println("You have a notification ("+seconds+"s)!"); timer.cancel(); //Terminate the timer thread } } public static void main(String args[]) { new Notifier(5); } } public class HelloApplication<e> extends Application { final Stage stage = new Stage(); final Stage stage1 = new Stage(); final Stage stage2 = new Stage(); final Stage stage3 = new Stage(); public WebView web = new WebView(); public WebView web1 = new WebView(); public WebView web2 = new WebView(); public WebView web3 = new WebView(); public static Button b50 = new Button("Prio 1"); public static Button b51 = new Button("Prio 2"); public static Button b52 = new Button("Prio 3"); public static Button b53 = new Button("Prio 4"); public static TextArea textArea0 = new TextArea(); public static TextArea textArea = new TextArea(); public static TextArea textArea1 = new TextArea(); public static TextArea textArea2 = new TextArea(); public static TextArea textArea3 = new TextArea(); public static TextArea textArea4 = new TextArea(); public static TreeItem rootItem = new TreeItem("Dohledové Centrum "); public static Document doc; public static HBox hbox,hbox1; public static VBox vbox,vbox1; public Integer count = 0; public JSONArray ja_data; @FXML public static Label welcomeText; public static Label label4; // create a textfield; public static TextField tf2 = new TextField("textfield"); static { TrustManager[] trustAllCerts = { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } } }; try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (KeyManagementException | java.security.NoSuchAlgorithmException e) { } HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); } String[] urls = new String[] { "http://www.google.com", "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&format=json", "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_1_Services&format=json", "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_2_Services&format=json", "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_3_Services&format=json", "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_4_Services&format=json", "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1", "https://rt.cesnet.cz/rt/", "https://app.smartsupp.com/app/dashboard/conversations" }; public void vypisCas(){ //textArea2.setText(String.valueOf(new Date())); //textArea2.setWrapText(true); //label4.setText(new Date().toString()); tf2.setText(new Date().toString()); } public static class VypisCas extends TimerTask { public void run() { System.out.println("You have a notification! VypisCas"); //vypisCas(); //timer.cancel(); //Terminate the timer thread } } //public Label label5= new Label("pokus"); @Override public void start(Stage stage) throws IOException { //Notifier not= new Notifier(20); Timer timer1 = new Timer(); //timer1.schedule(new VypisCas(), 2*1000); // schedule the task //hodiny, spusti jednou za vterinu; timer1.scheduleAtFixedRate(new TimerTask() { public void run() { //tf2.setText(new Date().toString()); //System.out.println("doing"); //textArea2.setText(String.valueOf(new Date())); //label5.setLabelFor(button2); /* label5.setPrefWidth(100); label5.setWrapText(true); label5.setAlignment(Pos.CENTER_LEFT); label5.setText("cas"); */ //hbox1.getChildren().add((label5)); //vypisCas(); //label4.setText("1100"); //welcomeText.setText(new Date().toString()); } }, 3000, 1 * 1000); FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); String url = "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&format=json"; String url1 = "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&showFullscreen=1"; String url2 = "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1"; String url3 = "https://app.smartsupp.com/app/dashboard/conversations"; web.setPrefHeight(700); web.setZoom(0.75); /* web.getEngine().load("http://google.com"); //web.getEngine().load("url"); WebEngine webEngine = web.getEngine(); Document document = webEngine.getDocument(); */ //java.net.CoockieHandler.getDefault(); //CookieStore cookieStore = new CookieManager(createCookieStore(), null).getCookieStore(); //String cookie = (String)webEngine.executeScript("return document.cookie"); Button button = new Button("Json"); Button button0 = new Button("Prio 1-4"); Button button01 = new Button("Prio 1"); Button button02 = new Button("Prio 2"); Button button03 = new Button("Prio 3"); Button button04 = new Button("Prio 4"); Button button1 = new Button("Full"); Button button2 = new Button("Dohled"); Button button3 = new Button("Smartsupp"); Button button30 = new Button("vloz"); Button button31 = new Button("otevri okno"); Button button32 = new Button("okno2"); Button button33 = new Button("cesnet"); //button.setOnAction(); HBox hbox31 = new HBox(); VBox vbox10 = new VBox(); stage1(vbox10, "Hello1!"); /* button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent actionEvent) { //... do something in here. web.getEngine().load("url"); } }); */ //nacteni ze souboru; button.setOnAction((event) -> { System.out.println("Button clicked!"); try { MyJson(); } catch (IOException e) { e.printStackTrace(); } //web.getEngine().load(url); }); button0.setOnAction((event) -> { System.out.println("Button clicked!"); web.getEngine().setJavaScriptEnabled(true); final WebEngine webEngine1 = web.getEngine(); webEngine1.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> { if (newState == Worker.State.SUCCEEDED) { doc = webEngine1.getDocument(); String docBody = doc.getElementsByTagName("body").item(0).getTextContent(); System.out.println(docBody); Gson g = new Gson(); //JSONObject person = new JSONObject(); if (docBody.charAt(0) == '{') { MyJson(docBody); System.out.println("------------JSON--------------"); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); //Student s = gson.fromJson(docBody, Student.class); Object s = gson.fromJson(docBody, Object.class); System.out.println(s.toString()); System.out.println(s.getClass()); Gson gson1 = new GsonBuilder().setPrettyPrinting().create(); String json1 = gson.toJson(docBody); System.out.println("------------System.out.println(json);--------------"); System.out.println(json1.toString()); System.out.println("------------JSONObject--------------"); /* System.out.println("------------mcArray--------------"); Object[] mcArray = gson.fromJson(docBody, Object[].class); System.out.println(mcArray.toString()); */ JSONObject json = new JSONObject(docBody); //obnova tree menu; try { rootItem.getParent().getChildren().removeAll(); } catch (Exception e) { } //rootItem.getChildren().removeAll(); //rootItem.getChildren().setStyle("-fx-background-color: rgba(96, 224, 16, 0.87)"); Tree(json, rootItem, 5); JSONArray arr = json.getJSONArray("children"); for (int i1 = 0; i1 < arr.length(); i1++) { Tree(arr.getJSONObject(i1), rootItem, 4); } JSONArray ar = (JSONArray) json.get("children"); //JSONObject json = (JSONObject) s; System.out.println(json.toString()); System.out.println("name: " + json.get("name")); System.out.println("path: " + json.get("path")); System.out.println("ar.path: " + ar.get(0)); System.out.println("ar.path1: " + ar.get(1)); JSONObject json0 = new JSONObject(ar.get(0).toString()); System.out.println("json0.get(path): " + json0.get("path")); System.out.println("children: " + json.get("children")); System.out.println("children: " + json.get("children")); System.out.println(json); /* Type listType = new TypeToken<s>() { }.getType(); List<s> keyPairBoolDataList = new Gson().fromJson(docBody, listType); */ //Class c = ob.getClass(); /* for (Class c = s.getClass(); c != null; c = c.getSuperclass()) { for (Method method : c.getDeclaredMethods()) { if (method.getAnnotation(PostConstruct.class) != null) { System.out.println(c.getName() + "." + method.getName()); } } } */ } } }); web.getEngine().load(urls[1]); System.out.println(urls[1]); }); button01.setOnAction((event) -> { System.out.println("Button01 clicked!"); final WebEngine webEngine1 = web.getEngine(); webEngine1.setJavaScriptEnabled(true); webEngine1.load(urls[2]); webEngine1.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> { if (newState == Worker.State.SUCCEEDED) { doc = webEngine1.getDocument(); stage.setTitle(webEngine1.getLocation()); String docBody = doc.getElementsByTagName("body").item(0).getTextContent(); System.out.println(docBody); Gson g = new Gson(); if (docBody.charAt(0) == '{') { MyJson(docBody); } } }); System.out.println(urls[2]); }); button02.setOnAction((event) -> { System.out.println("Button02 clicked!"); final WebEngine webEngine1 = web.getEngine(); webEngine1.setJavaScriptEnabled(true); webEngine1.load(urls[3]); webEngine1.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> { if (newState == Worker.State.SUCCEEDED) { doc = webEngine1.getDocument(); stage.setTitle(webEngine1.getLocation()); String docBody = doc.getElementsByTagName("body").item(0).getTextContent(); System.out.println(docBody); Gson g = new Gson(); if (docBody.charAt(0) == '{') { MyJson(docBody); } } }); System.out.println(urls[3]); }); button03.setOnAction((event) -> { System.out.println("Button03 clicked!"); final WebEngine webEngine1 = web.getEngine(); webEngine1.setJavaScriptEnabled(true); webEngine1.load(urls[4]); webEngine1.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> { if (newState == Worker.State.SUCCEEDED) { doc = webEngine1.getDocument(); stage.setTitle(webEngine1.getLocation()); String docBody = doc.getElementsByTagName("body").item(0).getTextContent(); System.out.println(docBody); Gson g = new Gson(); if (docBody.charAt(0) == '{') { MyJson(docBody); } } }); System.out.println(urls[4]); }); button04.setOnAction((event) -> { System.out.println("Button04 clicked!"); final WebEngine webEngine1 = web.getEngine(); webEngine1.setJavaScriptEnabled(true); webEngine1.load("https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=" + "Prio_4_Services" + "&format=json"); //https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_3_Services webEngine1.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> { if (newState == Worker.State.SUCCEEDED) { doc = webEngine1.getDocument(); stage.setTitle(webEngine1.getLocation()); String docBody = doc.getElementsByTagName("body").item(0).getTextContent(); System.out.println(docBody); Gson g = new Gson(); if (docBody.charAt(0) == '{') { MyJson(docBody); } } }); System.out.println(urls[5]); }); button1.setOnAction((event) -> { System.out.println("Button1 clicked!"); web.getEngine().load(url1); }); button2.setOnAction((event) -> { System.out.println("Button2 clicked!"); web.getEngine().load(url2); }); button30.setOnAction((event) -> { System.out.println("Button30 clicked!"); try { org.w3c.dom.Node s = doc.getElementsByTagName("input").item(1); s.setNodeValue("test1"); doc.getElementsByTagName("input").item(2).setNodeValue("test2"); System.out.println(doc.getElementsByTagName("input").item(1).toString()); System.out.println("getTextContent" + doc.getElementsByTagName("input").item(1).getTextContent()); System.out.println(doc.getElementsByTagName("input").item(1).getAttributes().toString()); org.w3c.dom.Node n; NodeList nodeList = doc.getElementsByTagName("input").item(0).getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { n = nodeList.item(i); System.out.println(n.getTextContent()); n.setTextContent("pokus5566"); } doc.getElementsByTagName("input").item(1).setTextContent("pokus5566"); } catch (Exception e) { System.out.println("Exception"); e.printStackTrace(); } //web.getEngine().load(url2); }); button31.setOnAction((event) -> { VBox vbox102 = new VBox(web, textArea0); stage1(vbox102, "Hello12!"); }); button32.setOnAction((event) -> { VBox vbox102 = new VBox(web1, textArea0); stage2(vbox102, "Hello122!"); web1.getEngine().load(url2); }); button33.setOnAction((event) -> { VBox vbox103 = new VBox(web3); WebEngine webEngine13 = web3.getEngine(); webEngine13.setJavaScriptEnabled(true); stage3(vbox103, "Cesnet","speedtest.cesnet.cz/"); webEngine13.load("https://speedtest.cesnet.cz/"); }); mySetOnAction(button3, url3, "Button3 clicked!"); b50.setOnAction((event) -> { System.out.println("Button3 clicked!"); web.getEngine().load("https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_1_Services&showFullscreen=1"); }); b51.setOnAction((event) -> { System.out.println("Button3 clicked!"); web.getEngine().load("https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_2_Services&showFullscreen=1"); }); b52.setOnAction((event) -> { System.out.println("Button3 clicked!"); web.getEngine().load("https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_3_Services&showFullscreen=1"); }); b53.setOnAction((event) -> { System.out.println("Button3 clicked!"); web.getEngine().load("https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1&node=Prio_4_Services&showFullscreen=1"); }); textArea0.setMaxHeight(40); textArea.setText("text"); textArea.setWrapText(true); textArea.setMaxWidth(270); textArea.setMaxHeight(270); textArea.setMinHeight(240); textArea.focusedProperty().addListener((obs, oldVal, newVal) -> System.out.println(newVal ? "Focused textArea" : "Unfocused textArea")); textArea1.setText("text"); textArea1.setWrapText(true); //textArea1.setMaxWidth(200); textArea1.setMaxHeight(50); textArea2.setText("text"); textArea2.setWrapText(true); textArea2.setMaxWidth(270); textArea2.setMaxHeight(270); textArea3.setText("text"); textArea3.setWrapText(true); textArea3.setMaxWidth(360); textArea3.setMaxHeight(270); textArea4.setText("text"); textArea4.setWrapText(true); textArea4.setMaxWidth(360); textArea4.setMaxHeight(270); //textArea.setText(cookie); hbox = new HBox(button, button0, button01, button02, button03, button04, button1, button2, button3, button30, button31, button32, button33); hbox.setSpacing(10); hbox.setLayoutX(20); hbox.setAlignment(Pos.CENTER_LEFT); //hbox1.getChildren().add((label5)); HBox hbox2 = new HBox(textArea, textArea2, textArea3); //HBox.setMargin(textArea, new Insets(10, 10, 10, 10)); HBox hbox3 = new HBox(); hbox1 = new HBox(); vbox10 = new VBox(hbox2, hbox3, textArea1); vbox10.setSpacing(5); vbox10.setLayoutX(100); vbox10.setLayoutY(100); vbox10.setAlignment(Pos.BOTTOM_CENTER); vbox1 = new VBox(); VBox vbox11 = new VBox(); //vbox = new VBox(textArea0,web,fxmlLoader.load(),hbox,hbox1,vbox10); vbox = new VBox(vbox11, fxmlLoader.load(), hbox, hbox1, vbox10); //vbox.setSpacing(5); JSONObject json = MyJson(); //vbox.getChildren().add(vbox1); System.out.println(InetAddress.getLocalHost()); System.out.println(InetAddress.getLoopbackAddress()); System.out.println(InetAddress.getLoopbackAddress()); //System.out.println(InetAddress.getAllByName()); //InetAddress[] addresses = InetAddress.getAllByName("www.google.com"); //Scene scene = new Scene(fxmlLoader.load(), 920, 940); Scene scene = new Scene(vbox, 900, 900); scene.getStylesheets().add("stylesheet.css"); stage.setTitle("Hello! " + InetAddress.getLocalHost()); stage.setScene(scene); tf2.setMaxSize(400, 30); tf2.setPrefSize(240, 30); tf2.setMinSize(240, 30); tf2.setAlignment(Pos.CENTER); tf2.setStyle("-fx-text-inner-color: red; -fx-font-size: 12px;-fx-background-color:#ffffff;"); HBox hbox5 = new HBox(tf2); hbox5.setAlignment(Pos.BOTTOM_CENTER); vbox.getChildren().add(hbox5); TreeView treeView = new TreeView(); treeView.setRoot(rootItem); Class<? extends TreeItem> aClass = rootItem.getClass(); System.out.println("Class" + aClass.toString()); treeView.setShowRoot(false); // Make the TreeView editable // Set a cell factory to use TextFieldTreeCell treeView.setCellFactory(TextFieldTreeCell.forTreeView()); // Helper Methods for the Event Handlers // Set editing related event handlers (OnEditStart) treeView.setOnEditStart(new EventHandler<TreeView.EditEvent>() { @Override public void handle(TreeView.EditEvent event) { editStart(event); } }); // Set editing related event handlers (OnEditCommit) treeView.setOnEditCommit(new EventHandler<TreeView.EditEvent>() { @Override public void handle(TreeView.EditEvent event) { editCommit(event); } }); // Set editing related event handlers (OnEditCancel) treeView.setOnEditCancel(new EventHandler<TreeView.EditEvent>() { @Override public void handle(TreeView.EditEvent event) { editCancel(event); } }); treeView.setEditable(true); treeView.setPrefSize(400, 50); //json.getJSONArray("children").getJSONObject(0) Tree(json, rootItem, 5); HBox hbox10 = new HBox(treeView, textArea4); //hbox10.getChildren().add(); vbox.getChildren().add(hbox10); //VBox vbox = new VBox(treeView); //scene.p stage.setX(-1900); stage.setY(100); stage.setWidth(900); stage.setHeight(1050); stage.show(); hbox31 = new HBox(); vbox10 = new VBox(textArea0, web, hbox31); stage1.setX(-2200); stage1.setY(100); stage1.setWidth(300); stage1.setHeight(950); stage1.show(); stage1(vbox10, "Hello1!"); if(true){ stage2.setX(-2550); stage2.setY(100); stage2.setWidth(400); stage2.setHeight(950); stage2.show(); //rootItem.setExpanded(true); StackPane stackPane = new StackPane(treeView); stackPane.setPrefSize(500,900); VBox vbox41 = new VBox(stackPane); //vbox41.setLayoutX(100); //vbox41.setLayoutY(100); vbox41.setPrefWidth(400);// prefWidth vbox41.setPrefHeight(900);// prefHeight // vbox41.setFillWidth(true); //vbox41.spacingProperty(); /* VBox treeContainer = new VBox(); TreeItem<String> hiddenRootItem = new TreeItem<String>(); TreeView<String> tree = new TreeView<String>(hiddenRootItem); tree.setShowRoot(false); treeContainer.getChildren().add(treeView); StackPane root = new StackPane(); root.getChildren().add(treeContainer); */ VBox vbox12 = new VBox(vbox41); vbox12.setPrefWidth(400);// prefWidth vbox12.setPrefHeight(900);// prefHeight ///VBox vbox12 = new VBox(root, textArea4); stage2(vbox12, "Hello2!"); } if(true){ stage3.setX(1550); stage3.setY(100); stage3.setWidth(400); stage3.setHeight(950); stage3.show(); VBox vbox13 = new VBox(web3); vbox13.setPrefWidth(400);// prefWidth vbox13.setPrefHeight(900);// prefHeight stage3(vbox13, "Hello3!"); } } private void editStart(TreeView.EditEvent event) { writeMessage("Started editing: " + event.getTreeItem() ); } private void editCommit(TreeView.EditEvent event) { writeMessage(event.getTreeItem() + " changed." + " old = " + event.getOldValue() + ", new = " + event.getNewValue()); } private void editCancel(TreeView.EditEvent event) { writeMessage("Cancelled editing: " + event.getTreeItem() ); } // Method for Logging private void writeMessage(String msg) { this.textArea2.appendText(msg + "\n"); } public void stage1(VBox vbox10,String title){ Scene scene1 = new Scene(vbox10, 500, 900); stage1.setTitle(title); stage1.setScene(scene1); stage1.setIconified(false); stage1.show(); } public void stage2(VBox vbox10,String title){ Scene scene1 = new Scene(vbox10, 400, 900); stage2.setTitle(title); stage2.setScene(scene1); stage2.setIconified(false); stage2.show(); openWebpage("is.muni.cz"); } public void stage3(VBox vbox10,String title,String url) { stage3(vbox10,title); openWebpage(url,"https://"); } public void stage3(VBox vbox10,String title){ Scene scene3 = new Scene(vbox10, 400, 900); stage3.setTitle(title); stage3.setScene(scene3); stage3.setIconified(false); stage3.show(); //openWebpage(url); } public static void openWebpage(String url,String protokol) { //jede; try { Desktop.getDesktop().browse(new URL(protokol+url).toURI()); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } } public static void openWebpage(String url) { /* try { new ProcessBuilder("x-www-browser", url).start(); } catch (IOException e) { e.printStackTrace(); } new BrowserLauncher().openURLinBrowser("http://www.google.com"); */ //jede; try { Desktop.getDesktop().browse(new URL("http://"+url).toURI()); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } } public void PingExample(String adr) { try{ InetAddress address = InetAddress.getByName(adr); boolean reachable = address.isReachable(10000); System.out.println("Is host reachable? " + reachable); } catch (Exception e){ e.printStackTrace(); } } public static void pi(String adr) throws IOException { // create the ping command as a list of strings //JavaPingExampleProgram ping = new JavaPingExampleProgram(); List<String> commands = new ArrayList<String>(); commands.add("ping"); //commands.add("-c"); //commands.add("5"); commands.add(adr); doCommand(commands); System.out.println(adr + " Host Reached\t" + java.net.Inet6Address.getByName(adr).getHostAddress()); InetAddress[] addresses = InetAddress.getAllByName(adr); textArea2.setWrapText(false); textArea2.setText("Pracuji\n"); String vys="\n"+adr + " Host Reached\t" + java.net.Inet6Address.getByName(adr).getHostAddress(); for (InetAddress address : addresses) { if (address.isReachable(10000)) { System.out.println("Connected "+ address); vys += "\nConnected "+ address; } else { System.out.println("Failed "+address); vys += "\nFailed "+ address; } textArea2.setWrapText(false); textArea2.setText(vys+"\n"); textArea2.setWrapText(true); } } /* public static String reverseDns(String hostIp) throws IOException { Resolver res = new ExtendedResolver(); Name name = ReverseMap.fromAddress(hostIp); int type = Type.PTR; int dclass = DClass.IN; Record rec = Record.newRecord(name, type, dclass); Message query = Message.newQuery(rec); Message response = res.send(query); Record[] answers = response.getSectionArray(Section.ANSWER); if (answers.length == 0) return hostIp; else return answers[0].rdataToString(); } */ public static void doCommand(List<String> command) throws IOException { ProcessBuilder pb = new ProcessBuilder(command); Process process = pb.start(); textArea3.setText(""+command); textArea3.setWrapText(false); javafx.application.Platform.runLater(new Runnable() { public void run() { try{ String s = null; BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); // read the output from the command System.out.println("Here is the standard output of the command:\n"); String vyst=""; textArea3.setText(vyst); while ((s = stdInput.readLine()) != null) { System.out.println(s); vyst += "\n " + s; textArea3.setText(vyst); //textArea3.re } } catch (IOException ex) { ex.printStackTrace(); } } }); javafx.application.Platform.runLater(new Runnable() { public void run() { try{ // read any errors from the attempted command BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream())); String s = null; String vyst=""; System.out.println("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); vyst += "\n " + s; textArea3.setText(vyst); } // some code here } catch (IOException ex) { ex.printStackTrace(); } } }); //textArea3.setWrapText(false); textArea3.setWrapText(true); } public void mySetOnAction (Button but,String url,String popis){ but.setOnAction((event) -> { System.out.println(popis); web.getEngine().load(url); }); } public static void main(String[] args) { launch(); } public static String CtiMyJson() throws IOException { //File file =new File("C:\\java\\show.json"); Path path = Paths.get("C:\\java\\show1.json"); //Path path = Paths.get("K:\\java\\show1.json"); String content = Files.readString(path); return content; } public JSONObject MyJson() throws IOException { String content = CtiMyJson(); return MyJson(content); } public JSONObject MyJson(String content){ //File file =new File("C:\\java\\show.json"); //Path path = Paths.get("K:\\java\\show.json"); //String content = Files.readString(path); /* WebEngine webEngine1 = web.getEngine(); doc = webEngine1.getDocument(); String content = doc.getElementsByTagName("body").item(0).getTextContent(); */ JSONObject json = new JSONObject(content); try { //String name = json.getString("name"); System.out.println("name: "+json.getString("name")); System.out.println("path: "+json.getString("path")); System.out.println("json.names() "+json.names()); //System.out.println("json.children " + json.getJSONObject("children").getString("name")); System.out.println("json.children " + json.getJSONArray("children").toString()); System.out.println("json.children " + json.getJSONArray("children")); }catch(NullPointerException e){ System.out.println("524"); throw e; } //loop to get all json objects from data json array try { ja_data = json.getJSONArray("children"); int length = ja_data.length(); String vyst = json.getString("name")+ " " + ":\n"; textArea.setWrapText(false); textArea.setText(vyst); //super vypise v citelnem stavu; //System.out.println(json.toString(4)); for (int i = 0; i < length; i++) { JSONObject jObj = ja_data.getJSONObject(i); String state=""; if(jObj.has("since")) { //state = jObj.getString("since"); }else{ } System.out.println("name" + i + ": " + jObj.getString("name")); System.out.println("state: " + jObj.getString("state")); String since="";try{ Number since0=jObj.getNumber("since"); Timestamp timestamp1 = new Timestamp(since0.longValue()*1000); since = sdf3.format(timestamp1); }catch(Exception e){ since="neni";}; vyst += " " + jObj.getString("name") + ": " + jObj.getString("state") + state +" " + since + "\n"; } textArea.setWrapText(false); textArea.setText(vyst); textArea.setWrapText(true); //final WebEngine webEngine1 = web.getEngine(); count++; label4= new Label("pokus label4 " + count); //label4.setText("1100"); label4.setLabelFor(hbox1); label4.setPrefWidth(120); label4.setWrapText(true); label4.setAlignment(Pos.CENTER); //prio 1 az 4; //hbox1 = new HBox(b50,b51,b52,b53); hbox1.setSpacing(7); hbox1.setLayoutX(100); hbox1.setLayoutY(100); hbox1.setMaxHeight(140); hbox1.setAlignment(Pos.CENTER); //hbox1.getChildren().add((label5)); hbox1.getChildren().add(label4); hbox1.setPrefHeight(70); vbox1.setSpacing(5); vbox1.getChildren().clear(); rada(ja_data); for(int i=0; i<ja_data.length(); i++){ rada(ja_data.getJSONObject(i).getJSONArray("children")); } /* rada(ja_data.getJSONObject(0).getJSONArray("children")); rada(ja_data.getJSONObject(1).getJSONArray("children")); rada(ja_data.getJSONObject(2).getJSONArray("children")); rada(ja_data.getJSONObject(3).getJSONArray("children")); */ /* TreeItem javaItem = new TreeItem("Java Tutorials"); JSONArray jsonArray= json.names(); for(int i=0; i<jsonArray.length(); i++) { String na = jsonArray.getString(i); //javaItem.getChildren().add(new TreeItem(na)); if (na.equals("children")) { //javaItem.getChildren().add(new TreeItem(jsonArray.getString(i) + json.getJSONArray(jsonArray.getString(i)))); }else{ javaItem.getChildren().add(new TreeItem(jsonArray.getString(i) + ": " + json.getString(na))); } } //javaItem.getChildren().add(new TreeItem("Java Language")); rootItem.getChildren().add(javaItem); */ //podskupina; //rada(ja_data.getJSONObject(2).getJSONArray("children").getJSONObject(4).getJSONArray("children")); try { vbox.getChildren().add(vbox1); }catch(Exception e){ System.out.println("934"); //throw e; } System.out.println("ja_data.getJSONObject(3).getString(\"state\"): "+ja_data.getJSONObject(3).getString("state")); }catch(Exception e){ System.out.println("538"); throw e; } //pekny vypis; //System.out.println("json: "+json.toString(4)); return json; } private final Node rootIcon = new ImageView( new Image(getClass().getClassLoader().getResourceAsStream("32.png")) ); public void Tree(JSONObject json,TreeItem rootItem,Integer hloubka){ hloubka--; System.out.println(hloubka); PseudoClass childPseudoClass = PseudoClass.getPseudoClass("child"); PseudoClass subElementPseudoClass = PseudoClass.getPseudoClass("OK"); String st=""; try { st=json.getString("state"); }catch (Exception e){} MyButton bu = new MyButton(st); obarvi_tlacitko(bu,st); //bu. TreeItem javaItem = new TreeItem(json.getString("name"),bu); //TreeItem javaItem = new TreeItem(json.getString("name")+" " + st,bu); //Button.pseudoClassStateChanged(PseudoClass.getPseudoClass("pressed"), true); //TreeItem javaItem = new TreeItem(json.getString("name")+" " + st,rootIcon); //TreeItem<String> javaItem = new TreeItem<String> ("Inbox", rootIcon); JSONArray jsonArray= json.names(); for(int i=0; i<jsonArray.length(); i++) { String na = jsonArray.getString(i); //javaItem.getChildren().add(new TreeItem(na)); if (na.equals("children")) { if (hloubka > 0) { System.out.println("json(" + hloubka + "): " + json.getJSONArray("children").toString(4)); try { System.out.println(json.getJSONArray("children").toString(4)); } catch (Exception e) { System.out.println("Something went wrong."); System.out.println(e.toString()); System.out.println(json.getJSONArray("children")); } JSONArray arr = json.getJSONArray("children"); for (int i1 = 0; i1 < arr.length(); i1++) { Tree(arr.getJSONObject(i1), javaItem, hloubka); } //Tree(json.getJSONObject(i1),javaItem,hloubka); //javaItem.getChildren().add(new TreeItem(jsonArray.getString(i) // + json.getJSONArray(jsonArray.getString(i)))); } }else if(na.equals("path")){ }else if(na.equals("state")){ }else if(na.equals("name")){ }else if(na.equals("since")){ try { if(json.get("since")=="null"){ }else { Number since0 = json.getNumber(na); Timestamp timestamp1 = new Timestamp(since0.longValue()*1000); Timestamp timestamp2 = new Timestamp(System.currentTimeMillis()-since0.longValue()*1000); String since = sdf3.format(timestamp1); String since1 = sdf4.format(timestamp2); TreeItem treeitem = new TreeItem("Od" + ": " //+ json.getNumber(na) + " " + since + " (" + since1+")" ); //treeitem.ps; // javaItem.getChildren().add(treeitem); } } catch (Exception e) { System.out.println("Something went wrong."); System.out.println(e.toString()); System.out.println(json.get("since")); } }else{ javaItem.getChildren().add(new TreeItem(jsonArray.getString(i) + ": " + json.getString(na))); } } //javaItem.getChildren().add(new TreeItem("Java Language")); rootItem.getChildren().add(javaItem); } public void rada(JSONArray ja_data){ HBox hbox3 = new HBox(); hbox3.setSpacing(10); new MyHbox(ja_data,hbox3); vbox1.getChildren().add(hbox3); } private static final SimpleDateFormat sdf3 = new SimpleDateFormat("HH:mm dd.MM.yyyy"); private static final SimpleDateFormat sdf4 = new SimpleDateFormat("d HH:mm"); public static MyButton obarvi_tlacitko(MyButton b,String stav) { if(stav.equals("OK")){ b.setStyle("-fx-background-color: rgba(96, 224, 16, 0.87);-fx-effect: dropshadow( gaussian , rgba(0,0,0,0.7) , 10,0,0,1 );"); } if(stav.equals("UP")){ b.setStyle("-fx-background-color: rgba(96, 224, 16, 0.87)"); } if(stav.equals("WARNING")){ b.setStyle("-fx-background-color: rgba(227, 210, 15, 0.87)"); //jede; HBox.setMargin(b, new Insets(3, 3, 3, 3)); } if(stav.equals("ERROR") || stav.equals("CRITICAL")){ b.setStyle("-fx-background-color: rgba(229, 88, 41, 0.87)"); } if(stav.equals("EMPTY")){ b.setStyle("-fx-background-color: rgba(229, 229, 229, 0.87)"); } return b; } //dodelat ofline variantu; private HBox obarvi(JSONObject data,WebView web) { String stav = data.getString("state"); String name = data.getString("name"); String path = data.getString("path"); String since="";String since1="";try{ Number since0=data.getNumber("since"); Timestamp timestamp1 = new Timestamp(since0.longValue()*1000); Timestamp timestamp2 = new Timestamp(System.currentTimeMillis()-since0.longValue()*1000); since = sdf3.format(timestamp1); since1 = sdf4.format(timestamp2); }catch(Exception e){ since="neni";}; String children="";try{children=data.getString("children");}catch(Exception e){ }; //String children = data.getString("children"); MyButton b,b12; b12 = new MyButton(); String replace = name.replace(":", "\n"); HBox hbox50 = new HBox(); //name = replace; //b.getAccessibleHelp(""+name + " " + since1 + "\n" + since); if(stav.equals("OK") || stav.equals("UP")){ b = new MyButton(replace + "\n "); b12 = new MyButton("ping"); b.setEffect(new Glow(0.4)); }else { b = new MyButton(replace + " " + since1 + "\n" + since); }//b.setText(popis); b.name = "88"; /* if(stav.equals("OK")){ b.setStyle("-fx-background-color: rgba(96, 224, 16, 0.87);-fx-effect: dropshadow( gaussian , rgba(0,0,0,0.7) , 10,0,0,1 );"); } if(stav.equals("UP")){ b.setStyle("-fx-background-color: rgba(96, 224, 16, 0.87)"); } if(stav.equals("WARNING")){ b.setStyle("-fx-background-color: rgba(227, 210, 15, 0.87)"); //jede; HBox.setMargin(b, new Insets(3, 3, 3, 3)); } */ obarvi_tlacitko(b,stav); if(stav.equals("ERROR") || stav.equals("CRITICAL")){ HBox.setMargin(b, new Insets(4, 4, 4, 4)); } //hbox1.getChildren().add(b); //Color c = new Color(255,255,0); hbox50.getChildren().add(b); //pomocne tlacitko pro ping; if(stav.equals("UP") || stav.equals("DOWN")) { b12.setStyle("-fx-background-color: rgba(41, 88, 229, 0.87)"); b12.setStyle("-fx-text-fill: rgba(55, 50, 229, 0.87)"); Scale scaleTransformation = new Scale(); scaleTransformation.setX(0.8); scaleTransformation.setY(0.8); scaleTransformation.setPivotX(0); scaleTransformation.setPivotY(0); b12.getTransforms().add(scaleTransformation); Translate translateTransform = new Translate(); translateTransform.setX(-20); translateTransform.setY(27); b12.getTransforms().add(translateTransform); hbox50.getChildren().add(b12); }; b12.setOnAction((event) -> { if(stav.equals("UP") || stav.equals("DOWN")) { PingExample(name); try { pi(name); } catch (IOException e) { e.printStackTrace(); } }; }); b.setOnAction((event) -> { System.out.println("Button04 clicked!"); if(stav.equals("UP") || stav.equals("DOWN")) { PingExample(name); try { pi(name); } catch (IOException e) { e.printStackTrace(); } }else{ final WebEngine webEngine1 = web.getEngine(); webEngine1.setJavaScriptEnabled(true); String url = "https://monitor.ics.muni.cz/icingaweb2/businessprocess/process/show?config=DCro&showCompact=1" + "&node=" + name.replace(' ', '_') + "&path=" + path.replace(' ', '_') //+"Prio_1_Services" + "&format=json"; webEngine1.load(url); textArea1.setWrapText(false); textArea1.setText(url); textArea1.setWrapText(true); webEngine1.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> { if (newState == Worker.State.SUCCEEDED) { doc = webEngine1.getDocument(); stage.setTitle(webEngine1.getLocation()); String docBody = doc.getElementsByTagName("body").item(0).getTextContent(); System.out.println(docBody); Gson g = new Gson(); if (docBody.charAt(0) == '{') { MyJson(docBody); } } }); //System.out.println(urls[5]); } }); return hbox50; } //radek tlacitek; class MyHbox extends HBox{ JSONArray ja_data; public MyHbox(JSONArray ja_data,HBox hbox1){ Integer length = ja_data.length(); hbox1.getChildren().clear(); hbox1.setSpacing(5); for (int i = 0; i < length; i++) { hbox1.getChildren().add( obarvi(ja_data.getJSONObject(i), web) ); } } } }