From 6977e6142a133673703769e092e6283dda73cf4f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 9 Jan 2019 10:29:21 +0100 Subject: [PATCH] Structure the code to respect MVC design pattern. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .idea/kotlinc.xml | 6 ++++++ src/Eye.java | 7 +++--- src/EyeView.java | 15 +++++++++++++ src/Firstname.java | 1 + src/FirstnameView.java | 15 +++++++++++++ src/OriginView.java | 15 +++++++++++++ src/Person.java | 15 ++++++++++--- src/PersonView.java | 49 ++++++++++++++++++++++++++++++++++++++++++ src/SizeView.java | 15 +++++++++++++ src/WeightView.java | 15 +++++++++++++ 10 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 .idea/kotlinc.xml create mode 100644 src/EyeView.java create mode 100644 src/FirstnameView.java create mode 100644 src/OriginView.java create mode 100644 src/PersonView.java create mode 100644 src/SizeView.java create mode 100644 src/WeightView.java diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..8b7f4af --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/src/Eye.java b/src/Eye.java index 595d3d3..7d5d804 100644 --- a/src/Eye.java +++ b/src/Eye.java @@ -16,10 +16,11 @@ public class Eye implements Comparable { 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 index 0000000..06de469 --- /dev/null +++ b/src/EyeView.java @@ -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; + } +} diff --git a/src/Firstname.java b/src/Firstname.java index 91e8d75..a813cd3 100644 --- a/src/Firstname.java +++ b/src/Firstname.java @@ -11,6 +11,7 @@ public class Firstname implements Comparable { @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 index 0000000..18323cf --- /dev/null +++ b/src/FirstnameView.java @@ -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 index 0000000..58dec5d --- /dev/null +++ b/src/OriginView.java @@ -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; + } +} diff --git a/src/Person.java b/src/Person.java index f0e5c6b..9c30e56 100644 --- a/src/Person.java +++ b/src/Person.java @@ -1,14 +1,18 @@ -import javax.swing.*; +import java.util.Comparator; -public class Person extends JPanel implements Comparable { +public class Person implements Comparable, Comparator { 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 { + 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 index 0000000..9743d39 --- /dev/null +++ b/src/PersonView.java @@ -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 index 0000000..4e7e4a0 --- /dev/null +++ b/src/SizeView.java @@ -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 index 0000000..e6b69c5 --- /dev/null +++ b/src/WeightView.java @@ -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; + } +} -- 2.34.1