-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
819f11d
commit 41edd64
Showing
738 changed files
with
151,571 additions
and
480 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
| ||
/* | ||
* This file is part of SharpMapMapViewer | ||
* SharpMapMapViewer is free software © 2008 Newgrove Consultants Limited, | ||
* http://www.newgrove.com; you can redistribute it and/or modify it under the terms | ||
* of the current GNU Lesser General Public License (LGPL) as published by and | ||
* available from the Free Software Foundation, Inc., | ||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA: http://fsf.org/ | ||
* This program is distributed without any warranty; | ||
* without even the implied warranty of merchantability or fitness for purpose. | ||
* See the GNU Lesser General Public License for the full details. | ||
* | ||
* Author: John Diss 2008 | ||
* | ||
*/ | ||
|
||
using System; | ||
using MapViewer.Commands; | ||
|
||
namespace MapViewer | ||
{ | ||
public class ActionCommandHandler | ||
: CommandHandlerBase | ||
{ | ||
public ActionCommandHandler() | ||
: this(null, null) | ||
{ | ||
} | ||
|
||
public ActionCommandHandler(ICommand command) | ||
: this(command, null) | ||
{ | ||
} | ||
|
||
public ActionCommandHandler(Action action) | ||
: this(null, action) | ||
{ | ||
} | ||
|
||
public ActionCommandHandler(ICommand command, Action action) | ||
: base(command) | ||
{ | ||
Action = action; | ||
} | ||
|
||
public Action Action { get; set; } | ||
|
||
public override void HandleCommand() | ||
{ | ||
if (Action != null) | ||
Action(); | ||
} | ||
} | ||
|
||
public class ActionCommandHandler<TEventArgs> | ||
: CommandHandlerBase<TEventArgs> | ||
where TEventArgs : CommandEventArgs | ||
{ | ||
public ActionCommandHandler() | ||
: this(null, null) | ||
{ | ||
} | ||
|
||
public ActionCommandHandler(ICommand<TEventArgs> command) | ||
: this(command, null) | ||
{ | ||
} | ||
|
||
public ActionCommandHandler(Action<TEventArgs> action) | ||
: this(null, action) | ||
{ | ||
} | ||
|
||
public ActionCommandHandler(ICommand<TEventArgs> command, Action<TEventArgs> action) | ||
: base(command) | ||
{ | ||
Action = action; | ||
} | ||
|
||
public Action<TEventArgs> Action { get; set; } | ||
|
||
public override void HandleCommand(TEventArgs args) | ||
{ | ||
if (Action != null) | ||
Action(args); | ||
} | ||
|
||
public override void HandleCommand() | ||
{ | ||
throw new InvalidOperationException(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Demos/SharpMapWinFormsDemo/Commands/ButtonCommandSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* This file is part of SharpMapMapViewer | ||
* SharpMapMapViewer is free software © 2008 Newgrove Consultants Limited, | ||
* http://www.newgrove.com; you can redistribute it and/or modify it under the terms | ||
* of the current GNU Lesser General Public License (LGPL) as published by and | ||
* available from the Free Software Foundation, Inc., | ||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA: http://fsf.org/ | ||
* This program is distributed without any warranty; | ||
* without even the implied warranty of merchantability or fitness for purpose. | ||
* See the GNU Lesser General Public License for the full details. | ||
* | ||
* Author: John Diss 2008 | ||
* | ||
*/ | ||
using System; | ||
using System.Windows.Forms; | ||
|
||
namespace MapViewer.Commands | ||
{ | ||
public class ButtonCommandSource | ||
: CommandControlSourceBase<Button> | ||
{ | ||
protected override void WireControl(Button control) | ||
{ | ||
control.Click += control_Click; | ||
} | ||
|
||
private void control_Click(object sender, EventArgs e) | ||
{ | ||
if (Command != null) | ||
Command.FireCommand(); | ||
} | ||
|
||
protected override void UnwireControl(Button control) | ||
{ | ||
control.Click -= control_Click; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* This file is part of SharpMapMapViewer | ||
* SharpMapMapViewer is free software © 2008 Newgrove Consultants Limited, | ||
* http://www.newgrove.com; you can redistribute it and/or modify it under the terms | ||
* of the current GNU Lesser General Public License (LGPL) as published by and | ||
* available from the Free Software Foundation, Inc., | ||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA: http://fsf.org/ | ||
* This program is distributed without any warranty; | ||
* without even the implied warranty of merchantability or fitness for purpose. | ||
* See the GNU Lesser General Public License for the full details. | ||
* | ||
* Author: John Diss 2008 | ||
* | ||
*/ | ||
using System; | ||
|
||
namespace MapViewer.Commands | ||
{ | ||
public class Command : ICommand | ||
{ | ||
protected readonly string _name; | ||
private bool _enabled = true; | ||
|
||
public Command(string name) | ||
{ | ||
_name = name; | ||
} | ||
|
||
#region ICommand Members | ||
|
||
public event EventHandler CommandFired; | ||
|
||
public bool Enabled | ||
{ | ||
get { return _enabled; } | ||
set | ||
{ | ||
if (_enabled != value) | ||
{ | ||
_enabled = value; | ||
if (EnabledChanged != null) | ||
EnabledChanged(this, EventArgs.Empty); | ||
} | ||
} | ||
} | ||
|
||
public void FireCommand() | ||
{ | ||
if (CommandFired != null) | ||
CommandFired(this, EventArgs.Empty); | ||
} | ||
|
||
public event EventHandler EnabledChanged; | ||
|
||
public string Name | ||
{ | ||
get { return _name; } | ||
} | ||
|
||
#endregion | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
Demos/SharpMapWinFormsDemo/Commands/CommandComponentSourceBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* This file is part of SharpMapMapViewer | ||
* SharpMapMapViewer is free software © 2008 Newgrove Consultants Limited, | ||
* http://www.newgrove.com; you can redistribute it and/or modify it under the terms | ||
* of the current GNU Lesser General Public License (LGPL) as published by and | ||
* available from the Free Software Foundation, Inc., | ||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA: http://fsf.org/ | ||
* This program is distributed without any warranty; | ||
* without even the implied warranty of merchantability or fitness for purpose. | ||
* See the GNU Lesser General Public License for the full details. | ||
* | ||
* Author: John Diss 2008 | ||
* | ||
*/ | ||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace MapViewer.Commands | ||
{ | ||
public abstract class CommandComponentSourceBase<TComponent> | ||
: ICommandComponentSource<TComponent> | ||
where TComponent : IComponent | ||
{ | ||
private ICommand _command; | ||
private TComponent _component; | ||
protected CommandEnabledChangedDelegate<TComponent> _enabledChangedAction; | ||
|
||
protected CommandComponentSourceBase() | ||
{ | ||
_enabledChangedAction = DefaultEnabledChangedAction(); | ||
} | ||
|
||
protected CommandComponentSourceBase(ICommand command) | ||
: this(default(TComponent), command) | ||
{ | ||
} | ||
|
||
protected CommandComponentSourceBase(TComponent component) | ||
: this(component, null) | ||
{ | ||
} | ||
|
||
protected CommandComponentSourceBase(TComponent component, ICommand command) | ||
: this() | ||
{ | ||
Command = command; | ||
Component = component; | ||
} | ||
|
||
private CommandEnabledChangedDelegate<TComponent> CommandEnabledChangedAction | ||
{ | ||
get { return _enabledChangedAction; } | ||
set { _enabledChangedAction = value; } | ||
} | ||
|
||
#region ICommandComponentSource<TComponent> Members | ||
|
||
public ICommand Command | ||
{ | ||
get { return _command; } | ||
set | ||
{ | ||
if (_command != null) | ||
_command.EnabledChanged -= CommandEnabledChanged; | ||
if (value != null) | ||
{ | ||
_command = value; | ||
_command.EnabledChanged += CommandEnabledChanged; | ||
} | ||
} | ||
} | ||
|
||
public TComponent Component | ||
{ | ||
get { return _component; } | ||
set | ||
{ | ||
if (!Equals(_component, default(TComponent))) | ||
UnwireComponent(_component); | ||
if (!Equals(value, default(TComponent))) | ||
{ | ||
_component = value; | ||
WireComponent(_component); | ||
CommandEnabledChanged(null, null); | ||
} | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
protected abstract CommandEnabledChangedDelegate<TComponent> DefaultEnabledChangedAction(); | ||
|
||
internal void CommandEnabledChanged(object sender, EventArgs e) | ||
{ | ||
if (!Equals(Component, default(TComponent)) && Command != null) | ||
CommandEnabledChangedAction(Component, Command.Enabled); | ||
} | ||
|
||
protected abstract void WireComponent(TComponent component); | ||
protected abstract void UnwireComponent(TComponent component); | ||
} | ||
|
||
public abstract class CommandComponentSourceBase<TComponent, TEventArgs> | ||
: CommandComponentSourceBase<TComponent>, ICommandComponentSource<TComponent, TEventArgs> | ||
where TComponent : IComponent | ||
where TEventArgs : CommandEventArgs | ||
{ | ||
public CommandComponentSourceBase(ICommand<TEventArgs> command) | ||
: this(default(TComponent), command) | ||
{ | ||
} | ||
|
||
public CommandComponentSourceBase(TComponent component) | ||
: this(component, null) | ||
{ | ||
} | ||
|
||
public CommandComponentSourceBase(TComponent component, ICommand<TEventArgs> command) | ||
: base(component, command) | ||
{ | ||
} | ||
|
||
#region ICommandComponentSource<TComponent,TEventArgs> Members | ||
|
||
public new ICommand<TEventArgs> Command | ||
{ | ||
get { return (ICommand<TEventArgs>) base.Command; } | ||
set { base.Command = value; } | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.