Skip to content

Commit 79ffd3f

Browse files
committed
- Fixed bugs, adapted to latest API.
1 parent 129316f commit 79ffd3f

File tree

15 files changed

+174
-182
lines changed

15 files changed

+174
-182
lines changed

javafx/money-fxdemo/src/main/java/org/javamoney/examples/fxdemo/AbstractFXMLComponent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ private void initComponent(String fxmlResource, String resourceBundle) {
9292
AnchorPane.setLeftAnchor(ui, 0d);
9393
AnchorPane.setRightAnchor(ui, 0d);
9494
} catch (IOException e) {
95+
e.printStackTrace();
9596
throw new IllegalArgumentException("Failed to load component: "
9697
+ this, e);
9798
}

javafx/money-fxdemo/src/main/java/org/javamoney/examples/fxdemo/MainScreen.fxml

Lines changed: 0 additions & 90 deletions
This file was deleted.

javafx/money-fxdemo/src/main/java/org/javamoney/examples/fxdemo/exchange/ConvertAmount.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public final static class ExamplePane extends AbstractSingleSamplePane {
4444
private CurrencySelector currencySelector1 = new CurrencySelector(
4545
"Term Currency");
4646
public ExamplePane() {
47+
exPane.getChildren().addAll(amountBox, currencySelector1);
4748
this.inputPane.getChildren().add(exPane);
4849

4950
AnchorPane.setLeftAnchor(exPane, 10d);

javafx/money-fxdemo/src/main/java/org/javamoney/examples/fxdemo/exchange/GetExchangeRate.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javafx.event.ActionEvent;
99
import javafx.scene.control.Button;
1010
import javafx.scene.control.Label;
11+
import javafx.scene.control.TextField;
1112
import javafx.scene.layout.AnchorPane;
1213
import javafx.scene.layout.VBox;
1314

@@ -40,10 +41,12 @@ public final static class ExamplePane extends AbstractSingleSamplePane {
4041
"Base Currency");
4142
private CurrencySelector currencySelector2 = new CurrencySelector(
4243
"Term Currency");
44+
private TextField rateProvider = new TextField();
4345

4446
public ExamplePane() {
4547
final Button swapButton = new Button("Swap");
4648
swapButton.setDisable(true);
49+
exPane.getChildren().addAll(currencySelector1, currencySelector2, new Label("Rate Provider(s)"), rateProvider);
4750
this.inputPane.getChildren().add(exPane);
4851
AnchorPane.setLeftAnchor(exPane, 10d);
4952
AnchorPane.setTopAnchor(exPane, 10d);
@@ -54,8 +57,17 @@ public void handle(ActionEvent action) {
5457
final StringWriter sw = new StringWriter();
5558
final PrintWriter pw = new PrintWriter(sw);
5659
try {
57-
ExchangeRateProvider prov = MonetaryConversions
60+
ExchangeRateProvider prov = null;
61+
String rp = rateProvider.getText();
62+
if(rp==null || rp.trim().isEmpty()){
63+
prov = MonetaryConversions
5864
.getExchangeRateProvider();
65+
}
66+
else{
67+
String[] rps = rp.split(",");
68+
prov = MonetaryConversions
69+
.getExchangeRateProvider(rps);
70+
}
5971
ExchangeRate rate = prov.getExchangeRate(
6072
currencySelector1.getCurrency(),
6173
currencySelector2.getCurrency());

javafx/money-fxdemo/src/main/java/org/javamoney/examples/fxdemo/format/FormatAmount.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void handle(ActionEvent action) {
7272
if (placement != null) {
7373
styleBuilder.setCurrencyStyle(placement);
7474
}
75-
MonetaryAmountFormat formatter = MonetaryFormats.getAmountFormat(Locale.getDefault());
75+
MonetaryAmountFormat formatter = MonetaryFormats.getAmountFormat(styleBuilder.create());
7676
pw.println("Formatted Amount");
7777
pw.println("----------------");
7878
if (formatter != null) {
@@ -92,8 +92,8 @@ public void handle(ActionEvent action) {
9292
fillButton
9393
.setOnAction(new javafx.event.EventHandler<ActionEvent>() {
9494
public void handle(ActionEvent action) {
95-
MonetaryAmount amount = Money.of("INR",
96-
12345678901234567890.123d);
95+
MonetaryAmount amount = Money.of(
96+
12345678901234567890.123d,"INR");
9797
amount1.setAmount(amount);
9898
groupSizes.setText("3,2");
9999
}

javafx/money-fxdemo/src/main/java/org/javamoney/examples/fxdemo/widgets/AmountEntry.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.javamoney.examples.fxdemo.widgets;
22

33
import java.math.BigDecimal;
4+
import java.util.Collections;
45

56
import javafx.fxml.FXML;
67
import javafx.scene.control.ChoiceBox;
@@ -40,6 +41,11 @@ public AmountEntry(String title) {
4041
amountTitle.setText(title);
4142
numberType.getItems().add("BigDecimal");
4243
numberType.getItems().add("Long");
44+
for(CurrencyUnit cu: MonetaryCurrencies.getCurrencies()){
45+
codeBox.getItems().add(cu.getCurrencyCode());
46+
}
47+
Collections.sort(codeBox.getItems());
48+
codeBox.getSelectionModel().select("CHF");
4349
}
4450

4551
public MonetaryAmount getAmount() {
@@ -50,10 +56,10 @@ public MonetaryAmount getAmount() {
5056
BigDecimal dec = new BigDecimal(numberValue.getText());
5157
if (typeClass != null) {
5258
if ("Long".equals(typeClass)) {
53-
return FastMoney.of(currency, dec);
59+
return FastMoney.of(dec,currency);
5460
}
5561
}
56-
return Money.of(currency, dec);
62+
return Money.of(dec,currency);
5763
}
5864

5965
public void setAmount(MonetaryAmount amount) {

javafx/money-fxdemo/src/main/java/org/javamoney/examples/fxdemo/widgets/CurrencySelector.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import org.javamoney.examples.fxdemo.AbstractFXMLComponent;
1212

13+
import java.util.Collections;
14+
1315

1416
/**
1517
* @author Anatole Tresch
@@ -18,18 +20,23 @@
1820
public class CurrencySelector extends AbstractFXMLComponent implements CurrencySupplier {
1921

2022
@FXML
21-
private ComboBox<CurrencyUnit> codeBox;
23+
private ComboBox<String> codeBox;
2224

2325
@FXML
2426
private Label currencyTitle;
2527

2628
public CurrencySelector(String title) {
2729
super("/org/javamoney/examples/fxdemo/widgets/CurrencySelector.fxml");
2830
this.currencyTitle.setText(title);
29-
}
31+
for(CurrencyUnit cu: MonetaryCurrencies.getCurrencies()){
32+
codeBox.getItems().add(cu.getCurrencyCode());
33+
}
34+
Collections.sort(codeBox.getItems());
35+
codeBox.getSelectionModel().select("CHF");
36+
}
3037

3138
public CurrencyUnit getCurrency() {
32-
String code = codeBox.getSelectionModel().getSelectedItem().getCurrencyCode();
39+
String code = codeBox.getSelectionModel().getSelectedItem();
3340
if (code != null) {
3441
return MonetaryCurrencies.getCurrency(code);
3542
}
@@ -38,7 +45,7 @@ public CurrencyUnit getCurrency() {
3845

3946
public void setCurrency(CurrencyUnit unit) {
4047
if (unit != null) {
41-
codeBox.getSelectionModel().select(unit);
48+
codeBox.getSelectionModel().select(unit.getCurrencyCode());
4249
} else {
4350
codeBox.getSelectionModel().clearSelection();
4451
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import java.lang.*?>
4+
<?import java.util.*?>
5+
<?import javafx.geometry.*?>
6+
<?import javafx.scene.control.*?>
7+
<?import javafx.scene.effect.*?>
8+
<?import javafx.scene.layout.*?>
9+
<?import javafx.scene.paint.*?>
10+
<?import javafx.scene.text.*?>
11+
12+
<BorderPane fx:id="BorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: rgb(30,60,30);" xmlns:fx="http://javafx.com/fxml">
13+
<center>
14+
<SplitPane dividerPositions="0.2993311036789298" focusTraversable="true" prefHeight="160.0" prefWidth="200.0">
15+
<items>
16+
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
17+
<children>
18+
<Accordion AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
19+
<expandedPane>
20+
<TitledPane fx:id="x2" animated="false" expanded="true" text="Extensions">
21+
<content>
22+
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
23+
<children>
24+
<VBox fx:id="extensionExamplesMenu" prefHeight="100.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
25+
</children>
26+
</AnchorPane>
27+
</content>
28+
</TitledPane>
29+
</expandedPane>
30+
<panes>
31+
<TitledPane fx:id="x1" alignment="TOP_LEFT" animated="false" text="Core Examples">
32+
<content>
33+
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
34+
<children>
35+
<VBox id="coreExamplesMenu" prefHeight="100.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
36+
</children>
37+
</AnchorPane>
38+
</content>
39+
</TitledPane>
40+
<TitledPane animated="false" text="Conversion">
41+
<content>
42+
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
43+
<children>
44+
<VBox fx:id="conversionExamplesMenu" prefHeight="100.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
45+
</children>
46+
</AnchorPane>
47+
</content>
48+
</TitledPane>
49+
<TitledPane animated="false" expanded="false" styleClass="first-titled-pane" text="Formatting">
50+
<content>
51+
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
52+
<children>
53+
<VBox fx:id="formattingExamplesMenu" prefHeight="100.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
54+
</children>
55+
</AnchorPane>
56+
</content>
57+
</TitledPane>
58+
<fx:reference source="x2" />
59+
</panes>
60+
</Accordion>
61+
</children>
62+
</AnchorPane>
63+
<AnchorPane fx:id="sampleContainer" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
64+
</items>
65+
</SplitPane>
66+
</center>
67+
<top>
68+
<HBox prefHeight="69.0" prefWidth="600.0">
69+
<children>
70+
<VBox id="VBox" alignment="TOP_LEFT" spacing="5.0">
71+
<children>
72+
<Label text="JavaMoney Demo Application" textFill="#ffe4cc">
73+
<effect>
74+
<Reflection bottomOpacity="0.23809523809523808" fraction="0.376984126984127" topOffset="-5.0" />
75+
</effect>
76+
<font>
77+
<Font name="System Bold" size="20.0" />
78+
</font>
79+
</Label>
80+
<Label text="This application shows several use cases related to JSR 354 Money &amp; Currency." textFill="WHITE" />
81+
</children>
82+
<padding>
83+
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
84+
</padding>
85+
</VBox>
86+
<Label fx:id="clockLabel" alignment="CENTER_RIGHT" contentDisplay="RIGHT" maxWidth="1.7976931348623157E308" text="00:00:00" textAlignment="RIGHT" textFill="WHITE" textOverrun="CLIP" HBox.hgrow="ALWAYS" />
87+
</children>
88+
</HBox>
89+
</top>
90+
</BorderPane>

javafx/money-fxdemo/src/main/resources/org/javamoney/examples/fxdemo/widgets/AmountEntry.fxml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@
1717
<Insets />
1818
</StackPane.margin>
1919
</Rectangle>
20-
<BorderPane name="BorderPane">
20+
<BorderPane id="BorderPane">
2121
<center>
2222
<VBox maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0">
2323
<children>
2424
<Label text="Currency Code" VBox.margin="$x2">
2525
<labelFor>
26-
<ComboBox fx:name="codeBox" editable="true" maxWidth="1.7976931348623157E308" VBox.margin="$x1" VBox.vgrow="NEVER" />
26+
<ComboBox fx:id="codeBox" editable="true" maxWidth="1.7976931348623157E308" VBox.margin="$x1" VBox.vgrow="NEVER" />
2727
</labelFor>
2828
</Label>
2929
<fx:reference source="codeBox" />
3030
<Label text="Amount (number)" VBox.margin="$x2">
3131
<labelFor>
32-
<TextField fx:name="numberValue" alignment="CENTER_RIGHT" maxWidth="1.7976931348623157E308" minHeight="28.0" minWidth="30.0" prefWidth="-1.0" promptText="Enter a number" text="0.0" VBox.margin="$x1" VBox.vgrow="NEVER" />
32+
<TextField fx:id="numberValue" alignment="CENTER_RIGHT" maxWidth="1.7976931348623157E308" minHeight="28.0" minWidth="30.0" prefWidth="-1.0" promptText="Enter a number" text="0.0" VBox.margin="$x1" VBox.vgrow="NEVER" />
3333
</labelFor>
3434
</Label>
3535
<fx:reference source="numberValue" />
3636
<Label text="Numeric Representation" VBox.margin="$x2">
3737
<labelFor>
38-
<ChoiceBox fx:name="numberType" maxWidth="1.7976931348623157E308" VBox.margin="$x1" VBox.vgrow="NEVER" />
38+
<ChoiceBox fx:id="numberType" maxWidth="1.7976931348623157E308" VBox.margin="$x1" VBox.vgrow="NEVER" />
3939
</labelFor>
4040
</Label>
4141
<fx:reference source="numberType" />
4242
</children>
4343
</VBox>
4444
</center>
4545
<top>
46-
<Label fx:name="amountTitle" text="Monetary Amount" BorderPane.alignment="TOP_LEFT" BorderPane.margin="$x1">
46+
<Label fx:id="amountTitle" text="Monetary Amount" BorderPane.alignment="TOP_LEFT" BorderPane.margin="$x1">
4747
<font>
4848
<Font name="System Bold" size="14.0" />
4949
</font>

0 commit comments

Comments
 (0)