Add a label to all views.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 9 Jan 2019 15:29:22 +0000 (16:29 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 9 Jan 2019 15:29:22 +0000 (16:29 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/Eye.java
src/EyeView.java
src/FirstnameView.java
src/MainWindowsView.java
src/OriginView.java
src/PersonView.java
src/SizeView.java
src/WeightView.java

index 6edc8a563d99af95b373270e2936592551bcf2c7..a165830f8a1f3cb67354d4c3a97fe48951798c90 100644 (file)
@@ -1,10 +1,11 @@
 import java.awt.Color;
-import java.util.List;
-import java.util.Arrays;
 
 public class Eye implements Comparable<Eye> {
     private Color color;
-    private List<String> colorList = Arrays.asList("black", "green", "blue", "brown");
+    private String[] colorsList = {"black", "green", "blue", "brown"};
+
+    Eye() {
+    }
 
     /**
      * @param color
@@ -13,6 +14,10 @@ public class Eye implements Comparable<Eye> {
         setColor(color);
     }
 
+    public String[] getColorsList() {
+        return colorsList;
+    }
+
     /**
      * @return
      */
@@ -31,7 +36,7 @@ public class Eye implements Comparable<Eye> {
                 this.color = Color.getColor(color);
 
         } else {
-            throw new IllegalArgumentException("Color must be " + colorList.toString());
+            throw new IllegalArgumentException("Color must be " + colorsList);
         }
     }
 
@@ -40,7 +45,12 @@ public class Eye implements Comparable<Eye> {
      * @return
      */
     private boolean validateColor(String color) {
-        return colorList.contains(color);
+        for (String c : colorsList) {
+            if (color.equals(c)) {
+                return true;
+            }
+        }
+        return false;
     }
 
     /**
index 8fbad2603d11a629691351c76e7fceb7d5e09099..f88e52eaab8428cf6f785fe8a00c2edd26d1701d 100644 (file)
@@ -2,8 +2,17 @@ import javax.swing.*;
 
 public class EyeView extends JComponent {
     private Eye eyeObj;
+    private JLabel label;
+    private JList colorsList;
 
     EyeView() {
+        setEyeObj(new Eye());
+        this.label = new JLabel();
+        this.label.setText("Eyes color");
+        this.colorsList = new JList(getEyeObj().getColorsList());
+        this.colorsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        add(label);
+        add(colorsList);
     }
 
     /**
index e9c387baa50ec142367facc28972e5c83820ba5c..3ff29770357320cdeaff4b132cbc0208c6878874 100644 (file)
@@ -9,6 +9,9 @@ public class FirstnameView extends JComponent {
         this.label = new JLabel();
         this.label.setText("Firstname");
         this.textField = new JTextField(length);
+        if (firstnameObj != null) {
+            this.textField.setText(this.firstnameObj.getFirstname());
+        }
         add(label);
         add(textField);
     }
index 065c90d8050f0deb9203ce7733bb26b49b64c029..2cda81104f0e394e85ab59d41b331397c268dddc 100644 (file)
@@ -10,6 +10,7 @@ public class MainWindowsView extends JFrame {
         setLocationRelativeTo(null);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
+        //Main pane
         JPanel panel = new PersonView();
 
         //Get all Swing/AWT primitive components in the views and add them to the panel.
index 2fc4189df734149123d81aba4f2ed3a0c491190e..2402e5fea6232f49326437c443ec1c4b1bb3a611 100644 (file)
@@ -2,8 +2,12 @@ import javax.swing.*;
 
 public class OriginView extends JComponent {
     private Origin originObj;
+    private JLabel label;
 
     OriginView() {
+        this.label = new JLabel();
+        this.label.setText("Origin");
+        add(label);
     }
 
     OriginView(Origin originObj) {
index a328f4797cec544983318d873bfa18c079b02352..76ccf5add249ff3fa272ef80d3ad2f4e5093b6c8 100644 (file)
@@ -1,6 +1,7 @@
 import javax.swing.*;
 
 public class PersonView extends JPanel {
+    private Person personObj;
     private FirstnameView firstnameView;
     private OriginView originView;
     private SizeView sizeView;
@@ -21,12 +22,20 @@ public class PersonView extends JPanel {
         add(eyeView);
     }
 
-    PersonView(FirstnameView firstnameView, OriginView originView, SizeView sizeView, WeightView weightView, EyeView eyeView) {
+   /* PersonView(FirstnameView firstnameView, OriginView originView, SizeView sizeView, WeightView weightView, EyeView eyeView) {
         setFirstnameView(firstnameView);
         setOriginView(originView);
         setSizeView(sizeView);
         setWeightView(weightView);
         setEyeView(eyeView);
+    }*/
+
+    public Person getPersonObj() {
+        return personObj;
+    }
+
+    public void setPersonObj(Person personObj) {
+        this.personObj = personObj;
     }
 
     /**
index 1d280c5c76c7bab68a0badf13c77cca98ffb0e02..d426cd9dd6932c83f63d2d3c9c37b54546ac37a7 100644 (file)
@@ -2,8 +2,12 @@ import javax.swing.*;
 
 public class SizeView extends JComponent {
     private Size sizeObj;
+    private JLabel label;
 
     SizeView() {
+        this.label = new JLabel();
+        this.label.setText("Size");
+        add(label);
     }
 
     SizeView(Size sizeObj) {
index 3e6d00f668a0270f8f0f9ee5b42e88410e8116f1..239c437556dededfbbaf3839a0dba0b5c528d89b 100644 (file)
@@ -2,8 +2,12 @@ import javax.swing.*;
 
 public class WeightView extends JComponent {
     private Weight weightObj;
+    private JLabel label;
 
     WeightView() {
+        this.label = new JLabel();
+        this.label.setText("Weight");
+        add(label);
     }
 
     WeightView(Weight weightObj) {