List of usage examples for javafx.scene.control ProgressBar ProgressBar
public ProgressBar(double progress)
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);//from w w w . j a v a 2s . co m final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);// w w w. j a v a 2 s. c o m final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Background Processes"); Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);//from ww w . j a v a 2 s . co m final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { final Label label = new Label("Progress:"); final ProgressBar progressBar = new ProgressBar(0); final ProgressIndicator progressIndicator = new ProgressIndicator(0); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final TextArea textArea = new TextArea(); startButton.setOnAction((ActionEvent event) -> { startButton.setDisable(true);/*from w w w.j a va 2 s .c om*/ progressBar.setProgress(0); progressIndicator.setProgress(0); textArea.setText(""); cancelButton.setDisable(false); copyWorker = createWorker(numFiles); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); progressIndicator.progressProperty().unbind(); progressIndicator.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener( (ObservableValue<? extends String> observable, String oldValue, String newValue) -> { textArea.appendText(newValue + "\n"); }); new Thread(copyWorker).start(); }); cancelButton.setOnAction((ActionEvent event) -> { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); progressIndicator.progressProperty().unbind(); progressIndicator.setProgress(0); textArea.appendText("File transfer was cancelled."); }); BorderPane root = new BorderPane(); Scene scene = new Scene(root, 500, 250, javafx.scene.paint.Color.WHITE); FlowPane topPane = new FlowPane(5, 5); topPane.setPadding(new Insets(5)); topPane.setAlignment(Pos.CENTER); topPane.getChildren().addAll(label, progressBar, progressIndicator); GridPane middlePane = new GridPane(); middlePane.setPadding(new Insets(5)); middlePane.setHgap(20); middlePane.setVgap(20); ColumnConstraints column1 = new ColumnConstraints(300, 400, Double.MAX_VALUE); middlePane.getColumnConstraints().addAll(column1); middlePane.setAlignment(Pos.CENTER); middlePane.add(textArea, 0, 0); FlowPane bottomPane = new FlowPane(5, 5); bottomPane.setPadding(new Insets(5)); bottomPane.setAlignment(Pos.CENTER); bottomPane.getChildren().addAll(startButton, cancelButton); root.setTop(topPane); root.setCenter(middlePane); root.setBottom(bottomPane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:eu.over9000.skadi.ui.dialogs.PerformUpdateDialog.java
public PerformUpdateDialog(RemoteVersionResult newVersion) { this.chosen = new SimpleObjectProperty<>( Paths.get(SystemUtils.USER_HOME, newVersion.getVersion() + ".jar").toFile()); this.setHeaderText("Updating to " + newVersion.getVersion()); this.setTitle("Skadi Updater"); this.getDialogPane().getStyleClass().add("alert"); this.getDialogPane().getStyleClass().add("information"); final ButtonType restartButtonType = new ButtonType("Start New Version", ButtonBar.ButtonData.OK_DONE); this.getDialogPane().getButtonTypes().addAll(restartButtonType, ButtonType.CANCEL); Node btn = this.getDialogPane().lookupButton(restartButtonType); btn.setDisable(true);//w w w . ja va2 s . c o m Label lbPath = new Label("Save as"); TextField tfPath = new TextField(); tfPath.textProperty() .bind(Bindings.createStringBinding(() -> this.chosen.get().getAbsolutePath(), this.chosen)); tfPath.setPrefColumnCount(40); tfPath.setEditable(false); Button btChangePath = GlyphsDude.createIconButton(FontAwesomeIcons.FOLDER_OPEN, "Browse..."); btChangePath.setOnAction(event -> { FileChooser fc = new FileChooser(); fc.setTitle("Save downloaded jar.."); fc.setInitialFileName(this.chosen.getValue().getName()); fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("Jar File", ".jar")); fc.setInitialDirectory(this.chosen.getValue().getParentFile()); File selected = fc.showSaveDialog(this.getOwner()); if (selected != null) { this.chosen.set(selected); } }); ProgressBar pbDownload = new ProgressBar(0); pbDownload.setDisable(true); pbDownload.setMaxWidth(Double.MAX_VALUE); Label lbDownload = new Label("Download"); Label lbDownloadValue = new Label(); Button btDownload = GlyphsDude.createIconButton(FontAwesomeIcons.DOWNLOAD, "Start"); btDownload.setMaxWidth(Double.MAX_VALUE); btDownload.setOnAction(event -> { btChangePath.setDisable(true); btDownload.setDisable(true); this.downloadService = new DownloadService(newVersion.getDownloadURL(), this.chosen.getValue()); lbDownloadValue.textProperty().bind(this.downloadService.messageProperty()); pbDownload.progressProperty().bind(this.downloadService.progressProperty()); this.downloadService.setOnSucceeded(dlEvent -> { btn.setDisable(false); }); this.downloadService.setOnFailed(dlFailed -> { LOGGER.error("new version download failed", dlFailed.getSource().getException()); lbDownloadValue.textProperty().unbind(); lbDownloadValue.setText("Download failed, check log file for details."); }); this.downloadService.start(); }); final GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.add(lbPath, 0, 0); grid.add(tfPath, 1, 0); grid.add(btChangePath, 2, 0); grid.add(new Separator(), 0, 1, 3, 1); grid.add(lbDownload, 0, 2); grid.add(pbDownload, 1, 2); grid.add(btDownload, 2, 2); grid.add(lbDownloadValue, 1, 3); this.getDialogPane().setContent(grid); this.setResultConverter(btnType -> { if (btnType == restartButtonType) { return this.chosen.getValue(); } if (btnType == ButtonType.CANCEL) { if (this.downloadService.isRunning()) { this.downloadService.cancel(); } } return null; }); }
From source file:fx.DownloadFxApp.java
public void createScene(Stage stage) { try {//from ww w.ja va2s . c o m stage.setTitle("Downloading JDK " + version + "..."); instance.set(this); appStartedLatch.countDown(); final SimpleBrowser browser = SimpleBrowser.newBuilder().useFirebug(false).useJQuery(true) .createWebView(!miniMode).build(); final ProgressBar progressBar = new ProgressBar(0); final Label progressLabel = new Label("Retrieving a link..."); VBox vBox = VBoxBuilder.create().children(progressLabel, progressBar, browser).fillWidth(true).build(); Scene scene = new Scene(vBox); stage.setScene(scene); if (miniMode) { stage.setWidth(300); } else { stage.setWidth(1024); stage.setHeight(768); } stage.show(); VBox.setVgrow(browser, Priority.ALWAYS); /** The sequence of calls location changed to: http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html? location changed to: http://download.oracle.com/otn/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz location changed to: https://edelivery.oracle.com/akam/otn/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz location changed to: https://login.oracle.com/pls/orasso/orasso.wwsso_app_admin.ls_login?Site2pstoreToken=v1.2~CA55CD32~750C6EFBC9B3CB198B2ADFE87BDD4DEB60E0218858C8BFE85DCCC65865D0E810E845839B422974847E1D489D3AF25FDC9574400197F9190C389876C1EC683A6006A06F7F05D41C94455B8354559F5699F5D0EF102F26FE905E77D40487455F7829501E3A783E1354EB0B8F05B828D0FC3BA22C62D3576883850E0B99849309B0C26F286E5650F63E9C6A7C376165C9A3EED86BF2FA0FAEE3D1F7F2957F5FBD5035AF0A3522E534141FE38DFDD55C4F7F517F9E81336C993BB76512C0D30A5B5C5FD82ED1C10E9D27284B6B1633E4B7B9FA5C2E38D9C5E3845C18C009E294E881FD8B654B67050958E57F0DC20885D6FA87A59FAA7564F94F location changed to: https://login.oracle.com/mysso/signon.jsp location changed to: https://login.oracle.com/oam/server/sso/auth_cred_submit location changed to: https://edelivery.oracle.com/osso_login_success?urlc=v1.2%7E30E69346FE17F27D4F83121B0B8EC362E0B315901364AAA7D6F0B7A05CD8AA31802F5A69D70C708F34C64B65D233922B57D3C31839E82CE78E5C8DA55D729DD339893285D21A8E8B1AE8557C9240D6E33C9965956E136F4CB093779F97AF67C3DB8FF19FF2A638296BD0AA81A7801904AC5607F0568B6CEAF7ED9FCE4B7BEA80071617E4B2779F60F0C76A89F7D195965D2F003F9EDD2A1ADFD264C1C4C7F921010B08D3846CEC9524237A9337B6B0BC433BB17993A670B6C913EB4CFDC217A753F9E2943DE0CBDC41D4705AC67C2B96A4892C65F5450B146939B0EBFDF098680BBBE1F13356460C95A23D8D198D1C6762E45E62F120E32C2549E6263071DA84F8321370D2410CCA93E9A071A02ED6EB40BF40EDFC6F65AC7BA73CDB06DF4265455419D9185A6256FFE41A7FF54042374D09F5C720F3104B2EAC924778482D4BE855A45B2636CE91C7D947FF1F764674CE0E42FFCCFE411AABFE07EA0E96838AFEA263D2D5A405BD location changed to: https://edelivery.oracle.com/akam/otn/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz location changed to: http://download.oracle.com/otn/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz?AuthParam=1390405890_f9186a44471784229268632878dd89e4 */ browser.getEngine().locationProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observableValue, String oldLoc, final String uri) { logger.info("change: {}", uri); if (uri.contains("signon.jsp")) { browser.getEngine().executeScript( "" + "alert(document);\n" + "alert(document.getElementById('sso_username'));\n"); new Thread("signon.jsp waiter") { @Override public void run() { setStatus("waiting for the login form..."); try { Thread.sleep(1000); } catch (InterruptedException e) { throw Exceptions.runtime(e); } browser.waitFor("$('#sso_username').length > 0", 10000); System.out.println("I see it all, I see it now!"); Platform.runLater(new Runnable() { @Override public void run() { browser.getEngine().executeScript("" + "alert(document.getElementById('sso_username'));\n" + "alert($('#sso_username').val('" + oracleUser + "'));\n" + "alert($('#ssopassword').val('" + oraclePassword + "'));\n" + downloadJDKJs() + "\n" + "clickIt($('.sf-btnarea a'))"); } }); } }.start(); } if (uri.contains("download.oracle") && uri.contains("?")) { // will be here after // clicking accept license and link -> * not logged in * -> here -> download -> redirect to login // download -> fill form -> * logged in * -> here -> download Thread thread = new Thread(new Runnable() { @Override public void run() { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httppost = new HttpGet(uri); HttpResponse response = httpClient.execute(httppost); int code = response.getStatusLine().getStatusCode(); if (code != 200) { System.out.println(IOUtils.toString(response.getEntity().getContent())); throw new RuntimeException("failed to download: " + uri); } final File file = new File(tempDestDir, StringUtils.substringBefore(FilenameUtils.getName(uri), "?")); HttpEntity entity = response.getEntity(); final long length = entity.getContentLength(); final CountingOutputStream os = new CountingOutputStream( new FileOutputStream(file)); System.out.printf("Downloading %s to %s...%n", uri, file); Thread progressThread = new Thread(new Runnable() { double lastProgress; @Override public void run() { while (!Thread.currentThread().isInterrupted()) { long copied = os.getCount(); double progress = copied * 100D / length; if (progress != lastProgress) { final String s = String.format("%s: %s/%s %s%%", file.getName(), FileUtils.humanReadableByteCount(copied, false, false), FileUtils.humanReadableByteCount(length, false, true), LangUtils.toConciseString(progress, 1)); setStatus(s); System.out.print("\r" + s); } lastProgress = progress; progressBar.setProgress(copied * 1D / length); // progressProp.set(progress); try { Thread.sleep(500); } catch (InterruptedException e) { break; } } } }, "progressThread"); progressThread.start(); ByteStreams.copy(entity.getContent(), os); progressThread.interrupt(); System.out.println("Download complete."); downloadResult.set(new DownloadResult(file, "", true)); downloadLatch.countDown(); } catch (Exception e) { LoggerFactory.getLogger("log").warn("", e); downloadResult.set(new DownloadResult(null, e.getMessage(), false)); throw Exceptions.runtime(e); } } }, "fx-downloader"); thread.start(); } } public void setStatus(final String s) { Platform.runLater(new Runnable() { @Override public void run() { progressLabel.setText(s); } }); } }); // links from http://www.oracle.com/technetwork/java/archive-139210.html Map<Integer, String> archiveLinksMap = new HashMap<Integer, String>(); archiveLinksMap.put(5, "http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html"); archiveLinksMap.put(6, "http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html"); archiveLinksMap.put(7, "http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html"); Map<Integer, String> latestLinksMap = new HashMap<Integer, String>(); latestLinksMap.put(7, "http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html"); String archiveUrl = null; String latestUrl = null; char ch = version.charAt(0); switch (ch) { case '7': case '6': case '5': latestUrl = latestLinksMap.get(ch - '0'); archiveUrl = archiveLinksMap.get(ch - '0'); break; default: archiveUrl = null; } if (latestUrl != null) { final String finalArchiveUrl = archiveUrl; tryFind(browser, latestUrl, new WhenDone() { @Override public void whenDone(boolean found) { tryArchiveLink(found, finalArchiveUrl, browser); } }); } else { tryArchiveLink(false, archiveUrl, browser); } } catch (Exception e) { e.printStackTrace(); } }
From source file:bear.fx.DownloadFxApp.java
public void createScene(Stage stage) { try {/*from www. ja v a 2s . c o m*/ stage.setTitle("Downloading JDK " + version + "..."); instance.set(this); appStartedLatch.countDown(); final SimpleBrowser browser = SimpleBrowser.newBuilder().useFirebug(false).useJQuery(true) .createWebView(!miniMode).build(); final ProgressBar progressBar = new ProgressBar(0); final Label progressLabel = new Label("Retrieving a link..."); VBox vBox = VBoxBuilder.create().children(progressLabel, progressBar, browser).fillWidth(true).build(); Scene scene = new Scene(vBox); stage.setScene(scene); if (miniMode) { stage.setWidth(300); } else { stage.setWidth(1024); stage.setHeight(768); } stage.show(); VBox.setVgrow(browser, Priority.ALWAYS); /** * location changed to: http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html? location changed to: http://download.oracle.com/otn/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz location changed to: https://edelivery.oracle.com/akam/otn/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz location changed to: https://login.oracle.com/pls/orasso/orasso.wwsso_app_admin.ls_login?Site2pstoreToken=v1.2~CA55CD32~750C6EFBC9B3CB198B2ADFE87BDD4DEB60E0218858C8BFE85DCCC65865D0E810E845839B422974847E1D489D3AF25FDC9574400197F9190C389876C1EC683A6006A06F7F05D41C94455B8354559F5699F5D0EF102F26FE905E77D40487455F7829501E3A783E1354EB0B8F05B828D0FC3BA22C62D3576883850E0B99849309B0C26F286E5650F63E9C6A7C376165C9A3EED86BF2FA0FAEE3D1F7F2957F5FBD5035AF0A3522E534141FE38DFDD55C4F7F517F9E81336C993BB76512C0D30A5B5C5FD82ED1C10E9D27284B6B1633E4B7B9FA5C2E38D9C5E3845C18C009E294E881FD8B654B67050958E57F0DC20885D6FA87A59FAA7564F94F location changed to: https://login.oracle.com/mysso/signon.jsp location changed to: https://login.oracle.com/oam/server/sso/auth_cred_submit location changed to: https://edelivery.oracle.com/osso_login_success?urlc=v1.2%7E30E69346FE17F27D4F83121B0B8EC362E0B315901364AAA7D6F0B7A05CD8AA31802F5A69D70C708F34C64B65D233922B57D3C31839E82CE78E5C8DA55D729DD339893285D21A8E8B1AE8557C9240D6E33C9965956E136F4CB093779F97AF67C3DB8FF19FF2A638296BD0AA81A7801904AC5607F0568B6CEAF7ED9FCE4B7BEA80071617E4B2779F60F0C76A89F7D195965D2F003F9EDD2A1ADFD264C1C4C7F921010B08D3846CEC9524237A9337B6B0BC433BB17993A670B6C913EB4CFDC217A753F9E2943DE0CBDC41D4705AC67C2B96A4892C65F5450B146939B0EBFDF098680BBBE1F13356460C95A23D8D198D1C6762E45E62F120E32C2549E6263071DA84F8321370D2410CCA93E9A071A02ED6EB40BF40EDFC6F65AC7BA73CDB06DF4265455419D9185A6256FFE41A7FF54042374D09F5C720F3104B2EAC924778482D4BE855A45B2636CE91C7D947FF1F764674CE0E42FFCCFE411AABFE07EA0E96838AFEA263D2D5A405BD location changed to: https://edelivery.oracle.com/akam/otn/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz location changed to: http://download.oracle.com/otn/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz?AuthParam=1390405890_f9186a44471784229268632878dd89e4 */ browser.getEngine().locationProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observableValue, String oldLoc, final String uri) { logger.info("change: {}", uri); if (uri.contains("signon.jsp")) { browser.getEngine().executeScript( "" + "alert(document);\n" + "alert(document.getElementById('sso_username'));\n"); new Thread("signon.jsp waiter") { @Override public void run() { setStatus("waiting for the login form..."); try { Thread.sleep(1000); } catch (InterruptedException e) { throw Exceptions.runtime(e); } browser.waitFor("$('#sso_username').length > 0", 10000); System.out.println("I see it all, I see it now!"); Platform.runLater(new Runnable() { @Override public void run() { browser.getEngine().executeScript("" + "alert(document.getElementById('sso_username'));\n" + "alert($('#sso_username').val('" + oracleUser + "'));\n" + "alert($('#ssopassword').val('" + oraclePassword + "'));\n" + downloadJDKJs() + "\n" + "clickIt($('.sf-btnarea a'))"); } }); } }.start(); } if (uri.contains("download.oracle") && uri.contains("?")) { //will be here after // clicking accept license and link -> * not logged in * -> here -> download -> redirect to login // download -> fill form -> * logged in * -> here -> download Thread thread = new Thread(new Runnable() { @Override public void run() { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httppost = new HttpGet(uri); HttpResponse response = httpClient.execute(httppost); int code = response.getStatusLine().getStatusCode(); if (code != 200) { System.out.println(IOUtils.toString(response.getEntity().getContent())); throw new RuntimeException("failed to download: " + uri); } final File file = new File(tempDestDir, StringUtils.substringBefore(FilenameUtils.getName(uri), "?")); HttpEntity entity = response.getEntity(); final long length = entity.getContentLength(); final CountingOutputStream os = new CountingOutputStream( new FileOutputStream(file)); System.out.printf("Downloading %s to %s...%n", uri, file); Thread progressThread = new Thread(new Runnable() { double lastProgress; @Override public void run() { while (!Thread.currentThread().isInterrupted()) { long copied = os.getCount(); double progress = copied * 100D / length; if (progress != lastProgress) { final String s = String.format("%s: %s/%s %s%%", file.getName(), FileUtils.humanReadableByteCount(copied, false, false), FileUtils.humanReadableByteCount(length, false, true), LangUtils.toConciseString(progress, 1)); setStatus(s); System.out.print("\r" + s); } lastProgress = progress; progressBar.setProgress(copied * 1D / length); // progressProp.set(progress); try { Thread.sleep(500); } catch (InterruptedException e) { break; } } } }, "progressThread"); progressThread.start(); ByteStreams.copy(entity.getContent(), os); progressThread.interrupt(); System.out.println("Download complete."); downloadResult.set(new DownloadResult(file, "", true)); downloadLatch.countDown(); } catch (Exception e) { LoggerFactory.getLogger("log").warn("", e); downloadResult.set(new DownloadResult(null, e.getMessage(), false)); throw Exceptions.runtime(e); } } }, "fx-downloader"); thread.start(); } } public void setStatus(final String s) { Platform.runLater(new Runnable() { @Override public void run() { progressLabel.setText(s); } }); } }); // links from http://www.oracle.com/technetwork/java/archive-139210.html Map<Integer, String> archiveLinksMap = new HashMap<Integer, String>(); archiveLinksMap.put(5, "http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html"); archiveLinksMap.put(6, "http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html"); archiveLinksMap.put(7, "http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html"); Map<Integer, String> latestLinksMap = new HashMap<Integer, String>(); latestLinksMap.put(7, "http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html"); String archiveUrl = null; String latestUrl = null; char ch = version.charAt(0); switch (ch) { case '7': case '6': case '5': latestUrl = latestLinksMap.get(ch - '0'); archiveUrl = archiveLinksMap.get(ch - '0'); break; default: archiveUrl = null; } if (latestUrl != null) { final String finalArchiveUrl = archiveUrl; tryFind(browser, latestUrl, new WhenDone() { @Override public void whenDone(boolean found) { tryArchiveLink(found, finalArchiveUrl, browser); } }); } else { tryArchiveLink(false, archiveUrl, browser); } } catch (Exception e) { e.printStackTrace(); } }
From source file:gov.va.isaac.sync.view.SyncView.java
private void initGui() { root_ = new BorderPane(); root_.setPrefWidth(550);// www .j a va2 s . c o m VBox titleBox = new VBox(); Label title = new Label("Datastore Synchronization"); title.getStyleClass().add("titleLabel"); title.setAlignment(Pos.CENTER); title.setMaxWidth(Double.MAX_VALUE); title.setPadding(new Insets(10)); titleBox.getChildren().add(title); titleBox.getStyleClass().add("headerBackground"); url_ = AppContext.getAppConfiguration().getCurrentChangeSetUrl(); String urlType = AppContext.getAppConfiguration().getChangeSetUrlTypeName(); String syncUsername = ExtendedAppContext.getCurrentlyLoggedInUserProfile().getSyncUsername(); if (StringUtils.isBlank(syncUsername)) { syncUsername = ExtendedAppContext.getCurrentlyLoggedInUser(); } url_ = syncService_.substituteURL(url_, syncUsername); Label info = new CopyableLabel("Sync using " + urlType + ": " + url_); info.setTooltip(new Tooltip(url_)); titleBox.getChildren().add(info); titleBox.setPadding(new Insets(5, 5, 5, 5)); root_.setTop(titleBox); VBox centerContent = new VBox(); centerContent.setFillWidth(true); centerContent.setPrefWidth(Double.MAX_VALUE); centerContent.setPadding(new Insets(10)); centerContent.getStyleClass().add("itemBorder"); centerContent.setSpacing(10.0); centerContent.getChildren().add(new Label("Status:")); summary_ = new TextArea(); summary_.setWrapText(true); summary_.setEditable(false); summary_.setMaxWidth(Double.MAX_VALUE); summary_.setMaxHeight(Double.MAX_VALUE); summary_.setPrefHeight(150.0); centerContent.getChildren().add(summary_); VBox.setVgrow(summary_, Priority.ALWAYS); pb_ = new ProgressBar(0.0); pb_.setPrefHeight(20); pb_.setMaxWidth(Double.MAX_VALUE); centerContent.getChildren().add(pb_); root_.setCenter(centerContent); //Bottom buttons HBox buttons = new HBox(); buttons.setMaxWidth(Double.MAX_VALUE); buttons.setAlignment(Pos.CENTER); buttons.setPadding(new Insets(5)); buttons.setSpacing(30); Button cancel = new Button("Close"); cancel.setOnAction((action) -> { if (running_.get()) { addLine("Cancelling..."); cancel.setDisable(true); cancelRequested_ = true; } else { cancel.getScene().getWindow().hide(); root_ = null; } }); buttons.getChildren().add(cancel); Button action = new Button("Synchronize"); action.disableProperty().bind(running_); action.setOnAction((theAction) -> { summary_.setText(""); pb_.setProgress(-1.0); running_.set(true); Utility.execute(() -> sync()); }); buttons.getChildren().add(action); cancel.minWidthProperty().bind(action.widthProperty()); running_.addListener(change -> { if (running_.get()) { cancel.setText("Cancel"); } else { cancel.setText("Close"); } cancel.setDisable(false); }); root_.setBottom(buttons); }
From source file:uk.co.everywheremusic.viewcontroller.SetupScene.java
private void startSetupWindow(Stage primaryStage) { try {/*from www .j a v a 2 s . c om*/ installFolder = new File(".").getCanonicalPath() + Globals.INSTALL_EXT; } catch (IOException ex) { Logger.getLogger(SetupScene.class.getName()).log(Level.SEVERE, null, ex); installFolder = System.getProperty("user.dir") + Globals.INSTALL_EXT; } primaryStage.setTitle(Globals.APP_NAME); grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); column1 = new ColumnConstraints(100, 100, Double.MAX_VALUE); column1.setHgrow(Priority.ALWAYS); column2 = new ColumnConstraints(100, 100, Double.MAX_VALUE); column2.setHgrow(Priority.ALWAYS); column3 = new ColumnConstraints(100, 100, Double.MAX_VALUE); column3.setHgrow(Priority.ALWAYS); column4 = new ColumnConstraints(100, 100, Double.MAX_VALUE); column4.setHgrow(Priority.ALWAYS); grid.getColumnConstraints().addAll(column1, column2, column3, column4); sceneTitle = new Label(Globals.SETUP_FRAME_TITLE); sceneTitle.setId(Globals.CSS_TITLE_ID); sceneTitle.setPrefWidth(Double.MAX_VALUE); sceneTitle.setAlignment(Pos.CENTER); ImageView imageView = null; try { imageView = new ImageView(); String img = new File(Globals.IC_LOGO).toURI().toURL().toString(); imgLogo = new Image(img); imageView.setImage(imgLogo); } catch (MalformedURLException ex) { Logger.getLogger(ServerScene.class.getName()).log(Level.SEVERE, null, ex); } GridPane titlePane = new GridPane(); ColumnConstraints c1 = new ColumnConstraints(50); ColumnConstraints c2 = new ColumnConstraints(400); titlePane.getColumnConstraints().addAll(c1, c2); titlePane.add(imageView, 0, 0); titlePane.add(sceneTitle, 1, 0); titlePane.setAlignment(Pos.CENTER); grid.add(titlePane, 0, 0, 4, 1); lblFolder = new Label(Globals.SETUP_LBL_MUSIC_FOLDER); grid.add(lblFolder, 0, 2, 3, 1); txtFolder = new TextField(); txtFolder.setText("/home/kyle/Music/Test music"); grid.add(txtFolder, 0, 3, 3, 1); btnFolder = new Button(Globals.SETUP_BTN_MUSIC_FOLDER); btnFolder.setPrefWidth(Double.MAX_VALUE); grid.add(btnFolder, 3, 3); final DirectoryChooser dirChooser = new DirectoryChooser(); btnFolder.setOnAction((ActionEvent event) -> { File dir = dirChooser.showDialog(primaryStage); if (dir != null) { txtFolder.setText(dir.getAbsolutePath()); } }); lblPassword = new Label("Choose a password:"); grid.add(lblPassword, 0, 4, 2, 1); lblConfirmPassword = new Label("Confirm your password:"); grid.add(lblConfirmPassword, 2, 4, 2, 1); txtPassword = new PasswordField(); grid.add(txtPassword, 0, 5, 2, 1); txtConfirmPassword = new PasswordField(); grid.add(txtConfirmPassword, 2, 5, 1, 1); textArea = new TextArea(); textArea.setPrefHeight(Double.MAX_VALUE); textArea.setDisable(true); textArea.setWrapText(true); grid.add(textArea, 0, 7, 4, 2); StackPane progressPane = new StackPane(); lblProgress = new Label(Globals.SETUP_LBL_PERCENT); lblProgress.setId(Globals.CSS_PROGBAR_LBL_ID); lblProgress.setVisible(false); progressBar = new ProgressBar(0); progressBar.setPrefWidth(Double.MAX_VALUE); progressBar.setVisible(false); progressPane.getChildren().addAll(progressBar, lblProgress); progressPane.setAlignment(Pos.CENTER_RIGHT); grid.add(progressPane, 0, 11, 3, 1); StackPane buttonPane = new StackPane(); btnInstall = new Button(Globals.SETUP_BTN_INSTALL); btnInstall.setPrefWidth(Double.MAX_VALUE); btnDone = new Button(Globals.SETUP_BTN_DONE); btnDone.setPrefWidth(Double.MAX_VALUE); btnDone.setVisible(false); buttonPane.getChildren().addAll(btnInstall, btnDone); grid.add(buttonPane, 3, 11); btnInstall.setOnAction((ActionEvent event) -> { boolean valid = validateForm(); if (valid) { lblFolder.setDisable(true); txtFolder.setDisable(true); btnFolder.setDisable(true); lblPassword.setDisable(true); txtPassword.setDisable(true); lblConfirmPassword.setDisable(true); txtConfirmPassword.setDisable(true); textArea.setDisable(false); lblProgress.setVisible(true); progressBar.setVisible(true); btnInstall.setDisable(true); musicFolder = txtFolder.getText(); password = txtPassword.getText(); setupWorker = createSetupWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(setupWorker.progressProperty()); setupWorker.messageProperty().addListener( (ObservableValue<? extends String> observable, String oldValue, String newValue) -> { String[] values = newValue.split("\\|"); lblProgress.setText(values[0] + "%"); textArea.appendText(values[1] + "\n"); if (values[1].equals(Globals.SETUP_MSG_DONE)) { btnInstall.setVisible(false); btnDone.setVisible(true); } }); new Thread(setupWorker).start(); } }); btnDone.setOnAction((ActionEvent event) -> { primaryStage.hide(); new ServerScene(installFolder, musicFolder).showWindow(new Stage()); }); try { String imgUrl = new File(Globals.IC_LOGO).toURI().toURL().toString(); javafx.scene.image.Image i = new javafx.scene.image.Image(imgUrl); primaryStage.getIcons().add(i); } catch (MalformedURLException ex) { Logger.getLogger(ServerScene.class.getName()).log(Level.SEVERE, null, ex); } scene = new Scene(grid, 600, 400); primaryStage.setScene(scene); scene.getStylesheets().add(SetupScene.class.getResource(Globals.CSS_FILE).toExternalForm()); // grid.setGridLinesVisible(true); primaryStage.show(); }