GeometrySettings.xaml.cs :  » GIS » DeepEarth » ExampleControl » Controls » GeometryTools » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GIS » DeepEarth 
DeepEarth » ExampleControl » Controls » GeometryTools » GeometrySettings.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.ComponentModel;
using System.Windows.Shapes;
using DeepEarth.Client.MapControl;
using DeepEarth.Client.MapControl.Controls.GeometryTools;

namespace ExampleControl.Controls.GeometryTools{
    public partial class GeometrySettings
    {
        [DefaultValue(Map.DragBehavior.Pan)]
        private Map.DragBehavior _DragBehaviour { get; set; }

        private Rectangle _ColourToSet;

        private Map _Map { get; set; }
        private Color _LineColor { get; set; }
        private Color _FillColor { get; set; }


        public GeometrySettings()
            : this(Map.DefaultInstance)
        {
        }

        public GeometrySettings(Map map)
        {
            InitializeComponent();

            _Map = map;

            _FreeDrawToggleButton.Unchecked += ToggleButton_Unchecked;
            _StringLineToggleButton.Unchecked += ToggleButton_Unchecked;
            _PolygonToggleButton.Unchecked += ToggleButton_Unchecked;
            _PointPinToggleButton.Unchecked += ToggleButton_Unchecked;
            _EraserToggleButton.Unchecked += ToggleButton_Unchecked;

            _FreeDrawToggleButton.Checked += ToggleButton_Checked;
            _StringLineToggleButton.Checked += ToggleButton_Checked;
            _PolygonToggleButton.Checked += ToggleButton_Checked;
            _PointPinToggleButton.Checked += ToggleButton_Checked;
            _EraserToggleButton.Checked += ToggleButton_Checked;

            _Opacity.ValueChanged += Opacity_ValueChanged;
            _OpacityValue.LostFocus += OpacityValue_LostFocus;
            _OpacityValue.KeyDown += OpacityValue_KeyDown;

            _LineThickness.ValueChanged += LineThickness_ValueChanged;
            _ThicknessValue.LostFocus += ThicknessValue_LostFocus;
            _ThicknessValue.KeyDown += ThicknessValue_KeyDown;

            _LineColour.Click += ShowColourPicker_Click;
            _FillColour.Click += ShowColourPicker_Click;

            _ColourPicker.UpdateColourButton.Click += HideColourPicker_Click;
            _ColourPicker.ColorChanged += ColourPicker_ColorChanged;

            _Map.Events.MapLoaded += Events_MapLoaded;
        }

        private void Events_MapLoaded(Map map, DeepEarth.Client.MapControl.Events.MapEventArgs args)
        {
            _OpacityValue.Text = (_Map.GeometryTools.DrawOpacity * 100).ToString();
            _ThicknessValue.Text = Math.Round(_Map.GeometryTools.DrawLineThickness, 2).ToString("0.00");
            _LineColorDisplay.Fill = new SolidColorBrush(_Map.GeometryTools.DrawLineColor);
            _FillColourDisplay.Fill = new SolidColorBrush(_Map.GeometryTools.DrawFillColor);

            SetThickness();
            SetOpacity();
        }


        private void ToggleButton_Checked(object sender, RoutedEventArgs e)
        {
            var tb = sender as ToggleButton;
            if(tb != null)
            {
                foreach(ToggleButton b in GeometryButtons.Children)
                {
                    if(_Map.DragMode != Map.DragBehavior.Draw) _DragBehaviour = _Map.DragMode;
                    if(tb != b) b.IsChecked = false;
                }

                _Map.DragMode = Map.DragBehavior.Draw;

                switch(tb.Name)
                {
                    case "_FreeDrawToggleButton":
                        _Map.GeometryTools.DrawMode = DrawControl.GeometryMode.FreeDraw;
                        break;

                    case "_StringLineToggleButton":
                        _Map.GeometryTools.DrawMode = DrawControl.GeometryMode.StringLine;
                        break;

                    case "_PolygonToggleButton":
                        _Map.GeometryTools.DrawMode = DrawControl.GeometryMode.Polygon;
                        break;

                    case "_PointPinToggleButton":
                        _Map.GeometryTools.DrawMode = DrawControl.GeometryMode.PointPin;
                        break;

                    case "_EraserToggleButton":
                        _Map.GeometryTools.DrawMode = DrawControl.GeometryMode.Eraser;
                        break;
                }
            }
        }

        private void ToggleButton_Unchecked(object sender, RoutedEventArgs e)
        {
            bool _IsDrawMode = false;
            foreach(ToggleButton b in GeometryButtons.Children)
            {
                if(b.IsChecked == true)
                {
                    _IsDrawMode = true;
                }
            }

            if(!_IsDrawMode) _Map.DragMode = _DragBehaviour;
        }


        private void ShowColourPicker_Click(object sender, RoutedEventArgs e)
        {
            var b = sender as Button;
            if(b != null)
            {
                switch(b.Name)
                {
                    case "_LineColour":
                        _ColourToSet = _LineColorDisplay;
                        _ColourPicker.SelectedColor.Color = _LineColor;
                        //_ColourPicker.SelectedColor.Color = _LineColor;
                        //_ColourPicker.SelectedColor.Color.B = _LineColor.B;
                        //_ColourPicker.SelectedColor.Color.G = _LineColor.G;
                        //_ColourPicker.SelectedColor.Color.R = _LineColor.R;
                        break;
                    case "_FillColour":
                        _ColourToSet = _FillColourDisplay;
                        _ColourPicker.SelectedColor.Color = _FillColor;
                        break;
                }
            }
            //_ColourPicker.UpdateSelectedColor();
            VisualStateManager.GoToState(this, "ShowColourPicker", true);
        }

        private void HideColourPicker_Click(object sender, RoutedEventArgs e)
        {
            VisualStateManager.GoToState(this, "HideColourPicker", true);
        }

        private void ColourPicker_ColorChanged(object sender, ColourPicker.ColorChangedEventArgs e)
        {
            _ColourToSet.Fill = e.newColor;

            switch(_ColourToSet.Name)
            {
                case "_LineColorDisplay":
                    _LineColor = e.newColor.Color;
                    _Map.GeometryTools.DrawLineColor = e.newColor.Color;
                    break;
                case "_FillColourDisplay":
                    _FillColor = e.newColor.Color;
                    _Map.GeometryTools.DrawFillColor = e.newColor.Color;
                    break;
            }
            //UpdateSettings();
        }


        private void LineThickness_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            _ThicknessValue.Text = Math.Round(_LineThickness.Value, 2).ToString("0.00");
            _Map.GeometryTools.DrawLineThickness = _LineThickness.Value;
        }

        private void Opacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            _OpacityValue.Text = Math.Round(_Opacity.Value).ToString();
            _Map.GeometryTools.DrawOpacity = _Opacity.Value / 100;
        }


        private void ThicknessValue_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.Enter)
            {
                SetThickness();
            }
        }

        private void ThicknessValue_LostFocus(object sender, RoutedEventArgs e)
        {
            SetThickness();
        }

        private void OpacityValue_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.Enter)
            {
                SetOpacity();
            }
        }

        private void OpacityValue_LostFocus(object sender, RoutedEventArgs e)
        {
            SetOpacity();
        }


        private void SetThickness()
        {
            var thickness = Math.Round(double.Parse(_ThicknessValue.Text), 2);

            //if(thickness > 10 || thickness < 0) HtmlPage.Window.Alert("Line Thinkness value between 0 and 10");
            if(thickness > 10) thickness = 10;
            if(thickness < 0) thickness = 0;

            _ThicknessValue.Text = thickness.ToString("0.00");
            _LineThickness.Value = thickness;
            _Map.GeometryTools.DrawLineThickness = _LineThickness.Value;
        }

        private void SetOpacity()
        {
            var opacity = (int)Math.Round(double.Parse(_OpacityValue.Text), 0);

            //if(opacity > 100 || opacity < 0) HtmlPage.Window.Alert("Opacity value between 0 and 100");
            if(opacity > 100) opacity = 100;
            if(opacity < 0) opacity = 0;

            _OpacityValue.Text = opacity.ToString();
            _Opacity.Value = opacity;
            _Map.GeometryTools.DrawOpacity = _Opacity.Value / 100;
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.