gusucode.com > vision工具箱matlab源码程序 > vision/+vision/+internal/+cascadeTrainer/+tool/LabelerFilePanel.m

    classdef LabelerFilePanel < vision.internal.uitools.FilePanel

%   Copyright 2016 The MathWorks, Inc.

    properties(Access=protected)        
        NewSessionToolTip  = 'vision:trainingtool:NewSessionToolTip';
        OpenSessionToolTip = 'vision:trainingtool:OpenSessionToolTip';
        SaveSessionToolTip = 'vision:trainingtool:SaveSessionToolTip';
        AddImagesToolTip   = 'vision:trainingtool:AddImagesToolTip';
                
        AddImagesIconFile = fullfile(toolboxdir('vision'),'vision',...
            '+vision','+internal','+cascadeTrainer','+tool','AddImage_24.png');  
        
        ImportROIsButton;
        ImportROIsToolTip = 'vision:trainingtool:ImportROIsToolTip';
    end
    
    methods        
        
        %------------------------------------------------------------------
        function this = LabelerFilePanel()
            this = this@vision.internal.uitools.FilePanel();
            addOpenSessionPopup(this)
        end
        
        %------------------------------------------------------------------
        function setAllButtonsEnabled(this, state)
        % setAllButtonsEnabled Enable/disable all buttons
        %   setAllButtonsEnabled(panel, state) If state is true, enable all
        %   buttons on the panel. if state is fals, disable all buttons on
        %   the panel.
            this.AddImagesButton.Enabled = state;
            this.NewSessionButton.Enabled = state;
            this.OpenSessionButton.Enabled = state;
            this.SaveSessionButton.Enabled = state;
            this.ImportROIsButton.Enabled = state;
        end
        
        %------------------------------------------------------------------                
        function addOpenSessionCallbacks(this, buttonFun, popupFun)
            addOpenSessionCallback(this, buttonFun);
            this.addPopupCallback(this.OpenSessionButton, popupFun);
        end                        
        
        %------------------------------------------------------------------                
        function addImportROIsCallback(this, fun, popupFun)
            this.addButtonCallback(this.ImportROIsButton, fun);
            this.addPopupCallback(this.ImportROIsButton, popupFun);
        end
    end
    
    methods(Access=protected)
        %------------------------------------------------------------------
        function createPanel(this)
            this.Panel = toolpack.component.TSPanel('f:p,f:p,f:p,2dlu,f:p,2dlu,f:p',...
                'f:p');
        end
        
        %------------------------------------------------------------------
        function addButtons(this)
            this.addNewSessionButton();
            this.addOpenSessionButton();
            this.addSaveSessionButton();
            this.addAddImagesButton();
            this.addImportROIsButton();
                                    
            add(this.Panel, this.NewSessionButton,'xy(1,1)');
            add(this.Panel, this.OpenSessionButton, 'xy(2,1)');            
            add(this.Panel, this.SaveSessionButton,'xy(3,1)');
            add(this.Panel, this.AddImagesButton,'xy(5,1)');
            add(this.Panel, this.ImportROIsButton,'xy(7,1)');            
        end
                
        %------------------------------------------------------------------
        function addImportROIsButton(this)
            icon = toolpack.component.Icon.IMPORT_24;
            nameId = 'vision:trainingtool:ImportROIs';
            tag = 'btnImportROIs';
            this.ImportROIsButton = this.createSplitButton(icon, nameId, tag, ...
                'vertical');
            this.setToolTipText(this.ImportROIsButton, this.ImportROIsToolTip);
            
            style = 'icon_text';
            this.ImportROIsButton.Popup = toolpack.component.TSDropDownPopup(...
                getImportOptions, style);
            this.ImportROIsButton.Popup.Name = 'ImportPopup';
        end
        
        %------------------------------------------------------------------
        function createOpenSessionButton(this, openSessionIcon, nameId)
             this.OpenSessionButton = this.createSplitButton(openSessionIcon, ...
                nameId, 'btnOpenSession', 'vertical');                        
        end

        %------------------------------------------------------------------
        function addOpenSessionPopup(this)
            style = 'icon_text';
            this.OpenSessionButton.Popup = toolpack.component.TSDropDownPopup(...
                getOpenOptions, style);
            this.OpenSessionButton.Popup.Name = 'OpenPopup';
        end
    end
end

%--------------------------------------------------------------------------
function items = getOpenOptions(~)
% defining the option entries appearing on the popup of the
% Save Split Button.

openIcon = com.mathworks.common.icons.CommonIcon.OPEN;
addToCurrentIcon = toolpack.component.Icon.ADD_16;

items(1) = struct(...
    'Title', getString(message('vision:trainingtool:OpenExistingSession')), ...
    'Description', '', ...
    'Icon', toolpack.component.Icon(openIcon.getIcon), ...
    'Help', [], ...
    'Header', false);
items(2) = struct(...
    'Title', getString(message('vision:trainingtool:AddToCurrentSession')), ...
    'Description', '', ...
    'Icon', addToCurrentIcon, ...
    'Help', [], ...
    'Header', false);
end

%------------------------------------------------------------------
function items = getImportOptions(~)
% defining the option entries appearing on the popup of the
% Import ROIs Split Button.

openIcon = com.mathworks.common.icons.CommonIcon.OPEN;
addToCurrentIcon = toolpack.component.Icon.ADD_16;

items(1) = struct(...
    'Title', getString(message('vision:trainingtool:ImportROIsFromFile')), ...
    'Description', '', ...
    'Icon', toolpack.component.Icon(openIcon.getIcon), ...
    'Help', [], ...
    'Header', false);
items(2) = struct(...
    'Title', getString(message('vision:trainingtool:ImportROIsFromWorkspace')), ...
    'Description', '', ...
    'Icon', addToCurrentIcon, ...
    'Help', [], ...
    'Header', false);
end