Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_p_radio_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_radio_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/CPRadio.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/CPRadio.j</h1><a href="_c_p_radio_8j.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * CPRadio.j</span>
<a name="l00003"></a>00003 <span class="comment"> * AppKit</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Created by Francisco Tolmasky.</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright 2009, 280 North, Inc.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
<a name="l00009"></a>00009 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<a name="l00010"></a>00010 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00011"></a>00011 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
<a name="l00016"></a>00016 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<a name="l00019"></a>00019 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 @<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="l00024"></a>00024 @<span class="keyword">import</span> &lt;Foundation/<a class="code" href="class_c_p_set.html" title="An unordered collection of objects.">CPSet</a>.j&gt;
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPButton.j&quot;</span>
<a name="l00027"></a>00027 
<a name="l00065"></a><a class="code" href="class_c_p_radio.html">00065</a> <span class="keyword">@implementation </span><a class="code" href="class_c_p_radio.html">CPRadio</a> : <a class="code" href="class_c_p_button.html">CPButton</a>
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067     <a class="code" href="class_c_p_radio_group.html">CPRadioGroup</a>    _radioGroup;
<a name="l00068"></a>00068 }
<a name="l00069"></a>00069 
<a name="l00070"></a><a class="code" href="class_c_p_radio.html#a83022c2719ff630aaa8db33de7b42387">00070</a> + (id)radioWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle theme:(<a class="code" href="class_c_p_theme.html">CPTheme</a>)aTheme
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072     <span class="keywordflow">return</span> [<span class="keyword">self</span> buttonWithTitle:aTitle theme:aTheme];
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074 
<a name="l00075"></a><a class="code" href="class_c_p_radio.html#a9a360c43b75c5aa22dbb9ff8de7e9b27">00075</a> + (id)radioWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077     <span class="keywordflow">return</span> [<span class="keyword">self</span> buttonWithTitle:aTitle];
<a name="l00078"></a>00078 }
<a name="l00079"></a>00079 
<a name="l00080"></a><a class="code" href="class_c_p_radio.html#a91be6109c21b95903de009e362c17834">00080</a> + (<a class="code" href="class_c_p_button.html">CPButton</a>)standardButtonWithTitle:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aTitle
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082     var button = [[<a class="code" href="class_c_p_radio.html">CPRadio</a> alloc] init];
<a name="l00083"></a>00083 
<a name="l00084"></a>00084     [button setTitle:aTitle];
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     <span class="keywordflow">return</span> button;
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 
<a name="l00089"></a><a class="code" href="class_c_p_radio.html#a6428039299c21c563560463ac3b70607">00089</a> + (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)themeClass
<a name="l00090"></a>00090 {
<a name="l00091"></a>00091     <span class="keywordflow">return</span> <span class="stringliteral">@&quot;radio&quot;</span>;
<a name="l00092"></a>00092 }
<a name="l00093"></a>00093 
<a name="l00094"></a>00094 <span class="comment">// Designated Initializer</span>
<a name="l00095"></a><a class="code" href="class_c_p_radio.html#a1bf179fdcdbe762e76da74d75f1f0b95">00095</a> - (id)initWithFrame:(CGRect)aFrame radioGroup:(<a class="code" href="class_c_p_radio_group.html">CPRadioGroup</a>)aRadioGroup
<a name="l00096"></a>00096 {
<a name="l00097"></a>00097     <span class="keyword">self</span> = [<span class="keyword">super</span> initWithFrame:aFrame];
<a name="l00098"></a>00098     
<a name="l00099"></a>00099     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00100"></a>00100     {
<a name="l00101"></a>00101         [<span class="keyword">self</span> <a class="code" href="class_c_p_radio.html#a3c7c02361805649a3d055776792f6888">setRadioGroup</a>:aRadioGroup];
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         [<span class="keyword">self</span> setHighlightsBy:CPContentsCellMask];
<a name="l00104"></a>00104         [<span class="keyword">self</span> setShowsStateBy:CPContentsCellMask];
<a name="l00105"></a>00105 
<a name="l00106"></a>00106         <span class="comment">// Defaults?</span>
<a name="l00107"></a>00107         [<span class="keyword">self</span> setImagePosition:CPImageLeft];
<a name="l00108"></a>00108         [<span class="keyword">self</span> setAlignment:CPLeftTextAlignment];
<a name="l00109"></a>00109 
<a name="l00110"></a>00110         [<span class="keyword">self</span> setBordered:YES];
<a name="l00111"></a>00111     }
<a name="l00112"></a>00112     
<a name="l00113"></a>00113     <span class="keywordflow">return</span> <span class="keyword">self</span>; 
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a><a class="code" href="class_c_p_radio.html#a51a3a1aed0b1d2c18815b53dd639a3f9">00116</a> - (id)initWithFrame:(CGRect)aFrame
<a name="l00117"></a>00117 {
<a name="l00118"></a>00118     <span class="keywordflow">return</span> [<span class="keyword">self</span> <a class="code" href="class_c_p_radio.html#a1bf179fdcdbe762e76da74d75f1f0b95">initWithFrame</a>:aFrame <a class="code" href="class_c_p_radio.html#a1bf179fdcdbe762e76da74d75f1f0b95">radioGroup</a>:[<a class="code" href="class_c_p_radio_group.html">CPRadioGroup</a> new]];
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120 
<a name="l00121"></a><a class="code" href="class_c_p_radio.html#abb96ecf6e03d225f3561e5de71a8e0f1">00121</a> - (CPInteger)nextState
<a name="l00122"></a>00122 {
<a name="l00123"></a>00123     <span class="keywordflow">return</span> <a class="code" href="_c_p_control_8j.html#ac927247dd7513ff04bb772aa70d3023f">CPOnState</a>;
<a name="l00124"></a>00124 }
<a name="l00125"></a>00125 
<a name="l00126"></a><a class="code" href="class_c_p_radio.html#a3c7c02361805649a3d055776792f6888">00126</a> - (void)setRadioGroup:(<a class="code" href="class_c_p_radio_group.html">CPRadioGroup</a>)aRadioGroup
<a name="l00127"></a>00127 {
<a name="l00128"></a>00128     <span class="keywordflow">if</span> (_radioGroup === aRadioGroup)
<a name="l00129"></a>00129         <span class="keywordflow">return</span>;
<a name="l00130"></a>00130 
<a name="l00131"></a>00131     [_radioGroup _removeRadio:self];
<a name="l00132"></a>00132     _radioGroup = aRadioGroup;
<a name="l00133"></a>00133     [_radioGroup _addRadio:self];
<a name="l00134"></a>00134 }
<a name="l00135"></a>00135 
<a name="l00136"></a><a class="code" href="class_c_p_radio.html#a7fd0c0c85329ce639780907de2d526e7">00136</a> - (<a class="code" href="class_c_p_radio_group.html">CPRadioGroup</a>)radioGroup
<a name="l00137"></a>00137 {
<a name="l00138"></a>00138     <span class="keywordflow">return</span> _radioGroup;
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 
<a name="l00141"></a><a class="code" href="class_c_p_radio.html#aa7edf2bec2e3a9a35ed372c8304a8826">00141</a> - (void)setObjectValue:(<span class="keywordtype">id</span>)aValue
<a name="l00142"></a>00142 {
<a name="l00143"></a>00143     [<span class="keyword">super</span> setObjectValue:aValue];
<a name="l00144"></a>00144     
<a name="l00145"></a>00145     <span class="keywordflow">if</span> ([<span class="keyword">self</span> state] === <a class="code" href="_c_p_control_8j.html#ac927247dd7513ff04bb772aa70d3023f">CPOnState</a>)
<a name="l00146"></a>00146         [_radioGroup _setSelectedRadio:self];
<a name="l00147"></a>00147 }
<a name="l00148"></a>00148 
<a name="l00149"></a>00149 <span class="keyword">@end</span>
<a name="l00150"></a>00150 
<a name="l00151"></a><a class="code" href="_c_p_radio_8j.html#afefc2add6a098081cc810ff6437bdd94">00151</a> var <a class="code" href="_c_p_radio_8j.html#afefc2add6a098081cc810ff6437bdd94">CPRadioRadioGroupKey</a>    = <span class="stringliteral">@&quot;CPRadioRadioGroupKey&quot;</span>;
<a name="l00152"></a>00152 
<a name="l00153"></a>00153 <span class="keyword">@implementation </span><a class="code" href="class_c_p_radio.html">CPRadio</a> (CPCoding)
<a name="l00154"></a>00154 
<a name="l00155"></a><a class="code" href="class_c_p_radio.html#a70f613eebc8ce78b995f3d58c385631a">00155</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="l00156"></a>00156 {
<a name="l00157"></a>00157     <span class="keyword">self</span> = [<span class="keyword">super</span> initWithCoder:aCoder];
<a name="l00158"></a>00158 
<a name="l00159"></a>00159     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00160"></a>00160         _radioGroup = [aCoder decodeObjectForKey:CPRadioRadioGroupKey];
<a name="l00161"></a>00161 
<a name="l00162"></a>00162     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 
<a name="l00165"></a><a class="code" href="class_c_p_radio.html#a7992ae2e48ee6a7ae07355bf24690052">00165</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="l00166"></a>00166 {
<a name="l00167"></a>00167     [<span class="keyword">super</span> encodeWithCoder:aCoder];
<a name="l00168"></a>00168 
<a name="l00169"></a>00169     [aCoder encodeObject:_radioGroup forKey:CPRadioRadioGroupKey];
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171 
<a name="l00172"></a>00172 <span class="keyword">@end</span>
<a name="l00173"></a>00173 
<a name="l00174"></a><a class="code" href="class_c_p_radio_group.html">00174</a> <span class="keyword">@implementation </span><a class="code" href="class_c_p_radio_group.html">CPRadioGroup</a> : <a class="code" href="class_c_p_object.html" title="The root class from which most classes are subclassed.">CPObject</a>
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176     <a class="code" href="class_c_p_set.html" title="An unordered collection of objects.">CPSet</a>   _radios;
<a name="l00177"></a>00177     <a class="code" href="class_c_p_radio.html">CPRadio</a> _selectedRadio;
<a name="l00178"></a>00178 
<a name="l00179"></a>00179     <span class="keywordtype">id</span>      _target @<a class="code" href="class_c_p_radio_group.html#a2cb362472cf3d112540e5385c8fe0776">accessors</a>(<a class="code" href="_c_p_table_header_view_8j.html#af2b8102aeac8f02ab62ac42828289569">property</a>=target);
<a name="l00180"></a>00180     <span class="keywordtype">SEL</span>     _action @<a class="code" href="class_c_p_radio_group.html#a2cb362472cf3d112540e5385c8fe0776">accessors</a>(<a class="code" href="_c_p_table_header_view_8j.html#af2b8102aeac8f02ab62ac42828289569">property</a>=action);
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 
<a name="l00183"></a><a class="code" href="class_c_p_radio_group.html#acaf6477ed4b5082d8a9ad18f7ad3629b">00183</a> - (id)init
<a name="l00184"></a>00184 {
<a name="l00185"></a>00185     <span class="keyword">self</span> = [<span class="keyword">super</span> init];
<a name="l00186"></a>00186 
<a name="l00187"></a>00187     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00188"></a>00188     {
<a name="l00189"></a>00189         _radios = [<a class="code" href="class_c_p_set.html" title="An unordered collection of objects.">CPSet</a> <a class="code" href="class_c_p_set.html#a89623be28c3a0913db1967b667874d39">set</a>];
<a name="l00190"></a>00190         _selectedRadio = nil;
<a name="l00191"></a>00191     }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 
<a name="l00196"></a>00196 - (void)_addRadio:(<a class="code" href="class_c_p_radio.html">CPRadio</a>)aRadio
<a name="l00197"></a>00197 {
<a name="l00198"></a>00198     [_radios addObject:aRadio];
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     <span class="keywordflow">if</span> ([aRadio state] === <a class="code" href="_c_p_control_8j.html#ac927247dd7513ff04bb772aa70d3023f">CPOnState</a>)
<a name="l00201"></a>00201         [<span class="keyword">self</span> _setSelectedRadio:aRadio];
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 - (void)_removeRadio:(<a class="code" href="class_c_p_radio.html">CPRadio</a>)aRadio
<a name="l00205"></a>00205 {
<a name="l00206"></a>00206     <span class="keywordflow">if</span> (_selectedRadio === aRadio)
<a name="l00207"></a>00207         _selectedRadio = nil;
<a name="l00208"></a>00208 
<a name="l00209"></a>00209     [_radios removeObject:aRadio];
<a name="l00210"></a>00210 }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212 - (void)_setSelectedRadio:(<a class="code" href="class_c_p_radio.html">CPRadio</a>)aRadio
<a name="l00213"></a>00213 {
<a name="l00214"></a>00214     <span class="keywordflow">if</span> (_selectedRadio === aRadio)
<a name="l00215"></a>00215         <span class="keywordflow">return</span>;
<a name="l00216"></a>00216 
<a name="l00217"></a>00217     [_selectedRadio setState:CPOffState];
<a name="l00218"></a>00218     _selectedRadio = aRadio;
<a name="l00219"></a>00219 
<a name="l00220"></a>00220     [CPApp sendAction:_action to:_target from:self];
<a name="l00221"></a>00221 }
<a name="l00222"></a>00222 
<a name="l00223"></a><a class="code" href="class_c_p_radio_group.html#a0aeb16d1cff9ccd6c2411af82a18a0bf">00223</a> - (<a class="code" href="class_c_p_radio.html">CPRadio</a>)selectedRadio
<a name="l00224"></a>00224 {
<a name="l00225"></a>00225     <span class="keywordflow">return</span> _selectedRadio;
<a name="l00226"></a>00226 }
<a name="l00227"></a>00227 
<a name="l00228"></a><a class="code" href="class_c_p_radio_group.html#acd985e766907b877bdde6c9262b0f8c6">00228</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>)radios
<a name="l00229"></a>00229 {
<a name="l00230"></a>00230     <span class="keywordflow">return</span> [_radios allObjects];
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232 
<a name="l00233"></a>00233 <span class="keyword">@end</span>
<a name="l00234"></a>00234 
<a name="l00235"></a><a class="code" href="_c_p_radio_8j.html#a0f4cefcacfdb21d13426ed61ac454b42">00235</a> var <a class="code" href="_c_p_radio_8j.html#a0f4cefcacfdb21d13426ed61ac454b42">CPRadioGroupRadiosKey</a>           = <span class="stringliteral">@&quot;CPRadioGroupRadiosKey&quot;</span>,
<a name="l00236"></a><a class="code" href="_c_p_radio_8j.html#a4e782ad1678c1f3a36ed8f0bf4929da0">00236</a>     <a class="code" href="_c_p_radio_8j.html#a4e782ad1678c1f3a36ed8f0bf4929da0">CPRadioGroupSelectedRadioKey</a>    = <span class="stringliteral">@&quot;CPRadioGroupSelectedRadioKey&quot;</span>;
<a name="l00237"></a>00237 
<a name="l00238"></a>00238 <span class="keyword">@implementation </span><a class="code" href="class_c_p_radio_group.html">CPRadioGroup</a> (CPCoding)
<a name="l00239"></a>00239 
<a name="l00240"></a><a class="code" href="class_c_p_radio_group.html#a690552e0139841586022232fb73f0d80">00240</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="l00241"></a>00241 {
<a name="l00242"></a>00242     <span class="keyword">self</span> = [<span class="keyword">super</span> init];
<a name="l00243"></a>00243 
<a name="l00244"></a>00244     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00245"></a>00245     {
<a name="l00246"></a>00246         _radios = [aCoder decodeObjectForKey:CPRadioGroupRadiosKey];
<a name="l00247"></a>00247         _selectedRadio = [aCoder decodeObjectForKey:CPRadioGroupSelectedRadioKey];
<a name="l00248"></a>00248     }
<a name="l00249"></a>00249 
<a name="l00250"></a>00250     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00251"></a>00251 }
<a name="l00252"></a>00252 
<a name="l00253"></a><a class="code" href="class_c_p_radio_group.html#a516315b4144e132679a2f2cd3a125c87">00253</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="l00254"></a>00254 {
<a name="l00255"></a>00255     [aCoder encodeObject:_radios forKey:CPRadioGroupRadiosKey];
<a name="l00256"></a>00256     [aCoder encodeObject:_selectedRadio forKey:CPRadioGroupSelectedRadioKey];
<a name="l00257"></a>00257 }
<a name="l00258"></a>00258 
<a name="l00259"></a>00259 <span class="keyword">@end</span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:55 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_radio_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:31 GMT -->
</html>