Search in sources :

Example 1 with FontAwesome5

use of com.sparrowwallet.sparrow.glyphfont.FontAwesome5 in project sparrow by sparrowwallet.

the class MainApp method start.

@Override
public void start(Stage stage) throws Exception {
    this.mainStage = stage;
    GlyphFontRegistry.register(new FontAwesome5());
    GlyphFontRegistry.register(new FontAwesome5Brands());
    Font.loadFont(AppServices.class.getResourceAsStream("/font/RobotoMono-Regular.ttf"), 13);
    AppServices.initialize(this);
    boolean createNewWallet = false;
    Mode mode = Config.get().getMode();
    if (mode == null) {
        WelcomeDialog welcomeDialog = new WelcomeDialog();
        Optional<Mode> optionalMode = welcomeDialog.showAndWait();
        if (optionalMode.isPresent()) {
            mode = optionalMode.get();
            Config.get().setMode(mode);
            if (mode.equals(Mode.ONLINE)) {
                PreferencesDialog preferencesDialog = new PreferencesDialog(PreferenceGroup.SERVER, true);
                Optional<Boolean> optNewWallet = preferencesDialog.showAndWait();
                createNewWallet = optNewWallet.isPresent() && optNewWallet.get();
            } else if (Network.get() == Network.MAINNET) {
                Config.get().setServerType(ServerType.PUBLIC_ELECTRUM_SERVER);
                List<PublicElectrumServer> servers = PublicElectrumServer.getServers();
                Config.get().setPublicElectrumServer(servers.get(new Random().nextInt(servers.size())).getUrl());
            }
        }
    }
    if (Config.get().getServerType() == null && Config.get().getCoreServer() == null && Config.get().getElectrumServer() != null) {
        Config.get().setServerType(ServerType.ELECTRUM_SERVER);
    }
    if (Config.get().getHdCapture() == null && Platform.getCurrent() == Platform.OSX) {
        Config.get().setHdCapture(Boolean.TRUE);
    }
    System.setProperty(Wallet.ALLOW_DERIVATIONS_MATCHING_OTHER_SCRIPT_TYPES_PROPERTY, Boolean.toString(!Config.get().isValidateDerivationPaths()));
    if (Config.get().getAppHeight() != null && Config.get().getAppWidth() != null) {
        mainStage.setWidth(Config.get().getAppWidth());
        mainStage.setHeight(Config.get().getAppHeight());
    }
    AppController appController = AppServices.newAppWindow(stage);
    if (createNewWallet) {
        appController.newWallet(null);
    }
    List<File> recentWalletFiles = Config.get().getRecentWalletFiles();
    if (recentWalletFiles != null) {
        // Preserve wallet order as far as possible. Unencrypted wallets will still be opened first.
        List<File> encryptedWalletFiles = recentWalletFiles.stream().filter(Storage::isEncrypted).collect(Collectors.toList());
        List<File> sortedWalletFiles = new ArrayList<>(recentWalletFiles);
        sortedWalletFiles.removeAll(encryptedWalletFiles);
        sortedWalletFiles.addAll(encryptedWalletFiles);
        for (File walletFile : sortedWalletFiles) {
            if (walletFile.exists()) {
                appController.openWalletFile(walletFile, false);
            }
        }
    }
    AppServices.openFileUriArguments(stage);
    AppServices.get().start();
}
Also used : FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) PreferencesDialog(com.sparrowwallet.sparrow.preferences.PreferencesDialog) FontAwesome5Brands(com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands) InstanceList(com.sparrowwallet.sparrow.instance.InstanceList) File(java.io.File)

Example 2 with FontAwesome5

use of com.sparrowwallet.sparrow.glyphfont.FontAwesome5 in project sparrow by sparrowwallet.

the class FileImportPane method createButton.

@Override
protected Control createButton() {
    if (scannable && fileFormatAvailable) {
        ToggleButton scanButton = new ToggleButton("Scan...");
        Glyph cameraGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.CAMERA);
        cameraGlyph.setFontSize(12);
        scanButton.setGraphic(cameraGlyph);
        scanButton.setOnAction(event -> {
            scanButton.setSelected(false);
            importQR();
        });
        ToggleButton fileButton = new ToggleButton("Import File...");
        fileButton.setAlignment(Pos.CENTER_RIGHT);
        fileButton.setOnAction(event -> {
            fileButton.setSelected(false);
            importFile();
        });
        importButton = fileButton;
        SegmentedButton segmentedButton = new SegmentedButton();
        segmentedButton.getButtons().addAll(scanButton, fileButton);
        return segmentedButton;
    } else if (scannable) {
        importButton = new Button("Scan...");
        Glyph cameraGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.CAMERA);
        cameraGlyph.setFontSize(12);
        importButton.setGraphic(cameraGlyph);
        importButton.setAlignment(Pos.CENTER_RIGHT);
        importButton.setOnAction(event -> {
            importQR();
        });
        return importButton;
    } else {
        importButton = new Button("Import File...");
        importButton.setAlignment(Pos.CENTER_RIGHT);
        importButton.setOnAction(event -> {
            importFile();
        });
        return importButton;
    }
}
Also used : JsonParseException(com.google.gson.JsonParseException) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) ImportException(com.sparrowwallet.sparrow.io.ImportException) Wallet(com.sparrowwallet.drongo.wallet.Wallet) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Control(javafx.scene.control.Control) LoggerFactory(org.slf4j.LoggerFactory) TextFields(org.controlsfx.control.textfield.TextFields) Insets(javafx.geometry.Insets) CustomPasswordField(org.controlsfx.control.textfield.CustomPasswordField) Glyph(org.controlsfx.glyphfont.Glyph) InvalidPasswordException(com.sparrowwallet.drongo.crypto.InvalidPasswordException) FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) HBox(javafx.scene.layout.HBox) Logger(org.slf4j.Logger) ButtonBase(javafx.scene.control.ButtonBase) Node(javafx.scene.Node) Platform(org.controlsfx.tools.Platform) KeystoreSource(com.sparrowwallet.drongo.wallet.KeystoreSource) FileImport(com.sparrowwallet.sparrow.io.FileImport) StandardCharsets(java.nio.charset.StandardCharsets) Priority(javafx.scene.layout.Priority) FileChooser(javafx.stage.FileChooser) List(java.util.List) AppServices(com.sparrowwallet.sparrow.AppServices) ToggleButton(javafx.scene.control.ToggleButton) Stage(javafx.stage.Stage) java.io(java.io) SegmentedButton(org.controlsfx.control.SegmentedButton) Optional(java.util.Optional) ScriptType(com.sparrowwallet.drongo.protocol.ScriptType) Keystore(com.sparrowwallet.drongo.wallet.Keystore) ToggleButton(javafx.scene.control.ToggleButton) SegmentedButton(org.controlsfx.control.SegmentedButton) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) SegmentedButton(org.controlsfx.control.SegmentedButton) Glyph(org.controlsfx.glyphfont.Glyph)

Example 3 with FontAwesome5

use of com.sparrowwallet.sparrow.glyphfont.FontAwesome5 in project sparrow by sparrowwallet.

the class ServerPreferencesController method initializeView.

@Override
public void initializeView(Config config) {
    EventManager.get().register(this);
    getMasterController().closingProperty().addListener((observable, oldValue, newValue) -> {
        EventManager.get().unregister(this);
    });
    Platform.runLater(this::setupValidation);
    publicElectrumForm.managedProperty().bind(publicElectrumForm.visibleProperty());
    coreForm.managedProperty().bind(coreForm.visibleProperty());
    electrumForm.managedProperty().bind(electrumForm.visibleProperty());
    serverTypeToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
        if (serverTypeToggleGroup.getSelectedToggle() != null) {
            ServerType existingType = config.getServerType();
            ServerType serverType = (ServerType) newValue.getUserData();
            publicElectrumForm.setVisible(serverType == ServerType.PUBLIC_ELECTRUM_SERVER);
            coreForm.setVisible(serverType == ServerType.BITCOIN_CORE);
            electrumForm.setVisible(serverType == ServerType.ELECTRUM_SERVER);
            config.setServerType(serverType);
            testConnection.setGraphic(getGlyph(FontAwesome5.Glyph.QUESTION_CIRCLE, ""));
            testResults.clear();
            if (existingType != serverType) {
                EventManager.get().post(new ServerTypeChangedEvent(serverType));
            }
        } else if (oldValue != null) {
            oldValue.setSelected(true);
        }
    });
    ServerType serverType = config.getServerType() != null ? (config.getServerType() == ServerType.PUBLIC_ELECTRUM_SERVER && !PublicElectrumServer.supportedNetwork() ? ServerType.BITCOIN_CORE : config.getServerType()) : (config.getCoreServer() == null && config.getElectrumServer() != null ? ServerType.ELECTRUM_SERVER : (config.getCoreServer() != null || !PublicElectrumServer.supportedNetwork() ? ServerType.BITCOIN_CORE : ServerType.PUBLIC_ELECTRUM_SERVER));
    if (!PublicElectrumServer.supportedNetwork()) {
        serverTypeSegmentedButton.getButtons().remove(publicElectrumToggle);
        serverTypeToggleGroup.getToggles().remove(publicElectrumToggle);
    }
    serverTypeToggleGroup.selectToggle(serverTypeToggleGroup.getToggles().stream().filter(toggle -> toggle.getUserData() == serverType).findFirst().orElse(null));
    publicElectrumServer.setItems(FXCollections.observableList(PublicElectrumServer.getServers()));
    publicElectrumServer.getSelectionModel().selectedItemProperty().addListener(getPublicElectrumServerListener(config));
    publicUseProxy.selectedProperty().bindBidirectional(useProxy.selectedProperty());
    publicProxyHost.textProperty().bindBidirectional(proxyHost.textProperty());
    publicProxyPort.textProperty().bindBidirectional(proxyPort.textProperty());
    corePort.setTextFormatter(new TextFieldValidator(TextFieldValidator.ValidationModus.MAX_INTEGERS, 5).getFormatter());
    electrumPort.setTextFormatter(new TextFieldValidator(TextFieldValidator.ValidationModus.MAX_INTEGERS, 5).getFormatter());
    proxyPort.setTextFormatter(new TextFieldValidator(TextFieldValidator.ValidationModus.MAX_INTEGERS, 5).getFormatter());
    coreProxyPort.setTextFormatter(new TextFieldValidator(TextFieldValidator.ValidationModus.MAX_INTEGERS, 5).getFormatter());
    publicProxyPort.setTextFormatter(new TextFieldValidator(TextFieldValidator.ValidationModus.MAX_INTEGERS, 5).getFormatter());
    coreHost.textProperty().addListener(getBitcoinCoreListener(config));
    corePort.textProperty().addListener(getBitcoinCoreListener(config));
    coreUser.textProperty().addListener(getBitcoinAuthListener(config));
    corePass.textProperty().addListener(getBitcoinAuthListener(config));
    coreUseProxy.selectedProperty().bindBidirectional(useProxy.selectedProperty());
    coreProxyHost.textProperty().bindBidirectional(proxyHost.textProperty());
    coreProxyPort.textProperty().bindBidirectional(proxyPort.textProperty());
    electrumHost.textProperty().addListener(getElectrumServerListener(config));
    electrumPort.textProperty().addListener(getElectrumServerListener(config));
    proxyHost.textProperty().addListener(getProxyListener(config));
    proxyPort.textProperty().addListener(getProxyListener(config));
    coreDataDirField.managedProperty().bind(coreDataDirField.visibleProperty());
    coreUserPassField.managedProperty().bind(coreUserPassField.visibleProperty());
    coreUserPassField.visibleProperty().bind(coreDataDirField.visibleProperty().not());
    coreAuthToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
        if (coreAuthToggleGroup.getSelectedToggle() != null) {
            CoreAuthType coreAuthType = (CoreAuthType) newValue.getUserData();
            coreDataDirField.setVisible(coreAuthType == CoreAuthType.COOKIE);
            config.setCoreAuthType(coreAuthType);
        } else if (oldValue != null) {
            oldValue.setSelected(true);
        }
    });
    CoreAuthType coreAuthType = config.getCoreAuthType() != null ? config.getCoreAuthType() : CoreAuthType.COOKIE;
    coreAuthToggleGroup.selectToggle(coreAuthToggleGroup.getToggles().stream().filter(toggle -> toggle.getUserData() == coreAuthType).findFirst().orElse(null));
    coreDataDir.textProperty().addListener((observable, oldValue, newValue) -> {
        File dataDir = getDirectory(newValue);
        config.setCoreDataDir(dataDir);
    });
    coreDataDirSelect.setOnAction(event -> {
        Stage window = new Stage();
        DirectoryChooser directorChooser = new DirectoryChooser();
        directorChooser.setTitle("Select Bitcoin Core Data Directory");
        directorChooser.setInitialDirectory(config.getCoreDataDir() != null ? config.getCoreDataDir() : new File(System.getProperty("user.home")));
        File dataDir = directorChooser.showDialog(window);
        if (dataDir != null) {
            coreDataDir.setText(dataDir.getAbsolutePath());
        }
    });
    recentCoreServers.setConverter(new UrlHostConverter());
    recentCoreServers.setItems(FXCollections.observableList(Config.get().getRecentCoreServers() == null ? new ArrayList<>() : Config.get().getRecentCoreServers()));
    recentCoreServers.prefWidthProperty().bind(coreHost.widthProperty());
    recentCoreServers.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null && Protocol.getProtocol(newValue) != null) {
            HostAndPort hostAndPort = Protocol.getProtocol(newValue).getServerHostAndPort(newValue);
            coreHost.setText(hostAndPort.getHost());
            corePort.setText(Integer.toString(hostAndPort.getPort()));
        }
    });
    recentElectrumServers.setConverter(new UrlHostConverter());
    recentElectrumServers.setItems(FXCollections.observableList(Config.get().getRecentElectrumServers() == null ? new ArrayList<>() : Config.get().getRecentElectrumServers()));
    recentElectrumServers.prefWidthProperty().bind(electrumHost.widthProperty());
    recentElectrumServers.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null && Protocol.getProtocol(newValue) != null) {
            HostAndPort hostAndPort = Protocol.getProtocol(newValue).getServerHostAndPort(newValue);
            electrumHost.setText(hostAndPort.getHost());
            electrumPort.setText(Integer.toString(hostAndPort.getPort()));
            electrumUseSsl.setSelected(Protocol.getProtocol(newValue) == Protocol.SSL);
        }
    });
    electrumUseSsl.selectedProperty().addListener((observable, oldValue, newValue) -> {
        setElectrumServerInConfig(config);
        electrumCertificate.setDisable(!newValue);
        electrumCertificateSelect.setDisable(!newValue);
    });
    electrumCertificate.textProperty().addListener((observable, oldValue, newValue) -> {
        File crtFile = getCertificate(newValue);
        config.setElectrumServerCert(crtFile);
    });
    electrumCertificateSelect.setOnAction(event -> {
        Stage window = new Stage();
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("Select Electrum Server certificate");
        fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("All Files", org.controlsfx.tools.Platform.getCurrent().equals(org.controlsfx.tools.Platform.UNIX) ? "*" : "*.*"), new FileChooser.ExtensionFilter("CRT", "*.crt"));
        AppServices.moveToActiveWindowScreen(window, 800, 450);
        File file = fileChooser.showOpenDialog(window);
        if (file != null) {
            electrumCertificate.setText(file.getAbsolutePath());
        }
    });
    useProxy.selectedProperty().addListener((observable, oldValue, newValue) -> {
        config.setUseProxy(newValue);
        proxyHost.setText(proxyHost.getText() + " ");
        proxyHost.setText(proxyHost.getText().trim());
        proxyHost.setDisable(!newValue);
        proxyPort.setDisable(!newValue);
        publicProxyHost.setDisable(!newValue);
        publicProxyPort.setDisable(!newValue);
    });
    boolean isConnected = AppServices.isConnecting() || AppServices.isConnected();
    if (AppServices.isConnecting()) {
        testResults.appendText("Connecting to server, please wait...");
    }
    testConnection.managedProperty().bind(testConnection.visibleProperty());
    testConnection.setVisible(!isConnected);
    setTestResultsFont();
    testConnection.setOnAction(event -> {
        testConnection.setGraphic(getGlyph(FontAwesome5.Glyph.ELLIPSIS_H, null));
        testResults.setText("Connecting to " + config.getServerAddress() + "...");
        if (Config.get().requiresInternalTor() && Tor.getDefault() == null) {
            startTor();
        } else {
            startElectrumConnection();
        }
    });
    editConnection.managedProperty().bind(editConnection.visibleProperty());
    editConnection.setVisible(isConnected);
    editConnection.setDisable(AppServices.isConnecting());
    editConnection.setOnAction(event -> {
        EventManager.get().post(new RequestDisconnectEvent());
        setFieldsEditable(true);
        editConnection.setVisible(false);
        testConnection.setVisible(true);
    });
    PublicElectrumServer configPublicElectrumServer = PublicElectrumServer.fromUrl(config.getPublicElectrumServer());
    if (configPublicElectrumServer == null && PublicElectrumServer.supportedNetwork()) {
        List<PublicElectrumServer> servers = PublicElectrumServer.getServers();
        if (!servers.isEmpty()) {
            publicElectrumServer.setValue(servers.get(new Random().nextInt(servers.size())));
        }
    } else {
        publicElectrumServer.setValue(configPublicElectrumServer);
    }
    String coreServer = config.getCoreServer();
    if (coreServer != null) {
        Protocol protocol = Protocol.getProtocol(coreServer);
        if (protocol != null) {
            HostAndPort server = protocol.getServerHostAndPort(coreServer);
            coreHost.setText(server.getHost());
            if (server.hasPort()) {
                corePort.setText(Integer.toString(server.getPort()));
            }
        }
    } else {
        coreHost.setText("127.0.0.1");
        corePort.setText(String.valueOf(Network.get().getDefaultPort()));
    }
    coreDataDir.setText(config.getCoreDataDir() != null ? config.getCoreDataDir().getAbsolutePath() : getDefaultCoreDataDir().getAbsolutePath());
    if (config.getCoreAuth() != null) {
        String[] userPass = config.getCoreAuth().split(":");
        if (userPass.length > 0) {
            coreUser.setText(userPass[0]);
        }
        if (userPass.length > 1) {
            corePass.setText(userPass[1]);
        }
    }
    String electrumServer = config.getElectrumServer();
    if (electrumServer != null) {
        Protocol protocol = Protocol.getProtocol(electrumServer);
        if (protocol != null) {
            boolean ssl = protocol.equals(Protocol.SSL);
            electrumUseSsl.setSelected(ssl);
            electrumCertificate.setDisable(!ssl);
            electrumCertificateSelect.setDisable(!ssl);
            HostAndPort server = protocol.getServerHostAndPort(electrumServer);
            electrumHost.setText(server.getHost());
            if (server.hasPort()) {
                electrumPort.setText(Integer.toString(server.getPort()));
            }
        }
    }
    File certificateFile = config.getElectrumServerCert();
    if (certificateFile != null) {
        electrumCertificate.setText(certificateFile.getAbsolutePath());
    }
    useProxy.setSelected(config.isUseProxy());
    proxyHost.setDisable(!config.isUseProxy());
    proxyPort.setDisable(!config.isUseProxy());
    publicProxyHost.setDisable(!config.isUseProxy());
    publicProxyPort.setDisable(!config.isUseProxy());
    String proxyServer = config.getProxyServer();
    if (proxyServer != null) {
        HostAndPort server = HostAndPort.fromString(proxyServer);
        proxyHost.setText(server.getHost());
        if (server.hasPort()) {
            proxyPort.setText(Integer.toString(server.getPort()));
        }
    }
    setFieldsEditable(!isConnected);
}
Also used : Form(tornadofx.control.Form) CertificateFactory(java.security.cert.CertificateFactory) javafx.scene.control(javafx.scene.control) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) SimpleDateFormat(java.text.SimpleDateFormat) ValidationSupport(org.controlsfx.validation.ValidationSupport) Random(java.util.Random) Config(com.sparrowwallet.sparrow.io.Config) ArrayList(java.util.ArrayList) Glyph(org.controlsfx.glyphfont.Glyph) StyleClassValidationDecoration(org.controlsfx.validation.decoration.StyleClassValidationDecoration) FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) ValidationResult(org.controlsfx.validation.ValidationResult) Subscribe(com.google.common.eventbus.Subscribe) TextFieldValidator(com.sparrowwallet.sparrow.control.TextFieldValidator) DateFormat(java.text.DateFormat) DirectoryChooser(javafx.stage.DirectoryChooser) Storage(com.sparrowwallet.sparrow.io.Storage) com.sparrowwallet.sparrow.net(com.sparrowwallet.sparrow.net) Logger(org.slf4j.Logger) UnlabeledToggleSwitch(com.sparrowwallet.sparrow.control.UnlabeledToggleSwitch) ComboBoxTextField(com.sparrowwallet.sparrow.control.ComboBoxTextField) Field(tornadofx.control.Field) com.sparrowwallet.sparrow.event(com.sparrowwallet.sparrow.event) Font(javafx.scene.text.Font) StringConverter(javafx.util.StringConverter) FileInputStream(java.io.FileInputStream) HostAndPort(com.google.common.net.HostAndPort) Tor(org.berndpruenster.netlayer.tor.Tor) File(java.io.File) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) FileChooser(javafx.stage.FileChooser) Duration(javafx.util.Duration) List(java.util.List) AppServices(com.sparrowwallet.sparrow.AppServices) Network(com.sparrowwallet.drongo.Network) Stage(javafx.stage.Stage) Mode(com.sparrowwallet.sparrow.Mode) EventManager(com.sparrowwallet.sparrow.EventManager) SegmentedButton(org.controlsfx.control.SegmentedButton) Optional(java.util.Optional) Validator(org.controlsfx.validation.Validator) ChangeListener(javafx.beans.value.ChangeListener) NotNull(org.jetbrains.annotations.NotNull) HostAndPort(com.google.common.net.HostAndPort) Random(java.util.Random) FileChooser(javafx.stage.FileChooser) Stage(javafx.stage.Stage) TextFieldValidator(com.sparrowwallet.sparrow.control.TextFieldValidator) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser)

Aggregations

FontAwesome5 (com.sparrowwallet.sparrow.glyphfont.FontAwesome5)3 AppServices (com.sparrowwallet.sparrow.AppServices)2 File (java.io.File)2 List (java.util.List)2 Optional (java.util.Optional)2 FileChooser (javafx.stage.FileChooser)2 Stage (javafx.stage.Stage)2 SegmentedButton (org.controlsfx.control.SegmentedButton)2 Glyph (org.controlsfx.glyphfont.Glyph)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Subscribe (com.google.common.eventbus.Subscribe)1 HostAndPort (com.google.common.net.HostAndPort)1 JsonParseException (com.google.gson.JsonParseException)1 Network (com.sparrowwallet.drongo.Network)1 InvalidPasswordException (com.sparrowwallet.drongo.crypto.InvalidPasswordException)1 ScriptType (com.sparrowwallet.drongo.protocol.ScriptType)1 Keystore (com.sparrowwallet.drongo.wallet.Keystore)1 KeystoreSource (com.sparrowwallet.drongo.wallet.KeystoreSource)1 Wallet (com.sparrowwallet.drongo.wallet.Wallet)1