walletfx: Extract MainWindowController abstract base class

* Extract `MainWindowController` from `wallettemplate.MainController`
* WalletApplication: `wallettemplate.MainController` with `MainWindowController`
This commit is contained in:
Sean Gilligan 2021-09-22 12:16:27 -07:00
parent d1aa5e3d36
commit 515a558ec2
3 changed files with 49 additions and 10 deletions

View File

@ -0,0 +1,41 @@
/*
* Copyright by the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bitcoinj.walletfx.application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import org.bitcoinj.core.listeners.DownloadProgressTracker;
import org.bitcoinj.walletfx.overlay.OverlayableStackPaneController;
/**
* Abstract controller class for a wallet application's main window (i.e. the one that is the primary @{code Stage})
*/
public abstract class MainWindowController extends OverlayableStackPaneController {
protected Scene scene;
public Scene scene() {
return scene;
}
public abstract void controllerStart(Pane mainUI, String cssResourceName);
public abstract void onBitcoinSetup();
public abstract void restoreFromSeedAnimation();
public abstract DownloadProgressTracker progressBarUpdater();
}

View File

@ -30,7 +30,6 @@ import org.bitcoinj.utils.BriefLogFormatter;
import org.bitcoinj.utils.Threading;
import org.bitcoinj.wallet.DeterministicSeed;
import org.bitcoinj.walletfx.utils.GuiUtils;
import wallettemplate.MainController;
import wallettemplate.WalletSetPasswordController;
import javax.annotation.Nullable;
@ -49,7 +48,7 @@ public abstract class WalletApplication implements AppDelegate {
public final NetworkParameters params;
public final Script.ScriptType preferredOutputScriptType;
protected final String walletFileName;
private MainController controller;
private MainWindowController controller;
public WalletApplication(String applicationName, NetworkParameters params, Script.ScriptType preferredOutputScriptType) {
instance = this;
@ -69,7 +68,7 @@ public abstract class WalletApplication implements AppDelegate {
}
}
abstract protected MainController loadController() throws IOException;
abstract protected MainWindowController loadController() throws IOException;
private void realStart(Stage mainWindow) throws IOException {
// Show the crash dialog for any exceptions that we don't handle and that hit the main loop.

View File

@ -33,8 +33,8 @@ import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.util.Duration;
import org.bitcoinj.walletfx.application.MainWindowController;
import org.bitcoinj.walletfx.application.WalletApplication;
import org.bitcoinj.walletfx.overlay.OverlayableStackPaneController;
import org.bitcoinj.walletfx.utils.GuiUtils;
import org.bitcoinj.walletfx.utils.TextFieldValidator;
import org.bitcoinj.walletfx.controls.ClickableBitcoinAddress;
@ -49,7 +49,7 @@ import static org.bitcoinj.walletfx.application.WalletApplication.bitcoin;
* Gets created auto-magically by FXMLLoader via reflection. The widget fields are set to the GUI controls they're named
* after. This class handles all the updates and event handling for the main UI.
*/
public class MainController extends OverlayableStackPaneController {
public class MainController extends MainWindowController {
static MainController instance;
public HBox controlsBox;
public Label balance;
@ -60,7 +60,6 @@ public class MainController extends OverlayableStackPaneController {
private NotificationBarPane.Item syncItem;
private static final MonetaryFormat MONETARY_FORMAT = MonetaryFormat.BTC.noCode();
private Scene scene;
private NotificationBarPane notificationBar;
// Called by FXMLLoader.
@ -73,10 +72,7 @@ public class MainController extends OverlayableStackPaneController {
addressControl.setOpacity(0.0);
}
public Scene scene() {
return scene;
}
@Override
public void controllerStart(Pane mainUI, String cssResourceName) {
this.mainUI = mainUI;
// Configure the window with a StackPane so we can overlay things on top of the main UI, and a
@ -92,6 +88,7 @@ public class MainController extends OverlayableStackPaneController {
scene.getAccelerators().put(KeyCombination.valueOf("Shortcut+F"), () -> bitcoin.peerGroup().getDownloadPeer().close());
}
@Override
public void onBitcoinSetup() {
model.setWallet(bitcoin.wallet());
addressControl.addressProperty().bind(model.addressProperty());
@ -143,6 +140,7 @@ public class MainController extends OverlayableStackPaneController {
GuiUtils.informationalAlert("Unused button #2", "You can hook this up in your app");
}
@Override
public void restoreFromSeedAnimation() {
// Buttons slide out ...
TranslateTransition leave = new TranslateTransition(Duration.millis(1200), controlsBox);
@ -163,6 +161,7 @@ public class MainController extends OverlayableStackPaneController {
group.play();
}
@Override
public DownloadProgressTracker progressBarUpdater() {
return model.getDownloadProgressTracker();
}