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();
}
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;
}
}
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);
}
Aggregations