use of io.bitsquare.BitsquareException in project bitsquare by bitsquare.
the class SystemTray method init.
private void init() {
if (!java.awt.SystemTray.isSupported()) {
log.error("System tray is not supported.");
return;
}
// prevent exiting the app when the last window gets closed
// For now we allow to close the app by closing the window.
// Later we only let it close via the system trays exit.
Platform.setImplicitExit(false);
MenuItem aboutItem = new MenuItem("Info about Bitsquare");
MenuItem exitItem = new MenuItem("Exit");
PopupMenu popupMenu = new PopupMenu();
popupMenu.add(aboutItem);
popupMenu.addSeparator();
popupMenu.add(toggleShowHideItem);
popupMenu.addSeparator();
popupMenu.add(exitItem);
String path;
if (Utilities.isOSX())
path = ImageUtil.isRetina() ? ICON_HI_RES : ICON_LO_RES;
else if (Utilities.isWindows())
path = ICON_WINDOWS;
else
path = ICON_LINUX;
try {
BufferedImage trayIconImage = ImageIO.read(getClass().getResource(path));
TrayIcon trayIcon = new TrayIcon(trayIconImage);
// On OSX we get the correct size from the provided image
if (!Utilities.isOSX()) {
int trayIconWidth = trayIcon.getSize().width;
trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
}
trayIcon.setPopupMenu(popupMenu);
trayIcon.setToolTip("Bitsquare: The decentralized bitcoin exchange");
java.awt.SystemTray.getSystemTray().add(trayIcon);
} catch (AWTException e1) {
log.error("Icon could not be added to system tray.", e1);
} catch (IOException e2) {
throw new BitsquareException(e2);
}
toggleShowHideItem.addActionListener(e -> {
if (stage.isShowing()) {
toggleShowHideItem.setLabel(SHOW_WINDOW_LABEL);
UserThread.execute(stage::hide);
} else {
toggleShowHideItem.setLabel(HIDE_WINDOW_LABEL);
UserThread.execute(stage::show);
}
});
aboutItem.addActionListener(e -> {
try {
GUIUtil.openWebPage("https://bitsquare.io");
} catch (Exception e1) {
e1.printStackTrace();
}
});
exitItem.addActionListener(e -> UserThread.execute(onExit::run));
}
use of io.bitsquare.BitsquareException in project bitsquare by bitsquare.
the class MainView method initialize.
@Override
protected void initialize() {
MainView.rootContainer = this.root;
ToggleButton marketButton = new NavButton(MarketView.class, "Market");
ToggleButton buyButton = new NavButton(BuyOfferView.class, "Buy BTC");
ToggleButton sellButton = new NavButton(SellOfferView.class, "Sell BTC");
ToggleButton portfolioButton = new NavButton(PortfolioView.class, "Portfolio");
ToggleButton fundsButton = new NavButton(FundsView.class, "Funds");
ToggleButton disputesButton = new NavButton(DisputesView.class, "Support");
ToggleButton settingsButton = new NavButton(SettingsView.class, "Settings");
ToggleButton accountButton = new NavButton(AccountView.class, "Account");
Pane portfolioButtonHolder = new Pane(portfolioButton);
Pane disputesButtonHolder = new Pane(disputesButton);
HBox leftNavPane = new HBox(marketButton, buyButton, sellButton, portfolioButtonHolder, fundsButton, disputesButtonHolder) {
{
setLeftAnchor(this, 10d);
setTopAnchor(this, 0d);
}
};
Tuple3<ComboBox<PriceFeedComboBoxItem>, Label, VBox> marketPriceBox = getMarketPriceBox("Market price");
ComboBox<PriceFeedComboBoxItem> priceComboBox = marketPriceBox.first;
priceComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
model.setPriceFeedComboBoxItem(newValue);
});
ChangeListener<PriceFeedComboBoxItem> selectedPriceFeedItemListender = (observable, oldValue, newValue) -> {
if (newValue != null)
priceComboBox.getSelectionModel().select(newValue);
};
model.selectedPriceFeedComboBoxItemProperty.addListener(selectedPriceFeedItemListender);
priceComboBox.setItems(model.priceFeedComboBoxItems);
marketPriceBox.second.textProperty().bind(createStringBinding(() -> {
PriceFeedService.Type type = model.typeProperty.get();
return type != null ? "Market price (" + type.name + ")" : "";
}, model.marketPriceCurrencyCode, model.typeProperty));
HBox.setMargin(marketPriceBox.third, new Insets(0, 0, 0, 0));
Tuple2<TextField, VBox> availableBalanceBox = getBalanceBox("Available balance");
availableBalanceBox.first.textProperty().bind(model.availableBalance);
Tuple2<TextField, VBox> reservedBalanceBox = getBalanceBox("Reserved in offers");
reservedBalanceBox.first.textProperty().bind(model.reservedBalance);
Tuple2<TextField, VBox> lockedBalanceBox = getBalanceBox("Locked in trades");
lockedBalanceBox.first.textProperty().bind(model.lockedBalance);
HBox rightNavPane = new HBox(marketPriceBox.third, availableBalanceBox.second, reservedBalanceBox.second, lockedBalanceBox.second, settingsButton, accountButton) {
{
setRightAnchor(this, 10d);
setTopAnchor(this, 0d);
}
};
root.widthProperty().addListener((observable, oldValue, newValue) -> {
double w = (double) newValue;
if (w > 0) {
leftNavPane.setSpacing(w >= 1080 ? 10 : 5);
rightNavPane.setSpacing(w >= 1080 ? 10 : 5);
}
});
AnchorPane contentContainer = new AnchorPane() {
{
setId("content-pane");
setLeftAnchor(this, 0d);
setRightAnchor(this, 0d);
setTopAnchor(this, 60d);
setBottomAnchor(this, 10d);
}
};
AnchorPane applicationContainer = new AnchorPane(leftNavPane, rightNavPane, contentContainer) {
{
setId("content-pane");
}
};
BorderPane baseApplicationContainer = new BorderPane(applicationContainer) {
{
setId("base-content-container");
}
};
baseApplicationContainer.setBottom(createFooter());
setupNotificationIcon(portfolioButtonHolder);
setupDisputesIcon(disputesButtonHolder);
navigation.addListener(viewPath -> {
if (viewPath.size() != 2 || viewPath.indexOf(MainView.class) != 0)
return;
Class<? extends View> viewClass = viewPath.tip();
View view = viewLoader.load(viewClass);
contentContainer.getChildren().setAll(view.getRoot());
navButtons.getToggles().stream().filter(toggle -> toggle instanceof NavButton).filter(button -> viewClass == ((NavButton) button).viewClass).findFirst().orElseThrow(() -> new BitsquareException("No button matching %s found", viewClass)).setSelected(true);
});
VBox splashScreen = createSplashScreen();
root.getChildren().addAll(baseApplicationContainer, splashScreen);
model.showAppScreen.addListener((ov, oldValue, newValue) -> {
if (newValue) {
navigation.navigateToPreviousVisitedView();
if (!persistedFilesCorrupted.isEmpty()) {
if (persistedFilesCorrupted.size() > 1 || !persistedFilesCorrupted.get(0).equals("Navigation")) {
// show warning that some files has been corrupted
new Popup().warning("We detected incompatible data base files!\n\n" + "Those database file(s) are not compatible with our current code base:" + "\n" + persistedFilesCorrupted.toString() + "\n\nWe made a backup of the corrupted file(s) and applied the default values to a new " + "database version." + "\n\nThe backup is located at:\n[you local app data directory]/db/backup_of_corrupted_data.\n\n" + "Please check if you have the latest version of Bitsquare installed.\n" + "You can download it at:\nhttps://github.com/bitsquare/bitsquare/releases\n\n" + "Please restart the application.").closeButtonText("Shut down").onClose(BitsquareApp.shutDownHandler::run).show();
} else {
log.debug("We detected incompatible data base file for Navigation. That is a minor issue happening with refactoring of UI classes " + "and we don't display a warning popup to the user.");
}
}
transitions.fadeOutAndRemove(splashScreen, 1500, actionEvent -> disposeSplashScreen());
}
});
// Delay a bit to give time for rendering the splash screen
UserThread.execute(model::start);
}
Aggregations