aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiederick de Vries <diederick@diederickdevries.net>2019-04-16 20:55:53 +0200
committerDiederick de Vries <diederick@diederickdevries.net>2019-04-16 21:00:03 +0200
commitcba71bace3a58425d7feb7aaaa8f16bc7508467a (patch)
tree1c992b7aaf455b7df32c825eb9ccb9f8e738ebcf
parent5fcf506711b7d8cf270a27ce28a479cc73e20366 (diff)
downloadcalcusaurus-feat/further-questions.tar.gz
calcusaurus-feat/further-questions.tar.bz2
calcusaurus-feat/further-questions.zip
fix: text alignment and solution parserfeat/further-questions
-rw-r--r--src/main/java/net/diederickdevries/calcusaurus/util/NumberUtil.java2
-rw-r--r--src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.form4
-rw-r--r--src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.java6
-rw-r--r--src/main/java/net/diederickdevries/calcusaurus/view/CalcusaurusFrame.java1
-rw-r--r--src/test/java/net/diederickdevries/calcusaurus/util/NumberUtilTest.java9
5 files changed, 11 insertions, 11 deletions
diff --git a/src/main/java/net/diederickdevries/calcusaurus/util/NumberUtil.java b/src/main/java/net/diederickdevries/calcusaurus/util/NumberUtil.java
index 4b60ecd..bb20e3e 100644
--- a/src/main/java/net/diederickdevries/calcusaurus/util/NumberUtil.java
+++ b/src/main/java/net/diederickdevries/calcusaurus/util/NumberUtil.java
@@ -33,7 +33,7 @@ public class NumberUtil
33 if (s.isBlank()) { 33 if (s.isBlank()) {
34 throw new IllegalArgumentException("Input cannot be blank"); 34 throw new IllegalArgumentException("Input cannot be blank");
35 } 35 }
36 return Integer.parseInt(s.replaceAll("[^\\d.]", "")); 36 return Integer.parseInt(s.strip());
37 } 37 }
38 38
39 /** 39 /**
diff --git a/src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.form b/src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.form
index 3adfcfd..40d86a1 100644
--- a/src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.form
+++ b/src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.form
@@ -17,8 +17,8 @@
17 <DimensionLayout dim="0"> 17 <DimensionLayout dim="0">
18 <Group type="103" groupAlignment="0" attributes="0"> 18 <Group type="103" groupAlignment="0" attributes="0">
19 <Group type="102" alignment="0" attributes="0"> 19 <Group type="102" alignment="0" attributes="0">
20 <EmptySpace min="-2" pref="55" max="-2" attributes="0"/> 20 <EmptySpace min="-2" pref="35" max="-2" attributes="0"/>
21 <Component id="label" min="-2" pref="136" max="-2" attributes="0"/> 21 <Component id="label" min="-2" pref="156" max="-2" attributes="0"/>
22 <EmptySpace max="-2" attributes="0"/> 22 <EmptySpace max="-2" attributes="0"/>
23 <Component id="responseTextField" min="-2" pref="49" max="-2" attributes="0"/> 23 <Component id="responseTextField" min="-2" pref="49" max="-2" attributes="0"/>
24 <EmptySpace pref="148" max="32767" attributes="0"/> 24 <EmptySpace pref="148" max="32767" attributes="0"/>
diff --git a/src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.java b/src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.java
index 470c10b..d3cb4e9 100644
--- a/src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.java
+++ b/src/main/java/net/diederickdevries/calcusaurus/view/AssignmentPanel.java
@@ -19,8 +19,6 @@ package net.diederickdevries.calcusaurus.view;
19 19
20import java.awt.Color; 20import java.awt.Color;
21import java.awt.event.ActionListener; 21import java.awt.event.ActionListener;
22import java.util.logging.Level;
23import java.util.logging.Logger;
24import net.diederickdevries.calcusaurus.model.Assignment; 22import net.diederickdevries.calcusaurus.model.Assignment;
25import net.diederickdevries.calcusaurus.util.RequestFocusListener; 23import net.diederickdevries.calcusaurus.util.RequestFocusListener;
26 24
@@ -75,8 +73,8 @@ public final class AssignmentPanel extends javax.swing.JPanel
75 layout.setHorizontalGroup( 73 layout.setHorizontalGroup(
76 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 74 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
77 .addGroup(layout.createSequentialGroup() 75 .addGroup(layout.createSequentialGroup()
78 .addGap(55, 55, 55) 76 .addGap(35, 35, 35)
79 .addComponent(label, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE) 77 .addComponent(label, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
80 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 78 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
81 .addComponent(responseTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) 79 .addComponent(responseTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
82 .addContainerGap(148, Short.MAX_VALUE)) 80 .addContainerGap(148, Short.MAX_VALUE))
diff --git a/src/main/java/net/diederickdevries/calcusaurus/view/CalcusaurusFrame.java b/src/main/java/net/diederickdevries/calcusaurus/view/CalcusaurusFrame.java
index f820577..62cf9ea 100644
--- a/src/main/java/net/diederickdevries/calcusaurus/view/CalcusaurusFrame.java
+++ b/src/main/java/net/diederickdevries/calcusaurus/view/CalcusaurusFrame.java
@@ -164,6 +164,7 @@ public final class CalcusaurusFrame extends javax.swing.JFrame
164 Integer solution = null; 164 Integer solution = null;
165 try { 165 try {
166 solution = NumberUtil.getInt(textField.getText()); 166 solution = NumberUtil.getInt(textField.getText());
167 System.out.println(textField.getText() + " -> " + solution);
167 } catch (IllegalArgumentException e) { 168 } catch (IllegalArgumentException e) {
168 textField.setText(""); 169 textField.setText("");
169 } 170 }
diff --git a/src/test/java/net/diederickdevries/calcusaurus/util/NumberUtilTest.java b/src/test/java/net/diederickdevries/calcusaurus/util/NumberUtilTest.java
index 0e2a17f..0b5befb 100644
--- a/src/test/java/net/diederickdevries/calcusaurus/util/NumberUtilTest.java
+++ b/src/test/java/net/diederickdevries/calcusaurus/util/NumberUtilTest.java
@@ -33,13 +33,14 @@ public class NumberUtilTest
33 public void testGetInt() 33 public void testGetInt()
34 { 34 {
35 assertEquals(NumberUtil.getInt("1"), 1); 35 assertEquals(NumberUtil.getInt("1"), 1);
36 assertEquals(NumberUtil.getInt("1s"), 1); 36 assertEquals(NumberUtil.getInt("1"), 1);
37 assertEquals(NumberUtil.getInt("1 "), 1); 37 assertEquals(NumberUtil.getInt("1 "), 1);
38 assertEquals(NumberUtil.getInt(" 1"), 1); 38 assertEquals(NumberUtil.getInt(" 1"), 1);
39 assertEquals(NumberUtil.getInt(" 1 "), 1); 39 assertEquals(NumberUtil.getInt(" 1 "), 1);
40 assertEquals(NumberUtil.getInt("14["), 14); 40 assertEquals(NumberUtil.getInt("14"), 14);
41 assertEquals(NumberUtil.getInt("14[5"), 145); 41 assertEquals(NumberUtil.getInt("145"), 145);
42 assertEquals(NumberUtil.getInt("14,5"), 145); 42 assertEquals(NumberUtil.getInt("145"), 145);
43 assertEquals(NumberUtil.getInt("-14"), -14);
43 } 44 }
44 45
45 @org.junit.jupiter.api.Test 46 @org.junit.jupiter.api.Test