public static EventHandler<ActionEvent> getBrowseHandler( FXController controller, TextField filePath) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Select a file to upload..."); return e -> { if (AESCTR.secretKey == null) { new Alert(Alert.AlertType.INFORMATION, "Please generate or choose a key", ButtonType.OK) .showAndWait(); return; } selectedFiles = fileChooser.showOpenMultipleDialog(null); if (selectedFiles != null) { controller.writeLog("Selected files: "); StringBuilder sb = new StringBuilder(1024); for (int i = 0; i < selectedFiles.size(); i++) { if (i == selectedFiles.size() - 1) { sb.append(selectedFiles.get(i).getAbsolutePath()); } else { sb.append(selectedFiles.get(i).getAbsolutePath() + ", "); } controller.writeLog(selectedFiles.get(i).getName()); } filePath.setText(sb.toString()); } }; }
public String orderArrayToString() { StringBuilder orderString = new StringBuilder(); int i = 1; for (Order order : myOrders) { orderString.append(String.format("%d. %s\n", i++, order.toString())); } return orderString.toString(); }
public static void showError(String message, Throwable t) { LOG.log(Level.SEVERE, "Сообщение: " + message, t); StringBuilder s = new StringBuilder(message).append('\n'); s.append(t.getClass().getName()).append(": ").append(t.getLocalizedMessage()); for (StackTraceElement e : t.getStackTrace()) { String line = e.toString(); if (line.startsWith("my")) { s.append("\n ").append(line); } } Alert alert = new Alert(Alert.AlertType.ERROR, s.toString(), ButtonType.OK); alert.showAndWait(); }
public static String generateCommand(Tile node) { String packageString = node.data.get("package").replace(".", "/") + "/"; String flags = node.data.get("flags"); if (packageString == null) { return null; } StringBuilder cmd = new StringBuilder(); cmd.append("jar cf"); if (flags != null) { cmd.append(flags); } cmd.append(" "); cmd.append(node.data.get("jarname")).append(" "); cmd.append(packageString); return cmd.toString().trim(); }
public void finishOrder(ActionEvent actionEvent) { StringBuilder orderString = new StringBuilder(); // create new alert Alert alert = new Alert(Alert.AlertType.INFORMATION, "", ButtonType.OK); // get date Date date = new Date(); DateFormat format1 = new SimpleDateFormat("MM/dd/yy hh:mm:ss a z"); DateFormat format2 = new SimpleDateFormat("yyMMddhhmmss"); orderString.append( String.format( "%s\n\nNumber of line items:%d\n\nItem#/ID/Title/Price/Qty/Disc%%/Subtotal:\n\n%s\n\nOrder Subtotal:$%.2f\n\n" + "Tax Rate:\t6%%\n\nTax Amount:$%.2f\n\nOrder Total:$%.2f\n\nThanks for shopping!", format1.format(date), myOrders.size(), orderArrayToString(), Order.getRunningTotal(), Order.getRunningTotal() * .06, Order.getRunningTotal() + Order.getRunningTotal() * .06)); // print order array // print subtotal // print 6% tax // add tax and generate new total // show alert // call new order alert.setHeaderText("Order Receipt"); alert.setResizable(true); alert.getDialogPane().setPrefWidth(alert.getDialogPane().getWidth() * 2); alert.setContentText(orderString.toString()); alert.show(); // output transactions.txt OpenOption[] options = { StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND }; Path file = Paths.get("transaction.txt"); try { BufferedWriter writer = Files.newBufferedWriter(file, Charset.defaultCharset(), options); int i = 0; for (Order order : myOrders) { // String[] strArray = order.toString().split(" "); // System.out.println(strArray[0] + strArray[1]); writer.write( String.format( "%s, %s, %s, %s, %s, %s, %s, %s\n", format2.format(date), order.getOrderedBook().getBookID(), order.getOrderedBook().getBookTitle(), order.getOrderedBook().getPrice(), order.getQuantity(), order.getDiscount(), order.getFinalPrice(), format1.format(date))); } writer.close(); } catch (IOException e) { System.out.println("OOPS"); e.printStackTrace(); } newOrder(new ActionEvent()); }