diff options
| author | mo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64> | 2008-01-05 07:16:52 +0000 |
|---|---|---|
| committer | mo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64> | 2008-01-05 07:16:52 +0000 |
| commit | 8c137f229c36a777ead5cacb3350cb8692646292 (patch) | |
| tree | 92876c5da0ffd17767e38f94a44415ac27a3c73e /DesignPatterns/src/app/DesignPatterns.Adapter | |
| parent | cbdf42a6427eef7849d1ab7731f9185b410431d3 (diff) | |
git-svn-id: http://mokhan.googlecode.com/svn/trunk@9 a0a4a051-f042-0410-9e78-9fae330bdb64
Diffstat (limited to 'DesignPatterns/src/app/DesignPatterns.Adapter')
9 files changed, 201 insertions, 0 deletions
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/DesignPatterns.Adapter.csproj b/DesignPatterns/src/app/DesignPatterns.Adapter/DesignPatterns.Adapter.csproj new file mode 100644 index 0000000..c4634e4 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/DesignPatterns.Adapter.csproj @@ -0,0 +1,55 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{A96C019F-1A15-4085-A94C-A0C55632A4EB}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DesignPatterns.Adapter</RootNamespace>
+ <AssemblyName>DesignPatterns.Adapter</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="DesktopDropDownList.cs" />
+ <Compile Include="DropDownListItem.cs" />
+ <Compile Include="IDropDownListAdapter.cs" />
+ <Compile Include="IDropDownListItem.cs" />
+ <Compile Include="IView.cs" />
+ <Compile Include="Presenter.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="WebDropDownList.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs new file mode 100644 index 0000000..cc876c4 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic;
+using System.Windows.Forms;
+
+namespace DesignPatterns.Adapter {
+ public class DesktopDropDownList : IDropDownListAdapter {
+ public DesktopDropDownList( ComboBox dropDown ) {
+ _dropDown = dropDown;
+ _pairs = new Dictionary< string, IDropDownListItem >( );
+ }
+
+ public void BindTo( IEnumerable< IDropDownListItem > pairs ) {
+ if ( pairs != null ) {
+ _pairs = new Dictionary< string, IDropDownListItem >( );
+
+ foreach ( IDropDownListItem pair in pairs ) {
+ _dropDown.Items.Add( pair.Text );
+ _pairs.Add( pair.Text, pair );
+ }
+ _dropDown.SelectedIndex = 0;
+ }
+ }
+
+ public IDropDownListItem SelectedItem {
+ get { return !string.IsNullOrEmpty( _dropDown.Text ) ? _pairs[ _dropDown.Text ] : null; }
+ }
+
+ private ComboBox _dropDown;
+ private IDictionary< string, IDropDownListItem > _pairs;
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/DropDownListItem.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/DropDownListItem.cs new file mode 100644 index 0000000..7c30efb --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/DropDownListItem.cs @@ -0,0 +1,19 @@ +namespace DesignPatterns.Adapter {
+ internal class DropDownListItem : IDropDownListItem {
+ public DropDownListItem( string text, string value ) {
+ _text = text;
+ _value = value;
+ }
+
+ public string Text {
+ get { return _text; }
+ }
+
+ public string Value {
+ get { return _value; }
+ }
+
+ private readonly string _text;
+ private readonly string _value;
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListAdapter.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListAdapter.cs new file mode 100644 index 0000000..ce2338d --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListAdapter.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic;
+
+namespace DesignPatterns.Adapter {
+ public interface IDropDownListAdapter {
+ void BindTo( IEnumerable< IDropDownListItem > pairs );
+
+ IDropDownListItem SelectedItem { get; }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListItem.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListItem.cs new file mode 100644 index 0000000..0e1099a --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListItem.cs @@ -0,0 +1,6 @@ +namespace DesignPatterns.Adapter {
+ public interface IDropDownListItem {
+ string Text { get; }
+ string Value { get; }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/IView.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/IView.cs new file mode 100644 index 0000000..28e25dc --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/IView.cs @@ -0,0 +1,5 @@ +namespace DesignPatterns.Adapter {
+ public interface IView {
+ IDropDownListAdapter AreYouHappy { get; }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/Presenter.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/Presenter.cs new file mode 100644 index 0000000..32fe136 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/Presenter.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic;
+
+namespace DesignPatterns.Adapter {
+ public class Presenter {
+ private readonly IView _view;
+
+ public Presenter( IView view ) {
+ _view = view;
+ }
+
+ public void Initialize( ) {
+ IList< IDropDownListItem > items = new List< IDropDownListItem >( );
+ items.Add( new DropDownListItem( "Yes", "1" ) );
+ items.Add( new DropDownListItem( "No", "2" ) );
+ _view.AreYouHappy.BindTo( items );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/Properties/AssemblyInfo.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dcbf00d --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("DesignPatterns.Adapter")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DesignPatterns.Adapter")]
+[assembly: AssemblyCopyright("Copyright © 2007")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("4d256698-91ca-4e2a-92a4-57a38f6202a9")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/WebDropDownList.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/WebDropDownList.cs new file mode 100644 index 0000000..e356a71 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/WebDropDownList.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic;
+using System.Web.UI.WebControls;
+
+namespace DesignPatterns.Adapter {
+ public class WebDropDownList : IDropDownListAdapter {
+ public WebDropDownList( DropDownList dropDown ) {
+ _dropDown = dropDown;
+ }
+
+ public void BindTo( IEnumerable< IDropDownListItem > pairs ) {
+ if ( pairs != null ) {
+ foreach ( IDropDownListItem pair in pairs ) {
+ _dropDown.Items.Add( new ListItem( pair.Text, pair.Value ) );
+ }
+ }
+ }
+
+ public IDropDownListItem SelectedItem {
+ get { return new DropDownListItem( _dropDown.SelectedItem.Text, _dropDown.SelectedItem.Value ); }
+ }
+
+ private DropDownList _dropDown;
+ }
+}
\ No newline at end of file |
