Coverage report

  %line %branch
com.nexes.wizard.WizardModel
0% 
0% 

 1  
 package com.nexes.wizard;
 2  
 
 3  
 import java.beans.*;
 4  
 import java.util.HashMap;
 5  
 
 6  
 import javax.swing.Icon;
 7  
 
 8  
 /**
 9  
  * The model for the Wizard component, which tracks the text, icons, and enabled state
 10  
  * of each of the buttons, as well as the current panel that is displayed. Note that 
 11  
  * the model, in its current form, is not intended to be subclassed. 
 12  
  */
 13  
 
 14  
 
 15  
 public class WizardModel {
 16  
 
 17  
     /**
 18  
      * Identification string for the current panel.
 19  
      */    
 20  
     public static final String CURRENT_PANEL_DESCRIPTOR_PROPERTY = "currentPanelDescriptorProperty";
 21  
     
 22  
     /**
 23  
      * Property identification String for the Back button's text
 24  
      */    
 25  
     public static final String BACK_BUTTON_TEXT_PROPERTY = "backButtonTextProperty";
 26  
     /**
 27  
      * Property identification String for the Back button's icon
 28  
      */    
 29  
     public static final String BACK_BUTTON_ICON_PROPERTY = "backButtonIconProperty";
 30  
     /**
 31  
      * Property identification String for the Back button's enabled state
 32  
      */    
 33  
     public static final String BACK_BUTTON_ENABLED_PROPERTY = "backButtonEnabledProperty";
 34  
 
 35  
     /**
 36  
      * Property identification String for the Next button's text
 37  
      */    
 38  
     public static final String NEXT_FINISH_BUTTON_TEXT_PROPERTY = "nextButtonTextProperty";
 39  
     /**
 40  
      * Property identification String for the Next button's icon
 41  
      */    
 42  
     public static final String NEXT_FINISH_BUTTON_ICON_PROPERTY = "nextButtonIconProperty";
 43  
     /**
 44  
      * Property identification String for the Next button's enabled state
 45  
      */    
 46  
     public static final String NEXT_FINISH_BUTTON_ENABLED_PROPERTY = "nextButtonEnabledProperty";
 47  
     
 48  
     /**
 49  
      * Property identification String for the Cancel button's text
 50  
      */    
 51  
     public static final String CANCEL_BUTTON_TEXT_PROPERTY = "cancelButtonTextProperty";
 52  
     /**
 53  
      * Property identification String for the Cancel button's icon
 54  
      */    
 55  
     public static final String CANCEL_BUTTON_ICON_PROPERTY = "cancelButtonIconProperty";
 56  
     /**
 57  
      * Property identification String for the Cancel button's enabled state
 58  
      */    
 59  
     public static final String CANCEL_BUTTON_ENABLED_PROPERTY = "cancelButtonEnabledProperty";
 60  
     
 61  
     private WizardPanelDescriptor currentPanel;
 62  
     
 63  
     private HashMap panelHashmap;
 64  
     
 65  
     private HashMap buttonTextHashmap;
 66  
     private HashMap buttonIconHashmap;
 67  
     private HashMap buttonEnabledHashmap;
 68  
     
 69  
     private PropertyChangeSupport propertyChangeSupport;
 70  
     
 71  
     
 72  
     /**
 73  
      * Default constructor.
 74  
      */    
 75  0
     public WizardModel() {
 76  
         
 77  0
         panelHashmap = new HashMap();
 78  
         
 79  0
         buttonTextHashmap = new HashMap();
 80  0
         buttonIconHashmap = new HashMap();
 81  0
         buttonEnabledHashmap = new HashMap();
 82  
         
 83  0
         propertyChangeSupport = new PropertyChangeSupport(this);
 84  
 
 85  0
     }
 86  
     
 87  
     /**
 88  
      * Returns the currently displayed WizardPanelDescriptor.
 89  
      * @return The currently displayed WizardPanelDescriptor
 90  
      */    
 91  
     WizardPanelDescriptor getCurrentPanelDescriptor() {
 92  0
         return currentPanel;
 93  
     }
 94  
     
 95  
     /**
 96  
      * Registers the WizardPanelDescriptor in the model using the Object-identifier specified.
 97  
      * @param id Object-based identifier
 98  
      * @param descriptor WizardPanelDescriptor that describes the panel
 99  
      */    
 100  
      void registerPanel(Object id, WizardPanelDescriptor descriptor) {
 101  
         
 102  
         //  Place a reference to it in a hashtable so we can access it later
 103  
         //  when it is about to be displayed.
 104  
         
 105  0
         panelHashmap.put(id, descriptor);
 106  
         
 107  0
     }  
 108  
     
 109  
     /**
 110  
      * Sets the current panel to that identified by the Object passed in.
 111  
      * @param id Object-based panel identifier
 112  
      * @return boolean indicating success or failure
 113  
      */    
 114  
      boolean setCurrentPanel(Object id) {
 115  
 
 116  
         //  First, get the hashtable reference to the panel that should
 117  
         //  be displayed.
 118  
         
 119  0
         WizardPanelDescriptor nextPanel =
 120  
             (WizardPanelDescriptor)panelHashmap.get(id);
 121  
         
 122  
         //  If we couldn't find the panel that should be displayed, return
 123  
         //  false.
 124  
         
 125  0
         if (nextPanel == null)
 126  0
             throw new WizardPanelNotFoundException();   
 127  
 
 128  0
         WizardPanelDescriptor oldPanel = currentPanel;
 129  0
         currentPanel = nextPanel;
 130  
         
 131  0
         if (oldPanel != currentPanel)
 132  0
             firePropertyChange(CURRENT_PANEL_DESCRIPTOR_PROPERTY, oldPanel, currentPanel);
 133  
         
 134  0
         return true;
 135  
         
 136  
     }
 137  
 
 138  
     Object getBackButtonText() {
 139  0
         return buttonTextHashmap.get(BACK_BUTTON_TEXT_PROPERTY);
 140  
     }
 141  
     
 142  
     void setBackButtonText(Object newText) {
 143  
         
 144  0
         Object oldText = getBackButtonText();        
 145  0
         if (!newText.equals(oldText)) {
 146  0
             buttonTextHashmap.put(BACK_BUTTON_TEXT_PROPERTY, newText);
 147  0
             firePropertyChange(BACK_BUTTON_TEXT_PROPERTY, oldText, newText);
 148  
         }
 149  0
     }
 150  
 
 151  
     Object getNextFinishButtonText() {
 152  0
         return buttonTextHashmap.get(NEXT_FINISH_BUTTON_TEXT_PROPERTY);
 153  
     }
 154  
     
 155  
     void setNextFinishButtonText(Object newText) {
 156  
         
 157  0
         Object oldText = getNextFinishButtonText();        
 158  0
         if (!newText.equals(oldText)) {
 159  0
             buttonTextHashmap.put(NEXT_FINISH_BUTTON_TEXT_PROPERTY, newText);
 160  0
             firePropertyChange(NEXT_FINISH_BUTTON_TEXT_PROPERTY, oldText, newText);
 161  
         }
 162  0
     }
 163  
 
 164  
     Object getCancelButtonText() {
 165  0
         return buttonTextHashmap.get(CANCEL_BUTTON_TEXT_PROPERTY);
 166  
     }
 167  
     
 168  
     void setCancelButtonText(Object newText) {
 169  
         
 170  0
         Object oldText = getCancelButtonText();        
 171  0
         if (!newText.equals(oldText)) {
 172  0
             buttonTextHashmap.put(CANCEL_BUTTON_TEXT_PROPERTY, newText);
 173  0
             firePropertyChange(CANCEL_BUTTON_TEXT_PROPERTY, oldText, newText);
 174  
         }
 175  0
     } 
 176  
     
 177  
     Icon getBackButtonIcon() {
 178  0
         return (Icon)buttonIconHashmap.get(BACK_BUTTON_ICON_PROPERTY);
 179  
     }
 180  
     
 181  
     void setBackButtonIcon(Icon newIcon) {
 182  
         
 183  0
         Object oldIcon = getBackButtonIcon();        
 184  0
         if (!newIcon.equals(oldIcon)) {
 185  0
             buttonIconHashmap.put(BACK_BUTTON_ICON_PROPERTY, newIcon);
 186  0
             firePropertyChange(BACK_BUTTON_ICON_PROPERTY, oldIcon, newIcon);
 187  
         }
 188  0
     }
 189  
 
 190  
     Icon getNextFinishButtonIcon() {
 191  0
         return (Icon)buttonIconHashmap.get(NEXT_FINISH_BUTTON_ICON_PROPERTY);
 192  
     }
 193  
     
 194  
     public void setNextFinishButtonIcon(Icon newIcon) {
 195  
         
 196  0
         Object oldIcon = getNextFinishButtonIcon();        
 197  0
         if (!newIcon.equals(oldIcon)) {
 198  0
             buttonIconHashmap.put(NEXT_FINISH_BUTTON_ICON_PROPERTY, newIcon);
 199  0
             firePropertyChange(NEXT_FINISH_BUTTON_ICON_PROPERTY, oldIcon, newIcon);
 200  
         }
 201  0
     }
 202  
 
 203  
     Icon getCancelButtonIcon() {
 204  0
         return (Icon)buttonIconHashmap.get(CANCEL_BUTTON_ICON_PROPERTY);
 205  
     }
 206  
     
 207  
     void setCancelButtonIcon(Icon newIcon) {
 208  
         
 209  0
         Icon oldIcon = getCancelButtonIcon();        
 210  0
         if (!newIcon.equals(oldIcon)) {
 211  0
             buttonIconHashmap.put(CANCEL_BUTTON_ICON_PROPERTY, newIcon);
 212  0
             firePropertyChange(CANCEL_BUTTON_ICON_PROPERTY, oldIcon, newIcon);
 213  
         }
 214  0
     } 
 215  
         
 216  
     
 217  
     Boolean getBackButtonEnabled() {
 218  0
         return (Boolean)buttonEnabledHashmap.get(BACK_BUTTON_ENABLED_PROPERTY);
 219  
     }
 220  
     
 221  
     void setBackButtonEnabled(Boolean newValue) {
 222  
         
 223  0
         Boolean oldValue = getBackButtonEnabled();        
 224  0
         if (newValue != oldValue) {
 225  0
             buttonEnabledHashmap.put(BACK_BUTTON_ENABLED_PROPERTY, newValue);
 226  0
             firePropertyChange(BACK_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
 227  
         }
 228  0
     }
 229  
 
 230  
     Boolean getNextFinishButtonEnabled() {
 231  0
         return (Boolean)buttonEnabledHashmap.get(NEXT_FINISH_BUTTON_ENABLED_PROPERTY);
 232  
     }
 233  
     
 234  
     void setNextFinishButtonEnabled(Boolean newValue) {
 235  
         
 236  0
         Boolean oldValue = getNextFinishButtonEnabled();        
 237  0
         if (newValue != oldValue) {
 238  0
             buttonEnabledHashmap.put(NEXT_FINISH_BUTTON_ENABLED_PROPERTY, newValue);
 239  0
             firePropertyChange(NEXT_FINISH_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
 240  
         }
 241  0
     }
 242  
     
 243  
     Boolean getCancelButtonEnabled() {
 244  0
         return (Boolean)buttonEnabledHashmap.get(CANCEL_BUTTON_ENABLED_PROPERTY);
 245  
     }
 246  
     
 247  
     void setCancelButtonEnabled(Boolean newValue) {
 248  
         
 249  0
         Boolean oldValue = getCancelButtonEnabled();        
 250  0
         if (newValue != oldValue) {
 251  0
             buttonEnabledHashmap.put(CANCEL_BUTTON_ENABLED_PROPERTY, newValue);
 252  0
             firePropertyChange(CANCEL_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
 253  
         }
 254  0
     }
 255  
     
 256  
     
 257  
     
 258  
     public void addPropertyChangeListener(PropertyChangeListener p) {
 259  0
         propertyChangeSupport.addPropertyChangeListener(p);
 260  0
     }
 261  
     
 262  
     public void removePropertyChangeListener(PropertyChangeListener p) {
 263  0
         propertyChangeSupport.removePropertyChangeListener(p);
 264  0
     }
 265  
     
 266  
     protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
 267  0
         propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
 268  0
     }
 269  
     
 270  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.