001    package org.springframework.richclient.widget;
002    
003    import org.apache.commons.logging.Log;
004    import org.apache.commons.logging.LogFactory;
005    import org.springframework.core.io.Resource;
006    import org.springframework.richclient.util.PopupMenuMouseListener;
007    import org.springframework.richclient.util.RcpSupport;
008    
009    import javax.swing.*;
010    
011    /**
012     * A widget that enables to mimic a screen. This is useful for application
013     * still under development, but that want to show how a certain screen will look
014     * like.
015     *
016     * The view consists of a image tab showing the screen look-a-like and/or a HTML tab
017     * consisting of an explanation on what this screen will do.
018     */
019    public class ScreenSimulationWidget extends AbstractWidget
020    {
021        JTabbedPane mainComponent;
022    
023        private static Log log = LogFactory.getLog(ScreenSimulationWidget.class);
024    
025        public ScreenSimulationWidget(Resource explanationPath)
026        {
027            this(explanationPath, null);
028        }
029    
030        public ScreenSimulationWidget(Resource explanationPath, Resource imagePath)
031        {
032            this(explanationPath, imagePath, null);
033        }
034    
035        public ScreenSimulationWidget(Resource explanationPath, Resource imagePath, JPopupMenu popup)
036        {
037            this.mainComponent = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
038    
039            JComponent imageArea = createImagePanel(imagePath);
040            if (imageArea != null)
041            {
042                String screenLabel = RcpSupport.getMessage("simulation", "screen", RcpSupport.LABEL);
043                this.mainComponent.addTab(screenLabel, imageArea);
044            }
045            else
046                log.warn("Image not found at " + imagePath);
047    
048            JComponent explanationArea = createTextPanel(explanationPath);
049            if (explanationArea != null)
050            {
051    
052                String explanationLabel = RcpSupport.getMessage("simulation", "explanation", RcpSupport.LABEL);
053                this.mainComponent.addTab(explanationLabel, explanationArea);
054            }
055            else
056                log.warn("Explanation html not found at " + explanationPath);
057    
058            if (popup != null)
059            {
060                this.mainComponent.addMouseListener(new PopupMenuMouseListener(popup));
061            }
062        }
063    
064        private JComponent createTextPanel(Resource textResource)
065        {
066            HTMLViewWidget hw = new HTMLViewWidget(textResource);
067            return hw.getComponent();
068        }
069    
070        private JComponent createImagePanel(Resource imageResource)
071        {
072            ImageViewWidget hw = new ImageViewWidget(imageResource);
073            return hw.getComponent();
074        }
075    
076        public JComponent getComponent()
077        {
078            return mainComponent;
079        }
080    }