diff --git a/Herd.java b/Herd.java index 15da9a5..16cf1f5 100755 --- a/Herd.java +++ b/Herd.java @@ -72,6 +72,11 @@ if (c != null) herd.remove(c); } + public Cow[] getParents() + { + return parents; + } + public boolean isParent(int id) { if ((parents[0] != null && parents[0].getID() == id) || @@ -122,6 +127,11 @@ if (noffs == 2) offspring[1] = new Cow(parents[0], parents[1]); } + public Cow[] getCalves() + { + return offspring; + } + public boolean isCalf(int id) { if ((offspring[0] != null && offspring[0].getID() == id) || diff --git a/Herd.java b/Herd.java index 15da9a5..16cf1f5 100755 --- a/Herd.java +++ b/Herd.java @@ -72,6 +72,11 @@ if (c != null) herd.remove(c); } + public Cow[] getParents() + { + return parents; + } + public boolean isParent(int id) { if ((parents[0] != null && parents[0].getID() == id) || @@ -122,6 +127,11 @@ if (noffs == 2) offspring[1] = new Cow(parents[0], parents[1]); } + public Cow[] getCalves() + { + return offspring; + } + public boolean isCalf(int id) { if ((offspring[0] != null && offspring[0].getID() == id) || diff --git a/MooBreeder.java b/MooBreeder.java index ad35f6b..756bb30 100755 --- a/MooBreeder.java +++ b/MooBreeder.java @@ -16,6 +16,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; +import javax.swing.border.*; public class MooBreeder extends JFrame implements MouseListener { @@ -55,7 +56,7 @@ save = new JMenuItem("Save"); load = new JMenuItem("Load"); reset = new JMenuItem("Reset"); - quit = new JMenuItem("Exit"); + quit = new JMenuItem("Quit"); help = new JMenuItem("Help"); about = new JMenuItem("About"); //TODO save,load,help @@ -109,11 +110,20 @@ { //TODO this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.X_AXIS)); + //Create the left half of the window with the herd box + JPanel herdBorderPanel = new JPanel(new BorderLayout()); + JLabel herdlabel = new JLabel("Your current herd:", JLabel.CENTER); + herdBorderPanel.add(herdlabel, BorderLayout.NORTH); herdBox = new Box(BoxLayout.Y_AXIS); herdScroller = new JScrollPane(herdBox, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); herdScroller.setWheelScrollingEnabled(true); - this.add(herdScroller); + herdBorderPanel.add(herdScroller, BorderLayout.CENTER); + herdBorderPanel.add(Box.createVerticalStrut(25), BorderLayout.SOUTH); + herdBorderPanel.add(Box.createHorizontalStrut(25), BorderLayout.EAST); + herdBorderPanel.add(Box.createHorizontalStrut(25), BorderLayout.WEST); + this.add(herdBorderPanel); + //Create the right half of the window with the breeding interface breedPanel = new JPanel(new GridLayout(2,2)); fatherBox = new Box(BoxLayout.Y_AXIS); motherBox = new Box(BoxLayout.Y_AXIS); @@ -132,15 +142,12 @@ updateHerdBox(); updateParentBox(); updateOffspringBox(); + this.repaint(); } private void updateHerdBox() { - //TODO herdBox.removeAll(); - JLabel label = new JLabel("Your current herd:"); - herdBox.add(label); - herdBox.add(Box.createVerticalStrut(3)); for (int c = 0; c < Herd.getInstance().size(); c++) { Box cowBox = getCowBox(Herd.getInstance().getNthCow(c)); herdBox.add(cowBox); @@ -151,21 +158,52 @@ private void updateParentBox() { - //TODO - JLabel dl = new JLabel("Father"); - JLabel ml = new JLabel("Mother"); + fatherBox.removeAll(); + motherBox.removeAll(); + //Label boxes + JLabel dl = new JLabel("Father:"); + JLabel ml = new JLabel("Mother:"); fatherBox.add(dl); motherBox.add(ml); + //Include information boxes + Cow[] parents = Herd.getInstance().getParents(); + if (parents[0] != null) { + Box db = getCowBox(parents[0]); + fatherBox.add(Box.createVerticalStrut(10)); + fatherBox.add(db); + } + if (parents[1] != null) { + Box mb = getCowBox(parents[1]); + motherBox.add(Box.createVerticalStrut(10)); + motherBox.add(mb); + } + fatherBox.validate(); + motherBox.validate(); } private void updateOffspringBox() { - //TODO - JLabel l1 = new JLabel("Calf 1"); - JLabel l2 = new JLabel("Calf 2"); + calf1Box.removeAll(); + calf2Box.removeAll(); + JLabel l1 = new JLabel("Calf 1:"); + JLabel l2 = new JLabel("Calf 2:"); calf1Box.add(l1); calf2Box.add(l2); + //Include information boxes + Cow[] calves = Herd.getInstance().getCalves(); + if (calves[0] != null) { + Box db = getCowBox(calves[0]); + fatherBox.add(Box.createVerticalStrut(10)); + fatherBox.add(db); + } + if (calves[1] != null) { + Box mb = getCowBox(calves[1]); + motherBox.add(Box.createVerticalStrut(10)); + motherBox.add(mb); + } + calf1Box.validate(); + calf2Box.validate(); } private void resetGame() @@ -183,13 +221,15 @@ " Father "+c.getParents()[0]+ " Mother "+c.getParents()[1]); //TODO display cow traits and rating - cowBox.add(Box.createGlue()); + //cowBox.add(Box.createGlue()); cowBox.add(name); cowBox.add(Box.createVerticalStrut(3)); - cowBox.add(Box.createGlue()); + //cowBox.add(Box.createGlue()); cowBox.add(genealogy); //TODO insert remaining labels - cowBox.add(Box.createGlue()); + //cowBox.add(Box.createGlue()); + cowBox.add(Box.createVerticalStrut(5)); + cowBox.setBorder(new BevelBorder(BevelBorder.RAISED)); cowBox.addMouseListener(this); return cowBox; } @@ -240,13 +280,14 @@ JMenuItem item1 = new JMenuItem(); JMenuItem item2 = new JMenuItem(); //Change item labels and actions depending on context + //FIXME Problem with animals occurring both in the herd list and the parent slots item1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mouseMainAction(selection); //always the same } }); if (Herd.getInstance().isParent(selection)) { - item1.setText("Remove parent"); + item1.setText("Remove as parent"); } else if (Herd.getInstance().isCalf(selection)) { item1.setText("Add calf to herd"); @@ -259,12 +300,12 @@ } else { item1.setText("Select for breeding"); - item2.setText("Delete from herd"); + item2.setText("Remove from herd"); item2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - String question = "Delete "+Herd.getInstance(). + String question = "Remove "+Herd.getInstance(). getCow(selection).getName()+" from herd?"; - int confirm = JOptionPane.showConfirmDialog(null, question, "Delete cow?", + int confirm = JOptionPane.showConfirmDialog(null, question, "Remove animal?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(confirm == JOptionPane.YES_OPTION)