drag file onto app, start tweaks

This commit is contained in:
Craig Raw 2020-04-12 16:12:12 +02:00
parent e860b32357
commit 7bbbc10c61
4 changed files with 96 additions and 44 deletions

View file

@ -17,6 +17,9 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.StackPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
@ -33,6 +36,9 @@ public class AppController implements Initializable {
@FXML
private CheckMenuItem showTxHex;
@FXML
private StackPane rootStack;
@FXML
private TabPane tabs;
@ -42,31 +48,55 @@ public class AppController implements Initializable {
}
void initializeView() {
rootStack.setOnDragOver(event -> {
if(event.getGestureSource() != rootStack && event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
event.consume();
});
rootStack.setOnDragDropped(event -> {
Dragboard db = event.getDragboard();
boolean success = false;
if(db.hasFiles()) {
for(File file : db.getFiles()) {
openFile(file);
}
success = true;
}
event.setDropCompleted(success);
event.consume();
});
tabs.getSelectionModel().selectedItemProperty().addListener((observable, old_val, selectedTab) -> {
if(selectedTab != null) {
String tabType = (String)selectedTab.getUserData();
if(tabType.equals(TRANSACTION_TAB_TYPE)) {
EventManager.get().post(new TransactionTabSelectedEvent(selectedTab));
}
}
});
showTxHex.setSelected(true);
addExampleTxTabs();
}
public void openFile(ActionEvent event) {
public void openFromFile(ActionEvent event) {
Stage window = new Stage();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Transaction");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("All Files", "*.*"),
new FileChooser.ExtensionFilter("PSBT", "*.psbt"),
new FileChooser.ExtensionFilter("TXN", "*.txn")
new FileChooser.ExtensionFilter("PSBT", "*.psbt")
);
File file = fileChooser.showOpenDialog(window);
if (file != null) {
openFile(file);
}
}
private void openFile(File file) {
if(file.exists()) {
try {
byte[] bytes = new byte[(int)file.length()];
@ -102,9 +132,8 @@ public class AppController implements Initializable {
}
}
}
}
public void openText(ActionEvent event) {
public void openFromText(ActionEvent event) {
TextAreaDialog dialog = new TextAreaDialog();
dialog.setTitle("Open from text");
dialog.getDialogPane().setHeaderText("Paste a transaction or PSBT:");
@ -140,7 +169,7 @@ public class AppController implements Initializable {
EventManager.get().post(new TransactionTabChangedEvent(tabs.getSelectionModel().getSelectedItem(), item.isSelected()));
}
private void addExampleTxTabs() {
public void openExamples(ActionEvent event) {
try {
addTransactionTab("p2pkh", "01000000019c2e0f24a03e72002a96acedb12a632e72b6b74c05dc3ceab1fe78237f886c48010000006a47304402203da9d487be5302a6d69e02a861acff1da472885e43d7528ed9b1b537a8e2cac9022002d1bca03a1e9715a99971bafe3b1852b7a4f0168281cbd27a220380a01b3307012102c9950c622494c2e9ff5a003e33b690fe4832477d32c2d256c67eab8bf613b34effffffff02b6f50500000000001976a914bdf63990d6dc33d705b756e13dd135466c06b3b588ac845e0201000000001976a9145fb0e9755a3424efd2ba0587d20b1e98ee29814a88ac06241559");
addTransactionTab("p2sh", "0100000003a5ee1a0fd80dfbc3142df136ab56e082b799c13aa977c048bdf8f61bd158652c000000006b48304502203b0160de302cded63589a88214fe499a25aa1d86a2ea09129945cd632476a12c022100c77727daf0718307e184d55df620510cf96d4b5814ae3258519c0482c1ca82fa0121024f4102c1f1cf662bf99f2b034eb03edd4e6c96793cb9445ff519aab580649120ffffffff0fce901eb7b7551ba5f414735ff93b83a2a57403df11059ec88245fba2aaf1a0000000006a47304402204089adb8a1de1a9e22aa43b94d54f1e54dc9bea745d57df1a633e03dd9ede3c2022037d1e53e911ed7212186028f2e085f70524930e22eb6184af090ba4ab779a5b90121030644cb394bf381dbec91680bdf1be1986ad93cfb35603697353199fb285a119effffffff0fce901eb7b7551ba5f414735ff93b83a2a57403df11059ec88245fba2aaf1a0010000009300493046022100a07b2821f96658c938fa9c68950af0e69f3b2ce5f8258b3a6ad254d4bc73e11e022100e82fab8df3f7e7a28e91b3609f91e8ebf663af3a4dc2fd2abd954301a5da67e701475121022afc20bf379bc96a2f4e9e63ffceb8652b2b6a097f63fbee6ecec2a49a48010e2103a767c7221e9f15f870f1ad9311f5ab937d79fcaeee15bb2c722bca515581b4c052aeffffffff02a3b81b00000000001976a914ea00917f128f569cbdf79da5efcd9001671ab52c88ac80969800000000001976a9143dec0ead289be1afa8da127a7dbdd425a05e25f688ac00000000");

View file

@ -19,11 +19,14 @@ public class MainApp extends Application {
scene.getStylesheets().add(getClass().getResource("app.css").toExternalForm());
stage.setTitle("Sparrow");
stage.setMinWidth(650);
stage.setMinHeight(700);
stage.setScene(scene);
stage.getIcons().add(new Image(MainApp.class.getResourceAsStream("/sparrow.png")));
stage.show();
appController.initializeView();
stage.show();
}
public static void main(String[] args) {

View file

@ -0,0 +1,13 @@
.background-box {
-fx-stroke: #696c77;
-fx-stroke-width: 1px;
-fx-stroke-dash-array: 5 5;
-fx-arc-height: 50;
-fx-arc-width: 50;
-fx-fill: transparent;
}
.background-text {
-fx-fill: #696c77;
-fx-font-size: 20;
}

View file

@ -3,6 +3,8 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import org.controlsfx.control.StatusBar?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.shape.Rectangle?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="200" minWidth="350" prefHeight="750.0" prefWidth="1000.0" fx:controller="com.sparrowwallet.sparrow.AppController" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
<children>
@ -12,8 +14,9 @@
<items>
<Menu mnemonicParsing="false" text="Open">
<items>
<MenuItem text="File..." onAction="#openFile"/>
<MenuItem text="From Text..." onAction="#openText"/>
<MenuItem text="File..." onAction="#openFromFile"/>
<MenuItem text="From Text..." onAction="#openFromText"/>
<MenuItem text="Examples" onAction="#openExamples"/>
</items>
</Menu>
<MenuItem mnemonicParsing="false" text="Close" onAction="#closeTab"/>
@ -28,7 +31,11 @@
</Menu>
</menus>
</MenuBar>
<TabPane prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" fx:id="tabs"/>
<StackPane fx:id="rootStack" VBox.vgrow="ALWAYS">
<Rectangle styleClass="background-box" width="400" height="125" />
<Text styleClass="background-text" text="Drag files here to open" />
<TabPane fx:id="tabs" />
</StackPane>
<StatusBar text=""/>
</children>