From: Jérôme Benoit Date: Wed, 9 Jan 2019 15:29:22 +0000 (+0100) Subject: Add a label to all views. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=883508cad71557d375580ce52a4e093f131405db;p=Persons_Comparator.git Add a label to all views. Signed-off-by: Jérôme Benoit --- diff --git a/src/Eye.java b/src/Eye.java index 6edc8a5..a165830 100644 --- a/src/Eye.java +++ b/src/Eye.java @@ -1,10 +1,11 @@ import java.awt.Color; -import java.util.List; -import java.util.Arrays; public class Eye implements Comparable { private Color color; - private List 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 { setColor(color); } + public String[] getColorsList() { + return colorsList; + } + /** * @return */ @@ -31,7 +36,7 @@ public class Eye implements Comparable { 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 { * @return */ private boolean validateColor(String color) { - return colorList.contains(color); + for (String c : colorsList) { + if (color.equals(c)) { + return true; + } + } + return false; } /** diff --git a/src/EyeView.java b/src/EyeView.java index 8fbad26..f88e52e 100644 --- a/src/EyeView.java +++ b/src/EyeView.java @@ -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); } /** diff --git a/src/FirstnameView.java b/src/FirstnameView.java index e9c387b..3ff2977 100644 --- a/src/FirstnameView.java +++ b/src/FirstnameView.java @@ -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); } diff --git a/src/MainWindowsView.java b/src/MainWindowsView.java index 065c90d..2cda811 100644 --- a/src/MainWindowsView.java +++ b/src/MainWindowsView.java @@ -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. diff --git a/src/OriginView.java b/src/OriginView.java index 2fc4189..2402e5f 100644 --- a/src/OriginView.java +++ b/src/OriginView.java @@ -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) { diff --git a/src/PersonView.java b/src/PersonView.java index a328f47..76ccf5a 100644 --- a/src/PersonView.java +++ b/src/PersonView.java @@ -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; } /** diff --git a/src/SizeView.java b/src/SizeView.java index 1d280c5..d426cd9 100644 --- a/src/SizeView.java +++ b/src/SizeView.java @@ -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) { diff --git a/src/WeightView.java b/src/WeightView.java index 3e6d00f..239c437 100644 --- a/src/WeightView.java +++ b/src/WeightView.java @@ -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) {