/// <summary> /// deletes a selected MarineLife object /// </summary> public void deleteMarineLife_btnClicked(Object Sender, EventArgs e) { if (lb_all_marine_life.SelectedIndex != -1) { theMarineLife = (MarineLife)theModel.MarineLifeList[lb_all_marine_life.SelectedIndex]; theModel.DeleteMarineLife(theMarineLife); } 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); } }
/// <summary> /// method to resequence arrayList so selected MarineLife-Object is drawn first /// </summary> public void SendToBack(MarineLife animal) { // first shape drawn is at the back // temp arrayList to resort shapes so selected shape is drawn first ArrayList sortList = new ArrayList(); // find index of shape to be drawn first int max = marineLifeList.IndexOf(animal); // first shape i.e. shape to send to back sortList.Add(animal); // copy to sortList in correct sequence for (int i = 0; i < max; i++) { sortList.Add(marineLifeList[i]); } // copy sortList back to shapeList for (int i = 0; i < sortList.Count; i++) { marineLifeList[i] = sortList[i]; } UpdateViews(); }
/// <summary> /// method to resequence arrayList so selected MarineLife-Object is drawn last /// </summary> public void BringToFront(MarineLife animal) { // last shape drawn is at the front // temp arrayList to resort shapes so selected shape is drawn last ArrayList sortList = new ArrayList(marineLifeList); // find index of shape to be drawn last int max = marineLifeList.IndexOf(animal); // find length of shapeList array int length = marineLifeList.Count; // copy shapeList to sortList excluding selected shape for (int i = max + 1; i < length; i++) { sortList[i - 1] = marineLifeList[i]; } // last shape i.e. shape to bring to front sortList[length - 1] = marineLifeList[max]; // copy sortList back to shapeList for (int i = 0; i < sortList.Count; i++) { marineLifeList[i] = sortList[i]; } UpdateViews(); }
/// <summary> /// mouse move handler /// </summary> public void writePanel_MouseMove(object sender, MouseEventArgs e) { // set last position to current position lastPosition = currentPosition; // set current position to mouse position currentPosition = new Point(e.X, e.Y); // calculate how far mouse has moved int xMove = currentPosition.X - lastPosition.X; int yMove = currentPosition.Y - lastPosition.Y; if (!dragging) // mouse not down { // reset variables topCritter = null; bool needsDisplay = false; // create arrayList of shaapes from myModel ArrayList theMarineLifeArray = theModel.MarineLifeList; // create array of shapes from array list MarineLife[] theMarineLifeList = (MarineLife[])theMarineLifeArray.ToArray(typeof(MarineLife)); // graphics object to draw shapes when required Graphics g = this.write_panel.CreateGraphics(); // loop through array checking if mouse is over shape foreach (MarineLife s in theMarineLifeList) { // check if mouse is over shape if (s.HitTest(new Point(e.X, e.Y))) { // if so make shape topShape topCritter = s; } if (s.Highlight == true) { // shape to be redrawn needsDisplay = true; // redraw shape s.Display(g); s.Highlight = false; } } if (topCritter != null) // if there is a topShape { needsDisplay = true; // need to redisplay topCritter.Display(g); // redisplay topShape topCritter.Highlight = true; } if (needsDisplay) { // redisplay model theModel.UpdateViews(); } } else // mouse is down { // reset position of selected shape by value of mouse move topCritter.xPosition = topCritter.xPosition + xMove; topCritter.yPosition = topCritter.yPosition + yMove; theModel.UpdateViews(); } }
/// <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; } }
/// <summary> /// delete a MarineLife-Object and update views /// </summary> public void DeleteMarineLife(MarineLife animal) { marineLifeList.Remove(animal); UpdateViews(); }
/// <summary> /// update views /// </summary> public void UpdateMarineLife(MarineLife animal) { UpdateViews(); }
/// <summary> /// add MarineLife-Object to the model and update views /// </summary> public void AddMarineLife(MarineLife animal) { marineLifeList.Add(animal); UpdateViews(); }