classdef TSButtonBehavior < toolpack.component.component
  % Toolstrip button behavior class to handle toolstrip-specific button
  % properties.
  %
  % See also toolpack.component.TSButton, toolpack.component.TSToggleButton,
  % toolpack.component.TSSplitButton, toolpack.component.TSDropDownButton.
  
  % Author(s): Bora Eryilmaz
  % Revised:
  % Copyright 2011 The MathWorks, Inc.
  
  % ----------------------------------------------------------------------------
  properties (Dependent, Access = public)
    % Component's orientation (ButtonOrientation, default = AUTO)
    Orientation
    % Component's priority on FlowToolSection (TSPriority, default = NORMAL)
    Priority
  end
  
  % ----------------------------------------------------------------------------
  methods
    function this = TSButtonBehavior(varargin)
      % Constructor.
      %
      % Subclasses should call
      %   obj = obj@toolpack.component.TSButtonBehavior( varargin{:} )
      
      this = this@toolpack.component.component(varargin{:});
    end
    
    function value = get.Orientation(this)
      % GET function for Orientation property.
      value = getOrientation_(this);
    end
    
    function set.Orientation(this, value)
      % SET function for Orientation property.
      setOrientation_(this, value);
    end
    
    function value = get.Priority(this)
      % GET function for Priority property.
      value = getPriority_(this);
    end
    
    function set.Priority(this, value)
      % SET function for Priority property.
      setPriority_(this, value);
    end
    
    function value = isAutoMnemonicEnabled(this)
      % Get mnemonics enabling status
      value = this.Peer.isAutoMnemonicEnabled;
    end
    
    function setAutoMnemonicEnabled(this, value)
      % Set mnemonics enabling status
      if islogical(value)
        this.Peer.setAutoMnemonicEnabled(value);
      else
        ctrlMsgUtils.error('Controllib:toolpack:LogicalArgumentNeeded')
      end
    end
    
  end
  
  methods (Access = protected)
    function value = getOrientation_(this)
      o = this.Peer.getOrientation;
      value = toolpack.component.ButtonOrientation.getOrientation(o);
    end
    
    function setOrientation_(this, value)
      if ~isa(value, 'toolpack.component.ButtonOrientation')
        ctrlMsgUtils.error('Controllib:toolpack:InvalidPropertyValue', ...
          'Orientation')
      end
      this.Peer.setOrientation( value.JavaEnum );
    end
    
    function value = getPriority_(this)
      o = javaMethodEDT('getPriority', 'com.mathworks.toolstrip.plaf.LAFUtil', this.Peer);
      value = toolpack.component.TSPriority.getPriority(o);
    end
    
    function setPriority_(this, value)
      if ~isa(value, 'toolpack.component.TSPriority')
        ctrlMsgUtils.error('Controllib:toolpack:InvalidPropertyValue', ...
          'Priority')
      end
      javaMethodEDT('setPriority', 'com.mathworks.toolstrip.plaf.LAFUtil', ...
        this.Peer, value.JavaEnum);
    end
  end
end
