Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Merge UI styles
Browse files Browse the repository at this point in the history
Adapt transaction dialog for different resolutions by removing presumed
font size.
Add standard stylesheet
Update headings on main controller and and transaction send dialog to use
stylesheet
  • Loading branch information
Ross Nicoll committed Jan 17, 2016
1 parent b89a825 commit 05738bb
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 164 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/libdohj/cate/CATE.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javax.swing.event.HyperlinkEvent;

import org.controlsfx.control.NotificationPane;
import org.libdohj.cate.controller.MainController;
Expand All @@ -40,6 +39,7 @@
* @author Ross Nicoll
*/
public class CATE extends Application {
public static final String DEFAULT_STYLESHEET = "/cate.css";

private static CATE instance;

Expand Down Expand Up @@ -75,6 +75,7 @@ public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/main.fxml"), resources);
Parent root = loader.load();

root.getStylesheets().add(DEFAULT_STYLESHEET);
this.controller = (MainController) loader.getController();
this.controller.connectTo(NetworkResolver.getParameter("Dogecoin"), dataDir);
this.controller.connectTo(NetworkResolver.getParameter("Dogecoin test"), dataDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2016 jrn.
*
* 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.libdohj.cate.controller;

import java.util.Objects;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.GridPane;
import org.libdohj.cate.CATE;
import static org.libdohj.cate.controller.MainController.DIALOG_HGAP;
import static org.libdohj.cate.controller.MainController.DIALOG_VGAP;

/**
* @author Qu3ntin0
*/
public class DualPasswordInputDialog extends Dialog<String> {
private final GridPane grid;
private final Label newLabel;
private final Label repeatLabel;
private final PasswordField newPass;
private final PasswordField repeatPass;

public DualPasswordInputDialog(final ResourceBundle resources) {
super();

newLabel = new Label(resources.getString("dialogEncrypt.passNew"));
repeatLabel = new Label(resources.getString("dialogEncrypt.passRepeat"));
newPass = new PasswordField();
repeatPass = new PasswordField();

newLabel.getStyleClass().add("label-heading");
repeatLabel.getStyleClass().add("label-heading");

grid = new GridPane();
grid.setHgap(DIALOG_HGAP);
grid.setVgap(DIALOG_VGAP);
grid.addRow(0, newLabel, newPass);
grid.addRow(1, repeatLabel, repeatPass);

getDialogPane().getStylesheets().add(CATE.DEFAULT_STYLESHEET);
getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
getDialogPane().setContent(grid);

Platform.runLater(newPass::requestFocus);

setResultConverter(dialogButton -> {
if (dialogButton.getButtonData() == ButtonBar.ButtonData.OK_DONE) {
if (!newPass.getText().trim().isEmpty() && !repeatPass.getText().trim().isEmpty()) {
if (Objects.equals(newPass.getText(), repeatPass.getText())) {
return newPass.getText();
} else {
return null;
}
} else {
return null;
}
}
return null;
});
}
}
39 changes: 4 additions & 35 deletions src/main/java/org/libdohj/cate/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,45 +416,12 @@ private void encryptWalletOnUIThread(final Network network) {
return;
}

Dialog<String> dialog = new Dialog<>();
DualPasswordInputDialog dialog = new DualPasswordInputDialog(resources);
dialog.setTitle(resources.getString("dialogEncrypt.title"));
dialog.setHeaderText(resources.getString("dialogEncrypt.msg"));

PasswordField pass1 = new PasswordField();
PasswordField pass2 = new PasswordField();

GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.add(new Label(resources.getString("dialogEncrypt.passNew")), 0, 0);
grid.add(pass1, 1, 0);
grid.add(new Label(resources.getString("dialogEncrypt.passRepeat")), 0, 1);
grid.add(pass2, 1, 1);

ButtonType buttonTypeOk = new ButtonType(resources.getString("buttonType.Ok"), ButtonBar.ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(buttonTypeOk, ButtonType.CANCEL);

dialog.getDialogPane().setContent(grid);

Platform.runLater(pass1::requestFocus);

dialog.setResultConverter(dialogButton -> {
if (dialogButton == buttonTypeOk) {
if (!pass1.getText().trim().isEmpty() && !pass2.getText().trim().isEmpty()) {
if (Objects.equals(pass1.getText(), pass2.getText())) {
return pass1.getText();
} else {
return resources.getString("responseType.False");
}
} else {
return resources.getString("responseType.False");
}
}
return null;
});

dialog.showAndWait().ifPresent(value -> {
if (Objects.equals(value, resources.getString("responseType.False"))) {
if (value == null) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.INFORMATION,
resources.getString("alert.encryptWallet.mismatchMsg"));
Expand Down Expand Up @@ -487,6 +454,8 @@ private void encryptWalletOnUIThread(final Network network) {
}
});
}
public static final int DIALOG_VGAP = 10;
public static final int DIALOG_HGAP = 10;

/**
* Take coin values to send from the user interface, prompt the user to
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/org/libdohj/cate/controller/PasswordInputDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,32 @@
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.GridPane;
import org.libdohj.cate.CATE;

/**
* @author Qu3ntin0
*/
public class PasswordInputDialog extends Dialog<String> {
final GridPane grid;
final PasswordField pass;
final Label content;
private final GridPane grid;
private final PasswordField pass;
private final Label heading;

public PasswordInputDialog() {
super();
pass = new PasswordField();
grid = new GridPane();
content = new Label();
heading = new Label();

heading.getStyleClass().add("label-heading");
contentTextProperty().addListener((observable, oldVal, newVal) -> {
content.setText(newVal);
heading.setText(newVal);
});

grid.setHgap(10);
grid.setVgap(10);
grid.add(content, 0, 0);
grid.add(pass, 1, 0);
grid.setHgap(MainController.DIALOG_HGAP);
grid.setVgap(MainController.DIALOG_VGAP);
grid.addRow(0, heading, pass);

getDialogPane().getStylesheets().add(CATE.DEFAULT_STYLESHEET);
getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
getDialogPane().setContent(grid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
Expand All @@ -28,6 +27,7 @@
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.utils.MonetaryFormat;
import org.libdohj.cate.CATE;

/**
* @author Ross Nicoll
Expand All @@ -50,8 +50,11 @@ public TransactionConfirmationAlert(final NetworkParameters params, final Resour

setTitle(resources.getString("sendCoins.confirm.title"));
addressLabel.setText(resources.getString("sendCoins.confirm.address"));
addressLabel.getStyleClass().add("label-heading");
amountLabel.setText(resources.getString("sendCoins.confirm.amount"));
amountLabel.getStyleClass().add("label-heading");
memoLabel.setText(resources.getString("sendCoins.confirm.memo"));
memoLabel.getStyleClass().add("label-heading");

format = params.getMonetaryFormat();
grid = new GridPane();
Expand All @@ -66,20 +69,15 @@ public TransactionConfirmationAlert(final NetworkParameters params, final Resour
address.setText(newVal.toBase58());
});

grid.setHgap(10);
grid.setVgap(10);
grid.setHgap(MainController.DIALOG_HGAP);
grid.setVgap(MainController.DIALOG_VGAP);
int row = 0;
grid.add(content, 0, row++);

grid.add(addressLabel, 0, row);
grid.add(address, 1, row++);

grid.add(memoLabel, 0, row);
grid.add(memo, 1, row++);

grid.add(amountLabel, 0, row);
grid.add(amount, 1, row++);
grid.addRow(row++, content);
grid.addRow(row++, addressLabel, address);
grid.addRow(row++, memoLabel, memo);
grid.addRow(row++, amountLabel, amount);

getDialogPane().getStylesheets().add(CATE.DEFAULT_STYLESHEET);
getDialogPane().setContent(grid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.text.MessageFormat;
import java.util.ResourceBundle;
import javafx.scene.control.TextField;
import javafx.scene.text.Font;
import org.libdohj.cate.CATE;

/**
* Created by maxke on 14.01.2016.
Expand Down Expand Up @@ -108,6 +110,11 @@ private void setTransaction(final WalletTransaction transaction) {
valAmount.setText(wtx.getNetwork().format(amount).toString());

valID.setText(wtx.getTransaction().getHashAsString());

// Try to adapt the button sizes to match font
int buttonSize = (int) Math.round(Font.getDefault().getSize()) + 6;
btnCopyId.setMaxSize(buttonSize, buttonSize);
btnCopyTo.setMaxSize(buttonSize, buttonSize);
}

/**
Expand All @@ -117,8 +124,11 @@ public static Stage build(final ResourceBundle resources, final WalletTransactio
throws IOException {
final Stage stage = new Stage();
final FXMLLoader loader = new FXMLLoader(TransactionDetailsDialog.class.getResource("/txDetailsDialog.fxml"), resources);
final Scene scene = new Scene(loader.load());

scene.getStylesheets().add(CATE.DEFAULT_STYLESHEET);
stage.setScene(scene);

stage.setScene(new Scene(loader.load()));
final TransactionDetailsDialog controller = loader.getController();

controller.setTransaction(transaction);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/cate.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.label-heading {
-fx-font-weight: bold;
}
4 changes: 2 additions & 2 deletions src/main/resources/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<VBox.margin>
<Insets bottom="5.0" left="0.0" right="0.0" top="10.0"/>
</VBox.margin>
<Label text="%walletReceive.addressLabel">
<Label text="%walletReceive.addressLabel" styleClass="label-heading">
<HBox.margin>
<Insets bottom="0.0" left="0.0" right="10.0" top="0.0"/>
</HBox.margin>
Expand Down Expand Up @@ -69,7 +69,7 @@
<BorderPane.margin>
<Insets bottom="10.0" left="5.0" right="10.0" top="10.0"/>
</BorderPane.margin>
<Label text="%walletList.label" VBox.vgrow="NEVER" />
<Label text="%walletList.label" VBox.vgrow="NEVER" styleClass="label-heading" />
<TableView fx:id="walletList" VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="networkName" text="%walletList.networkName.thead" prefWidth="95" />
Expand Down
Loading

0 comments on commit 05738bb

Please sign in to comment.