classdef ButtonGroup < handle
  % Toolstrip button group for radio buttons.
  %
  % See also toolpack.component.TSRadioButton
  
  % Author(s): Bora Eryilmaz
  % Revised:
  % Copyright 2010-2011 The MathWorks, Inc.
  
  % ----------------------------------------------------------------------------
  properties (Access = private)
    % A javax.swing.ButtonGroup object.
    Peer_
  end
  
  % ----------------------------------------------------------------------------
  methods
    function this = ButtonGroup()
      % Creates a button group for TSRadioButton widgets.
      %
      % Example:
      %   btn1 = toolpack.component.TSRadioButton('Current')
      %   btn2 = toolpack.component.TSRadioButton('All')
      %
      %   bg = toolpack.component.ButtonGroup
      %   bg.add(btn1)
      %   bg.add(btn2)
      
      cls = 'javax.swing.ButtonGroup';
      this.Peer_ = javaObjectEDT(cls);
    end
    
    function add(this, btn)
      % Adds the button to the button group.
      this.Peer_.add(btn.Peer);
      btn.utSetGroup(this);
    end
    
    function remove(this, btn)
      % Removes the button from the button group.
      this.Peer_.remove(btn.Peer)
      btn.utSetGroup([]);
    end
    
    function clearSelection(this)
      this.Peer_.clearSelection;
    end
  end
end

% ------------------------------------------------------------------------------
