author | sl |
Thu, 01 Jan 2015 23:35:49 +0100 | |
changeset 405 | 5715aefd2bcc |
permissions | -rw-r--r-- |
moel@345 | 1 |
using System; |
moel@345 | 2 |
using System.Text; |
moel@345 | 3 |
using System.Collections.ObjectModel; |
moel@345 | 4 |
|
moel@345 | 5 |
namespace Aga.Controls.Tree |
moel@345 | 6 |
{ |
moel@345 | 7 |
public class TreePath |
moel@345 | 8 |
{ |
moel@345 | 9 |
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] |
moel@345 | 10 |
public static readonly TreePath Empty = new TreePath(); |
moel@345 | 11 |
|
moel@345 | 12 |
private object[] _path; |
moel@345 | 13 |
public object[] FullPath |
moel@345 | 14 |
{ |
moel@345 | 15 |
get { return _path; } |
moel@345 | 16 |
} |
moel@345 | 17 |
|
moel@345 | 18 |
public object LastNode |
moel@345 | 19 |
{ |
moel@345 | 20 |
get |
moel@345 | 21 |
{ |
moel@345 | 22 |
if (_path.Length > 0) |
moel@345 | 23 |
return _path[_path.Length - 1]; |
moel@345 | 24 |
else |
moel@345 | 25 |
return null; |
moel@345 | 26 |
} |
moel@345 | 27 |
} |
moel@345 | 28 |
|
moel@345 | 29 |
public object FirstNode |
moel@345 | 30 |
{ |
moel@345 | 31 |
get |
moel@345 | 32 |
{ |
moel@345 | 33 |
if (_path.Length > 0) |
moel@345 | 34 |
return _path[0]; |
moel@345 | 35 |
else |
moel@345 | 36 |
return null; |
moel@345 | 37 |
} |
moel@345 | 38 |
} |
moel@345 | 39 |
|
moel@345 | 40 |
public TreePath() |
moel@345 | 41 |
{ |
moel@345 | 42 |
_path = new object[0]; |
moel@345 | 43 |
} |
moel@345 | 44 |
|
moel@345 | 45 |
public TreePath(object node) |
moel@345 | 46 |
{ |
moel@345 | 47 |
_path = new object[] { node }; |
moel@345 | 48 |
} |
moel@345 | 49 |
|
moel@345 | 50 |
public TreePath(object[] path) |
moel@345 | 51 |
{ |
moel@345 | 52 |
_path = path; |
moel@345 | 53 |
} |
moel@345 | 54 |
|
moel@345 | 55 |
public TreePath(TreePath parent, object node) |
moel@345 | 56 |
{ |
moel@345 | 57 |
_path = new object[parent.FullPath.Length + 1]; |
moel@345 | 58 |
for (int i = 0; i < _path.Length - 1; i++) |
moel@345 | 59 |
_path[i] = parent.FullPath[i]; |
moel@345 | 60 |
_path[_path.Length - 1] = node; |
moel@345 | 61 |
} |
moel@345 | 62 |
|
moel@345 | 63 |
public bool IsEmpty() |
moel@345 | 64 |
{ |
moel@345 | 65 |
return (_path.Length == 0); |
moel@345 | 66 |
} |
moel@345 | 67 |
} |
moel@345 | 68 |
} |