using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using J2i.Net.FindMe.Interface;
using J2i.Net.FindMe.Common;
namespace J2i.Net.FindMe.Controls
{
public partial class MainForm : Form
{
delegate void SetTextDelegate(Control c, string text);
SetTextDelegate _setText;
public ISession UserSession
{
get;
set;
}
public MainForm(ISession userSession)
{
_setText = new SetTextDelegate(this.SetText);
UserSession = userSession;
InitializeComponent();
}
void DisplayGeneralSettings()
{
SettingsForm settingsForm = new SettingsForm(UserSession.UserSettings);
if (settingsForm.ShowDialog() == DialogResult.OK)
{
UserSession.UserSettings.Save();
}
}
void SetText(Control c, string text)
{
if (c.InvokeRequired)
{
c.Invoke(_setText, new object[] { c, text });
}
else
{
c.Text = text;
}
}
void DisplayContactSettings()
{
ContactApprovalForm caf = new ContactApprovalForm(UserSession.UserContactApproval);
if (caf.ShowDialog() == DialogResult.OK)
{
UserSession.UserContactApproval.Save();
}
}
private void miGeneralSettings_Click(object sender, EventArgs e)
{
DisplayGeneralSettings();
}
private void miContactSettings_Click(object sender, EventArgs e)
{
DisplayContactSettings();
}
private void miPositioningTest_Click(object sender, EventArgs e)
{
(new PositioningServices(UserSession)).ShowDialog();
}
private void MainForm_Load(object sender, EventArgs e)
{
//Bitmap bm = new Bitmap(Path.Combine(ApplicationEnvironment.ApplicationFolder, "Assets\\Images\\SampleMap.jpg"));
//mapDisplay.MapImage = bm;
}
void MapRetrieved(object sender, MapRetrievedEventArgs args)
{
if (args.Success)
{
mapDisplay.MapImage = args.Map;
SetText(statusBar, "Location Displayed");
}
else
{
SetText(statusBar, "Map could not be retrieved");
}
}
private void miMyLocation_Click(object sender, EventArgs e)
{
int defaultZoom = (UserSession.GeoManager.MaxZoomLevel*2+UserSession.GeoManager.MinZoomLevel*1)/3;
Size s = new Size(mapDisplay.Width * 3, mapDisplay.Height * 3);
LocationResponse lr = new LocationResponse(UserSession.LocationProvider.LastLocation,string.Empty, "My Location", null, null);
UserSession.GeoManager.GetMapAsync(new MapRequest(UserSession.LocationProvider.LastLocation, s, defaultZoom,new ILocationResponse[]{lr}), new MapRetrievedCallback(MapRetrieved), null);
SetText(statusBar, "Obtaining map...");
//Image mapImage = UserSession.GeoManager.GetMap(UserSession.LocationProvider.LastLocation, s, defaultZoom);
//mapDisplay.MapImage = mapImage;
//string locationDescription = UserSession.GeoManager.GetLocationDescription(UserSession.LocationProvider.LastLocation);
//SetText(statusBar, locationDescription);
}
private void miExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void miKnownLocations_Click(object sender, EventArgs e)
{
LastLocationForm llf = new LastLocationForm(UserSession);
if (llf.ShowDialog() == DialogResult.OK)
{
switch (llf.ExitCommand)
{
case LastLocationForm.ExitCommands.DisplayMap:
{
int defaultZoom = (UserSession.GeoManager.MaxZoomLevel * 2 + UserSession.GeoManager.MinZoomLevel * 1) / 3;
Size s = new Size(mapDisplay.Width * 3, mapDisplay.Height * 3);
LocationResponse lr = new LocationResponse(UserSession.LocationProvider.LastLocation,string.Empty, "My Location", null, null);
UserSession.GeoManager.GetMapAsync(new MapRequest(llf.Location.LastKnownLocation, s, defaultZoom, new ILocationResponse[] { llf.Location, lr }), new MapRetrievedCallback(MapRetrieved), null);
SetText(statusBar, "Obtaining map...");
}
break;
case LastLocationForm.ExitCommands.Nop:
{
}
break;
default:
break;
}
}
}
}
}