HouseOver.UserInterface Class Reference

The user interface class. Presents data to the user and gets input from the user. More...

List of all members.

Public Member Functions

 UserInterface ()
 The UI constructor.
string Draw (string drawThis, params object[] arg)
 Draw an input screen.
int DrawInt (string drawThis, params object[] arg)
 Draw an input screen to get an integer.
bool DrawMenu (string drawThis, Dictionary< object, string > menuItems, bool showCancel, out T chosen)
 Draws the UI menu.
 UserInterface ()
 The UI constructor.
string Draw (string drawThis, params object[] arg)
 Draw an input screen.
int DrawInt (string drawThis, params object[] arg)
 Draw an input screen to get an integer.
bool DrawMenu (string drawThis, Dictionary< object, string > menuItems, bool showCancel, out T chosen)
 Draws the UI menu.

Private Member Functions

void DoDraw (string content, params object[] arg)
 Perform the actual drawing on screen of some content.
void DoDraw (string content, string errorMessage, params object[] arg)
 Perform the actual drawing on screen of some content - with error message.
void DoDraw (string content, params object[] arg)
 Perform the actual drawing on screen of some content.
void DoDraw (string content, string errorMessage, params object[] arg)
 Perform the actual drawing on screen of some content - with error message.

Private Attributes

int width = 80
 The width of the console.
int height = 25
 The height of the console.
int contentHeight
 The height of the content field.
string header
 The text shown at the top of each screen.
string footer
 The text shown at the bottom of each screen.


Detailed Description

The user interface class. Presents data to the user and gets input from the user.

Definition at line 10 of file UserInterface.cs.


Constructor & Destructor Documentation

HouseOver.UserInterface.UserInterface (  ) 

The UI constructor.

Definition at line 26 of file UserInterface.cs.

References HouseOver.UserInterface.contentHeight, HouseOver.UserInterface.footer, HouseOver.UserInterface.header, HouseOver.UserInterface.height, and HouseOver.UserInterface.width.

00027                 {
00028             string title = "The House And Realty Manager";
00029             string version = "v. 0.01a";
00030             string headSeparator = "¨";
00031             string enterChoiceString = "Enter your choice: ";
00032             string footSeparator = "_";
00033 
00034             // Generate the header contents
00035             int topSpace = width - (title.Length + version.Length);
00036             header = title;
00037             for (int i = 0; i < topSpace; i++)
00038                 header += " ";
00039             header += version;
00040             for (int i = 0; i < width; i++)
00041                 header += headSeparator;
00042             header += System.Environment.NewLine;
00043 
00044             // Generate the footer contents
00045             for (int i = 0; i < width; i++)
00046                 footer += footSeparator;
00047             footer += enterChoiceString;
00048 
00049             // Content height is set to the height of the console, minus the height of the header and footer
00050             contentHeight = height - 4;
00051         }

HouseOver.UserInterface.UserInterface (  ) 

The UI constructor.

Definition at line 26 of file UserInterface.cs.

References HouseOver.UserInterface.contentHeight, HouseOver.UserInterface.footer, HouseOver.UserInterface.header, HouseOver.UserInterface.height, and HouseOver.UserInterface.width.

00027                 {
00028             string title = "The House And Realty Manager";
00029             string version = "v. 0.01a";
00030             string headSeparator = "¨";
00031             string enterChoiceString = "Enter your choice: ";
00032             string footSeparator = "_";
00033 
00034             // Generate the header contents
00035             int topSpace = width - (title.Length + version.Length);
00036             header = title;
00037             for (int i = 0; i < topSpace; i++)
00038                 header += " ";
00039             header += version;
00040             for (int i = 0; i < width; i++)
00041                 header += headSeparator;
00042             header += System.Environment.NewLine;
00043 
00044             // Generate the footer contents
00045             for (int i = 0; i < width; i++)
00046                 footer += footSeparator;
00047             footer += enterChoiceString;
00048 
00049             // Content height is set to the height of the console, minus the height of the header and footer
00050             contentHeight = height - 4;
00051         }


Member Function Documentation

void HouseOver.UserInterface.DoDraw ( string  content,
params object[]  arg 
) [private]

Perform the actual drawing on screen of some content.

Parameters:
content The content to draw. Should preferably be less than twenty lines of text
arg A set of extra parameters, which is passed on to the console writer

Definition at line 58 of file UserInterface.cs.

References HouseOver.UserInterface.footer, and HouseOver.UserInterface.header.

Referenced by HouseOver.UserInterface.Draw(), and HouseOver.UserInterface.DrawInt().

00059         {
00060             // It fails to count the last newline
00061             int contentSize = content.Split(System.Environment.NewLine.ToCharArray(0, 1)).Length;
00062             int separateThisMuchTop = Convert.ToInt32(Math.Floor(Convert.ToDouble(this.contentHeight - contentSize) / 2));
00063             int separateThisMuchBottom = this.contentHeight - (contentSize + separateThisMuchTop);
00064 
00065             // We shouldn't be drawing anything taller than the screen... but oh well
00066             if (separateThisMuchTop < 0 || separateThisMuchBottom < 0)
00067             {
00068                 separateThisMuchTop = 0;
00069                 separateThisMuchBottom = 0;
00070             }
00071 
00072             Console.Clear();
00073             Console.Write(header);
00074 
00075             for (int i = 0; i < separateThisMuchTop; i++)
00076                 Console.WriteLine("");
00077             Console.Write(content,arg);
00078 
00079             for (int i = 0; i < separateThisMuchBottom; i++)
00080                 Console.WriteLine("");
00081             Console.Write(footer);
00082         }

Here is the caller graph for this function:

void HouseOver.UserInterface.DoDraw ( string  content,
string  errorMessage,
params object[]  arg 
) [private]

Perform the actual drawing on screen of some content - with error message.

Parameters:
content The content to draw. Should preferably be less than twenty lines of text
errorMessage The error message to show to the user
arg A set of extra parameters, which is passed on to the console writer

Definition at line 91 of file UserInterface.cs.

References HouseOver.UserInterface.contentHeight, HouseOver.UserInterface.footer, and HouseOver.UserInterface.header.

00092         {
00093             int contentSize = content.Split(System.Environment.NewLine.ToCharArray(0, 1)).Length + errorMessage.Split(System.Environment.NewLine.ToCharArray(0, 1)).Length + 1;
00094             int separateThisMuchTop = Convert.ToInt32(Math.Floor(Convert.ToDouble(contentHeight - contentSize) / 2));
00095             int separateThisMuchBottom = this.contentHeight - (contentSize + separateThisMuchTop);
00096 
00097             // We shouldn't be drawing anything taller than the screen... but oh well
00098             if (separateThisMuchTop < 0 || separateThisMuchBottom < 0)
00099             {
00100                 separateThisMuchTop = 0;
00101                 separateThisMuchBottom = 0;
00102             }
00103 
00104             Console.Clear();
00105 
00106             Console.Write(header);
00107             for (int i = 0; i < separateThisMuchTop; i++)
00108                 Console.WriteLine("");
00109 
00110             Console.BackgroundColor = ConsoleColor.DarkRed;
00111             Console.ForegroundColor = ConsoleColor.White;
00112             Console.WriteLine(errorMessage);
00113             Console.ResetColor();
00114 
00115             Console.Write(System.Environment.NewLine + content, arg);
00116 
00117             for (int i = 0; i < separateThisMuchBottom; i++)
00118                 Console.WriteLine("");
00119             Console.Write(footer);
00120         }

string HouseOver.UserInterface.Draw ( string  drawThis,
params object[]  arg 
)

Draw an input screen.

Parameters:
drawThis The content to paint on the screen
Returns:
A string containing the entered string
Parameters:
arg A set of extra parameters, which is passed on to the console writer

Definition at line 128 of file UserInterface.cs.

References HouseOver.UserInterface.DoDraw().

Referenced by HouseOver.THARM.RealtyManager.AddCustomer().

00129                 {
00130             DoDraw(drawThis, arg);
00131             return Console.ReadLine();
00132                 }

Here is the call graph for this function:

Here is the caller graph for this function:

int HouseOver.UserInterface.DrawInt ( string  drawThis,
params object[]  arg 
)

Draw an input screen to get an integer.

Parameters:
drawThis The content to paint on the screen
Returns:
An integer containing the entered number
Parameters:
arg A set of extra parameters, which is passed on to the console writer

Definition at line 140 of file UserInterface.cs.

References HouseOver.UserInterface.DoDraw().

Referenced by HouseOver.THARM.RealtyManager.AddCustomer().

00141         {
00142             int theValue;
00143             string tempValue;
00144 
00145             DoDraw(drawThis, arg);
00146 
00147             while (true)
00148             {
00149                 tempValue = Console.ReadLine();
00150                 try
00151                 {
00152                     theValue = Convert.ToInt32(tempValue);
00153                     break;
00154                 }
00155                 catch
00156                 {
00157                     // If we've caught the exception, the user didn't enter an integer
00158                     DoDraw(drawThis, "You did not enter a number - please try again!", arg);
00159                 }
00160             }
00161 
00162             return theValue;
00163         }

Here is the call graph for this function:

Here is the caller graph for this function:

bool HouseOver.UserInterface.DrawMenu ( string  drawThis,
Dictionary< object, string >  menuItems,
bool  showCancel,
out T  chosen 
)

Draws the UI menu.

Parameters:
drawThis The content to paint on the screen
menuItems A dictionary containing the menu items to draw
showCancel Wether or not to show the cancel item
chosen The object of the chosen item
Returns:
Wether a menu item was chosen

void HouseOver.UserInterface.DoDraw ( string  content,
params object[]  arg 
) [private]

Perform the actual drawing on screen of some content.

Parameters:
content The content to draw. Should preferably be less than twenty lines of text
arg A set of extra parameters, which is passed on to the console writer

Definition at line 58 of file UserInterface.cs.

References HouseOver.UserInterface.footer, and HouseOver.UserInterface.header.

00059         {
00060             // It fails to count the last newline
00061             int contentSize = content.Split(System.Environment.NewLine.ToCharArray(0, 1)).Length;
00062             int separateThisMuchTop = Convert.ToInt32(Math.Floor(Convert.ToDouble(this.contentHeight - contentSize) / 2));
00063             int separateThisMuchBottom = this.contentHeight - (contentSize + separateThisMuchTop);
00064 
00065             // We shouldn't be drawing anything taller than the screen... but oh well
00066             if (separateThisMuchTop < 0 || separateThisMuchBottom < 0)
00067             {
00068                 separateThisMuchTop = 0;
00069                 separateThisMuchBottom = 0;
00070             }
00071 
00072             Console.Clear();
00073             Console.Write(header);
00074 
00075             for (int i = 0; i < separateThisMuchTop; i++)
00076                 Console.WriteLine("");
00077             Console.Write(content,arg);
00078 
00079             for (int i = 0; i < separateThisMuchBottom; i++)
00080                 Console.WriteLine("");
00081             Console.Write(footer);
00082         }

void HouseOver.UserInterface.DoDraw ( string  content,
string  errorMessage,
params object[]  arg 
) [private]

Perform the actual drawing on screen of some content - with error message.

Parameters:
content The content to draw. Should preferably be less than twenty lines of text
errorMessage The error message to show to the user
arg A set of extra parameters, which is passed on to the console writer

Definition at line 91 of file UserInterface.cs.

References HouseOver.UserInterface.contentHeight, HouseOver.UserInterface.footer, and HouseOver.UserInterface.header.

00092         {
00093             int contentSize = content.Split(System.Environment.NewLine.ToCharArray(0, 1)).Length + errorMessage.Split(System.Environment.NewLine.ToCharArray(0, 1)).Length + 1;
00094             int separateThisMuchTop = Convert.ToInt32(Math.Floor(Convert.ToDouble(contentHeight - contentSize) / 2));
00095             int separateThisMuchBottom = this.contentHeight - (contentSize + separateThisMuchTop);
00096 
00097             // We shouldn't be drawing anything taller than the screen... but oh well
00098             if (separateThisMuchTop < 0 || separateThisMuchBottom < 0)
00099             {
00100                 separateThisMuchTop = 0;
00101                 separateThisMuchBottom = 0;
00102             }
00103 
00104             Console.Clear();
00105 
00106             Console.Write(header);
00107             for (int i = 0; i < separateThisMuchTop; i++)
00108                 Console.WriteLine("");
00109 
00110             Console.BackgroundColor = ConsoleColor.DarkRed;
00111             Console.ForegroundColor = ConsoleColor.White;
00112             Console.WriteLine(errorMessage);
00113             Console.ResetColor();
00114 
00115             Console.Write(System.Environment.NewLine + content, arg);
00116 
00117             for (int i = 0; i < separateThisMuchBottom; i++)
00118                 Console.WriteLine("");
00119             Console.Write(footer);
00120         }

string HouseOver.UserInterface.Draw ( string  drawThis,
params object[]  arg 
)

Draw an input screen.

Parameters:
drawThis The content to paint on the screen
Returns:
A string containing the entered string
Parameters:
arg A set of extra parameters, which is passed on to the console writer

Definition at line 128 of file UserInterface.cs.

References HouseOver.UserInterface.DoDraw().

00129                 {
00130             DoDraw(drawThis, arg);
00131             return Console.ReadLine();
00132                 }

Here is the call graph for this function:

int HouseOver.UserInterface.DrawInt ( string  drawThis,
params object[]  arg 
)

Draw an input screen to get an integer.

Parameters:
drawThis The content to paint on the screen
Returns:
An integer containing the entered number
Parameters:
arg A set of extra parameters, which is passed on to the console writer

Definition at line 140 of file UserInterface.cs.

References HouseOver.UserInterface.DoDraw().

00141         {
00142             int theValue;
00143             string tempValue;
00144 
00145             DoDraw(drawThis, arg);
00146 
00147             while (true)
00148             {
00149                 tempValue = Console.ReadLine();
00150                 try
00151                 {
00152                     theValue = Convert.ToInt32(tempValue);
00153                     break;
00154                 }
00155                 catch
00156                 {
00157                     // If we've caught the exception, the user didn't enter an integer
00158                     DoDraw(drawThis, "You did not enter a number - please try again!", arg);
00159                 }
00160             }
00161 
00162             return theValue;
00163         }

Here is the call graph for this function:

bool HouseOver.UserInterface.DrawMenu ( string  drawThis,
Dictionary< object, string >  menuItems,
bool  showCancel,
out T  chosen 
)

Draws the UI menu.

Parameters:
drawThis The content to paint on the screen
menuItems A dictionary containing the menu items to draw
showCancel Wether or not to show the cancel item
chosen The object of the chosen item
Returns:
Wether a menu item was chosen


Member Data Documentation

int HouseOver.UserInterface::width = 80 [private]

The width of the console.

Definition at line 13 of file UserInterface.cs.

Referenced by HouseOver.UserInterface.UserInterface().

int HouseOver.UserInterface::height = 25 [private]

The height of the console.

Definition at line 15 of file UserInterface.cs.

Referenced by HouseOver.UserInterface.UserInterface().

int HouseOver.UserInterface::contentHeight [private]

The height of the content field.

Definition at line 17 of file UserInterface.cs.

Referenced by HouseOver.UserInterface.DoDraw(), and HouseOver.UserInterface.UserInterface().

string HouseOver.UserInterface::header [private]

The text shown at the top of each screen.

Definition at line 19 of file UserInterface.cs.

Referenced by HouseOver.UserInterface.DoDraw(), and HouseOver.UserInterface.UserInterface().

string HouseOver.UserInterface::footer [private]

The text shown at the bottom of each screen.

Definition at line 21 of file UserInterface.cs.

Referenced by HouseOver.UserInterface.DoDraw(), and HouseOver.UserInterface.UserInterface().


The documentation for this class was generated from the following files:
Generated on Wed Jan 10 03:42:52 2007 for THARM by  doxygen 1.5.1-p1