wallettemplate.utils.GuiUtils Java Examples

The following examples show how to use wallettemplate.utils.GuiUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
/** Loads the FXML file with the given name, blurs out the main UI and puts this one on top. */
public <T> OverlayUI<T> overlayUI(String name) {
    try {
        checkGuiThread();
        // Load the UI from disk.
        URL location = GuiUtils.getResource(name);
        FXMLLoader loader = new FXMLLoader(location);
        Pane ui = loader.load();
        T controller = loader.getController();
        OverlayUI<T> pair = new OverlayUI<T>(ui, controller);
        // Auto-magically set the overlayUI member, if it's there.
        try {
            if (controller != null)
                controller.getClass().getField("overlayUI").set(controller, pair);
        } catch (IllegalAccessException | NoSuchFieldException ignored) {
            ignored.printStackTrace();
        }
        pair.show();
        return pair;
    } catch (IOException e) {
        throw new RuntimeException(e);  // Can't happen.
    }
}
 
Example #2
Source File: SendMoneyController.java    From thunder with GNU Affero General Public License v3.0 6 votes vote down vote up
public void send (ActionEvent event) {

        ByteBuffer byteBuffer = ByteBuffer.wrap(Tools.hexStringToByteArray(address.getText()));

        amount = byteBuffer.getLong();
        byteBuffer.get(hash);
        byteBuffer.get(destination);

        Main.thunderContext.makePayment(destination, amount, new PaymentSecret(null, hash), result -> {
            if (!result.wasSuccessful()) {
                GuiUtils.informationalAlert("Error", result.getMessage(), null);
            }
        });

        overlayUI.done();

    }
 
Example #3
Source File: Main.java    From thunder with GNU Affero General Public License v3.0 6 votes vote down vote up
private void prepareUI (Stage mainWindow) throws IOException {
    this.mainWindow = mainWindow;
    // Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
    GuiUtils.handleCrashesOnThisThread();

    // Load the GUI. The MainController class will be automagically created and wired up.
    File file = new File("main.fxml");
    URL location = getClass().getResource("main.fxml");
    FXMLLoader loader = new FXMLLoader(location);
    mainUI = loader.load();
    controller = loader.getController();
    // Configure the window with a StackPane so we can overlay things on top of the main UI, and a
    // NotificationBarPane so we can slide messages and progress bars in from the bottom. Note that
    // ordering of the construction and connection matters here, otherwise we get (harmless) CSS error
    // spew to the logs.
    notificationBar = new NotificationBarPane(mainUI);
    mainWindow.setTitle(APP_NAME);
    uiStack = new StackPane();
    Scene scene = new Scene(uiStack);
    TextFieldValidator.configureScene(scene);   // Add CSS that we need.
    scene.getStylesheets().add(getClass().getResource("wallet.css").toString());
    uiStack.getChildren().add(notificationBar);
    mainWindow.setScene(scene);
}
 
Example #4
Source File: Main.java    From thunder with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Loads the FXML file with the given name, blurs out the main UI and puts this one on top.
 */
public <T> OverlayUI<T> overlayUI (String name) {
    try {
        checkGuiThread();
        // Load the UI from disk.
        URL location = GuiUtils.getResource(name);
        FXMLLoader loader = new FXMLLoader(location);
        Pane ui = loader.load();
        T controller = loader.getController();
        OverlayUI<T> pair = new OverlayUI<T>(ui, controller);
        // Auto-magically set the overlayUI member, if it's there.
        try {
            if (controller != null) {
                controller.getClass().getField("overlayUI").set(controller, pair);
            }
        } catch (IllegalAccessException | NoSuchFieldException ignored) {
            ignored.printStackTrace();
        }
        pair.show();
        return pair;
    } catch (IOException e) {
        throw new RuntimeException(e);  // Can't happen.
    }
}
 
Example #5
Source File: Main.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
/** Loads the FXML file with the given name, blurs out the main UI and puts this one on top. */
public <T> OverlayUI<T> overlayUI(String name) {
    try {
        checkGuiThread();
        // Load the UI from disk.
        URL location = GuiUtils.getResource(name);
        FXMLLoader loader = new FXMLLoader(location);
        Pane ui = loader.load();
        T controller = loader.getController();
        OverlayUI<T> pair = new OverlayUI<T>(ui, controller);
        // Auto-magically set the overlayUI member, if it's there.
        try {
            if (controller != null)
                controller.getClass().getField("overlayUI").set(controller, pair);
        } catch (IllegalAccessException | NoSuchFieldException ignored) {
            ignored.printStackTrace();
        }
        pair.show();
        return pair;
    } catch (IOException e) {
        throw new RuntimeException(e);  // Can't happen.
    }
}
 
Example #6
Source File: Main.java    From thundernetwork with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Loads the FXML file with the given name, blurs out the main UI and puts this one on top.
 */
public <T> OverlayUI<T> overlayUI (String name) {
    try {
        checkGuiThread();
        // Load the UI from disk.
        URL location = GuiUtils.getResource(name);
        FXMLLoader loader = new FXMLLoader(location);
        Pane ui = loader.load();
        T controller = loader.getController();
        OverlayUI<T> pair = new OverlayUI<T>(ui, controller);
        // Auto-magically set the overlayUI member, if it's there.
        try {
            if (controller != null) {
                controller.getClass().getField("overlayUI").set(controller, pair);
            }
        } catch (IllegalAccessException | NoSuchFieldException ignored) {
            ignored.printStackTrace();
        }
        pair.show();
        return pair;
    } catch (IOException e) {
        throw new RuntimeException(e);  // Can't happen.
    }
}
 
Example #7
Source File: Main.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage mainWindow) throws Exception {
    try {
        realStart(mainWindow);
    } catch (Throwable e) {
        GuiUtils.crashAlert(e);
        throw e;
    }
}
 
Example #8
Source File: ClickableBitcoinAddress.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@FXML
protected void requestMoney(MouseEvent event) {
    if (event.getButton() == MouseButton.SECONDARY || (event.getButton() == MouseButton.PRIMARY && event.isMetaDown())) {
        // User right clicked or the Mac equivalent. Show the context menu.
        addressMenu.show(addressLabel, event.getScreenX(), event.getScreenY());
    } else {
        // User left clicked.
        try {
            Desktop.getDesktop().browse(URI.create(uri()));
        } catch (IOException e) {
            GuiUtils.informationalAlert("Opening wallet app failed", "Perhaps you don't have one installed?");
        }
    }
}
 
Example #9
Source File: Main.java    From thunder with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void start (Stage mainWindow) throws Exception {
    try {
        realStart(mainWindow);
    } catch (Throwable e) {
        GuiUtils.crashAlert(e);
        throw e;
    }
}
 
Example #10
Source File: Main.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage mainWindow) throws Exception {
    try {
        realStart(mainWindow);
    } catch (Throwable e) {
        GuiUtils.crashAlert(e);
        throw e;
    }
}
 
Example #11
Source File: ClickableBitcoinAddress.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@FXML
protected void requestMoney(MouseEvent event) {
    if (event.getButton() == MouseButton.SECONDARY || (event.getButton() == MouseButton.PRIMARY && event.isMetaDown())) {
        // User right clicked or the Mac equivalent. Show the context menu.
        addressMenu.show(addressLabel, event.getScreenX(), event.getScreenY());
    } else {
        // User left clicked.
        try {
            Desktop.getDesktop().browse(URI.create(uri()));
        } catch (IOException e) {
            GuiUtils.informationalAlert("Opening wallet app failed", "Perhaps you don't have one installed?");
        }
    }
}
 
Example #12
Source File: Main.java    From thundernetwork with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void start (Stage mainWindow) throws Exception {
    try {
        realStart(mainWindow);
    } catch (Throwable e) {
        GuiUtils.crashAlert(e);
        throw e;
    }
}
 
Example #13
Source File: Main.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
private void realStart(Stage mainWindow) throws IOException {
    this.mainWindow = mainWindow;
    instance = this;
    // Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
    GuiUtils.handleCrashesOnThisThread();

    if (System.getProperty("os.name").toLowerCase().contains("mac")) {
        // We could match the Mac Aqua style here, except that (a) Modena doesn't look that bad, and (b)
        // the date picker widget is kinda broken in AquaFx and I can't be bothered fixing it.
        // AquaFx.style();
    }

    // Load the GUI. The MainController class will be automagically created and wired up.
    URL location = getClass().getResource("main.fxml");
    FXMLLoader loader = new FXMLLoader(location);
    mainUI = loader.load();
    controller = loader.getController();
    // Configure the window with a StackPane so we can overlay things on top of the main UI, and a
    // NotificationBarPane so we can slide messages and progress bars in from the bottom. Note that
    // ordering of the construction and connection matters here, otherwise we get (harmless) CSS error
    // spew to the logs.
    notificationBar = new NotificationBarPane(mainUI);
    mainWindow.setTitle(APP_NAME);
    uiStack = new StackPane();
    Scene scene = new Scene(uiStack);
    TextFieldValidator.configureScene(scene);   // Add CSS that we need.
    scene.getStylesheets().add(getClass().getResource("wallet.css").toString());
    uiStack.getChildren().add(notificationBar);
    mainWindow.setScene(scene);

    // Make log output concise.
    BriefLogFormatter.init();
    // Tell bitcoinj to run event handlers on the JavaFX UI thread. This keeps things simple and means
    // we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
    // we give to the app kit is currently an exception and runs on a library thread. It'll get fixed in
    // a future version.
    Threading.USER_THREAD = Platform::runLater;
    // Create the app kit. It won't do any heavyweight initialization until after we start it.
    setupWalletKit(null);

    if (bitcoin.isChainFileLocked()) {
        informationalAlert("Already running", "This application is already running and cannot be started twice.");
        Platform.exit();
        return;
    }

    mainWindow.show();

    WalletSetPasswordController.estimateKeyDerivationTimeMsec();

    bitcoin.addListener(new Service.Listener() {
        @Override
        public void failed(Service.State from, Throwable failure) {
            GuiUtils.crashAlert(failure);
        }
    }, Platform::runLater);
    bitcoin.startAsync();

    scene.getAccelerators().put(KeyCombination.valueOf("Shortcut+F"), () -> bitcoin.peerGroup().getDownloadPeer().close());
}
 
Example #14
Source File: Main.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
private void realStart(Stage mainWindow) throws IOException {
    this.mainWindow = mainWindow;
    instance = this;
    // Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
    GuiUtils.handleCrashesOnThisThread();

    if (System.getProperty("os.name").toLowerCase().contains("mac")) {
        // We could match the Mac Aqua style here, except that (a) Modena doesn't look that bad, and (b)
        // the date picker widget is kinda broken in AquaFx and I can't be bothered fixing it.
        // AquaFx.style();
    }

    // Load the GUI. The MainController class will be automagically created and wired up.
    URL location = getClass().getResource("main.fxml");
    FXMLLoader loader = new FXMLLoader(location);
    mainUI = loader.load();
    controller = loader.getController();
    // Configure the window with a StackPane so we can overlay things on top of the main UI, and a
    // NotificationBarPane so we can slide messages and progress bars in from the bottom. Note that
    // ordering of the construction and connection matters here, otherwise we get (harmless) CSS error
    // spew to the logs.
    notificationBar = new NotificationBarPane(mainUI);
    mainWindow.setTitle(APP_NAME);
    uiStack = new StackPane();
    Scene scene = new Scene(uiStack);
    TextFieldValidator.configureScene(scene);   // Add CSS that we need.
    scene.getStylesheets().add(getClass().getResource("wallet.css").toString());
    uiStack.getChildren().add(notificationBar);
    mainWindow.setScene(scene);

    // Make log output concise.
    BriefLogFormatter.init();
    // Tell bitcoinj to run event handlers on the JavaFX UI thread. This keeps things simple and means
    // we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
    // we give to the app kit is currently an exception and runs on a library thread. It'll get fixed in
    // a future version.
    Threading.USER_THREAD = Platform::runLater;
    // Create the app kit. It won't do any heavyweight initialization until after we start it.
    setupWalletKit(null);

    if (bitcoin.isChainFileLocked()) {
        informationalAlert("Already running", "This application is already running and cannot be started twice.");
        Platform.exit();
        return;
    }

    mainWindow.show();

    WalletSetPasswordController.estimateKeyDerivationTimeMsec();

    bitcoin.addListener(new Service.Listener() {
        @Override
        public void failed(Service.State from, Throwable failure) {
            GuiUtils.crashAlert(failure);
        }
    }, Platform::runLater);
    bitcoin.startAsync();

    scene.getAccelerators().put(KeyCombination.valueOf("Shortcut+F"), () -> bitcoin.peerGroup().getDownloadPeer().close());
}
 
Example #15
Source File: Main.java    From thundernetwork with GNU Affero General Public License v3.0 4 votes vote down vote up
private void realStart (Stage mainWindow) throws IOException {
    this.mainWindow = mainWindow;
    instance = this;
    // Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
    GuiUtils.handleCrashesOnThisThread();

    // Load the GUI. The MainController class will be automagically created and wired up.
    File file = new File("main.fxml");
    URL location = getClass().getResource("main.fxml");
    FXMLLoader loader = new FXMLLoader(location);
    mainUI = loader.load();
    controller = loader.getController();
    // Configure the window with a StackPane so we can overlay things on top of the main UI, and a
    // NotificationBarPane so we can slide messages and progress bars in from the bottom. Note that
    // ordering of the construction and connection matters here, otherwise we get (harmless) CSS error
    // spew to the logs.
    notificationBar = new NotificationBarPane(mainUI);
    mainWindow.setTitle(APP_NAME);
    uiStack = new StackPane();
    Scene scene = new Scene(uiStack);
    TextFieldValidator.configureScene(scene);   // Add CSS that we need.
    scene.getStylesheets().add(getClass().getResource("wallet.css").toString());
    uiStack.getChildren().add(notificationBar);
    mainWindow.setScene(scene);

    // Make log output concise.
    BriefLogFormatter.init();
    // Tell bitcoinj to run event handlers on the JavaFX UI thread. This keeps things simple and means
    // we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
    // we give to the app kit is currently an exception and runs on a library thread. It'll get fixed in
    // a future version.
    Threading.USER_THREAD = Platform::runLater;
    // Create the app kit. It won't do any heavyweight initialization until after we start it.
    setupWalletKit(null);

    if (bitcoin.isChainFileLocked()) {
        if (REQUEST != null) {
            PaymentProtocolClientSocket.sendPaymentRequest(REQUEST);
            Platform.exit();
            return;
        }
        informationalAlert("Already running", "This application is already running and cannot be started twice.");
        Platform.exit();
        return;
    }
    PaymentProtocolServerSocket.init();

    mainWindow.show();

    WalletSetPasswordController.estimateKeyDerivationTimeMsec();

    bitcoin.addListener(new Service.Listener() {
        @Override
        public void failed (Service.State from, Throwable failure) {
            GuiUtils.crashAlert(failure);
        }
    }, Platform::runLater);
    bitcoin.startAsync();

    System.out.println("init");
    node.init();
    wallet = new MockWallet(Constants.getNetwork());
    thunderContext = new ThunderContext(wallet, dbHandler, node);
    thunderContext.startUp(new NullResultCommand());

    scene.getAccelerators().put(KeyCombination.valueOf("Shortcut+F"), () -> bitcoin.peerGroup().getDownloadPeer().close());
}