001    package org.springframework.richclient.widget;
002    
003    import org.springframework.richclient.command.AbstractCommand;
004    
005    import javax.swing.*;
006    import java.awt.*;
007    
008    
009    /* ButtonSwitcher is a simple widget that puts 2 buttons from the same command (but with
010     * different face id's) on a cardlayout.
011     *
012     * This makes it easy to switch between 2 faces.
013     */
014    public class ButtonSwitcherWidget extends AbstractWidget
015    {
016    
017        private final CardLayout switcher;
018        private final JPanel panel;
019    
020        public static final String DEFAULT = "default";
021        public static final String ALTERNATIVE = "alternative";
022    
023        public ButtonSwitcherWidget(AbstractCommand command, String alternativeFaceId)
024        {
025            AbstractButton defaultButton = command.createButton();
026            AbstractButton alternButton = command.createButton(alternativeFaceId);
027            this.switcher = new CardLayout();
028            this.panel = new JPanel(this.switcher);
029            this.panel.add(defaultButton, DEFAULT);
030            this.panel.add(alternButton, ALTERNATIVE);
031        }
032    
033        public JComponent getComponent()
034        {
035            return this.panel;
036        }
037    
038        public void showDefault()
039        {
040            this.switcher.first(this.panel);
041        }
042    
043        public void showAlternative()
044        {
045            this.switcher.last(this.panel);
046        }
047    
048        public void show(String mode)
049        {
050            this.switcher.show(this.panel, mode);
051    
052        }
053    }