瀏覽代碼

more buttons

Phil 9 月之前
父節點
當前提交
fff41c855e

+ 55 - 16
src/main/java/com/example/application/data/DataThingy.java

@@ -14,6 +14,10 @@ public class DataThingy {
     private int sum_r = 0;
     private int set_l = 0;
     private int set_r = 0;
+    private int sum_l_tmp = 0;
+    private int sum_r_tmp = 0;
+    private int set_l_tmp = 0;
+    private int set_r_tmp = 0;
     private BufferedWriter writer;
     private ArrowValue valueObj = null;
 
@@ -21,54 +25,81 @@ public class DataThingy {
 
     }
 
+    public void reset(){
+        String[] empty = {"","",""};
+        sum_l = 0;
+        set_l = 0;
+        sum_r = 0;
+        set_r = 0;
+        write(empty,empty);
+    }
+
     private void calc(String[] vals_l, String[] vals_r){
         int tmp_l = 0;
         int tmp_r = 0;
         String[] vals_out_l = new String[3];
         String[] vals_out_r = new String[3];
 
+
+        sum_l_tmp = sum_l;
+        sum_r_tmp = sum_r;
+        set_l_tmp = set_l;
+        set_r_tmp = set_r;
+
         if(set){
             for(String s : vals_l){
-                if(s.equals("m"))
+                if(s.equals("m") || s.equals("0") ) {
+                    s = "M";
                     tmp_l += 0;
-                if(s.equals("x")){
+                    continue;
+                }
+                if(s.equals("x")|| s.equals("*")){
                     s = "10";
-                    tmp_l += 10;}
+                    tmp_l += 10;
+                    continue;
+                }
                 if(!s.isBlank())
                     tmp_l += Integer.valueOf(s);
             }
             for(String s : vals_r){
-                if(s.equals("m"))
+                if(s.equals("m") || s.equals("0") ) {
+                    s = "M";
                     tmp_r += 0;
-                if(s.equals("x")){
+                    continue;
+                }
+                if(s.equals("x") || s.equals("*")){
                     s = "10";
-                    tmp_r += 10;}
+                    tmp_r += 10;
+                    continue;
+                }
                 if(!s.isBlank())
                     tmp_r += Integer.valueOf(s);
             }
 
             if(tmp_l > tmp_r){
-                set_l += 2;
+                set_l_tmp += 2;
             }else if(tmp_l < tmp_r){
-                set_r += 2;
+                set_r_tmp += 2;
             }else{
                 if (isSetDone(vals_l,vals_r)){
-                    set_l ++;
-                    set_r ++;
+                    set_l_tmp ++;
+                    set_r_tmp ++;
                 }
             }
         }else{
             for(String s : vals_l){
-                if(s.equals("m"))
-                    tmp_l += 0;
-                if(s.equals("x")){
+                if(s.equals("m") || s.equals("0") ){
+                    s = "M";
+                    tmp_l += 0;}
+                if(s.equals("x") || s.equals("*")){
                     s = "10";
                     tmp_l += 10;}
                 if(!s.isBlank())
                     tmp_l += Integer.valueOf(s);
             }
             for(String s : vals_r){
-                if(s.equals("m")){
+                if(s.equals("m") || s.equals("0") ){
+                    s = "M";
                     tmp_r += 0;
                     break;}
                 if(s.equals("x")){
@@ -79,13 +110,21 @@ public class DataThingy {
                     tmp_r += Integer.valueOf(s);
             }
             if (isSetDone(vals_l,vals_r)){
-                sum_l += tmp_l;
-                sum_r += tmp_r;
+                sum_l_tmp += tmp_l;
+                sum_r_tmp += tmp_r;
             }
         }
 
     }
 
+    public void confirm(){
+        sum_l = sum_l_tmp;
+        sum_r = sum_r_tmp;
+        set_l = set_l_tmp;
+        set_r = set_r_tmp;
+
+    }
+
     private boolean isSetDone(String[] vals_l, String[] vals_r){
         for (String s : vals_l){
             if (s.isBlank())

+ 46 - 6
src/main/java/com/example/application/views/list/Spotting.java

@@ -1,19 +1,16 @@
 package com.example.application.views.list;
 
-import com.example.application.data.ArrowValue;
 import com.example.application.data.DataThingy;
-import com.google.gson.Gson;
 import com.vaadin.flow.component.Component;
-import com.vaadin.flow.component.Key;
+import com.vaadin.flow.component.button.Button;
 import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
 import com.vaadin.flow.component.orderedlayout.VerticalLayout;
+import com.vaadin.flow.component.select.Select;
 import com.vaadin.flow.component.textfield.TextField;
 import com.vaadin.flow.router.PageTitle;
 import com.vaadin.flow.router.Route;
 
 import java.io.BufferedWriter;
-import java.io.FileWriter;
-import java.io.IOException;
 
 
 @PageTitle("Spotting")
@@ -23,6 +20,17 @@ public class Spotting extends HorizontalLayout {
     private BufferedWriter writer;
     private DataThingy data = new DataThingy();
 
+    //controls
+    private Button reset = new Button("Reset");
+    private Button confirm = new Button("Bestätigt");
+    Select<String> mode = new Select<>();
+    Select<String> start = new Select<>();
+
+    HorizontalLayout top = new HorizontalLayout();
+    HorizontalLayout mid = new HorizontalLayout();
+    HorizontalLayout bottom = new HorizontalLayout();
+
+
     //left
     VerticalLayout left = new VerticalLayout(Alignment.END);
     TextField left_one = new TextField("Pfeil 1");
@@ -39,13 +47,28 @@ public class Spotting extends HorizontalLayout {
 
 
     public Spotting(){
+
         left.add(left_one,left_two,left_three);
         right.add(right_one,right_two,right_three);
         init_listeners();
-        add(left,right);
+        initSelect();
+
+        top.add(mode,start);
+        right.add(confirm);
+        bottom.add(reset);
+
+        //layouts
+        add(top,mid,bottom);
+        mid.add(left,right);
+
     }
 
     private void init_listeners(){
+        //buttons
+        reset.addClickListener(buttonClickEvent -> matchReset());
+
+
+        //arrow fields
         for (Component c : left.getChildren().toList()){
             if(c instanceof TextField){
                 ((TextField)c).addValueChangeListener(textFieldStringComponentValueChangeEvent -> write());
@@ -63,6 +86,23 @@ public class Spotting extends HorizontalLayout {
 
     }
 
+    private void initSelect(){
+        //mode
+        mode.setLabel("Modus");
+        mode.setItems("Komulativ","Satz");
+        mode.setValue("Satz");
+
+        //beginning archer
+        start.setLabel("Beginner:");
+        start.setItems("Links","Rechts");
+        start.setValue("Links");
+    }
+
+    private void matchReset(){
+        data.reset();
+
+    }
+
     private void write(){
         String[] vals_l = {left_one.getValue(),left_two.getValue(),left_three.getValue()};
         String[] vals_r = {right_one.getValue(),right_two.getValue(),right_three.getValue()};