function varargout = groupDemo(varargin)
% GROUPDEMO M-file for groupDemo.fig
%
% See ButtonGroupDemo.doc file for more information.
% The status panel part of this program is not yet working.
%
% Created by Dr. C. S. Tritt
% Last revised 1/19/07
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help groupDemo

% Last Modified by GUIDE v2.5 18-Jan-2007 09:38:57

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @groupDemo_OpeningFcn, ...
                   'gui_OutputFcn',  @groupDemo_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before groupDemo is made visible.
function groupDemo_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to groupDemo (see VARARGIN)

% Choose default command line output for groupDemo
handles.output = hObject;

% Store initial status panel background color.
handles.InitColor = get(handles.statusPanel, 'backgroundColor');

% Initialize the GUI state.
set(handles.offToggle, 'Value', 1); % Preset this option. Assume Max is 1.
set(handles.greenRadio, 'Value', 1); % Preset this option. Assume Max is 1.

% Create and initialize the handles state properties.
handles.PowerStr = 'off'; % Allowed values: off, on.
handles.ColorStr = 'green';% Allowed values: red, green, blue.  

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes groupDemo wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = groupDemo_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --------------------------------------------------------------------
function colorGroup_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to colorGroup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Dr. Tritt's Comments...
% The group tag is used to generate the name of the ChangeFcn callback.
% The hObject passed to this callback is the newly selected button.

switch get(hObject,'Tag')
    case 'redRadio'
        handles.ColorStr = 'red';
    case 'blueRadio'
        handles.ColorStr = 'blue';
    case 'greenRadio'
        handles.ColorStr = 'green';
end

% Update handles structure
guidata(hObject, handles);

% --------------------------------------------------------------------
function powerGroup_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to powerGroup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

switch get(hObject,'Tag')
    case 'onToggle'
        handles.PowerStr = 'on'; % Save the new state.

        % Disable the color radio buttons.
        set(handles.redRadio, 'Enable', 'off');
        set(handles.greenRadio, 'Enable', 'off');
        set(handles.blueRadio, 'Enable', 'off');
        
        % Change the statusPanel color.
        if strcmp(handles.ColorStr, 'red')
           set(handles.statusPanel, 'backgroundColor', [1 0 0])
        elseif strcmp(handles.ColorStr, 'green')
           set(handles.statusPanel, 'backgroundColor', [0 0.7 0])
        elseif strcmp(handles.ColorStr, 'blue')
           set(handles.statusPanel, 'backgroundColor', [0 0 1])           
        end
    case 'offToggle'
       
        handles.PowerStr = 'off'; % Save the new state.

        % Enable the color radio buttons.
        set(handles.redRadio, 'Enable', 'on');
        set(handles.greenRadio, 'Enable', 'on');
        set(handles.blueRadio, 'Enable', 'on');
        
        % Restore initial status panel background color.
        set(handles.statusPanel, 'BackgroundColor', handles.InitColor);
end
