using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Nevron.Diagram.Extensions;
using Nevron.Diagram.WinForm;
using Nevron.Diagram.WinForm.Commands;
using Nevron.Globalization;
using Nevron.GraphicsCore;
using Nevron.UI.WinForm;
using Nevron.UI.WinForm.Controls;
using Nevron.UI.WinForm.Docking;
namespace Nevron.Diagram.Designer
{
///
/// The NDiagramDesignerForm represents the diagram designer form
///
///
/// The NDiagramDesignerForm encompasses most of the Win Form related features of the
/// Nevron Diagram for .NET product by exposing a ready to use diagramming application form to the end user.
/// It currently consists from the following components:
///
/// 1. View - used to the edit and preview a drawing document
///
///
/// 2. Library browser - used to create, edit and reuse library documents
///
///
/// 3. Property browser - used to edit the designer, active layer, drawing document or selection anchor properties.
///
///
/// 4. Statusbar - used to display the state of the view
///
/// The NDiagramDesignerForm is also packed with a command bars manager exposing all currently available diagram commands.
/// It is also a nice example of the Nevron UI docking library capabilities.
///
public class NDiagramDesignerForm : NForm, INLocalizable
{
#region Constructors
///
/// Default constructor
///
public NDiagramDesignerForm()
: this(null)
{
}
///
/// Initializing constructor.
///
///
public NDiagramDesignerForm(string fileName)
{
InitializeComponent();
// uncomment one of the following lines to define the frames appearance
// NUIManager.FrameAppearance = NUIManager.GetPredefinedFrame(PredefinedFrame.Office2007Aqua);
m_bExiting = false;
// first, create the components and controls from which the diagram designer consists of.
// all these components are availbable from Nevron.Diagram.dll and Nevron.Diagram.WinForm.dll
CreateDiagramComponents();
// second, create the docking panels and place the diagram controls in them
CreateDockingPanels();
if (fileName != null && fileName.Length > 0)
{
// load the specified file
NPersistencyManager manager = new NPersistencyManager();
NDrawingDocument document = manager.LoadDrawingFromFile(fileName);
if (document != null)
{
m_View.Document = document;
}
}
}
#endregion
#region INLocalizable
///
/// Gets the localization context name for this class.
///
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual string LocalizationContextName
{
get
{
return "$$Diagram Designer";
}
}
#endregion
#region Protected overridable
///
/// Creates the form components
///
protected virtual void CreateDiagramComponents()
{
// document
NDrawingDocument document = new NDrawingDocument();
// view
m_View = new NDrawingView();
m_View.Dock = DockStyle.Fill;
m_View.Document = document;
m_View.DocumentPadding = new NMargins(20);
m_View.AllowDrop = true;
// library browser
m_LibraryBrowser = new NLibraryBrowser();
m_LibraryBrowser.Dock = DockStyle.Fill;
m_LibraryBrowser.NewBasicShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewFlowchartingShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewConnectorShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewSymbolShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewBrainstormingShapesLibraryGroup( NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewNetworkShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewTrafficSignsShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewElectricalSymbolsShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewSimpleNetworkShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewFloorPlanShapesLibraryGroup(NGraphicsUnit.Millimeter);
m_LibraryBrowser.NewFlagsShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewTravelShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewWeatherShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewFoodShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewBusinessProcessShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
m_LibraryBrowser.NewFilesAndFoldersShapesLibraryGroup(NGraphicsUnit.Pixel, new NSizeF(80, 60));
// property browser
m_PropertyBrowser = new NPropertyBrowser();
m_PropertyBrowser.Dock = DockStyle.Fill;
m_PropertyBrowser.View = m_View;
// status bar
m_StatusBar = new NDiagramStatusBar();
m_StatusBar.View = m_View;
// pan and zoom
m_PanAndZoomControl = new NPanAndZoomControl();
m_PanAndZoomControl.Dock = DockStyle.Fill;
m_PanAndZoomControl.MasterView = m_View;
// command bars manager
m_CommandBarsManager = new NDiagramCommandBarsManager();
m_CommandBarsManager.View = m_View;
m_CommandBarsManager.StatusBar = m_StatusBar;
m_CommandBarsManager.PropertyBrowser = m_PropertyBrowser;
m_CommandBarsManager.LibraryBrowser = m_LibraryBrowser;
m_CommandBarsManager.PanAndZoomControl = m_PanAndZoomControl;
m_CommandBarsManager.Palette.PaletteChanged += new PaletteChangeEventHandler(OnPaletteChanged);
m_CommandBarsManager.ParentControl = this;
// install the delegate of the commander which exists the application
m_CommandBarsManager.Commander.DelegateExit += new SimpleMethod(Exit);
// install the delegates of the commander related to
// library browser, pan and zoom and property browser hosts visibility
m_CommandBarsManager.Commander.DelegateGetLibraryBrowserHostVisibility = new GetControlHostVisibility(GetLibraryBrowserHostVisibility);
m_CommandBarsManager.Commander.DelegateSetLibraryBrowserHostVisibility = new SetControlHostVisibility(SetLibraryBrowserHostVisibility);
m_CommandBarsManager.Commander.DelegateGetPanAndZoomHostVisibility = new GetControlHostVisibility(GetPanAndZoomHostVisibility);
m_CommandBarsManager.Commander.DelegateSetPanAndZoomHostVisibility = new SetControlHostVisibility(SetPanAndZoomHostVisibility);
m_CommandBarsManager.Commander.DelegateGetPropertyBrowserHostVisibility = new GetControlHostVisibility(GetPropertyBrowserHostVisibility);
m_CommandBarsManager.Commander.DelegateSetPropertyBrowserHostVisibility = new SetControlHostVisibility(SetPropertyBrowserHostVisibility);
// add the status bar to the form
SuspendLayout();
ClientSize = new System.Drawing.Size(800, 600);
Controls.Add(m_StatusBar);
ResumeLayout(false);
// init form
Text = "##Diagram Designer";
}
///
/// Creates the form docking panels
///
protected virtual void CreateDockingPanels()
{
// create and initialize the dock manager
m_DockManager = new NDockManager();
m_DockManager.ImageList = NDWFR.ImageListDockingPanels;
m_DockManager.Form = this;
m_DockManager.DocumentStyle.DocumentViewEnabled = false;
NDockingPanelContainer rootContainer = m_DockManager.RootContainer;
#region Library Browser
// create a docking panel for the library browser
NDockingPanel libraryPanel = new NDockingPanel();
libraryPanel.Text = "##Library Browser";
libraryPanel.TabInfo.Text = "##Library Browser";
libraryPanel.TabInfo.ImageIndex = 1;
libraryPanel.Controls.Add(m_LibraryBrowser);
// create a docking panel host for the library panel
NDockingPanelHost libraryPanelHost = new NDockingPanelHost();
libraryPanelHost.AddChild(libraryPanel);
NDockZone libraryZone = new NDockZone(Orientation.Vertical);
libraryZone.AddChild(libraryPanelHost);
// add the library panel zone
rootContainer.RootZone.AddChild(libraryZone);
#endregion
#region Drawing View
// drawing view
NControlHost ctrlHost = new NControlHost();
ctrlHost.Controls.Add(m_View);
ctrlHost.SizeInfo.SizeLogic = SizeLogic.FillInterior;
rootContainer.RootZone.AddChild(ctrlHost);
#endregion
#region Pan and Zoom
// pan and zoom
NDockingPanel panZoomPanel = new NDockingPanel();
panZoomPanel.Text = "##Pan and Zoom";
panZoomPanel.SizeInfo.SizeLogic = SizeLogic.Absolute;
panZoomPanel.SizeInfo.AbsoluteSize = new Size(0, 200);
panZoomPanel.TabInfo.Text = "##Pan and Zoom";
panZoomPanel.TabInfo.ImageIndex = 2;
panZoomPanel.Controls.Add(m_PanAndZoomControl);
NDockingPanelHost panAndZoomHost = new NDockingPanelHost();
panAndZoomHost.AddChild(panZoomPanel);
panAndZoomHost.SizeInfo.SizeLogic = SizeLogic.Absolute;
panAndZoomHost.SizeInfo.AbsoluteSize = new Size(0, 200);
libraryZone.AddChild(panAndZoomHost);
#endregion
#region Property Browser
// property browser
NDockingPanel propertyBrowserPanel = new NDockingPanel();
propertyBrowserPanel.Text = "##Property Browser";
propertyBrowserPanel.TabInfo.ImageIndex = 0;
propertyBrowserPanel.Controls.Add(m_PropertyBrowser);
NDockingPanelHost propertyBrowserPanelHost = new NDockingPanelHost();
propertyBrowserPanelHost.AddChild(propertyBrowserPanel);
rootContainer.RootZone.AddChild(propertyBrowserPanelHost);
#endregion
rootContainer.BringToFront();
}
///
/// Called by the Toggle Library Browser command
///
///
protected virtual bool GetLibraryBrowserHostVisibility()
{
return GetPanelHostVisibility(m_LibraryBrowser);
}
///
/// Called by the Toggle Library Browser command
///
///
protected virtual void SetLibraryBrowserHostVisibility(bool visible)
{
SetPanelHostVisibility(m_LibraryBrowser, visible);
}
///
/// Called by the Toggle Pan and Zoom command
///
///
protected virtual bool GetPanAndZoomHostVisibility()
{
return GetPanelHostVisibility(m_PanAndZoomControl);
}
///
/// Called by the Toggle Pan and Zoom command
///
///
protected virtual void SetPanAndZoomHostVisibility(bool visible)
{
SetPanelHostVisibility(m_PanAndZoomControl, visible);
}
///
/// Called by the Toggle Property Browser command
///
///
protected virtual bool GetPropertyBrowserHostVisibility()
{
return GetPanelHostVisibility(m_PropertyBrowser);
}
///
/// Called by the Toggle Property Browser command
///
///
protected virtual void SetPropertyBrowserHostVisibility(bool visible)
{
SetPanelHostVisibility(m_PropertyBrowser, visible);
}
///
/// Gets the visibility of the first ancestor docking panel control of the specified control
///
///
///
protected virtual bool GetPanelHostVisibility(Control control)
{
NDockingPanel panel = (NControlHelper.GetParentOfType(control, typeof(NDockingPanel)) as NDockingPanel);
if (panel == null)
return true;
return panel.DockState != DockState.Hidden;
}
///
/// Sets the visibility of the first ancestor docking panel control of the specified control
///
///
///
protected virtual void SetPanelHostVisibility(Control control, bool visible)
{
NDockingPanel panel = (NControlHelper.GetParentOfType(control, typeof(NDockingPanel)) as NDockingPanel);
if (panel == null)
return;
if (visible)
{
panel.Display();
}
else
{
panel.Close();
}
}
///
/// Called by the diagram commander when the user executes the exit command
///
protected virtual void Exit()
{
m_bExiting = true;
Close();
m_bExiting = false;
}
///
/// Called when the global Nevron UI palette has changed
///
/// new palette
///
protected virtual void OnPaletteChanged(NPalette palette, PaletteChangeEventArgs e)
{
NUIManager.Palette.Copy(palette);
}
#endregion
#region Protected overrides
///
/// Overriden to save the currently edited document if it was modified
///
///
protected override void OnClosing(CancelEventArgs e)
{
if (m_bExiting)
return;
if (m_CommandBarsManager.Commander.SaveDocumentIfModified() == false)
{
e.Cancel = true;
}
}
#endregion
#region Implementation
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(NDiagramDesignerForm));
//
// NDiagramDesignerForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(632, 509);
this.Name = "NDiagramDesignerForm";
this.Load += new System.EventHandler(this.NDiagramDesignerForm_Load);
}
#endregion
#region Event Handlers
private void NDiagramDesignerForm_Load(object sender, System.EventArgs e)
{
// init the test skin
NSkinResource res = new NSkinResource(SkinResourceType.GlobalAssembly, "Vista");
res.AssemblyName = "Nevron.UI.WinForm.Skins";
NSkin skin = new NSkin();
// apply skin if load successful
if (skin.Load(res))
{
NSkinManager.Instance.Skin = skin;
}
}
#endregion
#region Fields
internal NDrawingView m_View;
internal NDiagramCommandBarsManager m_CommandBarsManager;
internal NLibraryBrowser m_LibraryBrowser;
internal NPropertyBrowser m_PropertyBrowser;
internal NDiagramStatusBar m_StatusBar;
internal NDockManager m_DockManager;
internal NPanAndZoomControl m_PanAndZoomControl;
internal bool m_bExiting;
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
// Localization test
//string fileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "nevron_bg-BG.xml");
//Nevron.Globalization.NLocalizationManager.Instance.Load(fileName);
string fileName = args.Length > 0 ? args[0] : null;
Application.Run(new NDiagramDesignerForm(fileName));
}
}
}