gui #1

Merged
Ghost merged 5 commits from gui into main 2023-07-01 10:52:33 +00:00
13 changed files with 179 additions and 113 deletions
Showing only changes of commit b301f685a5 - Show all commits

View File

@ -7,5 +7,15 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component> </component>
</module> </module>

View File

@ -6,53 +6,79 @@ import me.teridax.jcash.gui.login.LoginController;
import javax.swing.*; import javax.swing.*;
public class Main { public final class Main {
/**
* Main instance of this program. Contains the primary window.
*/
private static Main instance; private static Main instance;
/**
* Primary window of this program
*/
private final JFrame window; private final JFrame window;
private Main() { private Main() {
window = new JFrame(); // create main window and set defaults
window.setTitle("Bankautomat"); this.window = new JFrame();
window.setLocationByPlatform(true); this.window.setTitle("Bankautomat");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.window.setLocationByPlatform(true);
this.window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} }
public static void main(String[] args) { public static void main(String[] args) {
// create main instance and show the login screen
instance(); instance();
getInstance().popLoginScreen(); getInstance().showLoginScreen();
} }
public static Main getInstance() { public static Main getInstance() {
return instance; return instance;
} }
/**
* Attempts to create a new instance of the singleton class Main.
* This method throws an exception if the class is already instantiated.
* @throws IllegalStateException if the class is already instantiated
* @pre the static instance of this class should be null.
* @post the static instance of this class will be set
*/
public static void instance() { public static void instance() {
if (instance == null) { if (null != instance)
instance = new Main(); throw new IllegalStateException(Main.class.getName() + " is already initialized");
return;
Main.instance = new Main();
} }
throw new IllegalStateException("me.teridax.jcash.Main is already initialized"); /**
} * Shows the open dialog for selecting a database file. After selection, it then proceeds to prompt login.
* Afterward the selected account can be managed.
public void popLoginScreen() { * This method is non-blocking and all work described is performed asynchronously on the AWT Event dispatcher.
*/
public void showLoginScreen() {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
// select db file
var path = Loader.load(); var path = Loader.load();
// read database and login
var login = new LoginController(path); var login = new LoginController(path);
// when we have logged in set the account viewer as window content
login.addAccountSelectionListener(account -> { login.addAccountSelectionListener(account -> {
var profileCont = new AccountController(account); var profileCont = new AccountController(account);
window.setContentPane(profileCont.getView()); this.window.setContentPane(profileCont.getView());
window.pack(); this.window.pack();
}); });
window.setContentPane(login.getView()); // we are not logged in yet, so show the login prompt on the main window
window.pack(); this.window.setContentPane(login.getView());
window.setVisible(true); this.window.pack();
this.window.setVisible(true);
}); });
} }
/**
* Logs the user out of the database, hiding the main window.
*/
public void logout() { public void logout() {
window.setContentPane(new JLabel("you're logged out")); window.setContentPane(new JLabel("you're logged out"));
window.setVisible(false); window.setVisible(false);

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.banking; package me.teridax.jcash.banking;
import me.teridax.jcash.decode.Decoder; import me.teridax.jcash.decode.StringUtils;
import java.util.Objects; import java.util.Objects;
@ -20,17 +20,17 @@ public abstract class Account {
public static Account fromColumns(String[] columns) { public static Account fromColumns(String[] columns) {
Objects.requireNonNull(columns); Objects.requireNonNull(columns);
var iban = Decoder.decodeUniqueIdentificationNumber(columns[0]); var iban = StringUtils.decodeUniqueIdentificationNumber(columns[0]);
var pin = Decoder.decodeUniqueIdentificationNumber(columns[1]); var pin = StringUtils.decodeUniqueIdentificationNumber(columns[1]);
var balance = Decoder.decodeCurrency(columns[2]); var balance = StringUtils.decodeCurrency(columns[2]);
var type = Decoder.decodeName(columns[3]); var type = StringUtils.decodeName(columns[3]);
try { try {
if (type.equals("Sparkonto")) { if (type.equals("Sparkonto")) {
var interest = Decoder.decodePercent(columns[4]); var interest = StringUtils.decodePercent(columns[4]);
return new SavingsAccount(iban, pin, balance, interest); return new SavingsAccount(iban, pin, balance, interest);
} else if (type.equals("Girokonto")) { } else if (type.equals("Girokonto")) {
var overdraft = Decoder.decodeCurrency(columns[5]); var overdraft = StringUtils.decodeCurrency(columns[5]);
return new Girokonto(iban, pin, balance, overdraft); return new Girokonto(iban, pin, balance, overdraft);
} else { } else {
throw new IllegalArgumentException("Invalid account type: " + type); throw new IllegalArgumentException("Invalid account type: " + type);

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.banking; package me.teridax.jcash.banking;
import me.teridax.jcash.decode.Decoder; import me.teridax.jcash.decode.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -34,7 +34,7 @@ public final class BankingManagementSystem {
var account = Account.fromColumns(tail(columns, 2)); var account = Account.fromColumns(tail(columns, 2));
var blz = Bank.validateBlz(columns[1]); var blz = Bank.validateBlz(columns[1]);
var name = Decoder.decodeName(columns[0]); var name = StringUtils.decodeName(columns[0]);
var bankOfLine = new Bank(blz, name); var bankOfLine = new Bank(blz, name);
var bankOfSet = bms.banks.stream().filter(b -> b.equals(bankOfLine)).findFirst(); var bankOfSet = bms.banks.stream().filter(b -> b.equals(bankOfLine)).findFirst();

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.banking; package me.teridax.jcash.banking;
import me.teridax.jcash.decode.Decoder; import me.teridax.jcash.decode.StringUtils;
import java.util.Objects; import java.util.Objects;
@ -28,12 +28,12 @@ public final class Owner {
if (columns.length != 6) if (columns.length != 6)
throw new IllegalArgumentException("Invalid number of columns: " + columns.length); throw new IllegalArgumentException("Invalid number of columns: " + columns.length);
var uid = Decoder.decodeUniqueIdentificationNumber(columns[0]); var uid = StringUtils.decodeUniqueIdentificationNumber(columns[0]);
var familyName = Decoder.decodeName(columns[1]); var familyName = StringUtils.decodeName(columns[1]);
var name = Decoder.decodeName(columns[2]); var name = StringUtils.decodeName(columns[2]);
var street = Decoder.decodeStreet(columns[3]); var street = StringUtils.decodeStreet(columns[3]);
var zip = Decoder.decodeUniqueIdentificationNumber(columns[4]); var zip = StringUtils.decodeUniqueIdentificationNumber(columns[4]);
var city = Decoder.decodeName(columns[5]); var city = StringUtils.decodeName(columns[5]);
return new Owner(uid, familyName, name, zip, city, street); return new Owner(uid, familyName, name, zip, city, street);
} }

View File

@ -4,7 +4,7 @@ import org.junit.Test;
import java.nio.file.Paths; import java.nio.file.Paths;
public class Testing { public class Tests {
@Test @Test
public void test() { public void test() {

View File

@ -10,11 +10,29 @@ import java.util.regex.Pattern;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
public class Decoder { /**
* Utility class for converting various single line strings into a specific data type according
* to a format mostly dictated by a locale.
*/
public class StringUtils {
/**
* Locale to use when converting strings
*/
private static final Locale LOCALE = Locale.GERMANY; private static final Locale LOCALE = Locale.GERMANY;
/**
* NumberFormat to use when converting strings
*/
public static final NumberFormat LOCAL_NUMBER_FORMAT = NumberFormat.getInstance(LOCALE); public static final NumberFormat LOCAL_NUMBER_FORMAT = NumberFormat.getInstance(LOCALE);
/**
* Attempts to convert the given string into a double value representing a percentage.
* The percentage is stored in the range [0,1] and can linearly be mapped to [0, 100] by multiplying with 100.
* @param number the string to convert
* @return the double value
* @throws IllegalArgumentException when the format is invalid
* @throws NullPointerException when the argument is null
*/
public static double decodePercent(String number) throws IllegalArgumentException, NullPointerException { public static double decodePercent(String number) throws IllegalArgumentException, NullPointerException {
Objects.requireNonNull(number); Objects.requireNonNull(number);
@ -28,6 +46,13 @@ public class Decoder {
} }
} }
/**
* Attempts to convert the given string into a currency value.
* @param currency the string to convert
* @return the double value
* @throws IllegalArgumentException when the format is invalid
* @throws NullPointerException when the argument is null
*/
public static double decodeCurrency(String currency) throws IllegalArgumentException, NullPointerException { public static double decodeCurrency(String currency) throws IllegalArgumentException, NullPointerException {
Objects.requireNonNull(currency); Objects.requireNonNull(currency);
@ -38,6 +63,14 @@ public class Decoder {
} }
} }
/**
* Attempts to convert the given string into universally unique number.
* This function does not check for duplicates. The number must be a positive integer.
* @param number the string to convert
* @return the integer serial number
* @throws IllegalArgumentException when the format is invalid
* @throws NullPointerException when the argument is null
*/
public static int decodeUniqueIdentificationNumber(String number) throws IllegalArgumentException, NullPointerException { public static int decodeUniqueIdentificationNumber(String number) throws IllegalArgumentException, NullPointerException {
Objects.requireNonNull(number); Objects.requireNonNull(number);
@ -56,6 +89,14 @@ public class Decoder {
} }
} }
/**
* Attempts to convert the given string into a name.
* This method performs validation and trimming.
* @param name the string to convert
* @return the qualified name
* @throws IllegalArgumentException when the format is invalid
* @throws NullPointerException when the argument is null
*/
public static String decodeName(String name) throws IllegalArgumentException, NullPointerException { public static String decodeName(String name) throws IllegalArgumentException, NullPointerException {
Objects.requireNonNull(name); Objects.requireNonNull(name);
@ -70,6 +111,13 @@ public class Decoder {
} }
} }
/**
* Attempts to convert the given string into a street and an optional house address.
* @param street the string to convert
* @return the address name
* @throws IllegalArgumentException when the format is invalid
* @throws NullPointerException when the argument is null
*/
public static String decodeStreet(String street) throws IllegalArgumentException, NullPointerException { public static String decodeStreet(String street) throws IllegalArgumentException, NullPointerException {
Objects.requireNonNull(street); Objects.requireNonNull(street);

View File

@ -6,10 +6,26 @@ import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File; import java.io.File;
import static javax.swing.JFileChooser.APPROVE_OPTION;
/**
* Utility class for loading a BMS configuration from a csv file.
*/
public class Loader { public class Loader {
/**
* Filter that only allows for files with *.csv extension
*/
private static final FileNameExtensionFilter FILE_FILTER = new FileNameExtensionFilter("Comma separated value spreadsheet", "csv", "CSV"); private static final FileNameExtensionFilter FILE_FILTER = new FileNameExtensionFilter("Comma separated value spreadsheet", "csv", "CSV");
private Loader() {}
/**
* Load a BMS from a csv file. Opens up a dialog which prompts the user to select a single file.
* Once the file is selected this function will try to parse the contents to a BMS and return the instance.
* @return a valid BMS instance loaded from a file
* @throws IllegalStateException When either no file is selected or the selected files content is invalid
*/
public static BankingManagementSystem load() throws IllegalStateException { public static BankingManagementSystem load() throws IllegalStateException {
var fileChooser = new JFileChooser(); var fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(false); fileChooser.setMultiSelectionEnabled(false);
@ -19,7 +35,8 @@ public class Loader {
fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setCurrentDirectory(new File("/home/teridax/IdeaProjects/JCash/res")); fileChooser.setCurrentDirectory(new File("/home/teridax/IdeaProjects/JCash/res"));
if (fileChooser.showDialog(null, "Load database") == JFileChooser.APPROVE_OPTION) { if (fileChooser.showDialog(null, "Load database") == APPROVE_OPTION) {
// parse file content
try { try {
return BankingManagementSystem.loadFromCsv(fileChooser.getSelectedFile().toPath()); return BankingManagementSystem.loadFromCsv(fileChooser.getSelectedFile().toPath());
} catch (Exception e) { } catch (Exception e) {

View File

@ -26,7 +26,7 @@ public class AccountController {
this.view.getLogout().addActionListener(e -> { this.view.getLogout().addActionListener(e -> {
Main.getInstance().logout(); Main.getInstance().logout();
Main.getInstance().popLoginScreen(); Main.getInstance().showLoginScreen();
}); });
this.view.getDeposit().addActionListener(e -> { this.view.getDeposit().addActionListener(e -> {

View File

@ -1,7 +1,7 @@
package me.teridax.jcash.gui.account; package me.teridax.jcash.gui.account;
import me.teridax.jcash.banking.*; import me.teridax.jcash.banking.*;
import me.teridax.jcash.decode.Decoder; import me.teridax.jcash.decode.StringUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -22,7 +22,6 @@ public class AccountView extends JPanel {
private JComboBox<String> accountSelection; private JComboBox<String> accountSelection;
private JPanel content; private JPanel content;
private JPanel buttonPanel;
private JButton logout; private JButton logout;
private JButton transfer; private JButton transfer;
@ -48,12 +47,12 @@ public class AccountView extends JPanel {
this.name.setText(owner.getName() + " " + owner.getFamilyName()); this.name.setText(owner.getName() + " " + owner.getFamilyName());
this.address.setText(owner.getStreet() + " " + owner.getCity()); this.address.setText(owner.getStreet() + " " + owner.getCity());
this.balance.setText(Decoder.LOCAL_NUMBER_FORMAT.format(account.getBalance()) + ""); this.balance.setText(StringUtils.LOCAL_NUMBER_FORMAT.format(account.getBalance()) + "");
this.type.setText(account.getClass().getSimpleName()); this.type.setText(account.getClass().getSimpleName());
if (account instanceof Girokonto) { if (account instanceof Girokonto) {
this.typeSpecialLabel.setText("Überziehungsbetrag"); this.typeSpecialLabel.setText("Überziehungsbetrag");
this.typeSpecialProperty.setText( Decoder.LOCAL_NUMBER_FORMAT.format(((Girokonto) account).getOverdraft()) + ""); this.typeSpecialProperty.setText( StringUtils.LOCAL_NUMBER_FORMAT.format(((Girokonto) account).getOverdraft()) + "");
} else if (account instanceof SavingsAccount) { } else if (account instanceof SavingsAccount) {
this.typeSpecialLabel.setText("Zinsbetrag"); this.typeSpecialLabel.setText("Zinsbetrag");
this.typeSpecialProperty.setText( ((SavingsAccount) account).getInterest() + " %" ); this.typeSpecialProperty.setText( ((SavingsAccount) account).getInterest() + " %" );
@ -70,7 +69,6 @@ public class AccountView extends JPanel {
private void createLayout() { private void createLayout() {
setLayout(new BorderLayout(16, 16)); setLayout(new BorderLayout(16, 16));
add(new JScrollPane(content), BorderLayout.CENTER); add(new JScrollPane(content), BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
content.setLayout(new GridBagLayout()); content.setLayout(new GridBagLayout());
var constraints = new GridBagConstraints(); var constraints = new GridBagConstraints();
@ -91,13 +89,17 @@ public class AccountView extends JPanel {
addInputRow(constraints, content, typeSpecialProperty, 7, typeSpecialLabel); addInputRow(constraints, content, typeSpecialProperty, 7, typeSpecialLabel);
addInputRow(constraints, content, balance, 8, new JLabel("Kontostand", SwingConstants.RIGHT)); addInputRow(constraints, content, balance, 8, new JLabel("Kontostand", SwingConstants.RIGHT));
var buttonRightPanel = new JPanel(); var buttonPanel = Box.createHorizontalBox();
buttonRightPanel.add(transfer); buttonPanel.add(Box.createHorizontalStrut(4));
buttonRightPanel.add(deposit); buttonPanel.add(logout);
buttonRightPanel.add(takeoff); buttonPanel.add(Box.createHorizontalStrut(4));
buttonPanel.add(Box.createGlue());
buttonPanel.add(logout, BorderLayout.LINE_START); buttonPanel.add(transfer);
buttonPanel.add(buttonRightPanel, BorderLayout.LINE_END); buttonPanel.add(Box.createHorizontalStrut(4));
buttonPanel.add(deposit);
buttonPanel.add(Box.createHorizontalStrut(4));
buttonPanel.add(takeoff);
add(buttonPanel, BorderLayout.SOUTH);
} }
private void createComponents() { private void createComponents() {
@ -124,7 +126,6 @@ public class AccountView extends JPanel {
this.accountSelection = new JComboBox<>(); this.accountSelection = new JComboBox<>();
this.content = new JPanel(); this.content = new JPanel();
this.buttonPanel = new JPanel(new BorderLayout());
this.logout = new JButton("Abmelden"); this.logout = new JButton("Abmelden");
this.transfer = new JButton("Überweisen"); this.transfer = new JButton("Überweisen");

View File

@ -1,6 +1,7 @@
package me.teridax.jcash.gui.takeoff; package me.teridax.jcash.gui.takeoff;
import me.teridax.jcash.banking.Account; import me.teridax.jcash.banking.Account;
import me.teridax.jcash.decode.StringUtils;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.NumberFormatter; import javax.swing.text.NumberFormatter;
@ -34,19 +35,6 @@ public class TakeoffView {
dialog.setVisible(true); dialog.setVisible(true);
} }
private NumberFormatter getNumberFormat(double balance) {
var format = NumberFormat.getNumberInstance(Locale.GERMANY);
format.setParseIntegerOnly(false);
format.setMaximumFractionDigits(2);
var formatter = new NumberFormatter(format);
formatter.setValueClass(Double.class);
formatter.setAllowsInvalid(true);
formatter.setMaximum(balance);
return formatter;
}
private void layoutComponents() { private void layoutComponents() {
dialog.getContentPane().setLayout(new GridBagLayout()); dialog.getContentPane().setLayout(new GridBagLayout());
@ -98,7 +86,7 @@ public class TakeoffView {
this.cancel = new JButton("Abbrechen"); this.cancel = new JButton("Abbrechen");
this.deposit = new JButton("Auszahlen"); this.deposit = new JButton("Auszahlen");
this.value = new JFormattedTextField(getNumberFormat(account.getBalance())); this.value = new JFormattedTextField(StringUtils.LOCAL_NUMBER_FORMAT);
this.dialog.setContentPane(new JPanel(new GridBagLayout())); this.dialog.setContentPane(new JPanel(new GridBagLayout()));
} }

View File

@ -6,7 +6,7 @@ public class TransferDialog {
public TransferDialog(Account account, Runnable onDeposit) { public TransferDialog(Account account, Runnable onDeposit) {
var view = new TransferView(account); var view = new TransferView(account);
view.getDeposit().addActionListener(e -> { view.getTransfer().addActionListener(e -> {
account.takeoff(view.getAmount()); account.takeoff(view.getAmount());
onDeposit.run(); onDeposit.run();
view.dispose(); view.dispose();

View File

@ -1,13 +1,12 @@
package me.teridax.jcash.gui.transfer; package me.teridax.jcash.gui.transfer;
import me.teridax.jcash.banking.Account; import me.teridax.jcash.banking.Account;
import me.teridax.jcash.decode.StringUtils;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.NumberFormatter;
import java.awt.*; import java.awt.*;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.ParseException; import java.text.ParseException;
import java.util.Locale;
import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog; import static javax.swing.JOptionPane.showMessageDialog;
@ -16,7 +15,7 @@ public class TransferView {
private JDialog dialog; private JDialog dialog;
private JButton cancel; private JButton cancel;
private JButton deposit; private JButton transfer;
private JFormattedTextField iban; private JFormattedTextField iban;
private JFormattedTextField blz; private JFormattedTextField blz;
private JFormattedTextField value; private JFormattedTextField value;
@ -28,45 +27,33 @@ public class TransferView {
public void showDialog() { public void showDialog() {
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setTitle("Deposit money"); dialog.setTitle("Transfer money");
dialog.pack(); dialog.pack();
dialog.setSize(dialog.getWidth() * 2, dialog.getHeight());
dialog.setResizable(false); dialog.setResizable(false);
dialog.setLocationRelativeTo(null); dialog.setLocationRelativeTo(null);
dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
dialog.setVisible(true); dialog.setVisible(true);
} }
private NumberFormatter getNumberFormat(double balance) {
var format = NumberFormat.getNumberInstance(Locale.GERMANY);
format.setParseIntegerOnly(false);
format.setMaximumFractionDigits(2);
var formatter = new NumberFormatter(format);
formatter.setValueClass(Double.class);
formatter.setAllowsInvalid(true);
formatter.setMaximum(balance);
return formatter;
}
private void layoutComponents() { private void layoutComponents() {
dialog.getContentPane().setLayout(new GridBagLayout());
var c = new GridBagConstraints(); var c = new GridBagConstraints();
c.gridx = 0; c.gridx = 0;
c.gridy = 0; c.gridy = 0;
c.weightx = 1; c.weightx = 1;
c.weighty = 1; c.weighty = 1;
c.fill = GridBagConstraints.BOTH; c.gridwidth = 3;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER; c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(10, 10, 10, 10); c.insets = new Insets(4, 4, 4, 4);
dialog.getContentPane().add(new JLabel("Takeoff money"), c); dialog.getContentPane().add(new JLabel("Transfer money"), c);
c.gridx = 0; c.gridx = 0;
c.gridy = 1; c.gridy = 1;
c.gridwidth = 1;
c.fill = GridBagConstraints.NONE; c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.LAST_LINE_END; c.anchor = GridBagConstraints.LAST_LINE_END;
c.insets = new Insets(10, 10, 10, 10);
c.weightx = 0; c.weightx = 0;
dialog.getContentPane().add(new JLabel("BLZ", SwingConstants.RIGHT), c); dialog.getContentPane().add(new JLabel("BLZ", SwingConstants.RIGHT), c);
@ -74,15 +61,13 @@ public class TransferView {
c.gridy = 1; c.gridy = 1;
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.LAST_LINE_END; c.anchor = GridBagConstraints.LAST_LINE_END;
c.insets = new Insets(10, 10, 10, 10); c.weightx = 0.5;
c.weightx = 1;
dialog.getContentPane().add(blz, c); dialog.getContentPane().add(blz, c);
c.gridx = 2; c.gridx = 2;
c.gridy = 1; c.gridy = 1;
c.fill = GridBagConstraints.NONE; c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.LAST_LINE_END; c.anchor = GridBagConstraints.LAST_LINE_END;
c.insets = new Insets(10, 10, 10, 10);
c.weightx = 0; c.weightx = 0;
dialog.getContentPane().add(new JLabel("IBAN", SwingConstants.RIGHT), c); dialog.getContentPane().add(new JLabel("IBAN", SwingConstants.RIGHT), c);
@ -90,7 +75,6 @@ public class TransferView {
c.gridy = 1; c.gridy = 1;
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.LAST_LINE_END; c.anchor = GridBagConstraints.LAST_LINE_END;
c.insets = new Insets(10, 10, 10, 10);
c.weightx = 1; c.weightx = 1;
dialog.getContentPane().add(iban, c); dialog.getContentPane().add(iban, c);
@ -98,7 +82,6 @@ public class TransferView {
c.gridy = 2; c.gridy = 2;
c.fill = GridBagConstraints.NONE; c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.LAST_LINE_END; c.anchor = GridBagConstraints.LAST_LINE_END;
c.insets = new Insets(10, 10, 10, 10);
c.weightx = 0; c.weightx = 0;
dialog.getContentPane().add(new JLabel("Betrag", SwingConstants.RIGHT), c); dialog.getContentPane().add(new JLabel("Betrag", SwingConstants.RIGHT), c);
@ -106,35 +89,28 @@ public class TransferView {
c.gridy = 2; c.gridy = 2;
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.LAST_LINE_END; c.anchor = GridBagConstraints.LAST_LINE_END;
c.insets = new Insets(10, 10, 10, 10); c.weightx = 0.5;
c.weightx = 1;
dialog.getContentPane().add(value, c); dialog.getContentPane().add(value, c);
c.gridx = 2; var buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
buttonPanel.add(cancel);
buttonPanel.add(transfer);
c.gridx = 0;
c.gridy = 3; c.gridy = 3;
c.gridwidth = 4;
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.LAST_LINE_END; c.anchor = GridBagConstraints.LAST_LINE_END;
c.insets = new Insets(10, 10, 10, 10); c.insets = new Insets(10, 10, 10, 10);
c.weightx = 1; dialog.getContentPane().add(buttonPanel, c);
dialog.getContentPane().add(cancel, c);
c.gridx = 3;
c.gridy = 3;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.LAST_LINE_END;
c.insets = new Insets(10, 10, 10, 10);
c.weightx = 1;
dialog.getContentPane().add(deposit, c);
dialog.getContentPane().add(value, c);
} }
private void createComponents(Account account) { private void createComponents(Account account) {
this.dialog = new JDialog(); this.dialog = new JDialog();
this.cancel = new JButton("Abbrechen"); this.cancel = new JButton("Cancel");
this.deposit = new JButton("Auszahlen"); this.transfer = new JButton("Transfer");
this.value = new JFormattedTextField(getNumberFormat(account.getBalance())); this.value = new JFormattedTextField(StringUtils.LOCAL_NUMBER_FORMAT);
this.iban = new JFormattedTextField(); this.iban = new JFormattedTextField();
this.blz = new JFormattedTextField(); this.blz = new JFormattedTextField();
@ -158,8 +134,8 @@ public class TransferView {
return cancel; return cancel;
} }
public JButton getDeposit() { public JButton getTransfer() {
return deposit; return transfer;
} }
public void dispose() { public void dispose() {