summaryrefslogtreecommitdiff
path: root/libs/FLib/JWizard/doc/tutorial.html
blob: 3a8dc2decdefbd586346d20ad7cb98af757ae3b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/JWizard.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>JWizard - Tutorial</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<p><img src="images/Logo.png" width="800" height="150" /></p>
<table width="800" border="0" cellspacing="0" cellpadding="10">
  <tr>
    <td width="150" align="left" valign="top" id="sidebar"> 
      <p><a href="index.html">Introduction</a></p>
      <p><a href="features.html">Features</a></p>
      <p><a href="screenshots.html">Screen<br />
        shots</a></p>
      <p><a href="tutorial.html">Tutorial</a></p>
      <p><a href="examples.html">Examples</a></p>
      <p><a href="api/index.html">API<br />
        documentation</a></p>
      <p><a href="https://sourceforge.net/project/showfiles.php?group_id=113939">Download</a></p>
      <p><a href="resources.html">Other<br />
        resources</a></p>
      <p><a href="../../index.html">Return to<br />
        FLib</a> </p>
      <p><a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=113939&amp;type=1" alt="SourceForge.net Logo" width="88" height="31" border="0" align="top" title="" /></a></p>
      <p><a href="http://www.jars.com/"><img src="http://www.jars.com/images/r750.gif" alt="Rated JARS Top 25%" width="104" height="56" border="0" align="top" title="" /></a></p>    </td>
    <td id="content" width="614" align="left" valign="top"><!-- InstanceBeginEditable name="content" --> 
      <h1>Tutorial</h1>
      <h2>JWizard</h2>
      <h3>Creating the JWizardDialog</h3>
      <p>To create a Wizard, begin by creating a storyboard, sketching each step 
        and the sequence through the steps. The sequencing may depend on the information 
        users supply as they proceed through the Wizard. Number each step, from 
        0 to <em>n</em>, roughly following the flow from beginning to end.</p>
      <p>Now you're ready to create your Wizard class. The basic pattern is:</p>
      <pre>public class SampleWizard
    extends JWizardDialog
{


public SampleWizard(Frame owner) {
    super(owner, &quot;Sample Wizard&quot;, true);

    // Set the logo image

    URL url = getClass().getResource(&quot;SampleWizard.gif&quot;);
    setWizardIcon(new ImageIcon(url));

    // Create each step

    addWizardPanel(new Step0());
    addWizardPanel(new Step1());
    addWizardPanel(new Step2());
    ...
    
    // Make the dialog visible

    pack();
    setVisible(true);
}

}
</pre>
      <p>Each Wizard is a subclass of JWizardDialog. In this case, the sample 
        wizard will be the child of a Frame. This will center the Wizard over 
        the Frame. If the Frame is null, the Wizard will be centered in the middle 
        of the screen. You can turn off the centering behavior by calling <code>disableCentering()</code> 
        before calling <code>setVisible()</code>.</p>
      <p>The dialog title will be &quot;Sample Wizard&quot; and the dialog will 
        be modal (which is fairly standard for Wizards). An icon is added to the 
        Wizard and will be displayed on the left side of the dialog.</p>
      <p>Note that each Wizard step is a separate class that is instantiated and 
        added to the dialog. The class names are arbitrary, but the first step 
        will be identified as step 0, so the above naming makes it easy to associate 
        a step with its corresponding class.</p>
      <p>The step classes can be created however you like, but my recommendation 
        is that they be inner classes of the JWizardDialog. This makes it very 
        easy for global information to be accumulated in a central place (the 
        JWizardDialog) and accessed by all steps.</p>
      <h3>Creating the Wizard Steps</h3>
      <p>The basic pattern for a Wizard step is as follows:</p>
      <pre>private class Step0
      extends JWizardPanel
{

public
Step0()
{
    setStepTitle(&quot;Sample Wizard Step 0&quot;);

    JPanel contentPane = getContentPane();
    ...

    // Set the previous and next steps

    setBackStep(-1);
    setNextStep(1);
}

}
</pre>
      <p>Each step is a subclass of JWizardPanel. You will normally start by setting 
        the title for this specific step. Then you will construct all the appropriate 
        components for the step and add them to the JPanel obtained by calling 
        <code>getContentPane()</code> (don't add them directly to the JWizardPanel).</p>
      <p>You end each step constructor by calling <code>setBackStep()</code> and 
        <code>setNextStep()</code>. This defines the flow from this panel to the 
        previous and next panels. A previous panel of -1 means that we are on 
        the first panel; a -1 for the next panel means we are on the last panel. 
        Any other number identifies the step we will sequence back or forwards 
        to.</p>
      <p>If you need more dynamic sequencing, you will set up the default sequence 
        in the constructor. Then you will override the <code>back()</code> or 
        <code>next()</code> methods. You would determine the correct previous 
        or next step (calling <code>setBackStep()</code> or <code>setNextStep()</code>) 
        and then call <code>super.back()</code> or <code>super.next()</code>.</p>
      <p>This also allows you to perform error checking. You override the <code>next()</code> 
        method and perform error checking based on the user's step entries. If 
        there is an error, you can display an error dialog and return without 
        calling <code>super.next()</code>. This will leave the step unchanged.</p>
      <p>The <code>next()</code> method is also a convenient place to read the 
        user's entries and copy them into JWizardDialog fields so that the information 
        is globally available to all steps.</p>
      <p>If you have a complicated Wizard with many steps and lots of components, 
        it may take a while to display if you construct each panel in the JWizardPanel 
        constructor. You perform a delayed construction by overriding <code>makingVisible()</code>. 
        <code>makingVisible()</code> is called just prior to displaying the step, 
        so you'll need to make sure you construct the panel only the first time 
        its called.</p>
      <p>This will speed up the initial appearance of the Wizard, but it will 
        make it difficult to size the dialog properly (the dialog should be large 
        enough to accommodate the largest panel). You may think you can manually 
        set the size by calling <code>setSize()</code> on the JWizardDialog. This 
        is not a good idea. There are various circumstances which may change the 
        size needed:</p>
      <ul>
        <li>If the application is internationalized, the translated labels may 
          be longer than expected.</li>
        <li>If the application is designed for people with poor vision, you may 
          want to allow for larger font sizes.</li>
        <li>You may also want larger font sizes for demo purposes (showing the 
          application to a group of people gathered around a display).</li>
      </ul>
      <p>JWizardDialog does make allowances for panels created in makingVisible(). 
        Before each panel is displayed, it checks the preferred size against the 
        current size. If the preferred size is bigger, it will increase the dialog's 
        size to match. It will never decrease the size&#8212;this minimizes the 
        amount of size changes the dialog goes through.</p>
      <h3>Handling Finish and Cancel</h3>
      <p>In JWizardDialog, the <code>finish()</code> and <code>cancel()</code> 
        methods are called when the Finish and Cancel buttons are called, respectively. 
        Each of these methods calls dispose(). You may want to override them. 
        For instance, <code>finish()</code> may want to take all the user's input 
        and do something with it. In <code>cancel()</code>, you may want to query 
        the user to confirm the cancellation. Call <code>super.cancel()</code> 
        if confirmed or else just return.</p>
      <h3>Handling Help</h3>
      <p>You add a Help button by calling <code>addHelpButton()</code> in the 
        JWizardDialog constructor. If all Wizard panels have the same help message, 
        you would override <code>help()</code> in the JWizardDialog class. Otherwise, 
        each step should over JWizardPanel's <code>help()</code> method.</p>
      <h3>Sequencing Options</h3>
      <p>In general, the sequencing is handled by each step. This is usually the 
        easiest way to do it as each step usually has the information it needs 
        to decide where to go next. However, if you need more central control 
        of the sequencing algorithm, you can override <code>switchToStep()</code> 
        in the JWizardDialog. This method receives the current step value and 
        the requested next step (from the JWizardPanel). Note that the &quot;next&quot; 
        step is the step selected by the user pressing either the Back or Next 
        button. You can change the change the next step value based on whatever 
        criteria you want.</p>
      <h3>Other Options</h3>
      <p>In most Wizards, the Finish button is enabled only on the last step. 
        But some Wizards allow the user to call Finish while steps still remain. 
        The information gathered in the remaining steps is defaulted. If you have 
        this model, call <code>setEarlyFinish()</code> in the JWizardDialog.</p>
      <p>In some Wizards, the last step is simply where all the necessary user 
        information has been gathered&#8212;pressing Finish begins processing 
        the information. In other Wizards, actions may be performed as the Wizard 
        proceeds and the last step is simply to confirm completion of the task. 
        In this latter case, call <code>disableCancelAtEnd()</code> in the JWizardDialog. 
        This disables the Cancel button on the last step.</p>
      <h3>Summary</h3>
      <p>The JWizard components are designed to be easy to use. In most cases
         you will override just a few methods. The rest will normally do the
        right 
        thing. After reading this tutorial, you should examine the <a href="examples.html">example
         program</a> provided which exercises many of the features of JWizard.</p>
      <!-- InstanceEndEditable --></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>