using System; using System.Collections.Generic; using System.Text; using System.Xml.Serialization; namespace OSGeo.MapGuide.Viewer.AppLayoutEngine { /// /// Models an Application Layout, defining the user interface and functionality of your application /// public class AppLayout { /// /// The window title /// [XmlElement] public string Title { get; set; } /// /// The application icon /// [XmlElement] public string Icon { get; set; } /// /// The application locale /// [XmlElement] public string Language { get; set; } /// /// A set of top-level application settings /// [XmlArray] public List Settings { get; set; } /// /// Settings for the information pane (legend + properties) /// [XmlElement] public InfoPaneSettings InfoPane { get; set; } /// /// Settings for the Map Definition to be loaded /// [XmlElement] public MapReference Map { get; set; } /// /// Defines the layout of the application's menus /// [XmlElement] public MenuDefinition Menu { get; set; } /// /// Defines the layout of the application's toolbar /// [XmlElement] public ToolbarDefinition Toolbar { get; set; } /// /// Defines the layout of the viewer's context menu /// [XmlElement] public MenuDefinition ContextMenu { get; set; } /// /// Defines settings for the application's task pane /// [XmlElement] public TaskPaneDefinition TaskPane { get; set; } /// /// Defines the list of components available to this application /// [XmlArray] public List Components { get; set; } /// /// Creates a default AppLayout based on the given map definition /// /// /// /// public static AppLayout CreateDefault(string title, string mapDefinition) { var layout = new AppLayout(); layout.Title = title; layout.Settings = new List() { new NameValue() { Name = "ConvertTiledGroupsToNonTiled", Value = "true" }, //NOXLATE new NameValue() { Name = "UseRenderMap", Value = "true" }, //NOXLATE new NameValue() { Name = "SelectionColor", Value = "color:" + Util.ToHtmlColorWithAlpha(System.Drawing.Color.Blue) }, //NOXLATE new NameValue() { Name = "ShowVertexCoordinatesWhenDigitizing", Value = "true" }, //NOXLATE new NameValue() { Name = "ZoomInFactor", Value = "0.5" }, //NOXLATE new NameValue() { Name = "ZoomOutFactor", Value = "2.0" }, //NOXLATE new NameValue() { Name = "PointPixelBuffer", Value = "3" } //NOXLATE }; layout.InfoPane = new InfoPaneSettings() { Legend = new LegendSettings() { Visible = true, ThemeCompressionLimit = 25 }, PropertyPane = new PropertyPaneSettings() { Visible = true }, Width = 200 }; layout.Map = new MapReference() { MapDefinition = mapDefinition }; layout.Menu = new MenuDefinition() { Items = new List() { new SubMenu(Strings.MenuFile) { Items = new List() { new CommandItem("LoadMap"), //NOXLATE new CommandItem("LoadPackage"), //NOXLATE new SeparatorItem(), new CommandItem("Quit") //NOXLATE } }, new SubMenu(Strings.MenuTools) { Items = new List() { new CommandItem("Buffer"), //NOXLATE new CommandItem("Measure"), //NOXLATE new CommandItem("Query"), //NOXLATE new CommandItem("Theme"), //NOXLATE new SeparatorItem(), new CommandItem("ViewerOptions") //NOXLATE } } } }; layout.Toolbar = new ToolbarDefinition() { Items = new List() { new CommandItem("PrintMap", false), //NOXLATE new SeparatorItem(), new CommandItem("CopyMap", false), //NOXLATE new SeparatorItem(), new CommandItem("ZoomIn", false), //NOXLATE new CommandItem("ZoomOut", false), //NOXLATE new CommandItem("InitialView", false), //NOXLATE new SeparatorItem(), new CommandItem("ZoomPrev", false), //NOXLATE new CommandItem("ZoomNext", false), //NOXLATE new SeparatorItem(), new CommandItem("Select", false), //NOXLATE new CommandItem("SelectRadius", false), //NOXLATE new CommandItem("SelectPolygon", false), //NOXLATE new CommandItem("Pan", false), //NOXLATE new SeparatorItem(), new CommandItem("ClearSelection", false), //NOXLATE new CommandItem("RefreshMap", false), //NOXLATE new SeparatorItem(), new CommandItem("TooltipToggle", true), //NOXLATE new SeparatorItem(), new SubMenu(Strings.MenuTools) { Items = new List() { new CommandItem("Buffer"), //NOXLATE new CommandItem("Measure"), //NOXLATE new CommandItem("Query"), //NOXLATE new CommandItem("Theme"), //NOXLATE new SeparatorItem(), new CommandItem("ViewerOptions") //NOXLATE } } } }; layout.ContextMenu = new MenuDefinition() { Items = new List() { new CommandItem("RefreshMap"), //NOXLATE new SeparatorItem(), new CommandItem("ZoomIn"), //NOXLATE new CommandItem("ZoomOut"), //NOXLATE new CommandItem("ZoomToSelection"), //NOXLATE new CommandItem("InitialView"), //NOXLATE new SeparatorItem(), new CommandItem("Pan"), //NOXLATE new CommandItem("Select"), //NOXLATE new CommandItem("ClearSelection"), //NOXLATE new SeparatorItem(), new SubMenu(Strings.MenuTools) { Items = new List() { new CommandItem("Buffer"), //NOXLATE new CommandItem("Measure"), //NOXLATE new CommandItem("Query"), //NOXLATE new CommandItem("Theme") //NOXLATE } }, new SeparatorItem(), new CommandItem("ViewerOptions"), //NOXLATE } }; layout.TaskPane = new TaskPaneDefinition() { Width = 250, TaskMenu = new MenuDefinition() { Items = new List() { new CommandItem("Buffer"), //NOXLATE new CommandItem("Measure"), //NOXLATE new CommandItem("Query"), //NOXLATE new CommandItem("Theme") //NOXLATE } } }; layout.Components = new List() { new ComponentDefinition() { ClassName = typeof(Viewer.MgBufferComponent).FullName, Assembly = null, ComponentID = "Buffer", //NOXLATE Properties = new List() { new NameValue("DefaultLayerName", "BufferLayer"), //NOXLATE new NameValue("DefaultBufferUnits", "enum:" + typeof(MeasurementUnit).FullName + ":" + MeasurementUnit.Meters.ToString()), //NOXLATE new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE new NameValue("TaskPane", "taskpane:") //NOXLATE } }, new ComponentDefinition(typeof(Viewer.MgCircleSelectComponent).FullName, "SelectRadius"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgClearSelectionComponent).FullName, "ClearSelection"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgCopyMapComponent).FullName, "CopyMap"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgInitialViewComponent).FullName, "InitialView"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgLoadMapComponent).FullName, "LoadMap") //NOXLATE { Properties = new List() { new NameValue("MapDefinition", mapDefinition) //NOXLATE } }, new ComponentDefinition(typeof(Viewer.MgLoadPackageComponent).FullName, "LoadPackage") //NOXLATE { Properties = new List() { new NameValue("InvokeOnPackageLoad", "component:LoadMap") //NOXLATE } }, new ComponentDefinition(typeof(Viewer.MgMeasureComponent).FullName, "Measure") //NOXLATE { Properties = new List() { new NameValue("MeasureMode", "enum:" + typeof(MeasureMode).FullName + ":" + MeasureMode.Line.ToString()), //NOXLATE new NameValue("PreferredUnits", "enum:" + typeof(MeasurementUnit).FullName + ":" + MeasurementUnit.Meters.ToString()), //NOXLATE new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE new NameValue("TaskPane", "taskpane:") //NOXLATE } }, new ComponentDefinition(typeof(Viewer.MgPanComponent).FullName, "Pan"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgPolygonSelectComponent).FullName, "SelectPolygon"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgPrintComponent).FullName, "PrintMap"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgQueryComponent).FullName, "Query") //NOXLATE { Properties = new List() { new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE new NameValue("TaskPane", "taskpane:") //NOXLATE } }, new ComponentDefinition(typeof(Viewer.AppLayoutEngine.MgQuitComponent).FullName, "Quit"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgRefreshMapComponent).FullName, "RefreshMap"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgSelectComponent).FullName, "Select"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgThemeComponent).FullName, "Theme") //NOXLATE { Properties = new List() { new NameValue("Target", "enum:" + typeof(MgViewerTarget).FullName + ":" + MgViewerTarget.TaskPane), //NOXLATE new NameValue("TaskPane", "taskpane:") //NOXLATE } }, new ComponentDefinition(typeof(Viewer.MgTooltipToggleComponent).FullName, "TooltipToggle"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgViewerOptionsComponent).FullName, "ViewerOptions"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgZoomInComponent).FullName, "ZoomIn"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgZoomNextComponent).FullName, "ZoomNext"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgZoomOutComponent).FullName, "ZoomOut"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgZoomPreviousComponent).FullName, "ZoomPrev"), //NOXLATE new ComponentDefinition(typeof(Viewer.MgZoomToSelectionComponent).FullName, "ZoomToSelection") //NOXLATE }; return layout; } } /// /// Defines settings for the information pane (legend + properties) /// public class InfoPaneSettings { /// /// The width of this pane /// [XmlElement] public uint Width { get; set; } /// /// Settings for the legend /// [XmlElement] public LegendSettings Legend { get; set; } /// /// Settings for the property pane /// [XmlElement] public PropertyPaneSettings PropertyPane { get; set; } /// /// Gets whether this pane is visible /// [XmlIgnore] public bool IsVisible { get { return this.Legend.Visible || this.PropertyPane.Visible; } } } /// /// Defines settigs for the legend /// public class LegendSettings { /// /// Gets or sets whether this element is visible /// [XmlElement] public bool Visible { get; set; } /// /// Gets or sets the value at which themes (containing a number of rules greater than this property) are compressed /// [XmlElement] public int? ThemeCompressionLimit { get; set; } /// /// Gets or sets whether tooltips are shown /// [XmlElement] public bool ShowTooltips { get; set; } } /// /// Defines settings for the property pane /// public class PropertyPaneSettings { /// /// Gets or sets whether this element is visible /// [XmlElement] public bool Visible { get; set; } } /// /// Defines settings for the Map Definition /// public class MapReference { /// /// The name of this map /// [XmlElement] public string Name { get; set; } /// /// The Map Definition resource id /// [XmlElement] public string MapDefinition { get; set; } } /// /// Defines the layout of the application's menus /// public class MenuDefinition { /// /// The list of top level items /// [XmlArray] public List Items { get; set; } } /// /// Defines the layout of the application's toolbar /// public class ToolbarDefinition { /// /// The list of top level items /// [XmlArray] public List Items { get; set; } } /// /// Defines settings for the Task Pane /// public class TaskPaneDefinition { /// /// The width of this element /// [XmlElement] public uint Width { get; set; } /// /// Specifies the component ID of the Task Pane resident component. A Task Pane resident component /// has a "Target" property of Task Pane. /// [XmlElement] public string InitialComponentID { get; set; } /// /// Defines the layout of the menu in the Task Pane /// [XmlElement] public MenuDefinition TaskMenu { get; set; } } /// /// The super class of all toolbar and menu items /// [XmlInclude(typeof(CommandItem))] [XmlInclude(typeof(SeparatorItem))] [XmlInclude(typeof(SubMenu))] public class ItemBase { } /// /// A menu/toolbar separator /// public class SeparatorItem : ItemBase { } /// /// A sub-menu item /// public class SubMenu : ItemBase { /// /// Constructor /// public SubMenu() { } /// /// Constructor /// /// public SubMenu(string label) { this.Label = label; } /// /// The label /// [XmlElement] public string Label { get; set; } /// /// The list of child items /// [XmlArray] public List Items { get; set; } } /// /// A menu/toolbar items that invokes a registered component /// public class CommandItem : ItemBase { /// /// Constructor /// public CommandItem() { } /// /// Constructor /// /// public CommandItem(string componentId) { this.ComponentID = componentId; } /// /// Constructor /// /// /// public CommandItem(string componentId, bool showLabel) { this.ComponentID = componentId; this.ShowLabel = showLabel; } /// /// The id of the component to invoke when this item is clicked /// [XmlElement] public string ComponentID { get; set; } /// /// Gets whether to display labels in this item /// [XmlElement] public bool ShowLabel { get; set; } } /// /// Defines a component, a discrete piece of built-in or custom application functionality /// public class ComponentDefinition { /// /// Constructor /// public ComponentDefinition() { this.Properties = new List(); } /// /// Constructor /// /// /// public ComponentDefinition(string typeName, string componentID) : base() { this.Assembly = null; this.ClassName = typeName; this.ComponentID = componentID; } /// /// The id of this component /// [XmlElement] public string ComponentID { get; set; } /// /// The label to assign to any toolbar/menu item that's tied to this component /// [XmlElement] public string Label { get; set; } /// /// The fully qualified .net name of the class that implements this component /// [XmlElement] public string ClassName { get; set; } /// /// The assembly that contains the .net class that implements this component. If empty /// it is assumed to originate from the viewer assembly /// [XmlElement] public string Assembly { get; set; } /// /// A list of properties that define and customize component behaviour /// [XmlArray] public List Properties { get; set; } } /// /// A key-value pair used to define properties /// public class NameValue { /// /// Constructor /// public NameValue() { } /// /// Constructor /// /// /// public NameValue(string name, string value) { this.Name = name; this.Value = value; } /// /// The name of the property /// [XmlElement] public string Name { get; set; } /// /// The property's value /// [XmlElement] public string Value { get; set; } } /// /// Defines the set of prefixes for serialized component property string values /// to hint at what type to deserialize this value as. CLR property values are /// serialized/deserialized as is without any need for prefixing. /// public class StringPrefixes { /// /// Map Definition /// public const string MAPDEFINITION = "map:"; //NOXLATE /// /// Component ID /// public const string COMPONENTID = "component:"; //NOXLATE /// /// Color /// public const string COLOR = "color:"; //NOXLATE /// /// A .net enum /// public const string ENUM = "enum:"; //NOXLATE /// /// Viewer ID /// public const string VIEWERID = "viewer:"; //NOXLATE /// /// Task Pane ID /// public const string TASKPANEID = "taskpane:"; //NOXLATE /// /// An array of string values /// public const string STRINGARRAY = "stringarray:"; //NOXLATE } }