Structure the code to respect MVC design pattern.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 9 Jan 2019 09:29:21 +0000 (10:29 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 9 Jan 2019 09:29:21 +0000 (10:29 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
.idea/kotlinc.xml [new file with mode: 0644]
src/Eye.java
src/EyeView.java [new file with mode: 0644]
src/Firstname.java
src/FirstnameView.java [new file with mode: 0644]
src/OriginView.java [new file with mode: 0644]
src/Person.java
src/PersonView.java [new file with mode: 0644]
src/SizeView.java [new file with mode: 0644]
src/WeightView.java [new file with mode: 0644]

diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644 (file)
index 0000000..8b7f4af
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Kotlin2JsCompilerArguments">
+    <option name="sourceMapEmbedSources" />
+  </component>
+</project>
\ No newline at end of file
index 595d3d3990da3e71fa5cbf403ffde791e81704f5..7d5d80401879470faa13c37560b705f4d1fedd63 100644 (file)
@@ -16,10 +16,11 @@ public class Eye implements Comparable<Eye> {
 
     public void setColor(String color) {
         if (validateColor(color)) {
-            if (color != "brown")
-                this.color = Color.getColor(color);
-            else
+            if (color.equals("brown"))
                 this.color = new Color(88, 41, 0);
+            else
+                this.color = Color.getColor(color);
+
         } else {
             throw new IllegalArgumentException("Color must be " + colorList.toString());
         }
diff --git a/src/EyeView.java b/src/EyeView.java
new file mode 100644 (file)
index 0000000..06de469
--- /dev/null
@@ -0,0 +1,15 @@
+public class EyeView {
+    private Eye eyeObj;
+
+    EyeView(Eye eyeObj) {
+        setEyeObj(eyeObj);
+    }
+
+    public Eye getEyeObj() {
+        return eyeObj;
+    }
+
+    public void setEyeObj(Eye eyeObj) {
+        this.eyeObj = eyeObj;
+    }
+}
index 91e8d75012fe828bf042323a99d08f6899ccbf7a..a813cd3555a4ea0d6bdc3e2da2ed8ee94ff9e660 100644 (file)
@@ -11,6 +11,7 @@ public class Firstname implements Comparable<Firstname> {
 
     @Override
     public int compareTo(Firstname firstname) {
+        //return StringUtils.getLevenshteinDistance(this.getFirstname(), firstname.getFirstname());
         return 0;
     }
 }
diff --git a/src/FirstnameView.java b/src/FirstnameView.java
new file mode 100644 (file)
index 0000000..18323cf
--- /dev/null
@@ -0,0 +1,15 @@
+public class FirstnameView {
+    private Firstname firstnameObj;
+
+    FirstnameView(Firstname firstnameObj) {
+        setFirstnameObj(firstnameObj);
+    }
+
+    public Firstname getFirstnameObj() {
+        return firstnameObj;
+    }
+
+    public void setFirstnameObj(Firstname firstnameObj) {
+        this.firstnameObj = firstnameObj;
+    }
+}
diff --git a/src/OriginView.java b/src/OriginView.java
new file mode 100644 (file)
index 0000000..58dec5d
--- /dev/null
@@ -0,0 +1,15 @@
+public class OriginView {
+    private Origin originObj;
+
+    OriginView(Origin originObj) {
+        setOriginObj(originObj);
+    }
+
+    public Origin getOriginObj() {
+        return originObj;
+    }
+
+    public void setOriginObj(Origin originObj) {
+        this.originObj = originObj;
+    }
+}
index f0e5c6bc58fd5f3c8e24de2692e854b80ee96e97..9c30e56c9e4e5d3055f7e1bea97466520a86597a 100644 (file)
@@ -1,14 +1,18 @@
-import javax.swing.*;
+import java.util.Comparator;
 
-public class Person extends JPanel implements Comparable<Person> {
+public class Person implements Comparable<Person>, Comparator<Person> {
     private Firstname firstname;
     private Origin origin;
     private Size size;
     private Weight weight;
     private Eye eye;
 
-    Person(Firstname firstname) {
+    Person(Firstname firstname, Origin origin, Size size, Weight weight, Eye eye) {
         setFirstname(firstname);
+        setOrigin(origin);
+        setPersonSize(size);
+        setWeight(weight);
+        setEye(eye);
     }
 
     public void setFirstname(Firstname firstname) {
@@ -57,4 +61,9 @@ public class Person extends JPanel implements Comparable<Person> {
                 + this.size.compareTo(person.getPersonSize()) + this.weight.compareTo(person.getWeight())
                 + this.eye.compareTo(person.getEye());
     }
+
+    @Override
+    public int compare(Person person, Person t1) {
+        return 0;
+    }
 }
diff --git a/src/PersonView.java b/src/PersonView.java
new file mode 100644 (file)
index 0000000..9743d39
--- /dev/null
@@ -0,0 +1,49 @@
+import javax.swing.*;
+
+public class PersonView extends JPanel {
+    private FirstnameView firstnameView;
+    private OriginView originView;
+    private SizeView sizeView;
+    private WeightView weightView;
+    private EyeView eyeView;
+
+    public FirstnameView getFirstnameView() {
+        return firstnameView;
+    }
+
+    public void setFirstnameView(FirstnameView firstnameView) {
+        this.firstnameView = firstnameView;
+    }
+
+    public OriginView getOriginView() {
+        return originView;
+    }
+
+    public void setOriginView(OriginView originView) {
+        this.originView = originView;
+    }
+
+    public SizeView getSizeView() {
+        return sizeView;
+    }
+
+    public void setSizeView(SizeView sizeView) {
+        this.sizeView = sizeView;
+    }
+
+    public WeightView getWeightView() {
+        return weightView;
+    }
+
+    public void setWeightView(EyeView eyeView) {
+        this.eyeView = eyeView;
+    }
+
+    public void setEyeView(EyeView eyeView) {
+        this.eyeView = eyeView;
+    }
+
+    public EyeView getEyeView() {
+        return eyeView;
+    }
+}
diff --git a/src/SizeView.java b/src/SizeView.java
new file mode 100644 (file)
index 0000000..4e7e4a0
--- /dev/null
@@ -0,0 +1,15 @@
+public class SizeView {
+    private Size sizeObj;
+
+    SizeView(Size sizeObj) {
+        setSizeObj(sizeObj);
+    }
+
+    public Size getSizeObj() {
+        return sizeObj;
+    }
+
+    public void setSizeObj(Size sizeObj) {
+        this.sizeObj = sizeObj;
+    }
+}
diff --git a/src/WeightView.java b/src/WeightView.java
new file mode 100644 (file)
index 0000000..e6b69c5
--- /dev/null
@@ -0,0 +1,15 @@
+public class WeightView {
+    private Weight weightObj;
+
+    WeightView(Weight weightObj) {
+        setWeightObj(weightObj);
+    }
+
+    public Weight getWeightObj() {
+        return weightObj;
+    }
+
+    public void setWeightObj(Weight weightObj) {
+        this.weightObj = weightObj;
+    }
+}