예제 #1
0
        private void InitCommands()
        {
            #region "ApplicationExit Command"

            Command exitCommand = new Command(CommandNames.ApplicationExit);
            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    exitToolStripMenuItem, exitCommand));

            ExitCommandHandler exitHandler = new ExitCommandHandler(exitCommand);
            CommandManager.AddCommandHandler(exitHandler);

            #endregion

            #region "AddLayer Command"

            Command addLayerCommand = new Command(CommandNames.AddLayer);
            ActionCommandHandler addLayerHandler = new ActionCommandHandler(addLayerCommand, AddLayer);
            CommandManager.AddCommand(addLayerCommand);
            CommandManager.AddCommandHandler(addLayerHandler);
            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    addLayerToolStripMenuItem, addLayerCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    addLayerToolStripMenuItem1, addLayerCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    addLayerToolStripMenuItem2, addLayerCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    bAddLayer, addLayerCommand));

            #endregion

            #region "ClearLayers Command"

            Command clearLayersCommand = new Command(CommandNames.ClearLayers);
            ActionCommandHandler clearLayersHandler = new ActionCommandHandler(clearLayersCommand, ClearLayers);
            CommandManager.AddCommandHandler(clearLayersHandler);

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    clearLayersToolStripMenuItem, clearLayersCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    clearLayersToolStripMenuItem1, clearLayersCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    clearLayersButton1, clearLayersCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    clearLayersToolStripMenuItem2, clearLayersCommand));

            #endregion

            #region "Refresh map command"

            ICommand refreshMapCommand = new Command(CommandNames.RefreshMap);
            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    refreshMapToolBarButton, refreshMapCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    refreshMapToolStripMenuItem, refreshMapCommand));

            CommandManager.AddCommandHandler(
                new ActionCommandHandler(refreshMapCommand, delegate { mapViewControl1.Refresh(); }));

            #endregion

            #region "Zoom map extent command"

            ICommand zoomMapExtentCommand = new Command(CommandNames.ZoomFullExtent);
            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource <ToolStripItem>(
                    zoomMapExtentsToolstripButton, zoomMapExtentCommand));

            CommandManager.AddCommandHandler(
                new ActionCommandHandler(zoomMapExtentCommand, ZoomMapExtent));

            #endregion

            #region "Zoom Layer Extent"

            ICommand <CommandEventArgs <ILayer> > zoomLayerCommand
                = new Command <CommandEventArgs <ILayer> >(CommandNames.ZoomLayerExtent);

            ICommandComponentSource <ToolStripItem, CommandEventArgs <ILayer> > zoomLayerExtentToolStripMenuItemSource
                = new ToolStripItemCommandSource <ToolStripItem, CommandEventArgs <ILayer> >(
                      zoomLayerExtentToolStripMenuItem, zoomLayerCommand);

            CommandManager.AddCommandSource(zoomLayerExtentToolStripMenuItemSource);
            ICommandHandler <CommandEventArgs <ILayer> > zoomLayerHandler
                = new ActionCommandHandler <CommandEventArgs <ILayer> >(
                      zoomLayerCommand, ZoomLayerExtent);
            CommandManager.AddCommandHandler(zoomLayerHandler);

            #endregion

            #region "Edit Layer Symbology"

            ICommand <CommandEventArgs <ILayer> > editLayerSymbology
                = new Command <CommandEventArgs <ILayer> >(CommandNames.EditLayerSymbology);

            ICommandComponentSource <ToolStripItem, CommandEventArgs <ILayer> > editLayerSymbologySource
                = new ToolStripItemCommandSource <ToolStripItem, CommandEventArgs <ILayer> >(
                      editSymbologyToolStripMenuItem, editLayerSymbology);
            CommandManager.AddCommandSource(editLayerSymbologySource);


            CommandManager.AddCommandHandler(new ActionCommandHandler <CommandEventArgs <ILayer> >(editLayerSymbology,
                                                                                                   EditLayerSymbology));

            #endregion

            ICommand mapLayersChangedCommand = new Command(CommandNames.MapLayersChanged);


            Map.Layers.ListChanged += delegate { mapLayersChangedCommand.FireCommand(); };

            CommandManager.AddCommand(mapLayersChangedCommand);

            CommandManager.AddCommandHandler(
                new ActionCommandHandler(mapLayersChangedCommand, EnableDisableCommandsRequiringLayers));

            #region fixed zoom in /out

            ICommand fixedZoomInCommand = new Command(CommandNames.FixedZoomIn);
            CommandManager.AddCommand(fixedZoomInCommand);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripButton>(fixedZoomInButton,
                                                                                             fixedZoomInCommand));
            CommandManager.AddCommandHandler(new ActionCommandHandler(fixedZoomInCommand, FixedZoomIn));


            ICommand fixedZoomOutCommand = new Command(CommandNames.FixedZoomOut);
            CommandManager.AddCommand(fixedZoomInCommand);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripButton>(fixedZoomOutButton,
                                                                                             fixedZoomOutCommand));
            CommandManager.AddCommandHandler(new ActionCommandHandler(fixedZoomOutCommand, FixedZoomOut));

            #endregion

            #region mouse pan and zoom

            ICommand enablePan = new Command(CommandNames.EnablePan);
            CommandManager.AddCommand(enablePan);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripButton>(panButton, enablePan));
            CommandManager.AddCommandHandler(new ActionCommandHandler(enablePan, EnablePan));

            ICommand zoomInMouse = new Command(CommandNames.ZoomInMouse);
            CommandManager.AddCommand(zoomInMouse);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripButton>(zoomInButton, zoomInMouse));
            CommandManager.AddCommandHandler(new ActionCommandHandler(zoomInMouse, EnableZoomInMouse));


            ICommand zoomOutMouse = new Command(CommandNames.ZoomOutMouse);
            CommandManager.AddCommand(zoomOutMouse);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripButton>(zoomOutButton, zoomOutMouse));
            CommandManager.AddCommandHandler(new ActionCommandHandler(zoomOutMouse, EnableZoomOutMouse));

            #endregion

            #region Query

            ICommand queryAdd = new Command(CommandNames.QueryAdd);

            CommandManager.AddCommand(queryAdd);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripButton>(queryAddButton,
                                                                                             queryAdd));
            CommandManager.AddCommandHandler(new ActionCommandHandler(queryAdd, EnableQueryAdd));

            ICommand queryRemove = new Command(CommandNames.QueryRemove);
            CommandManager.AddCommand(queryRemove);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripButton>(queryRemoveButton,
                                                                                             queryRemove));
            CommandManager.AddCommandHandler(new ActionCommandHandler(queryRemove, EnableQueryRemove));

            #endregion

            ICommand addStyle = new Command(CommandNames.AddStyle);
            CommandManager.AddCommand(addStyle);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripMenuItem>(addStyleMenuStripItem,
                                                                                               addStyle));
            CommandManager.AddCommandSource(new ToolStripItemCommandSource <ToolStripMenuItem>(
                                                addStylesToolStripMenuItem,
                                                addStyle));
            CommandManager.AddCommandHandler(new ActionCommandHandler(addStyle, AddStyle));


            EnableDisableCommandsRequiringLayers();
        }
예제 #2
0
        private void InitCommands()
        {
            #region "ApplicationExit Command"

            Command exitCommand = new Command(CommandNames.ApplicationExit);
            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    exitToolStripMenuItem, exitCommand));

            ExitCommandHandler exitHandler = new ExitCommandHandler(exitCommand);
            CommandManager.AddCommandHandler(exitHandler);

            #endregion

            #region"AddLayer Command"

            Command addLayerCommand = new Command(CommandNames.AddLayer);
            ActionCommandHandler addLayerHandler = new ActionCommandHandler(addLayerCommand, AddLayer);
            CommandManager.AddCommand(addLayerCommand);
            CommandManager.AddCommandHandler(addLayerHandler);
            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    addLayerToolStripMenuItem, addLayerCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    addLayerToolStripMenuItem1, addLayerCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    addLayerToolStripMenuItem2, addLayerCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    bAddLayer, addLayerCommand));

            #endregion

            #region "ClearLayers Command"

            Command clearLayersCommand = new Command(CommandNames.ClearLayers);
            ActionCommandHandler clearLayersHandler = new ActionCommandHandler(clearLayersCommand, ClearLayers);
            CommandManager.AddCommandHandler(clearLayersHandler);

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    clearLayersToolStripMenuItem, clearLayersCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    clearLayersToolStripMenuItem1, clearLayersCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    clearLayersButton1, clearLayersCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    clearLayersToolStripMenuItem2, clearLayersCommand));

            #endregion

            #region "Refresh map command"

            ICommand refreshMapCommand = new Command(CommandNames.RefreshMap);
            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    refreshMapToolBarButton, refreshMapCommand));

            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    refreshMapToolStripMenuItem, refreshMapCommand));

            CommandManager.AddCommandHandler(
                new ActionCommandHandler(refreshMapCommand, delegate { mapViewControl1.Refresh(); }));

            #endregion

            #region "Zoom map extent command"

            ICommand zoomMapExtentCommand = new Command(CommandNames.ZoomFullExtent);
            CommandManager.AddCommandSource(
                new ToolStripItemCommandSource<ToolStripItem>(
                    zoomMapExtentsToolstripButton, zoomMapExtentCommand));

            CommandManager.AddCommandHandler(
                new ActionCommandHandler(zoomMapExtentCommand, ZoomMapExtent));

            #endregion

            #region "Zoom Layer Extent"

            ICommand<CommandEventArgs<ILayer>> zoomLayerCommand
                = new Command<CommandEventArgs<ILayer>>(CommandNames.ZoomLayerExtent);

            ICommandComponentSource<ToolStripItem, CommandEventArgs<ILayer>> zoomLayerExtentToolStripMenuItemSource
                = new ToolStripItemCommandSource<ToolStripItem, CommandEventArgs<ILayer>>(
                    zoomLayerExtentToolStripMenuItem, zoomLayerCommand);

            CommandManager.AddCommandSource(zoomLayerExtentToolStripMenuItemSource);
            ICommandHandler<CommandEventArgs<ILayer>> zoomLayerHandler
                = new ActionCommandHandler<CommandEventArgs<ILayer>>(
                    zoomLayerCommand, ZoomLayerExtent);
            CommandManager.AddCommandHandler(zoomLayerHandler);

            #endregion

            #region "Edit Layer Symbology"

            ICommand<CommandEventArgs<ILayer>> editLayerSymbology
                = new Command<CommandEventArgs<ILayer>>(CommandNames.EditLayerSymbology);

            ICommandComponentSource<ToolStripItem, CommandEventArgs<ILayer>> editLayerSymbologySource
                = new ToolStripItemCommandSource<ToolStripItem, CommandEventArgs<ILayer>>(
                    editSymbologyToolStripMenuItem, editLayerSymbology);
            CommandManager.AddCommandSource(editLayerSymbologySource);


            CommandManager.AddCommandHandler(new ActionCommandHandler<CommandEventArgs<ILayer>>(editLayerSymbology,
                                                                                                EditLayerSymbology));

            #endregion

            ICommand mapLayersChangedCommand = new Command(CommandNames.MapLayersChanged);


            Map.Layers.ListChanged += delegate { mapLayersChangedCommand.FireCommand(); };

            CommandManager.AddCommand(mapLayersChangedCommand);

            CommandManager.AddCommandHandler(
                new ActionCommandHandler(mapLayersChangedCommand, EnableDisableCommandsRequiringLayers));

            #region fixed zoom in /out

            ICommand fixedZoomInCommand = new Command(CommandNames.FixedZoomIn);
            CommandManager.AddCommand(fixedZoomInCommand);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripButton>(fixedZoomInButton,
                                                                                            fixedZoomInCommand));
            CommandManager.AddCommandHandler(new ActionCommandHandler(fixedZoomInCommand, FixedZoomIn));


            ICommand fixedZoomOutCommand = new Command(CommandNames.FixedZoomOut);
            CommandManager.AddCommand(fixedZoomInCommand);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripButton>(fixedZoomOutButton,
                                                                                            fixedZoomOutCommand));
            CommandManager.AddCommandHandler(new ActionCommandHandler(fixedZoomOutCommand, FixedZoomOut));

            #endregion

            #region mouse pan and zoom

            ICommand enablePan = new Command(CommandNames.EnablePan);
            CommandManager.AddCommand(enablePan);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripButton>(panButton, enablePan));
            CommandManager.AddCommandHandler(new ActionCommandHandler(enablePan, EnablePan));

            ICommand zoomInMouse = new Command(CommandNames.ZoomInMouse);
            CommandManager.AddCommand(zoomInMouse);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripButton>(zoomInButton, zoomInMouse));
            CommandManager.AddCommandHandler(new ActionCommandHandler(zoomInMouse, EnableZoomInMouse));


            ICommand zoomOutMouse = new Command(CommandNames.ZoomOutMouse);
            CommandManager.AddCommand(zoomOutMouse);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripButton>(zoomOutButton, zoomOutMouse));
            CommandManager.AddCommandHandler(new ActionCommandHandler(zoomOutMouse, EnableZoomOutMouse));

            #endregion

            #region Query

            ICommand queryAdd = new Command(CommandNames.QueryAdd);

            CommandManager.AddCommand(queryAdd);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripButton>(queryAddButton,
                                                                                            queryAdd));
            CommandManager.AddCommandHandler(new ActionCommandHandler(queryAdd, EnableQueryAdd));

            ICommand queryRemove = new Command(CommandNames.QueryRemove);
            CommandManager.AddCommand(queryRemove);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripButton>(queryRemoveButton,
                                                                                            queryRemove));
            CommandManager.AddCommandHandler(new ActionCommandHandler(queryRemove, EnableQueryRemove));

            #endregion

            ICommand addStyle = new Command(CommandNames.AddStyle);
            CommandManager.AddCommand(addStyle);
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripMenuItem>(addStyleMenuStripItem,
                                                                                              addStyle));
            CommandManager.AddCommandSource(new ToolStripItemCommandSource<ToolStripMenuItem>(
                                                addStylesToolStripMenuItem,
                                                addStyle));
            CommandManager.AddCommandHandler(new ActionCommandHandler(addStyle, AddStyle));


            EnableDisableCommandsRequiringLayers();
        }