From 64418ffb240e30ec22560aafd85b07792ac71c80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 18 Jan 2019 20:06:30 +0100 Subject: [PATCH] Rearrange code. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/Country.java | 24 ++++++++++++------------ src/MainWindowsView.java | 8 ++++---- src/Person.java | 32 ++++++++++++++++---------------- src/PersonRightPanel.java | 10 +++++----- src/RegionView.java | 13 ++++++------- 5 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Country.java b/src/Country.java index 7f2486b..2e35db2 100644 --- a/src/Country.java +++ b/src/Country.java @@ -27,42 +27,42 @@ public class Country { setFlag(flag); } - public void setName(String name) { - this.name = name; - } - public String getName() { return name; } - public void setRegion(String region) { - this.region = region; + public void setName(String name) { + this.name = name; } - public void setLat(double lat) { - this.lat = lat; + public void setRegion(String region) { + this.region = region; } public double getLat() { return lat; } - public void setLng(double lng) { - this.lng = lng; + public void setLat(double lat) { + this.lat = lat; } public double getLng() { return lng; } - public void setFlag(String flag) { - this.flag = flag; + public void setLng(double lng) { + this.lng = lng; } public String getFlag() { return flag; } + public void setFlag(String flag) { + this.flag = flag; + } + public int distanceTo(Country country) { if ((this.getLat() == country.getLat()) && (this.getLng() == country.getLng())) { return 0; diff --git a/src/MainWindowsView.java b/src/MainWindowsView.java index 7037921..18e1ba1 100644 --- a/src/MainWindowsView.java +++ b/src/MainWindowsView.java @@ -13,6 +13,10 @@ public class MainWindowsView extends JFrame { private MainWindowsView() { } + public static MainWindowsView getInstance() { + return ourInstance; + } + public void setMainWindowsView(String title, PersonView personView) { this.currentPersonView = personView; Container panel = getContentPane(); @@ -42,10 +46,6 @@ public class MainWindowsView extends JFrame { panel.add(getCurrentPersonView().getPersonPanel(), BorderLayout.CENTER); } - public static MainWindowsView getInstance() { - return ourInstance; - } - public PersonView getCurrentPersonView() { return currentPersonView; } diff --git a/src/Person.java b/src/Person.java index f843250..6e5ff40 100644 --- a/src/Person.java +++ b/src/Person.java @@ -29,62 +29,62 @@ public class Person implements Comparator { setDistanceFromReference(0); } - public void setFirstname(Firstname firstname) { - this.firstname = firstname; - } - public Firstname getFirstname() { return firstname; } - public void setOrigin(Origin origin) { - this.origin = origin; + public void setFirstname(Firstname firstname) { + this.firstname = firstname; } public Origin getOrigin() { return origin; } - public void setCountry(Country country) { - this.country = country; + public void setOrigin(Origin origin) { + this.origin = origin; } public Country getCountry() { return country; } - public void setPersonSize(Size size) { - this.size = size; + public void setCountry(Country country) { + this.country = country; } public Size getPersonSize() { return size; } - public void setWeight(Weight weight) { - this.weight = weight; + public void setPersonSize(Size size) { + this.size = size; } public Weight getWeight() { return weight; } - public void setEye(Eye eye) { - this.eye = eye; + public void setWeight(Weight weight) { + this.weight = weight; } public Eye getEye() { return eye; } - public void setDistanceFromReference(Integer distanceFromReference) { - this.distanceFromReference = distanceFromReference; + public void setEye(Eye eye) { + this.eye = eye; } public Integer getDistanceFromReference() { return distanceFromReference; } + public void setDistanceFromReference(Integer distanceFromReference) { + this.distanceFromReference = distanceFromReference; + } + @Override public String toString() { return "Person{" + diff --git a/src/PersonRightPanel.java b/src/PersonRightPanel.java index 8814863..7cbf331 100644 --- a/src/PersonRightPanel.java +++ b/src/PersonRightPanel.java @@ -19,14 +19,14 @@ public class PersonRightPanel extends JPanel { } } - public void setContentText(String contentText) { - this.contentText = contentText; - } - public String getContentText() { return contentText; } + public void setContentText(String contentText) { + this.contentText = contentText; + } + //FIXME: redraw on resizing /*@Override public void paint(Graphics g) { @@ -48,7 +48,7 @@ public class PersonRightPanel extends JPanel { g2d.setColor(personObj.getEye().getColor()); g2d.fillOval(50, 50, 6, 3); g2d.fillOval(62, 50, 6, 3); - // Weigth + // Weight g2d.setColor(Color.black); g2d.fillOval(44, 80, 30, (personObj.getWeight().getWeight() * 30) / 250); } diff --git a/src/RegionView.java b/src/RegionView.java index 42941ac..c5921d6 100644 --- a/src/RegionView.java +++ b/src/RegionView.java @@ -56,7 +56,7 @@ public class RegionView extends JPanel { add(new JScrollPane(tree)); } - public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) { + private void sortTree(DefaultMutableTreeNode root) { { for (int i = 0; i < root.getChildCount() - 1; i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i); @@ -72,10 +72,9 @@ public class RegionView extends JPanel { } } if (node.getChildCount() > 0) { - sortTree(node); + this.sortTree(node); } } - return root; } } @@ -83,11 +82,11 @@ public class RegionView extends JPanel { return tree; } - public void setRegionObj(Region regionObj) { - this.regionObj = regionObj; - } - public Region getRegionObj() { return regionObj; } + + public void setRegionObj(Region regionObj) { + this.regionObj = regionObj; + } } -- 2.34.1