-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from lizaalert/dev_desktopApp
feat: add geo tags and prepare 0.3.0 release
- Loading branch information
Showing
4 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
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,118 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace RescuerLaApp.Models | ||
{ | ||
public interface ITextRow | ||
{ | ||
String Output(); | ||
void Output(StringBuilder sb); | ||
Object Tag { get; set; } | ||
} | ||
|
||
public class TextTableBuilder : IEnumerable<ITextRow> | ||
{ | ||
protected class TextRow : List<String>, ITextRow | ||
{ | ||
protected TextTableBuilder owner = null; | ||
public TextRow(TextTableBuilder Owner) | ||
{ | ||
owner = Owner; | ||
if (owner == null) throw new ArgumentException("Owner"); | ||
} | ||
public String Output() | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
Output(sb); | ||
return sb.ToString(); | ||
} | ||
public void Output(StringBuilder sb) | ||
{ | ||
sb.AppendFormat(owner.FormatString, this.ToArray()); | ||
} | ||
public Object Tag { get; set; } | ||
} | ||
|
||
public String Separator { get; set; } | ||
|
||
protected List<ITextRow> rows = new List<ITextRow>(); | ||
protected List<int> colLength = new List<int>(); | ||
|
||
public TextTableBuilder() | ||
{ | ||
Separator = " "; | ||
} | ||
|
||
public TextTableBuilder(String separator) | ||
: this() | ||
{ | ||
Separator = separator; | ||
} | ||
|
||
public ITextRow AddRow(params object[] cols) | ||
{ | ||
TextRow row = new TextRow(this); | ||
foreach (object o in cols) | ||
{ | ||
String str = o.ToString().Trim(); | ||
row.Add(str); | ||
if (colLength.Count >= row.Count) | ||
{ | ||
int curLength = colLength[row.Count - 1]; | ||
if (str.Length > curLength) colLength[row.Count - 1] = str.Length; | ||
} | ||
else | ||
{ | ||
colLength.Add(str.Length); | ||
} | ||
} | ||
rows.Add(row); | ||
return row; | ||
} | ||
|
||
protected String _fmtString = null; | ||
public String FormatString | ||
{ | ||
get | ||
{ | ||
if (_fmtString == null) | ||
{ | ||
String format = ""; | ||
int i = 0; | ||
foreach (int len in colLength) | ||
{ | ||
format += String.Format("{{{0},-{1}}}{2}", i++, len, Separator); | ||
} | ||
format += "\r\n"; | ||
_fmtString = format; | ||
} | ||
return _fmtString; | ||
} | ||
} | ||
|
||
public String Output() | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
foreach (TextRow row in rows) | ||
{ | ||
row.Output(sb); | ||
} | ||
return sb.ToString(); | ||
} | ||
|
||
#region IEnumerable Members | ||
|
||
public IEnumerator<ITextRow> GetEnumerator() | ||
{ | ||
return rows.GetEnumerator(); | ||
} | ||
|
||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | ||
{ | ||
return rows.GetEnumerator(); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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
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
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