| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| com.nexes.wizard.WizardPanelDescriptor$FinishIdentifier |
|
|
| 1 | package com.nexes.wizard; |
|
| 2 | ||
| 3 | import java.awt.*; |
|
| 4 | import javax.swing.*; |
|
| 5 | ||
| 6 | ||
| 7 | /** |
|
| 8 | * A base descriptor class used to reference a Component panel for the Wizard, as |
|
| 9 | * well as provide general rules as to how the panel should behave. |
|
| 10 | */ |
|
| 11 | public class WizardPanelDescriptor { |
|
| 12 | ||
| 13 | private static final String DEFAULT_PANEL_IDENTIFIER = "defaultPanelIdentifier"; |
|
| 14 | ||
| 15 | ||
| 16 | /** |
|
| 17 | * Identifier returned by getNextPanelDescriptor() to indicate that this is the |
|
| 18 | * last panel and the text of the 'Next' button should change to 'Finish'. |
|
| 19 | */ |
|
| 20 | public static final FinishIdentifier FINISH = new FinishIdentifier(); |
|
| 21 | ||
| 22 | private Wizard wizard; |
|
| 23 | private Component targetPanel; |
|
| 24 | private Object panelIdentifier; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Default constructor. The id and the Component panel must be set separately. |
|
| 28 | */ |
|
| 29 | public WizardPanelDescriptor() { |
|
| 30 | panelIdentifier = DEFAULT_PANEL_IDENTIFIER; |
|
| 31 | targetPanel = new JPanel(); |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Constructor which accepts both the Object-based identifier and a reference to |
|
| 36 | * the Component class which makes up the panel. |
|
| 37 | * @param id Object-based identifier |
|
| 38 | * @param panel A class which extends java.awt.Component that will be inserted as a |
|
| 39 | * panel into the wizard dialog. |
|
| 40 | */ |
|
| 41 | public WizardPanelDescriptor(Object id, Component panel) { |
|
| 42 | panelIdentifier = id; |
|
| 43 | targetPanel = panel; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Returns to java.awt.Component that serves as the actual panel. |
|
| 48 | * @return A reference to the java.awt.Component that serves as the panel |
|
| 49 | */ |
|
| 50 | public final Component getPanelComponent() { |
|
| 51 | return targetPanel; |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Sets the panel's component as a class that extends java.awt.Component |
|
| 56 | * @param panel java.awt.Component which serves as the wizard panel |
|
| 57 | */ |
|
| 58 | public final void setPanelComponent(Component panel) { |
|
| 59 | targetPanel = panel; |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Returns the unique Object-based identifier for this panel descriptor. |
|
| 64 | * @return The Object-based identifier |
|
| 65 | */ |
|
| 66 | public final Object getPanelDescriptorIdentifier() { |
|
| 67 | return panelIdentifier; |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * Sets the Object-based identifier for this panel. The identifier must be unique |
|
| 72 | * from all the other identifiers in the panel. |
|
| 73 | * @param id Object-based identifier for this panel. |
|
| 74 | */ |
|
| 75 | public final void setPanelDescriptorIdentifier(Object id) { |
|
| 76 | panelIdentifier = id; |
|
| 77 | } |
|
| 78 | ||
| 79 | final void setWizard(Wizard w) { |
|
| 80 | wizard = w; |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Returns a reference to the Wizard component. |
|
| 85 | * @return The Wizard class hosting this descriptor. |
|
| 86 | */ |
|
| 87 | public final Wizard getWizard() { |
|
| 88 | return wizard; |
|
| 89 | } |
|
| 90 | ||
| 91 | /** |
|
| 92 | * Returns a reference to the current WizardModel for this Wizard component. |
|
| 93 | * @return The current WizardModel for this Wizard component. |
|
| 94 | */ |
|
| 95 | public WizardModel getWizardModel() { |
|
| 96 | return wizard.getModel(); |
|
| 97 | } |
|
| 98 | ||
| 99 | // Override this method to provide an Object-based identifier |
|
| 100 | // for the next panel. |
|
| 101 | ||
| 102 | /** |
|
| 103 | * Override this class to provide the Object-based identifier of the panel that the |
|
| 104 | * user should traverse to when the Next button is pressed. Note that this method |
|
| 105 | * is only called when the button is actually pressed, so that the panel can change |
|
| 106 | * the next panel's identifier dynamically at runtime if necessary. Return null if |
|
| 107 | * the button should be disabled. Return FinishIdentfier if the button text |
|
| 108 | * should change to 'Finish' and the dialog should end. |
|
| 109 | * @return Object-based identifier. |
|
| 110 | */ |
|
| 111 | public Object getNextPanelDescriptor() { |
|
| 112 | return null; |
|
| 113 | } |
|
| 114 | ||
| 115 | // Override this method to provide an Object-based identifier |
|
| 116 | // for the previous panel. |
|
| 117 | ||
| 118 | /** |
|
| 119 | * Override this class to provide the Object-based identifier of the panel that the |
|
| 120 | * user should traverse to when the Back button is pressed. Note that this method |
|
| 121 | * is only called when the button is actually pressed, so that the panel can change |
|
| 122 | * the previous panel's identifier dynamically at runtime if necessary. Return null if |
|
| 123 | * the button should be disabled. |
|
| 124 | * @return Object-based identifier |
|
| 125 | */ |
|
| 126 | public Object getBackPanelDescriptor() { |
|
| 127 | return null; |
|
| 128 | } |
|
| 129 | ||
| 130 | // Override this method in the subclass if you wish it to be called |
|
| 131 | // just before the panel is displayed. |
|
| 132 | ||
| 133 | /** |
|
| 134 | * Override this method to provide functionality that will be performed just before |
|
| 135 | * the panel is to be displayed. |
|
| 136 | */ |
|
| 137 | public void aboutToDisplayPanel() { |
|
| 138 | ||
| 139 | } |
|
| 140 | ||
| 141 | // Override this method in the subclass if you wish to do something |
|
| 142 | // while the panel is displaying. |
|
| 143 | ||
| 144 | /** |
|
| 145 | * Override this method to perform functionality when the panel itself is displayed. |
|
| 146 | */ |
|
| 147 | public void displayingPanel() { |
|
| 148 | ||
| 149 | } |
|
| 150 | ||
| 151 | // Override this method in the subclass if you wish it to be called |
|
| 152 | // just before the panel is switched to another or finished. |
|
| 153 | ||
| 154 | /** |
|
| 155 | * Override this method to perform functionality just before the panel is to be |
|
| 156 | * hidden. |
|
| 157 | */ |
|
| 158 | public void aboutToHidePanel() { |
|
| 159 | ||
| 160 | } |
|
| 161 | ||
| 162 | ||
| 163 | ||
| 164 | 0 | static class FinishIdentifier { |
| 165 | public static final String ID = "FINISH"; |
|
| 166 | } |
|
| 167 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |