예제 #1
0
        /// <summary>
        /// button click handler for adding MarineLife to theModel
        /// </summary>
        public void sumbitAdd(Object sender, EventArgs e)
        {
            int        X, Y, Height, Width;
            MarineLife aMarineLife;

            // fields left blank
            if (tba_x.Text.ToString() == "" || tba_y.Text.ToString() == "" || tba_height.Text.ToString() == "" || tba_width.Text.ToString() == "")
            {
                MessageBox.Show("Please enter X and Y co-ordinates and the Width and Height.", "Required Data Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // No fields left blank
            else
            {
                // If X and Y positions are valid
                if (InputValid(tba_x.Text.ToString(), tba_y.Text.ToString()))
                {
                    X      = Convert.ToInt32(tba_x.Text.ToString());
                    Y      = Convert.ToInt32(tba_y.Text.ToString());
                    Width  = Convert.ToInt32(tba_width.Text.ToString());
                    Height = Convert.ToInt32(tba_height.Text.ToString());

                    if (rba_fish.Checked)
                    {
                        // red fish
                        if (rba_red.Checked)
                        {
                            aMarineLife = new Fish(X, Y, Width, Height, FishType.red);
                            theModel.AddMarineLife(aMarineLife);
                        }
                        // green fish
                        else if (rba_green.Checked)
                        {
                            aMarineLife = new Fish(X, Y, Width, Height, FishType.green);
                            theModel.AddMarineLife(aMarineLife);
                        }
                        // blue fish
                        else if (rba_blue.Checked)
                        {
                            aMarineLife = new Fish(X, Y, Width, Height, FishType.blue);
                            theModel.AddMarineLife(aMarineLife);
                        }
                        // orange fish
                        else
                        {
                            aMarineLife = new Fish(X, Y, Width, Height, FishType.orange);
                            theModel.AddMarineLife(aMarineLife);
                        }
                    }
                    else if (rba_crustacean.Checked)
                    {
                        // crab crustacean
                        if (rba_crab.Checked)
                        {
                            aMarineLife = new Crustacean(X, Y, Width, Height, CrustaceanType.Crab);
                            theModel.AddMarineLife(aMarineLife);
                        }
                        // shrimp crustacean
                        else if (rba_shrimp.Checked)
                        {
                            aMarineLife = new Crustacean(X, Y, Width, Height, CrustaceanType.Shrimp);
                            theModel.AddMarineLife(aMarineLife);
                        }
                        // lobster crustacean
                        else
                        {
                            aMarineLife = new Crustacean(X, Y, Width, Height, CrustaceanType.Lobster);
                            theModel.AddMarineLife(aMarineLife);
                        }
                    }
                    else
                    {
                        // baleen whale
                        if (rba_baleen.Checked)
                        {
                            aMarineLife = new Whale(X, Y, Width, Height, WhaleType.Baleen);
                            theModel.AddMarineLife(aMarineLife);
                        }
                        // toothed whale
                        else
                        {
                            aMarineLife = new Whale(X, Y, Width, Height, WhaleType.Toothed);
                            theModel.AddMarineLife(aMarineLife);
                        }
                    }
                }
                add_panel.Enabled = false;
            }
        }
예제 #2
0
 /// <summary>
 /// right click menu handler - edit
 /// </summary>
 public void miEdit_Click(Object sender, EventArgs e)
 {
     Console.WriteLine("Edit");
     if (topCritter != null)
     {
         edit_panel.Show();
         add_panel.Hide();
         edit_panel.Enabled = true;
         editCritter        = topCritter;
         tb_width.Text      = Convert.ToString(editCritter.ml_width);
         tb_height.Text     = Convert.ToString(editCritter.ml_height);
         tb_x.Text          = Convert.ToString(editCritter.xPosition);
         tb_y.Text          = Convert.ToString(editCritter.yPosition);
         if (editCritter.ml_type == "Whale")
         {
             rb_whale.Checked = true;
             Whale theWhale = (Whale)editCritter;
             if (theWhale.getWhaleType() == WhaleType.Baleen)
             {
                 rb_baleen.Checked = true;
             }
             else
             {
                 rb_toothed.Checked = true;
             }
             rb_whale.Enabled       = true;
             pnl_whale.Enabled      = true;
             rb_fish.Enabled        = false;
             pnl_fish.Enabled       = false;
             rb_crustacean.Enabled  = false;
             pnl_crustacean.Enabled = false;
         }
         else if (editCritter.ml_type == "Fish")
         {
             rb_fish.Checked = true;
             Fish theFish = (Fish)editCritter;
             if (theFish.getFishType() == FishType.blue)
             {
                 rb_blue.Checked = true;
             }
             else if (theFish.getFishType() == FishType.green)
             {
                 rb_green.Checked = true;
             }
             else if (theFish.getFishType() == FishType.red)
             {
                 rb_red.Checked = true;
             }
             else
             {
                 rb_orange.Checked = true;
             }
             rb_fish.Enabled        = true;
             pnl_fish.Enabled       = true;
             rb_whale.Enabled       = false;
             pnl_whale.Enabled      = false;
             rb_crustacean.Enabled  = false;
             pnl_crustacean.Enabled = false;
         }
         else
         {
             rb_crustacean.Checked = true;
             Crustacean theCrustacean = (Crustacean)editCritter;
             if (theCrustacean.getCrustaceanType() == CrustaceanType.Crab)
             {
                 rb_crab.Checked = true;
             }
             else if (theCrustacean.getCrustaceanType() == CrustaceanType.Lobster)
             {
                 rb_lobster.Checked = true;
             }
             else
             {
                 rb_shrimp.Checked = true;
             }
             rb_crustacean.Enabled  = true;
             pnl_crustacean.Enabled = true;
             rb_whale.Enabled       = false;
             pnl_whale.Enabled      = false;
             rb_fish.Enabled        = false;
             pnl_fish.Enabled       = false;
         }
     }
     else
     {
         MessageBox.Show("There was no marine-life within the selected region", "Error");
     }
 }
예제 #3
0
 /// <summary>
 /// commits MarineLife object modifications to theModel and updates display
 /// </summary>
 public void submitEdit_btnClicked(object sender, EventArgs e)
 {
     if (targetIndex != -1 && editCritter != null)
     {
         editCritter.yPosition = Convert.ToInt32(tbe_y.Text);
         editCritter.xPosition = Convert.ToInt32(tbe_x.Text);
         editCritter.ml_height = Convert.ToInt32(tbe_height.Text);
         editCritter.ml_width  = Convert.ToInt32(tbe_width.Text);
         if (editCritter.ml_type == "Whale")
         {
             Whale theWhale = (Whale)editCritter;
             if (rbe_baleen.Checked == true)
             {
                 theWhale.setWhaleType(WhaleType.Baleen);
             }
             else
             {
                 theWhale.setWhaleType(WhaleType.Toothed);
             }
             editCritter = theWhale;
         }
         else if (editCritter.ml_type == "Fish")
         {
             Fish theFish = (Fish)editCritter;
             if (rbe_red.Checked == true)
             {
                 theFish.setFishType(FishType.red);
             }
             else if (rbe_blue.Checked == true)
             {
                 theFish.setFishType(FishType.blue);
             }
             else if (rbe_green.Checked == true)
             {
                 theFish.setFishType(FishType.green);
             }
             else
             {
                 theFish.setFishType(FishType.orange);
             }
             editCritter = theFish;
         }
         else
         {
             Crustacean theCrustacean = (Crustacean)editCritter;
             if (rbe_crab.Checked == true)
             {
                 theCrustacean.setCrustaceanType(CrustaceanType.Crab);
             }
             else if (rbe_lobster.Checked == true)
             {
                 theCrustacean.setCrustaceanType(CrustaceanType.Lobster);
             }
             else
             {
                 theCrustacean.setCrustaceanType(CrustaceanType.Shrimp);
             }
             editCritter = theCrustacean;
         }
         theModel.UpdateViews();
     }
     edit_panel.Hide();
     add_panel.Show();
 }
예제 #4
0
 /// <summary>
 /// submits changes made to MarineLife object to theModel
 /// </summary>
 public void sumbitEdits(Object sender, EventArgs e)
 {
     if (editCritter != null)
     {
         editCritter.yPosition = Convert.ToInt32(tb_y.Text);
         editCritter.xPosition = Convert.ToInt32(tb_x.Text);
         editCritter.ml_height = Convert.ToInt32(tb_height.Text);
         editCritter.ml_width  = Convert.ToInt32(tb_width.Text);
         if (editCritter.ml_type == "Whale")
         {
             Whale theWhale = (Whale)editCritter;
             if (rb_baleen.Checked == true)
             {
                 theWhale.setWhaleType(WhaleType.Baleen);
             }
             else
             {
                 theWhale.setWhaleType(WhaleType.Toothed);
             }
             editCritter = theWhale;
         }
         else if (editCritter.ml_type == "Fish")
         {
             Fish theFish = (Fish)editCritter;
             if (rb_red.Checked == true)
             {
                 theFish.setFishType(FishType.red);
             }
             else if (rb_blue.Checked == true)
             {
                 theFish.setFishType(FishType.blue);
             }
             else if (rb_green.Checked == true)
             {
                 theFish.setFishType(FishType.green);
             }
             else
             {
                 theFish.setFishType(FishType.orange);
             }
             editCritter = theFish;
         }
         else
         {
             Crustacean theCrustacean = (Crustacean)editCritter;
             if (rb_crab.Checked == true)
             {
                 theCrustacean.setCrustaceanType(CrustaceanType.Crab);
             }
             else if (rb_lobster.Checked == true)
             {
                 theCrustacean.setCrustaceanType(CrustaceanType.Lobster);
             }
             else
             {
                 theCrustacean.setCrustaceanType(CrustaceanType.Shrimp);
             }
             editCritter = theCrustacean;
         }
         topCritter = editCritter;
         theModel.UpdateViews();
         edit_panel.Enabled = false;
     }
 }
예제 #5
0
        /// <summary>
        /// display interface for changing MarineLife object attributes
        /// </summary>
        public void editMarineLife_btnClicked(Object Sender, EventArgs e)
        {
            Console.WriteLine("Edit");
            if (lb_all_marine_life.SelectedIndex != -1)
            {
                targetIndex = lb_all_marine_life.SelectedIndex;
                edit_panel.Show();
                add_panel.Hide();

                editCritter     = (MarineLife)theModel.MarineLifeList[targetIndex];
                tbe_width.Text  = Convert.ToString(editCritter.ml_width);
                tbe_height.Text = Convert.ToString(editCritter.ml_height);
                tbe_x.Text      = Convert.ToString(editCritter.xPosition);
                tbe_y.Text      = Convert.ToString(editCritter.yPosition);
                if (editCritter.ml_type == "Whale")
                {
                    rbe_whale.Checked = true;
                    Whale theWhale = (Whale)editCritter;
                    if (theWhale.getWhaleType() == WhaleType.Baleen)
                    {
                        rbe_baleen.Checked = true;
                    }
                    else
                    {
                        rbe_toothed.Checked = true;
                    }
                    rbe_whale.Enabled        = true;
                    pnle_whales.Enabled      = true;
                    rbe_fish.Enabled         = false;
                    pnle_fish.Enabled        = false;
                    rbe_crustacean.Enabled   = false;
                    pnle_crustaceans.Enabled = false;
                }
                else if (editCritter.ml_type == "Fish")
                {
                    rbe_fish.Checked = true;
                    Fish theFish = (Fish)editCritter;
                    if (theFish.getFishType() == FishType.blue)
                    {
                        rbe_blue.Checked = true;
                    }
                    else if (theFish.getFishType() == FishType.green)
                    {
                        rbe_green.Checked = true;
                    }
                    else if (theFish.getFishType() == FishType.red)
                    {
                        rbe_red.Checked = true;
                    }
                    else
                    {
                        rbe_orange.Checked = true;
                    }
                    rbe_fish.Enabled         = true;
                    pnle_fish.Enabled        = true;
                    rbe_whale.Enabled        = false;
                    pnle_whales.Enabled      = false;
                    rbe_crustacean.Enabled   = false;
                    pnle_crustaceans.Enabled = false;
                }
                else
                {
                    rbe_crustacean.Checked = true;
                    Crustacean theCrustacean = (Crustacean)editCritter;
                    if (theCrustacean.getCrustaceanType() == CrustaceanType.Crab)
                    {
                        rbe_crab.Checked = true;
                    }
                    else if (theCrustacean.getCrustaceanType() == CrustaceanType.Lobster)
                    {
                        rbe_lobster.Checked = true;
                    }
                    else
                    {
                        rbe_shrimp.Checked = true;
                    }
                    rbe_crustacean.Enabled   = true;
                    pnle_crustaceans.Enabled = true;
                    rbe_whale.Enabled        = false;
                    pnle_whales.Enabled      = false;
                    rbe_fish.Enabled         = false;
                    pnle_fish.Enabled        = false;
                }
            }
            else
            {
                MessageBox.Show("You must select a critter in the list-view (displayed above) before attempting deletion.", "Error - No selection arguement", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }