1. Stewart Mackenzie
  2. cappuccino-docs

Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_p_tree_node_8j_source.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_tree_node_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:31 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: AppKit/CPTreeNode.j Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>AppKit/CPTreeNode.j</h1><a href="_c_p_tree_node_8j.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 @<span class="keyword">import</span> &lt;Foundation/<a class="code" href="class_c_p_object.html" title="The root class from which most classes are subclassed.">CPObject</a>.j&gt;
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 
<a name="l00005"></a><a class="code" href="class_c_p_tree_node.html">00005</a> <span class="keyword">@implementation </span><a class="code" href="class_c_p_tree_node.html">CPTreeNode</a> : <a class="code" href="class_c_p_object.html" title="The root class from which most classes are subclassed.">CPObject</a>
<a name="l00006"></a>00006 {
<a name="l00007"></a><a class="code" href="_c_p_tree_node_8j.html#af2b8102aeac8f02ab62ac42828289569">00007</a>     <span class="keywordtype">id</span>              _representedObject @<a class="code" href="class_c_p_tree_node.html#a248365779a47c6a8ab48903307b9e3de">accessors</a>(readonly, <a class="code" href="_c_p_table_header_view_8j.html#af2b8102aeac8f02ab62ac42828289569">property</a>=representedObject);
<a name="l00008"></a>00008     
<a name="l00009"></a>00009     <a class="code" href="class_c_p_tree_node.html">CPTreeNode</a>      _parentNode @<a class="code" href="class_c_p_tree_node.html#a248365779a47c6a8ab48903307b9e3de">accessors</a>(readonly, <a class="code" href="_c_p_table_header_view_8j.html#af2b8102aeac8f02ab62ac42828289569">property</a>=parentNode);
<a name="l00010"></a>00010     <a class="code" href="class_c_p_mutable_array.html">CPMutableArray</a>  _childNodes;
<a name="l00011"></a>00011 }
<a name="l00012"></a>00012 
<a name="l00013"></a><a class="code" href="class_c_p_tree_node.html#a5d95e99effeafa7a3e4c838c72ff3089">00013</a> + (id)treeNodeWithRepresentedObject:(<span class="keywordtype">id</span>)anObject
<a name="l00014"></a>00014 {
<a name="l00015"></a>00015     <span class="keywordflow">return</span> [[<span class="keyword">self</span> alloc] initWithRepresentedObject:anObject];
<a name="l00016"></a>00016 }
<a name="l00017"></a>00017 
<a name="l00018"></a><a class="code" href="class_c_p_tree_node.html#a05a772ff9e5d9b06101705864125445f">00018</a> - (id)initWithRepresentedObject:(<span class="keywordtype">id</span>)anObject
<a name="l00019"></a>00019 {
<a name="l00020"></a>00020     <span class="keyword">self</span> = [<span class="keyword">super</span> init];
<a name="l00021"></a>00021 
<a name="l00022"></a>00022     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00023"></a>00023     {
<a name="l00024"></a>00024         _representedObject = anObject;
<a name="l00025"></a>00025         _childNodes = [];
<a name="l00026"></a>00026     }
<a name="l00027"></a>00027 
<a name="l00028"></a>00028     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00029"></a>00029 }
<a name="l00030"></a>00030 
<a name="l00031"></a><a class="code" href="class_c_p_tree_node.html#ac77c6095706f4ef60db68e29059e7bcc">00031</a> - (BOOL)isLeaf
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033     <span class="keywordflow">return</span> [_childNodes count] &lt;= 0;
<a name="l00034"></a>00034 }
<a name="l00035"></a>00035 
<a name="l00036"></a><a class="code" href="class_c_p_tree_node.html#a7256a6645dd76c25661225c23a028bd3">00036</a> - (<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)childNodes
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038     <span class="keywordflow">return</span> [_childNodes copy];
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 
<a name="l00041"></a><a class="code" href="class_c_p_tree_node.html#acdca9b6dfaa8cf4a4b9e205c6fcee2fd">00041</a> - (<a class="code" href="class_c_p_mutable_array.html">CPMutableArray</a>)mutableChildNodes
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043     <span class="keywordflow">return</span> [<span class="keyword">self</span> mutableArrayValueForKey:@&quot;childNodes&quot;];
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 
<a name="l00046"></a><a class="code" href="class_c_p_tree_node.html#afa716234ba6d35e7dfc3263ab329f1f2">00046</a> - (void)insertObject:(<span class="keywordtype">id</span>)aTreeNode inChildNodesAtIndex:(CPInteger)anIndex
<a name="l00047"></a>00047 {
<a name="l00048"></a>00048     [[aTreeNode._parentNode mutableChildNodes] removeObjectIdenticalTo:aTreeNode];
<a name="l00049"></a>00049 
<a name="l00050"></a>00050     aTreeNode._parentNode = <span class="keyword">self</span>;
<a name="l00051"></a>00051 
<a name="l00052"></a>00052     [_childNodes insertObject:aTreeNode atIndex:anIndex];
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054 
<a name="l00055"></a><a class="code" href="class_c_p_tree_node.html#a0a0357426fd5c055ce202b2b5b76bf64">00055</a> - (void)removeObjectFromChildNodesAtIndex:(CPInteger)anIndex
<a name="l00056"></a>00056 {
<a name="l00057"></a>00057     [_childNodes objectAtIndex:anIndex]._parentNode = nil;
<a name="l00058"></a>00058 
<a name="l00059"></a>00059     [_childNodes removeObjectAtIndex:anIndex];
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061 
<a name="l00062"></a><a class="code" href="class_c_p_tree_node.html#a2c78d6dbd2d3bbc1756a29a1702302f2">00062</a> - (void)replaceObjectFromChildNodesAtIndex:(CPInteger)anIndex withObject:(<span class="keywordtype">id</span>)aTreeNode
<a name="l00063"></a>00063 {
<a name="l00064"></a>00064     var oldTreeNode = [_childNodes objectAtIndex:anIndex];
<a name="l00065"></a>00065 
<a name="l00066"></a>00066     oldTreeNode._parentNode = nil;
<a name="l00067"></a>00067     aTreeNode._parentNode = <span class="keyword">self</span>;
<a name="l00068"></a>00068 
<a name="l00069"></a>00069     [_childNodes replaceObjectAtIndex:anIndex withObject:aTreeNode];
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 
<a name="l00072"></a><a class="code" href="class_c_p_tree_node.html#abd2351cff9b62237ab006da98d91e252">00072</a> - (id)objectInChildNodesAtIndex:(CPInteger)anIndex
<a name="l00073"></a>00073 {
<a name="l00074"></a>00074     <span class="keywordflow">return</span> _childNodes[anIndex];
<a name="l00075"></a>00075 }
<a name="l00076"></a>00076 
<a name="l00077"></a><a class="code" href="class_c_p_tree_node.html#ab3b93166762da194f2557a8afa5bace2">00077</a> - (void)sortWithSortDescriptors:(<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)sortDescriptors recursively:(BOOL)shouldSortRecursively
<a name="l00078"></a>00078 {
<a name="l00079"></a>00079     [_childNodes sortUsingDescriptors:sortDescriptors];
<a name="l00080"></a>00080 
<a name="l00081"></a>00081     <span class="keywordflow">if</span> (!shouldSortRecursively)
<a name="l00082"></a>00082         <span class="keywordflow">return</span>;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084     var count = [_childNodes count];
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     <span class="keywordflow">while</span> (count--)
<a name="l00087"></a>00087         [_childNodes[count] sortWithSortDescriptors:sortDescriptors recursively:YES];
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 <span class="keyword">@end</span>
<a name="l00091"></a>00091 
<a name="l00092"></a><a class="code" href="_c_p_tree_node_8j.html#a1cb4f95da177e060533b9b52ed242251">00092</a> var <a class="code" href="_c_p_tree_node_8j.html#a1cb4f95da177e060533b9b52ed242251">CPTreeNodeRepresentedObjectKey</a>  = <span class="stringliteral">@&quot;CPTreeNodeRepresentedObjectKey&quot;</span>,
<a name="l00093"></a><a class="code" href="_c_p_tree_node_8j.html#ac40c3f089638516b56d22294798a1b31">00093</a>     <a class="code" href="_c_p_tree_node_8j.html#ac40c3f089638516b56d22294798a1b31">CPTreeNodeParentNodeKey</a>         = <span class="stringliteral">@&quot;CPTreeNodeParentNodeKey&quot;</span>,
<a name="l00094"></a><a class="code" href="_c_p_tree_node_8j.html#a2663cc6498c45c5ca106decbafc28e35">00094</a>     <a class="code" href="_c_p_tree_node_8j.html#a2663cc6498c45c5ca106decbafc28e35">CPTreeNodeChildNodesKey</a>         = <span class="stringliteral">@&quot;CPTreeNodeChildNodesKey&quot;</span>;
<a name="l00095"></a>00095 
<a name="l00096"></a>00096 <span class="keyword">@implementation </span><a class="code" href="class_c_p_tree_node.html">CPTreeNode</a> (CPCoding)
<a name="l00097"></a>00097 
<a name="l00098"></a><a class="code" href="class_c_p_tree_node.html#a35c8311e140301f77e8d7739360758d6">00098</a> - (id)initWithCoder:(<a class="code" href="class_c_p_coder.html" title="Defines methods for use when archiving &amp;amp; restoring (enc/decoding).">CPCoder</a>)aCoder
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100     <span class="keyword">self</span> = [<span class="keyword">super</span> init];
<a name="l00101"></a>00101 
<a name="l00102"></a>00102     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00103"></a>00103     {
<a name="l00104"></a>00104         _representedObject = [aCoder decodeObjectForKey:CPTreeNodeRepresentedObjectKey];
<a name="l00105"></a>00105         _parentNode = [aCoder decodeObjectForKey:CPTreeNodeParentNodeKey];
<a name="l00106"></a>00106         _childNodes = [aCoder decodeObjectForKey:CPTreeNodeChildNodesKey];
<a name="l00107"></a>00107     }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00110"></a>00110 }
<a name="l00111"></a>00111 
<a name="l00112"></a><a class="code" href="class_c_p_tree_node.html#a06621d79589396d7bec7f3770d559fc1">00112</a> - (void)encodeWithCoder:(<a class="code" href="class_c_p_coder.html" title="Defines methods for use when archiving &amp;amp; restoring (enc/decoding).">CPCoder</a>)aCoder
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114     [aCoder encodeObject:_representedObject forKey:CPTreeNodeRepresentedObjectKey];
<a name="l00115"></a>00115     [aCoder encodeConditionalObject:_parentNode forKey:CPTreeNodeParentNodeKey];
<a name="l00116"></a>00116     [aCoder encodeObject:_childNodes forKey:CPTreeNodeChildNodesKey];
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 
<a name="l00119"></a>00119 <span class="keyword">@end</span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:56 2010 for Cappuccino API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_tree_node_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:31 GMT -->
</html>