private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { // Cast the sender object back to ListBox type. ListBox theListBox = (ListBox)sender; // Get the string contained in each item. object item = theListBox.Items[e.Index]; // If the item is the selected item, then draw the rectangle // filled in blue. The item is selected when a bitwise And // of the State property and the DrawItemState.Selected // property is true. if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds); } else { // Otherwise, draw the rectangle filled in beige. e.Graphics.FillRectangle(SystemBrushes.ControlLightLight, e.Bounds); } // Draw a rectangle in blue around each item. //e.Graphics.DrawRectangle(Pens.Blue, e.Bounds); if (item is GPLocation) { GPLocation loc = item as GPLocation; e.Graphics.DrawString(loc.getName(), labelCount.Font, Brushes.Black, e.Bounds.X + 4, e.Bounds.Y + 4); e.Graphics.DrawString("Timezone: " + loc.getTimeZone().getFullName(), label1.Font, Brushes.Black, e.Bounds.X + 4, e.Bounds.Y + 20); } else if (item is GPLocationChange) { GPLocationChange chan = item as GPLocationChange; GPGregorianTime gt = new GPGregorianTime(chan.LocationA); gt.setJulianGreenwichTime(new GPJulianTime(chan.julianStart, 0)); string humanStart = string.Format("{0} {1}", gt.getLongTimeString(), chan.LocationA.getTimeZoneName()); e.Graphics.DrawString(gt.getLongDateString() + " - travelling", labelCount.Font, Brushes.Black, e.Bounds.X + 48, e.Bounds.Y + 4); e.Graphics.DrawLine(Pens.Black, e.Bounds.X + 40, e.Bounds.Y + 4, e.Bounds.X + 40, e.Bounds.Bottom - 4); e.Graphics.DrawString("Start: " + chan.humanStart, label1.Font, Brushes.Black, e.Bounds.X + 48, e.Bounds.Y + 20); //e.Graphics.DrawString("End: " + chan.humanEnd, label1.Font, Brushes.Black, e.Bounds.X + 48, e.Bounds.Y + 36); e.Graphics.DrawString("Length: " + chan.humanLength, label1.Font, Brushes.Black, e.Bounds.X + 48, e.Bounds.Y + 36); } // Draw the focus rectangle around the selected item. e.DrawFocusRectangle(); }
/// <summary> /// Add new travelling /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { WizardDlg wizard = new WizardDlg(); LocationPickerControl lpc = new LocationPickerControl(); lpc.TravellerVisible = false; wizard.AddPage(lpc, "Start Location", "Select location, where you start your travelling"); LocationPickerControl lpc2 = new LocationPickerControl(); lpc2.TravellerVisible = false; wizard.AddPage(lpc2, "Target Location", "Select location, where you finish your traveling"); TravellingEditControl tec = new TravellingEditControl(); tec.LocationPicker = lpc; tec.LocationPicker2 = lpc2; tec.TransitionTimezoneIndex = 0; wizard.AddPage(tec, "Travelling time", "Specify travelling time"); wizard.ResetPages(); if (wizard.ShowDialog() == DialogResult.OK) { GPLocationChange newChange = new GPLocationChange(); newChange.LocationA = lpc.SelectedLocation.getLocation(0); newChange.LocationB = lpc2.SelectedLocation.getLocation(0); GPGregorianTime start = new GPGregorianTime(newChange.LocationA); start.setDateTime(tec.getUTCDateTime(0).AddHours(newChange.LocationA.getTimeZoneOffsetHours())); newChange.julianStart = start.getJulianGreenwichTime(); GPGregorianTime end = new GPGregorianTime(newChange.LocationB); end.setDateTime(tec.getUTCDateTime(1).AddHours(newChange.LocationB.getTimeZoneOffsetHours())); newChange.julianEnd = end.getJulianGreenwichTime(); newChange.TimezoneStart = (tec.TransitionTimezoneIndex == 0); GPLocationProvider lp = GPAppHelper.getMyLocation(); lp.addChange(newChange); RefreshList(); travellingChanged = true; } }
private void EditTravellingInListbox(ListBox lbox, int index) { GPLocationChange newChange = (GPLocationChange)lbox.SelectedItem; if (newChange != null) { WizardDlg wizard = new WizardDlg(); GPGregorianTime start, end; TravellingEditControl tec = new TravellingEditControl(); tec.LocationObj = newChange.LocationA; tec.LocationObj2 = newChange.LocationB; wizard.AddPage(tec, "Travelling time", "Specify travelling time"); tec.TransitionTimezoneIndex = (newChange.TimezoneStart ? 0 : 1); start = new GPGregorianTime(newChange.TimezoneStart ? newChange.LocationA : newChange.LocationB); start.setJulianGreenwichTime(new GPJulianTime(newChange.julianStart, 0)); tec.setUTCDateTime(start.getLocalTime(), 0); start.setJulianGreenwichTime(new GPJulianTime(newChange.julianEnd, 0)); tec.setUTCDateTime(start.getLocalTime(), 1); wizard.ResetPages(); if (wizard.ShowDialog() == DialogResult.OK) { start = new GPGregorianTime(newChange.LocationA); start.setDateTime(tec.getUTCDateTime(0).AddHours(newChange.LocationA.getTimeZoneOffsetHours())); newChange.julianStart = start.getJulianGreenwichTime(); end = new GPGregorianTime(newChange.LocationB); end.setDateTime(tec.getUTCDateTime(1).AddHours(newChange.LocationB.getTimeZoneOffsetHours())); newChange.julianEnd = end.getJulianGreenwichTime(); newChange.TimezoneStart = (tec.TransitionTimezoneIndex == 0); listBox1.Invalidate(); listBox1.Update(); } } }
public void SetData(GPLocationProvider loa, GPLocationProvider lob, GPGregorianTime sd, double travelDurationHours) { GPLocationProvider lp = new GPLocationProvider(); lp.setDefaultLocation(loa.getDefaultLocation()); GPLocationChange locChange = new GPLocationChange(); locChange.LocationA = loa.getDefaultLocation(); locChange.LocationB = lob.getDefaultLocation(); locChange.TimezoneStart = true; locChange.julianStart = sd.getJulianGreenwichTime(); locChange.julianEnd = locChange.julianStart + travelDurationHours / 24.0; lp.addChange(locChange); provider = lp; startDateA = new GPGregorianTime(sd); startDateA.setLocationProvider(lp); startDateA.AddDays(-6); nCount = 15; }
// insert after private void button7_Click(object sender, EventArgs e) { ListBox lbox = listBox1; int index = lbox.SelectedIndex; int changeIndex = getChangeIndexFromListBoxIndex(index); GPLocationChange chng = null; GPLocationProvider provider = GPAppHelper.getMyLocation(); // ask for travelling time // ask for starting location WizardDlg wizard = new WizardDlg(); LocationPickerControl lpc = new LocationPickerControl(); lpc.TravellerVisible = false; wizard.AddPage(lpc, "Target Location", "Select location, where you end your travelling"); //LocationPickerControl lpc2 = new LocationPickerControl(); //lpc2.TravellerVisible = false; //wizard.AddPage(lpc2, "Target Location", "Select location, where you finish your traveling"); TravellingEditControl tec = new TravellingEditControl(); if (IsSelectedLocation) { tec.LocationObj = listBox1.SelectedItem as GPLocation; if ((listBox1.SelectedIndex - 1) > 0) { chng = (listBox1.Items[listBox1.SelectedIndex - 1] as GPLocationChange); } } if (IsSelectedTravelling) { chng = (listBox1.SelectedItem as GPLocationChange); tec.LocationObj = chng.LocationB; } tec.LocationPicker2 = lpc; tec.TransitionTimezoneIndex = 0; if (chng != null) { GPGregorianTime start = new GPGregorianTime(tec.LocationObj); start.setJulianGreenwichTime(new GPJulianTime(chng.julianStart, 0)); tec.SetBottomEndDateLimit(start.getLocalTime()); } wizard.AddPage(tec, "Travelling time", "Specify travelling time"); wizard.ResetPages(); if (wizard.ShowDialog() == DialogResult.OK) { GPLocationChange newChange = new GPLocationChange(); newChange.LocationA = tec.LocationObj; newChange.LocationB = lpc.SelectedLocation.getLocation(0); GPGregorianTime start = new GPGregorianTime(newChange.LocationA); start.setDateTime(tec.getUTCDateTime(0).AddHours(newChange.LocationA.getTimeZoneOffsetHours())); newChange.julianStart = start.getJulianGreenwichTime(); GPGregorianTime end = new GPGregorianTime(newChange.LocationB); end.setDateTime(tec.getUTCDateTime(1).AddHours(newChange.LocationB.getTimeZoneOffsetHours())); newChange.julianEnd = end.getJulianGreenwichTime(); newChange.TimezoneStart = (tec.TransitionTimezoneIndex == 0); // remove travellings before changeIndex // insert new travelling at index 0 provider.removeChangesAfterIndex(changeIndex); provider.addChange(newChange); RefreshList(); travellingChanged = true; } }