various small fixes
This commit is contained in:
parent
c88212b7e1
commit
b6ec9ba52c
|
@ -53,6 +53,8 @@ public final class Main {
|
|||
}
|
||||
|
||||
private void initialize() {
|
||||
// create the login mask
|
||||
|
||||
this.loginMask = new LoginController();
|
||||
|
||||
// when we have logged in set the account viewer as window content
|
||||
|
@ -64,6 +66,8 @@ public final class Main {
|
|||
|
||||
this.window.getContentPane().add(loginMask.getView(), LOGIN_SCREEN_STRING_IDENT);
|
||||
|
||||
// create the account viewer
|
||||
|
||||
this.accountController = new AccountController();
|
||||
this.window.getContentPane().add(accountController.getView(), PROFILE_SCREEN_STRING_IDENT);
|
||||
}
|
||||
|
@ -72,7 +76,9 @@ public final class Main {
|
|||
this.bms = Loader.load();
|
||||
this.loginMask.setBankingManagementSystem(bms);
|
||||
showLoginScreen();
|
||||
this.window.setSize(800, 600);
|
||||
this.window.pack();
|
||||
this.window.setResizable(false);
|
||||
this.window.setLocationRelativeTo(null);
|
||||
this.window.setVisible(true);
|
||||
}
|
||||
|
||||
|
@ -90,13 +96,16 @@ public final class Main {
|
|||
getInstance().loadDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the extra font file used on the login button
|
||||
*/
|
||||
private static void loadExtraFont() {
|
||||
try {
|
||||
var font = Font.createFont(Font.TRUETYPE_FONT, IconProvider.class.getResourceAsStream("res/Circus.ttf"));
|
||||
var font = Font.createFont(Font.TRUETYPE_FONT, Objects.requireNonNull(IconProvider.class.getResourceAsStream("res/Circus.ttf")));
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(font);
|
||||
} catch (IOException | FontFormatException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException | FontFormatException | NullPointerException e) {
|
||||
LOGGER.warning("Could not load font file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,6 +182,7 @@ public final class Main {
|
|||
* Logs the user out of the database, hiding the main window.
|
||||
*/
|
||||
public void logout() {
|
||||
this.loginMask.logout();
|
||||
this.layout.show(this.window.getContentPane(), LOGIN_SCREEN_STRING_IDENT);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,16 @@ public class StringDecoder {
|
|||
return formatter;
|
||||
}
|
||||
|
||||
public static Object getIntegerNumberFormatter() {
|
||||
var formatter = new NumberFormatter();
|
||||
formatter.setValueClass(Integer.class);
|
||||
formatter.setMinimum(0d);
|
||||
formatter.setAllowsInvalid(true);
|
||||
formatter.setCommitsOnValidEdit(true);
|
||||
|
||||
return formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to convert the given string into a double value representing a percentage.
|
||||
* The output value will be in the range [0, 100]. Strings formatted without a percentage
|
||||
|
@ -129,7 +139,7 @@ public class StringDecoder {
|
|||
|
||||
var trimmed = name.trim();
|
||||
|
||||
var pattern = Pattern.compile("[^\\s]+", Pattern.CASE_INSENSITIVE);
|
||||
var pattern = Pattern.compile("[^\\d]+", Pattern.CASE_INSENSITIVE);
|
||||
var matcher = pattern.matcher(trimmed);
|
||||
if (matcher.find()) {
|
||||
return matcher.group();
|
||||
|
|
|
@ -26,7 +26,7 @@ public class IconProvider {
|
|||
return DEFAULT_IMAGE;
|
||||
}
|
||||
|
||||
public static Image getSetupIcon() {
|
||||
return loadIcon("res/login.jpg");
|
||||
public static Image getBackground() {
|
||||
return loadIcon("res/background.png");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package me.teridax.jcash.gui;
|
||||
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.DocumentFilter;
|
||||
import javax.swing.text.NumberFormatter;
|
||||
|
||||
public class NumberDocumentFilter extends DocumentFilter {
|
||||
@Override
|
||||
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
|
||||
super.insertString(fb, offset, string, attr);
|
||||
}
|
||||
|
||||
private String filterString(String text) {
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -32,6 +32,9 @@ public class Utils {
|
|||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
target.add(new JLabel(name, SwingConstants.RIGHT), constraints);
|
||||
|
||||
if (comp == null)
|
||||
return;
|
||||
|
||||
constraints.gridx = 2;
|
||||
constraints.gridy = row;
|
||||
constraints.weightx = 1;
|
||||
|
|
|
@ -57,13 +57,13 @@ public class LoginController {
|
|||
var blz = this.view.getBlz().getText();
|
||||
var iban = this.getIban();
|
||||
if (iban.isEmpty()) {
|
||||
Utils.error("no IBAN entered");
|
||||
Utils.error("invalid IBAN entered");
|
||||
return;
|
||||
}
|
||||
|
||||
var pin = this.getPin();
|
||||
if (pin.isEmpty()) {
|
||||
Utils.error("no PIN entered");
|
||||
Utils.error("invalid PIN entered");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -86,4 +86,8 @@ public class LoginController {
|
|||
public LoginData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
this.view.getPin().setText("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
package me.teridax.jcash.gui.login;
|
||||
|
||||
import me.teridax.jcash.decode.StringDecoder;
|
||||
import me.teridax.jcash.gui.IconProvider;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import static java.awt.BorderLayout.NORTH;
|
||||
import static javax.swing.SwingConstants.CENTER;
|
||||
import static me.teridax.jcash.gui.Utils.addGridBagRow;
|
||||
import static me.teridax.jcash.gui.Utils.addHeading;
|
||||
import static me.teridax.jcash.lang.Translator.translate;
|
||||
|
@ -33,41 +30,47 @@ public class LoginView extends JPanel {
|
|||
}
|
||||
|
||||
private void layoutComponents() {
|
||||
var content = new JPanel(new GridBagLayout());
|
||||
var content = new JLabel();
|
||||
content.setIcon(new ImageIcon(IconProvider.getBackground()));
|
||||
content.setLayout(new BorderLayout());
|
||||
|
||||
this.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
||||
this.setLayout(new BorderLayout(16, 16));
|
||||
var loginPane = new JPanel(new GridBagLayout());
|
||||
loginPane.setOpaque(true);
|
||||
content.add(loginPane, BorderLayout.CENTER);
|
||||
content.add(Box.createHorizontalStrut(400), BorderLayout.WEST);
|
||||
|
||||
this.setLayout(new BorderLayout(32, 32));
|
||||
this.add(new JScrollPane(content), BorderLayout.CENTER);
|
||||
this.add(new JLabel(addHeading(translate("Cashmachine")), CENTER), NORTH);
|
||||
|
||||
var constraints = new GridBagConstraints();
|
||||
|
||||
constraints.gridwidth = 4;
|
||||
constraints.insets = new Insets(12, 12, 12, 12);
|
||||
|
||||
addGridBagRow(constraints, content, blz, 1, translate("BLZ"));
|
||||
addGridBagRow(constraints, content, iban, 2, translate("IBAN"));
|
||||
addGridBagRow(constraints, content, pin, 3, translate("PIN"));
|
||||
addGridBagRow(constraints, loginPane, new JLabel(addHeading(translate("Cashmachine"))), 0, "");
|
||||
addGridBagRow(constraints, loginPane, blz, 1, translate("BLZ"));
|
||||
addGridBagRow(constraints, loginPane, iban, 2, translate("IBAN"));
|
||||
addGridBagRow(constraints, loginPane, pin, 3, translate("PIN"));
|
||||
|
||||
constraints.gridy = 4;
|
||||
constraints.anchor = GridBagConstraints.PAGE_END;
|
||||
constraints.weightx = 0;
|
||||
constraints.fill = GridBagConstraints.NONE;
|
||||
constraints.insets = new Insets(12, 12, 12, 12);
|
||||
content.add(login, constraints);
|
||||
constraints.insets = new Insets(0, 0, 0, 12);
|
||||
loginPane.add(login, constraints);
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
this.blz = new JFormattedTextField();
|
||||
this.iban = new JFormattedTextField(getNumberFormat());
|
||||
this.iban = new JFormattedTextField();
|
||||
this.pin = new JPasswordField();
|
||||
this.login = new JButton(translate("Login"));
|
||||
|
||||
this.login.setFont(new Font("Circus", Font.PLAIN, 72));
|
||||
this.login.setBackground(Color.RED);
|
||||
this.login.setForeground(Color.CYAN);
|
||||
this.login.setFont(new Font("Circus", Font.PLAIN, 28));
|
||||
this.login.setBackground(Color.CYAN);
|
||||
|
||||
restrictPasswordToDigits();
|
||||
restrictIbanInput();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,17 +91,22 @@ public class LoginView extends JPanel {
|
|||
});
|
||||
}
|
||||
|
||||
private NumberFormatter getNumberFormat() {
|
||||
var format = NumberFormat.getIntegerInstance();
|
||||
format.setGroupingUsed(false);
|
||||
/**
|
||||
* Adds a document filter onto {@link #iban} that filters out everything that is not a digit.
|
||||
* The filter also restricts the amount of digits that can be entered to {@link #MAX_PIN_DECIMAL_DIGITS}
|
||||
*/
|
||||
private void restrictIbanInput() {
|
||||
((AbstractDocument) this.iban.getDocument()).setDocumentFilter(new DocumentFilter() {
|
||||
@Override
|
||||
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
|
||||
throws BadLocationException {
|
||||
String newText = fb.getDocument().getText(0, fb.getDocument().getLength()) + text;
|
||||
|
||||
var formatter = new NumberFormatter(format);
|
||||
formatter.setValueClass(Integer.class);
|
||||
formatter.setMinimum(0);
|
||||
formatter.setMaximum(Integer.MAX_VALUE);
|
||||
formatter.setAllowsInvalid(false);
|
||||
|
||||
return formatter;
|
||||
if (newText.matches(String.format("\\d{1,%s}", MAX_PIN_DECIMAL_DIGITS))) {
|
||||
super.replace(fb, offset, length, text, attrs);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public JTextField getBlz() {
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.7 MiB |
|
@ -1,2 +1,4 @@
|
|||
https://pixabay.com/vectors/register-cash-register-modern-23666/
|
||||
![register](https://cdn.pixabay.com/photo/2012/04/01/17/34/register-23666_960_720.png)
|
||||
Font file
|
||||
https://www.dafont.com/de/circus.font?text=Login
|
Binary file not shown.
Before Width: | Height: | Size: 294 KiB |
Loading…
Reference in New Issue