Search in sources :

Example 1 with View

use of io.bitsquare.gui.common.view.View in project bitsquare by bitsquare.

the class BitsquareApp method start.

@Override
public void start(Stage stage) throws IOException {
    BitsquareApp.primaryStage = stage;
    String logPath = Paths.get(env.getProperty(AppOptionKeys.APP_DATA_DIR_KEY), "bitsquare").toString();
    Log.setup(logPath);
    log.info("Log files under: " + logPath);
    Version.printVersion();
    Utilities.printSysInfo();
    Log.setLevel(Level.toLevel(env.getRequiredProperty(CommonOptionKeys.LOG_LEVEL_KEY)));
    UserThread.setExecutor(Platform::runLater);
    UserThread.setTimerClass(UITimer.class);
    shutDownHandler = this::stop;
    // setup UncaughtExceptionHandler
    Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
        // Might come from another thread 
        if (throwable.getCause() != null && throwable.getCause().getCause() != null && throwable.getCause().getCause() instanceof BlockStoreException) {
            log.error(throwable.getMessage());
        } else if (throwable instanceof ClassCastException && "sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData".equals(throwable.getMessage())) {
            log.warn(throwable.getMessage());
        } else {
            log.error("Uncaught Exception from thread " + Thread.currentThread().getName());
            log.error("throwableMessage= " + throwable.getMessage());
            log.error("throwableClass= " + throwable.getClass());
            log.error("Stack trace:\n" + ExceptionUtils.getStackTrace(throwable));
            throwable.printStackTrace();
            UserThread.execute(() -> showErrorPopup(throwable, false));
        }
    };
    Thread.setDefaultUncaughtExceptionHandler(handler);
    Thread.currentThread().setUncaughtExceptionHandler(handler);
    try {
        Utilities.checkCryptoPolicySetup();
    } catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
        e.printStackTrace();
        UserThread.execute(() -> showErrorPopup(e, true));
    }
    Security.addProvider(new BouncyCastleProvider());
    try {
        // Guice
        bitsquareAppModule = new BitsquareAppModule(env, primaryStage);
        injector = Guice.createInjector(bitsquareAppModule);
        injector.getInstance(InjectorViewFactory.class).setInjector(injector);
        Version.setBtcNetworkId(injector.getInstance(BitsquareEnvironment.class).getBitcoinNetwork().ordinal());
        if (Utilities.isLinux())
            System.setProperty("prism.lcdtext", "false");
        Storage.setDatabaseCorruptionHandler((String fileName) -> {
            corruptedDatabaseFiles.add(fileName);
            if (mainView != null)
                mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
        });
        // load the main view and create the main scene
        CachingViewLoader viewLoader = injector.getInstance(CachingViewLoader.class);
        mainView = (MainView) viewLoader.load(MainView.class);
        mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
        /* Storage.setDatabaseCorruptionHandler((String fileName) -> {
                corruptedDatabaseFiles.add(fileName);
                if (mainView != null)
                    mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
            });*/
        //740
        scene = new Scene(mainView.getRoot(), 1200, 700);
        Font.loadFont(getClass().getResource("/fonts/Verdana.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaBold.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaItalic.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaBoldItalic.ttf").toExternalForm(), 13);
        scene.getStylesheets().setAll("/io/bitsquare/gui/bitsquare.css", "/io/bitsquare/gui/images.css", "/io/bitsquare/gui/CandleStickChart.css");
        // configure the system tray
        SystemTray.create(primaryStage, shutDownHandler);
        primaryStage.setOnCloseRequest(event -> {
            event.consume();
            stop();
        });
        scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent -> {
            if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(keyEvent) || new KeyCodeCombination(KeyCode.W, KeyCombination.CONTROL_DOWN).match(keyEvent)) {
                stop();
            } else if (new KeyCodeCombination(KeyCode.Q, KeyCombination.SHORTCUT_DOWN).match(keyEvent) || new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN).match(keyEvent)) {
                stop();
            } else if (new KeyCodeCombination(KeyCode.E, KeyCombination.SHORTCUT_DOWN).match(keyEvent) || new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN).match(keyEvent)) {
                showEmptyWalletPopup();
            } else if (new KeyCodeCombination(KeyCode.M, KeyCombination.ALT_DOWN).match(keyEvent)) {
                showSendAlertMessagePopup();
            } else if (new KeyCodeCombination(KeyCode.F, KeyCombination.ALT_DOWN).match(keyEvent)) {
                showFilterPopup();
            } else if (new KeyCodeCombination(KeyCode.F, KeyCombination.ALT_DOWN).match(keyEvent)) {
                showFPSWindow();
            } else if (new KeyCodeCombination(KeyCode.J, KeyCombination.ALT_DOWN).match(keyEvent)) {
                WalletService walletService = injector.getInstance(WalletService.class);
                if (walletService.getWallet() != null)
                    new ShowWalletDataWindow(walletService).information("Wallet raw data").show();
                else
                    new Popup<>().warning("The wallet is not initialized yet").show();
            } else if (new KeyCodeCombination(KeyCode.G, KeyCombination.ALT_DOWN).match(keyEvent)) {
                TradeWalletService tradeWalletService = injector.getInstance(TradeWalletService.class);
                WalletService walletService = injector.getInstance(WalletService.class);
                if (walletService.getWallet() != null)
                    new SpendFromDepositTxWindow(tradeWalletService).information("Emergency wallet tool").show();
                else
                    new Popup<>().warning("The wallet is not initialized yet").show();
            } else if (DevFlags.DEV_MODE && new KeyCodeCombination(KeyCode.D, KeyCombination.SHORTCUT_DOWN).match(keyEvent)) {
                showDebugWindow();
            }
        });
        // configure the primary stage
        primaryStage.setTitle(env.getRequiredProperty(APP_NAME_KEY));
        primaryStage.setScene(scene);
        // 1190
        primaryStage.setMinWidth(1000);
        primaryStage.setMinHeight(620);
        // on windows the title icon is also used as task bar icon in a larger size
        // on Linux no title icon is supported but also a large task bar icon is derived from that title icon
        String iconPath;
        if (Utilities.isOSX())
            iconPath = ImageUtil.isRetina() ? "/images/window_icon@2x.png" : "/images/window_icon.png";
        else if (Utilities.isWindows())
            iconPath = "/images/task_bar_icon_windows.png";
        else
            iconPath = "/images/task_bar_icon_linux.png";
        primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(iconPath)));
        // make the UI visible
        primaryStage.show();
        if (!Utilities.isCorrectOSArchitecture()) {
            String osArchitecture = Utilities.getOSArchitecture();
            // We don't force a shutdown as the osArchitecture might in strange cases return a wrong value.
            // Needs at least more testing on different machines...
            new Popup<>().warning("You probably have the wrong Bitsquare version for this computer.\n" + "Your computer's architecture is: " + osArchitecture + ".\n" + "The Bitsquare binary you installed is: " + Utilities.getJVMArchitecture() + ".\n" + "Please shut down and re-install the correct version (" + osArchitecture + ").").show();
        }
        UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES);
    } catch (Throwable throwable) {
        showErrorPopup(throwable, false);
    }
}
Also used : StageStyle(javafx.stage.StageStyle) Popup(io.bitsquare.gui.main.overlays.popups.Popup) LoggerFactory(org.slf4j.LoggerFactory) Security(java.security.Security) View(io.bitsquare.gui.common.view.View) StackPane(javafx.scene.layout.StackPane) KeyCombination(javafx.scene.input.KeyCombination) Application(javafx.application.Application) Parent(javafx.scene.Parent) UITimer(io.bitsquare.gui.common.UITimer) TradeWalletService(io.bitsquare.btc.TradeWalletService) ResultHandler(io.bitsquare.common.handlers.ResultHandler) BlockStoreException(org.bitcoinj.store.BlockStoreException) Pane(javafx.scene.layout.Pane) Font(javafx.scene.text.Font) LimitedKeyStrengthException(io.bitsquare.common.util.LimitedKeyStrengthException) FilterManager(io.bitsquare.filter.FilterManager) KeyEvent(javafx.scene.input.KeyEvent) InjectorViewFactory(io.bitsquare.gui.common.view.guice.InjectorViewFactory) Platform(javafx.application.Platform) List(java.util.List) io.bitsquare.gui.main.overlays.windows(io.bitsquare.gui.main.overlays.windows) Logger(ch.qos.logback.classic.Logger) MainViewModel(io.bitsquare.gui.main.MainViewModel) Environment(org.springframework.core.env.Environment) Dialogs(org.controlsfx.dialog.Dialogs) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EventStreams(org.reactfx.EventStreams) CommonOptionKeys(io.bitsquare.common.CommonOptionKeys) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Scene(javafx.scene.Scene) MainView(io.bitsquare.gui.main.MainView) DebugView(io.bitsquare.gui.main.debug.DebugView) P2PService(io.bitsquare.p2p.P2PService) ArrayList(java.util.ArrayList) TradeManager(io.bitsquare.trade.TradeManager) CachingViewLoader(io.bitsquare.gui.common.view.CachingViewLoader) WalletService(io.bitsquare.btc.WalletService) SystemTray(io.bitsquare.gui.SystemTray) APP_NAME_KEY(io.bitsquare.app.AppOptionKeys.APP_NAME_KEY) KeyCode(javafx.scene.input.KeyCode) Modality(javafx.stage.Modality) Utilities(io.bitsquare.common.util.Utilities) Label(javafx.scene.control.Label) UserThread(io.bitsquare.common.UserThread) ImageUtil(io.bitsquare.gui.util.ImageUtil) IOException(java.io.IOException) ViewLoader(io.bitsquare.gui.common.view.ViewLoader) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Injector(com.google.inject.Injector) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) TimeUnit(java.util.concurrent.TimeUnit) Level(ch.qos.logback.classic.Level) Stage(javafx.stage.Stage) Paths(java.nio.file.Paths) OpenOfferManager(io.bitsquare.trade.offer.OpenOfferManager) ArbitratorManager(io.bitsquare.arbitration.ArbitratorManager) Guice(com.google.inject.Guice) Profiler(io.bitsquare.common.util.Profiler) Storage(io.bitsquare.storage.Storage) Image(javafx.scene.image.Image) AlertManager(io.bitsquare.alert.AlertManager) Platform(javafx.application.Platform) TradeWalletService(io.bitsquare.btc.TradeWalletService) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Image(javafx.scene.image.Image) TradeWalletService(io.bitsquare.btc.TradeWalletService) WalletService(io.bitsquare.btc.WalletService) CachingViewLoader(io.bitsquare.gui.common.view.CachingViewLoader) LimitedKeyStrengthException(io.bitsquare.common.util.LimitedKeyStrengthException) Popup(io.bitsquare.gui.main.overlays.popups.Popup) InjectorViewFactory(io.bitsquare.gui.common.view.guice.InjectorViewFactory) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) BlockStoreException(org.bitcoinj.store.BlockStoreException) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) Scene(javafx.scene.Scene) UserThread(io.bitsquare.common.UserThread)

Example 2 with View

use of io.bitsquare.gui.common.view.View in project bitsquare by bitsquare.

the class BitsquareApp method showDebugWindow.

// Used for debugging trade process
private void showDebugWindow() {
    ViewLoader viewLoader = injector.getInstance(ViewLoader.class);
    View debugView = viewLoader.load(DebugView.class);
    Parent parent = (Parent) debugView.getRoot();
    Stage stage = new Stage();
    stage.setScene(new Scene(parent));
    stage.setTitle("Debug window");
    stage.initModality(Modality.NONE);
    stage.initStyle(StageStyle.UTILITY);
    stage.initOwner(scene.getWindow());
    stage.setX(primaryStage.getX() + primaryStage.getWidth() + 10);
    stage.setY(primaryStage.getY());
    stage.show();
}
Also used : Parent(javafx.scene.Parent) Stage(javafx.stage.Stage) CachingViewLoader(io.bitsquare.gui.common.view.CachingViewLoader) ViewLoader(io.bitsquare.gui.common.view.ViewLoader) Scene(javafx.scene.Scene) View(io.bitsquare.gui.common.view.View) MainView(io.bitsquare.gui.main.MainView) DebugView(io.bitsquare.gui.main.debug.DebugView)

Example 3 with View

use of io.bitsquare.gui.common.view.View in project bitsquare by bitsquare.

the class FxmlViewLoader method loadFromFxml.

private View loadFromFxml(URL fxmlUrl) {
    checkNotNull(fxmlUrl, "FXML URL must not be null");
    try {
        FXMLLoader loader = new FXMLLoader(fxmlUrl, resourceBundle);
        loader.setControllerFactory(viewFactory);
        loader.load();
        Object controller = loader.getController();
        if (controller == null)
            throw new ViewfxException("Failed to load view from FXML file at [%s]. " + "Does it declare an fx:controller attribute?", fxmlUrl);
        if (!(controller instanceof View))
            throw new ViewfxException("Controller of type [%s] loaded from FXML file at [%s] " + "does not implement [%s] as expected.", controller.getClass(), fxmlUrl, View.class);
        return (View) controller;
    } catch (IOException ex) {
        throw new ViewfxException(ex, "Failed to load view from FXML file at [%s]", fxmlUrl);
    }
}
Also used : ViewfxException(io.bitsquare.gui.common.ViewfxException) IOException(java.io.IOException) FXMLLoader(javafx.fxml.FXMLLoader) View(io.bitsquare.gui.common.view.View) FxmlView(io.bitsquare.gui.common.view.FxmlView)

Example 4 with View

use of io.bitsquare.gui.common.view.View in project bitsquare by bitsquare.

the class OfferView method loadView.

private void loadView(Class<? extends View> viewClass) {
    TabPane tabPane = root;
    View view;
    boolean isBuy = direction == Offer.Direction.BUY;
    if (viewClass == OfferBookView.class && offerBookView == null) {
        view = viewLoader.load(viewClass);
        // Offerbook must not be cached by ViewLoader as we use 2 instances for sell and buy screens.
        offerBookTab = new Tab(isBuy ? "Buy bitcoin" : "Sell bitcoin");
        offerBookTab.setClosable(false);
        offerBookTab.setContent(view.getRoot());
        tabPane.getTabs().add(offerBookTab);
        offerBookView = (OfferBookView) view;
        offerBookView.onTabSelected(true);
        OfferActionHandler offerActionHandler = new OfferActionHandler() {

            @Override
            public void onCreateOffer(TradeCurrency tradeCurrency) {
                if (!createOfferViewOpen) {
                    OfferView.this.createOfferViewOpen = true;
                    OfferView.this.tradeCurrency = tradeCurrency;
                    OfferView.this.navigation.navigateTo(MainView.class, OfferView.this.getClass(), CreateOfferView.class);
                } else {
                    new Popup().information("You have already a \"Create offer\" tab open.").show();
                }
            }

            @Override
            public void onTakeOffer(Offer offer) {
                if (!takeOfferViewOpen) {
                    OfferView.this.takeOfferViewOpen = true;
                    OfferView.this.offer = offer;
                    OfferView.this.navigation.navigateTo(MainView.class, OfferView.this.getClass(), TakeOfferView.class);
                } else {
                    new Popup().information("You have already a \"Take offer\" tab open.").show();
                }
            }
        };
        offerBookView.setOfferActionHandler(offerActionHandler);
        offerBookView.setDirection(direction);
    } else if (viewClass == CreateOfferView.class && createOfferView == null) {
        view = viewLoader.load(viewClass);
        // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
        // in different graphs
        createOfferView = (CreateOfferView) view;
        createOfferView.initWithData(direction, tradeCurrency);
        createOfferPane = createOfferView.getRoot();
        createOfferTab = new Tab(getCreateOfferTabName());
        // close handler from close on create offer action
        createOfferView.setCloseHandler(() -> tabPane.getTabs().remove(createOfferTab));
        createOfferTab.setContent(createOfferPane);
        tabPane.getTabs().add(createOfferTab);
        tabPane.getSelectionModel().select(createOfferTab);
    } else if (viewClass == TakeOfferView.class && takeOfferView == null && offer != null) {
        view = viewLoader.load(viewClass);
        // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
        // in different graphs
        takeOfferView = (TakeOfferView) view;
        takeOfferView.initWithData(offer);
        takeOfferPane = ((TakeOfferView) view).getRoot();
        takeOfferTab = new Tab(getTakeOfferTabName());
        // close handler from close on take offer action
        takeOfferView.setCloseHandler(() -> tabPane.getTabs().remove(takeOfferTab));
        takeOfferTab.setContent(takeOfferPane);
        tabPane.getTabs().add(takeOfferTab);
        tabPane.getSelectionModel().select(takeOfferTab);
    }
}
Also used : TabPane(javafx.scene.control.TabPane) TradeCurrency(io.bitsquare.locale.TradeCurrency) CreateOfferView(io.bitsquare.gui.main.offer.createoffer.CreateOfferView) Tab(javafx.scene.control.Tab) Offer(io.bitsquare.trade.offer.Offer) Popup(io.bitsquare.gui.main.overlays.popups.Popup) OfferBookView(io.bitsquare.gui.main.offer.offerbook.OfferBookView) MainView(io.bitsquare.gui.main.MainView) TakeOfferView(io.bitsquare.gui.main.offer.takeoffer.TakeOfferView) View(io.bitsquare.gui.common.view.View) ActivatableView(io.bitsquare.gui.common.view.ActivatableView) CreateOfferView(io.bitsquare.gui.main.offer.createoffer.CreateOfferView) OfferBookView(io.bitsquare.gui.main.offer.offerbook.OfferBookView)

Aggregations

View (io.bitsquare.gui.common.view.View)4 MainView (io.bitsquare.gui.main.MainView)3 CachingViewLoader (io.bitsquare.gui.common.view.CachingViewLoader)2 ViewLoader (io.bitsquare.gui.common.view.ViewLoader)2 DebugView (io.bitsquare.gui.main.debug.DebugView)2 Popup (io.bitsquare.gui.main.overlays.popups.Popup)2 IOException (java.io.IOException)2 Parent (javafx.scene.Parent)2 Scene (javafx.scene.Scene)2 Stage (javafx.stage.Stage)2 Level (ch.qos.logback.classic.Level)1 Logger (ch.qos.logback.classic.Logger)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 AlertManager (io.bitsquare.alert.AlertManager)1 APP_NAME_KEY (io.bitsquare.app.AppOptionKeys.APP_NAME_KEY)1 ArbitratorManager (io.bitsquare.arbitration.ArbitratorManager)1 TradeWalletService (io.bitsquare.btc.TradeWalletService)1 WalletService (io.bitsquare.btc.WalletService)1 CommonOptionKeys (io.bitsquare.common.CommonOptionKeys)1