function varargout = janis_gui_feature_options(varargin)
% JANIS_GUI_FEATURE_OPTIONS M-file for janis_gui_feature_options.fig
%      JANIS_GUI_FEATURE_OPTIONS, by itself, creates a new JANIS_GUI_FEATURE_OPTIONS or raises the existing
%      singleton*.
%
%      H = JANIS_GUI_FEATURE_OPTIONS returns the handle to a new JANIS_GUI_FEATURE_OPTIONS or the handle to
%      the existing singleton*.
%
%      JANIS_GUI_FEATURE_OPTIONS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in JANIS_GUI_FEATURE_OPTIONS.M with the given input arguments.
%
%      JANIS_GUI_FEATURE_OPTIONS('Property','Value',...) creates a new JANIS_GUI_FEATURE_OPTIONS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before janis_gui_feature_options_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to janis_gui_feature_options_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

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

% Last Modified by GUIDE v2.5 28-Feb-2013 12:15:59

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @janis_gui_feature_options_OpeningFcn, ...
                   'gui_OutputFcn',  @janis_gui_feature_options_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 janis_gui_feature_options is made visible.
function janis_gui_feature_options_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 janis_gui_feature_options (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes janis_gui_feature_options wait for user response (see UIRESUME)
% uiwait(handles.figure1);
ud.preMap = varargin{3};
ud.proMap = varargin{4};
active = varargin{1};
default = varargin{2};
ud.default = default;
ud.active = active;
set(handles.listbox_pre_active,'String',active.preprocessors);
set(handles.listbox_pre_inactive,'String',active.available_pps);
set(handles.listbox_intra_active,'String',active.intravalidationPreprocessors);
set(handles.listbox_intra_inactive,'String',active.available_ips);
set(handles.figure1,'UserData',ud);
listbox_pre_active_Callback(handles.listbox_pre_active, eventdata, handles);
listbox_intra_active_Callback(handles.listbox_intra_active, eventdata, handles);
uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = janis_gui_feature_options_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
try
    ud = get(handles.figure1,'UserData');
    out{1} = get(handles.listbox_pre_active,'String');
    out{2} = get(handles.listbox_intra_active,'String');
    out{3} = 'never used';
    out{4} = get(handles.listbox_pre_inactive,'String');
    out{5} = get(handles.listbox_intra_inactive,'String');
    out{6} = ud.preMap;
    out{7} = ud.proMap;
    out{8} = handles;
    handles.output = out;
    varargout{1} = handles.output;
catch
    msgbox({'Selection has been canceled. ';'Will leave data unchanged.'});
    varargout{1} = [];
end


% --- Executes on button press in pushbutton_cancel.
function pushbutton_cancel_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_cancel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ud = get(handles.figure1,'UserData');
set(handles.listbox_pre_active,'String',ud.active.preprocessors);
set(handles.listbox_pre_inactive,'String',ud.active.available_pps);
set(handles.listbox_intra_active,'String',ud.active.intravalidationPreprocessors);
set(handles.listbox_intra_inactive,'String',ud.active.available_ips);
uiresume;
return

% --- Executes on button press in pushbutton_appy.
function pushbutton_appy_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_appy (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
uiresume;
return


% --- Executes on button press in pushbutton_restore.
function pushbutton_restore_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_restore (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ud = get(handles.figure1,'UserData');
set(handles.listbox_pre_active,'String',ud.default.preprocessors);
set(handles.listbox_pre_inactive,'String',ud.default.available_pps);
set(handles.listbox_intra_active,'String',ud.default.intravalidationPreprocessors);
set(handles.listbox_intra_inactive,'String',ud.default.available_ips);


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

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox_intra_inactive.
function listbox_intra_inactive_Callback(hObject, eventdata, handles)
% hObject    handle to listbox_intra_inactive (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox_intra_inactive contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox_intra_inactive


% --- Executes during object creation, after setting all properties.
function listbox_intra_inactive_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_intra_inactive (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton_add_intra.
function pushbutton_add_intra_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_add_intra (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
toAdd_Idx = get(handles.listbox_intra_inactive,'Value');
inactive = get(handles.listbox_intra_inactive,'String');
if size(inactive) > 0
    toAdd_Str = inactive{toAdd_Idx};
    if size(toAdd_Str,1) > 0 && ~isempty(toAdd_Str)
        active = get(handles.listbox_intra_active,'String');
        active{size(active,1)+1} = toAdd_Str;
        inactive(toAdd_Idx) = [];
        set(handles.listbox_intra_active,'String',active);
        set(handles.listbox_intra_inactive,'String',inactive);
        set(handles.listbox_intra_active,'Value',1);
        set(handles.listbox_intra_inactive,'Value',1);
    end
end
listbox_intra_active_Callback(handles.listbox_intra_active, eventdata, handles);

% --- Executes on button press in pushbutton_rem_intra.
function pushbutton_rem_intra_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_rem_intra (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
toRem_Idx = get(handles.listbox_intra_active,'Value');
inactive = get(handles.listbox_intra_inactive,'String');
active = get(handles.listbox_intra_active,'String');
if (size(active) > 0)
toRem_Str = active{toRem_Idx};
    if size(toRem_Str,1) > 0 && ~isempty(toRem_Str)
        inactive{size(inactive,1)+1} = toRem_Str;
        active(toRem_Idx) = [];
        set(handles.listbox_intra_active,'String',active);
        set(handles.listbox_intra_inactive,'String',inactive);
        set(handles.listbox_intra_active,'Value',1);
        set(handles.listbox_intra_inactive,'Value',1);
    end
end
listbox_intra_active_Callback(handles.listbox_intra_active, eventdata, handles);

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

% Hints: get(hObject,'String') returns contents of listbox_pre_active as text
%        str2double(get(hObject,'String')) returns contents of listbox_pre_active as a double
ud = get(handles.figure1,'UserData');
contents = get(hObject,'String');
if get(hObject,'Value') <= size(contents,1)
    marked = contents(get(hObject,'Value'));
    preObj = ud.preMap(marked{:});
    if preObj.isConfigurable
       set(handles.pushbutton_settings_pre,'Enable','on');
    else
       set(handles.pushbutton_settings_pre,'Enable','off');
    end
else
    set(handles.pushbutton_settings_pre,'Enable','off')
end

% --- Executes during object creation, after setting all properties.
function listbox_pre_active_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_pre_active (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox_pre_inactive.
function listbox_pre_inactive_Callback(hObject, eventdata, handles)
% hObject    handle to listbox_pre_inactive (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox_pre_inactive contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox_pre_inactive



% --- Executes during object creation, after setting all properties.
function listbox_pre_inactive_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_pre_inactive (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton_add_pre.
function pushbutton_add_pre_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_add_pre (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
toAdd_Idx = get(handles.listbox_pre_inactive,'Value');
inactive = get(handles.listbox_pre_inactive,'String');
if size(inactive) > 0
toAdd_Str = inactive{toAdd_Idx};
    if size(toAdd_Str,1) > 0 && ~isempty(toAdd_Str)
        active = get(handles.listbox_pre_active,'String');
        active{size(active,1)+1} = toAdd_Str;
        inactive(toAdd_Idx) = [];
        set(handles.listbox_pre_active,'String',active);
        set(handles.listbox_pre_inactive,'String',inactive);
        set(handles.listbox_pre_active,'Value',1);
        set(handles.listbox_pre_inactive,'Value',1);
    end
end
listbox_pre_active_Callback(handles.listbox_pre_active, eventdata, handles);

% --- Executes on button press in pushbutton_rem_pre.
function pushbutton_rem_pre_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_rem_pre (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
toRem_Idx = get(handles.listbox_pre_active,'Value');
inactive = get(handles.listbox_pre_inactive,'String');
active = get(handles.listbox_pre_active,'String');
if (size(active)) > 0
    toRem_Str = active{toRem_Idx};
    if size(toRem_Str,1) > 0 && ~isempty(toRem_Str)
        inactive{size(inactive,1)+1} = toRem_Str;
        active(toRem_Idx) = [];
        set(handles.listbox_pre_active,'String',active);
        set(handles.listbox_pre_inactive,'String',inactive);
        set(handles.listbox_pre_active,'Value',1);
        set(handles.listbox_pre_inactive,'Value',1);
    end
end
listbox_pre_active_Callback(handles.listbox_pre_active, eventdata, handles);


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

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox6.
function listbox6_Callback(hObject, eventdata, handles)
% hObject    handle to listbox6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox6 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox6


% --- Executes during object creation, after setting all properties.
function listbox6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on selection change in listbox_intra_active.
function listbox_intra_active_Callback(hObject, eventdata, handles)
% hObject    handle to listbox_intra_active (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox_intra_active contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox_intra_active
ud = get(handles.figure1,'UserData');
contents = get(hObject,'String');
if get(hObject,'Value') <= size(contents,1)
    marked = contents(get(hObject,'Value'));
    preObj = ud.proMap(marked{:});
    if preObj.isConfigurable
       set(handles.pushbutton_settings_pro,'Enable','on');
    else
       set(handles.pushbutton_settings_pro,'Enable','off');
    end
else
    set(handles.pushbutton_settings_pro,'Enable','off')
end

% --- Executes during object creation, after setting all properties.
function listbox_intra_active_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_intra_active (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on key press with focus on pushbutton_add_pre and none of its controls.
function pushbutton_add_pre_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton_add_pre (see GCBO)
% eventdata  structure with the following fields (see UICONTROL)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)
disp('bla')


% --- Executes on button press in pushbutton_settings_pro.
function pushbutton_settings_pro_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_settings_pro (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ud = get(handles.figure1,'UserData');
contents = get(handles.listbox_intra_active,'String');
marked = contents(get(handles.listbox_intra_active,'Value'));
proObj = ud.proMap(marked{:});
proObj.uiconfigure;

% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over listbox_pre_active.
function listbox_pre_active_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to listbox_pre_active (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp('Button Down');


% --- Executes on button press in pushbutton_settings_pre.
function pushbutton_settings_pre_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_settings_pre (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ud = get(handles.figure1,'UserData');
contents = get(handles.listbox_pre_active,'String');
marked = contents(get(handles.listbox_pre_active,'Value'));
preObj = ud.preMap(marked{:});
preObj.uiconfigure;


% --- Executes on key press with focus on listbox_pre_active and none of its controls.
function listbox_pre_active_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to listbox_pre_active (see GCBO)
% eventdata  structure with the following fields (see UICONTROL)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)
disp('key press');


% --- Executes on button press in pushbutton_view_pro.
function pushbutton_view_pro_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_view_pro (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ud = get(handles.figure1,'UserData');
contents = get(handles.listbox_intra_active,'String');
marked = contents(get(handles.listbox_intra_active,'Value'));
proObj = ud.proMap(marked{:});
msg = evalc('proObj.viewSettings');
msgbox(msg, ['type: ' class(proObj)]);


% --- Executes on button press in pushbutton_view_pre.
function pushbutton_view_pre_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_view_pre (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ud = get(handles.figure1,'UserData');
contents = get(handles.listbox_pre_active,'String');
marked = contents(get(handles.listbox_pre_active,'Value'));
preObj = ud.preMap(marked{:});
msg = evalc('preObj.viewSettings');
msgbox(msg, ['type: ' class(preObj)]);