Home > English, Linux & Programming > A Java Wizard Toolkit

A Java Wizard Toolkit

Well, here goes my first post. This is a toolkit I started developing back in 2006. I am sure there are other, better implementations and I did not develop this small project any further, but I think it’s also a good example on how to program in OO (though I am sure there is much room for improvement, any flames appreciated 😉 ). So, here it goes:

Introduction

The Wizard Toolkit is a java framework / toolkit for the easy use and creation of wizards. This toolkit lets you focus on defining and validating input fields while the control flow and data storage is automated by the surrounding toolkit.

Wizards are a useful way to gather information for different purposes. They interact in form of dialogs, allowing step-by-step data input. Wizards can be used to gather information, for creating specific output or for setting preferences.

Tutorial

The following example serves as a step-by-step tutorial demonstrating the possibilities provided by the toolkit and how to implement a custom wizard based on it. It will consist of three parts, which will be found in most wizards:

  • A welcome dialog
  • Some input forms
  • A final dialog for checking / presenting all input

The toolkit provides two classes for implementing a wizard:

  • Wizard: The main class of any wizard, extending JDialog. Manages the control flow and displays the panels provided. After finishing the input process, it contains the data entered.
  • WizardPanel: An extension of JPanel. Every WizardPanel stands for one step in the dialog process. It may contain everything a JPanel can contain, usually text or input fields.

The welcome dialog

The first step in a dialog system should always be a welcoming screen, describing what needs to be done in the next steps. This way the user can get an overview of the data required or the process he is about to start. So we create a first class extending WizardPanel:

Note: All following sources are excerpts from the example files. For copyright issues look in the according java files.

public class Panel1 extends WizardPanel {
  public Panel1() {
    super(“Welcome”);
    add(new JLabel(“Welcome to the Wizard toolkit demonstration!));
  }
}

The title Welcome is set in the constructor. It is used for the header and for the menu. You might add further welcome information or for example add licence information here.

Theoretically one WizardPanel is sufficient to create the Wizard class, but in the next step we will add the skeleton of the other two panels and then create the Wizard.

Starting the Wizard

public class Panel2 extends WizardPanel {
  public Panel2() {
    super("Options");
  }
}
public class Panel3 extends WizardPanel {
  public Panel3() {
    super(“Finish”);
  }
}
public class WizardExample {
  public static void main(String[] args) {
    WizardPanel[] panels = new WizardPanel[] { new Panel1(),
        new Panel2(), new Panel3() };
    Wizard wizard = new Wizard((JFrame) null, “Wizard Example”, panels);
    wizard.setVisible (true);
    System.out.println(wizard.getProperties());
  }
}

The Wizard class needs three arguments: A parent dialog or frame (may be null), a title and an array with WizardPanels to display. The constructor automatically initializes everything needed for the process and starts after being set visible. When the user finished using the wizard, all data may be gathered via getProperties. With the WizardPanels implemented so far, calling the constructor will open the following dialog:

Welcoming Screen of the Wizard

Welcoming Screen of the Wizard

Menu, header and buttons are created and managed by the toolkit. Only the main panel / content panel needs to be implemented. Back and Finish cannot be selected, as there is no previous WizardPanel and this is not the last WizardPanel. The buttons behaviour may be modified. Selecting Next will display the next dialog, which will be further implemented now.

The options dialog

After the first dialog, the data input forms begin. In this tutorial a WizardPanel with some sample input fields will be implemented, including verification and storage of the data entered. At first, some input components will be added in the panel’s constructor:

public class Panel2 extends WizardPanel {
  private JCheckBox box1, box2;
  private JRadioButton rbutton1, rbutton2;
  private JTextField textField;
 
  public Panel2() {
    super("Options");
 
    box1 = new JCheckBox("Some option");
    box2 = new JCheckBox(
        "If this radio button is selected, you cannot select "next"");
    rbutton1 = new JRadioButton("Select me");
    rbutton2 = new JRadioButton(
        "If this button is selected, clicking "next" will open a Dialog Box.");
    textField = new JTextField(30);
 
    rbutton1.setSelected(true);
 
    setLayout(new GridBagLayout());
 
    GridBagConstraints gc = new GridBagConstraints();
    ButtonGroup rbuttons = new ButtonGroup();
 
    rbuttons.add(rbutton1);
    rbuttons.add(rbutton2);
 
    gc.gridx = gc.gridy = 0;
    gc.anchor = GridBagConstraints.NORTHWEST;
    add(new JLabel("Checkbox options:"), gc);
 
    gc.gridy++;
    add(box1, gc);
 
    // Add other Components
    // ...
  }

The toolkit enables the Back-Button as there is a previous dialog. But we do not want the user to go back, as there is only a welcome screen. On the other hand, we want to disable the forward button if box2 is selected (as described in its text). The toolkit’s control over the buttons may be overridden to implement panel-specific behaviour:

  protected boolean backButtonEnabled() {
    return false;
  }
 
  protected boolean nextButtonEnabled() {
    return !box2.isSelected();
  }

The Wizard toolkit must be specifically told when to refresh the buttons. Therefore it is necessary to add an ActionListener to the component and tell it to refresh the buttons upon selection:

public class Panel2 extends WizardPanel implements ActionListener {
  // ...
 
  public Panel2() {
    // ...
 
    // Refresh buttons upon selecting / deselecting this checkbox
    box2.addActionListener(this);
    box2.setActionCommand("box1");
 
    // ...
  }
 
  public void actionPerformed(ActionEvent e) {
    refreshButtons();
  }
}

If the second radio button is selected, a confirmation box will be opened upon clicking Next. This can be done via verification of the data input. To use this method, all data must be made available to the toolkit. Every information that needs to be stored must be added to a Property object. This data is gathered by the toolkit.

  protected Properties getProperties() {
    Properties properties = new Properties();
 
    properties.setProperty("box1", String.valueOf(box1.isSelected()));
    properties.setProperty("box2", String.valueOf(box2.isSelected()));
    properties.setProperty("rbutton1", String
        .valueOf(rbutton1.isSelected()));
    properties.setProperty("rbutton2", String
        .valueOf(rbutton2.isSelected()));
    properties.setProperty("textfield", textField.getText());
 
    return properties;
  }
 
  protected boolean verifyChanges(Properties properties) {
    if (Boolean.parseBoolean(properties.getProperty("rbutton2"))) {
      return JOptionPane
          .showConfirmDialog(
              this,
              "Are you sure you want to continue with radio button 2 selected?",
              "Please confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
    }
 
    return ALLOW;
  }

Every WizardPanel which gathers information must provide the getProperties method to store its data. Every WizardPanel that needs verification must provide the verifyChanges method. This method either returns ALLOW (true) or DENY (false). If DENY is returned, the toolkit will do nothing upon selecting Next or Finish. Note: The properties given as parameter here are not only the properties of this WizardPanel but the properties of all Panels. This way, data can be verified over multiple steps.

Second Dialog of the Wizard

Second Dialog of the Wizard

Confirmation before Advancing to the next Step

Confirmation before Advancing to the next Step

The finish dialog

On the last dialog we want to display all information entered by the user so far. Therefore we cannot use the constructor for initializing the components, as we do not know what the user has entered previously. Even worse, the user may use the back button and change the data. So we need a way to update all components upon displaying the WizardPanel. This is done via setComponents, which is called upon every display of the WizardPanel and is provided all properties so far:

public class Panel3 extends WizardPanel {
  public Panel3() {
    super("Finish");
 
    setLayout(new GridBagLayout());
  }
 
  protected void setComponents(Properties properties) {
    removeAll();
 
    GridBagConstraints gc = new GridBagConstraints();
 
    gc.gridx = gc.gridy = 0;
    add(new JLabel("All required information have been entered."), gc);
 
    gc.gridy++;
    add(new JLabel(" "), gc);
 
    gc.anchor = GridBagConstraints.NORTHWEST;
    gc.gridy++;
    add(new JLabel("Boxes selected:"), gc);
 
    if (Boolean.valueOf(properties.getProperty("box1"))) {
      gc.gridy++;
      add(new JLabel("Checkbox 1"), gc);
    }
 
    if (Boolean.valueOf(properties.getProperty("box2"))) {
      gc.gridy++;
      add(new JLabel("Checkbox 2"), gc);
    }
 
    if (Boolean.valueOf(properties.getProperty("rbutton1"))) {
      gc.gridy++;
      add(new JLabel("Radio button 1"), gc);
    }
 
    if (Boolean.valueOf(properties.getProperty("rbutton2"))) {
      gc.gridy++;
      add(new JLabel("Radio button 2"), gc);
    }
 
    gc.gridy++;
    add(new JLabel(" "), gc);
 
    gc.gridy++;
    add(new JLabel("Text entered: "), gc);
 
    gc.gridy++;
    add(new JLabel(properties.getProperty("textfield")), gc);
  }
}

Final Dialog of the Wizard, showing Summary

Final Dialog of the Wizard, showing Summary

Conclusion

With this step, all implementation for the example is finished, showing all possibilities this framework provides. You may verify data on the fly or after selecting buttons and override the button behaviour. The toolkit lets you specify custom behaviour when necessary and provides standard control flow when applicable, supporting a very easy and structured way to implement Wizards.

Source code (SVN)

Sorry, this outdated information, if you need the source code, download it from the section below.

This software is developed as open source under the general public licence. You may freely use or modify this software in terms specified by the GPL. The source code is accessible via Subversion with the repository lying at:

feanorscurse.dyndns.org/home/svn/toolkit

Please inform me before publishing any code changes.

Download

The current stable version is 0.2. You may download the toolkit as jar-files or access the source. If you are planning to use this toolkit, it would be nice to leave a comment 🙂 .

Wizard Toolkit v0.2

Wizard Toolkit v0.2 with example application

Categories: English, Linux & Programming Tags: ,
  1. January 24th, 2020 at 19:58 | #1

    I was just seeking this information for a while. After 6 hours of continuous Googleing, at last I got it in your web site. I wonder what’s the lack of Google strategy that don’t rank this type of informative web sites in top of the list. Generally the top sites are full of garbage. viagra without a doctor prescription

  2. January 24th, 2020 at 20:46 | #2

    Hi it’s me, I am also visiting this web page
    daily, this web site is genuinely nice and the users are really sharing fastidious thoughts.

  3. Herbertwrida
    January 24th, 2020 at 21:58 | #3

    Love the site– extremely individual pleasant and whole lots to see! http://machinalansu.pl/zmarszczki-pod-oczami/

  4. January 24th, 2020 at 23:18 | #4

    I precisely had to say thanks again. I do not know the things that I could possibly have worked on in the absence of those advice shown by you directly on my problem. Completely was a difficult condition in my position, but seeing a professional strategy you resolved it made me to weep with happiness. I am thankful for the information and as well , have high hopes you really know what a great job you’re undertaking teaching people today through the use of your webblog. Probably you haven’t encountered any of us.. cbd oil

  5. January 24th, 2020 at 23:59 | #5
  6. StacyRoots
    January 25th, 2020 at 00:54 | #6

    Definitely wanted to accent I’m valid ecstatic that i came in your site! grĂĽntee entgiftung

  7. StacyRoots
    January 25th, 2020 at 04:42 | #7

    Great website! It looks extremely first-rate! Say the excellent fit in! voedingsschema opstellen spiermassa

  8. StacyRoots
    January 25th, 2020 at 12:09 | #8

    Provide for up the outstanding appointment !! Lovin’ it! saponata per muscoli

  9. StacyRoots
    January 25th, 2020 at 23:19 | #9

    Hi-ya, cool webpage you’ve got at this metre there. plat pour musculation

  10. Wayneved
    January 26th, 2020 at 03:24 | #10

    I friendship checking your website. Thanks be given to you so much! http://nl.t-booster2020.com/oorzaken-laag-testosteron/

  11. Wayneved
    January 26th, 2020 at 07:07 | #11

    Thanks in the service of furnishing such fine subject quantity.
    http://zwickausuche.de/penisbander/

  12. Wayneved
    January 26th, 2020 at 10:47 | #12
  13. WayneSpign
    January 26th, 2020 at 13:17 | #13

    Cialis cialis dosages generic cialis tadalafil

  14. Wayneved
    January 26th, 2020 at 14:30 | #14

    How are you, cold-blooded internet site you’ve gotten dyed in the wool at once. supplĂ©mentation testostĂ©rone

  15. Wayneved
    January 26th, 2020 at 18:15 | #15

    Wow, nifty site. Thnx … quelle charge pour musculation

  16. Wayneved
    January 26th, 2020 at 23:18 | #16

    Even-handed lack to speak I am thrilled that i happened on the website! penile implant before and after pics erect

  17. Wayneved
    January 27th, 2020 at 03:26 | #17

    Thanks on the subject of supplying like totally good written felicity.
    http://publica-pr.de/erogan-pillole/

  18. January 27th, 2020 at 06:13 | #18

    I’m extremely impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it’s rare to see a nice blog like this one today.. cheap viagra

  19. Wayneved
    January 27th, 2020 at 07:47 | #19

    Great internet website! It looks exceptionally gifted! Keep in repair the critical mission! rimedi naturali contro l impotenza maschile

  20. Wayneved
    January 27th, 2020 at 12:05 | #20

    Withstand the fearful burden !! Lovin’ it! flebo per disintossicazione

  21. Wayneved
    January 27th, 2020 at 16:20 | #21

    Fondness the website– very individual open and extensive deals to take in! detox smoothie

  22. Wayneved
    January 27th, 2020 at 20:41 | #22

    Keep up the notable burden !! Lovin’ it!

  23. January 28th, 2020 at 00:26 | #23

    I precisely needed to appreciate you once more. I am not sure what I would have handled in the absence of the recommendations shown by you directly on this theme. It was actually a real distressing scenario in my view, but considering a specialised fashion you handled that took me to weep over contentment. Now i’m grateful for your assistance and expect you know what an amazing job you happen to be providing instructing most people by way of a site. Most likely you haven’t met any of us.. viagra walgreens

  24. Wayneved
    January 28th, 2020 at 02:47 | #24

    Surprisingly peculiar demonstrative website. Voluminous info offered on couple of clicks. dieta disintossicante per perdere peso

  25. Wayneved
    January 28th, 2020 at 07:08 | #25

    Your stuff is utter serviceable. jamon masa muscular

  26. Wayneved
    January 28th, 2020 at 11:29 | #26

    Many thanks, this site is danged useful. el cuerpo del deseo youtube

  27. Wayneved
    January 28th, 2020 at 15:52 | #27

    Self-controlled subject-matter you acquire there. http://nl.musclemass.space/eiwitten-voor-spieropbouw/

  28. Wayneved
    January 28th, 2020 at 20:13 | #28

    Thank you so much! This is positively an superb online area! peni piu piccoli

  29. WayneSpign
    January 28th, 2020 at 21:20 | #29

    Cialis daily use of cialis 30 day cialis trial offer

  30. Wayneved
    January 29th, 2020 at 00:37 | #30

    Fully desired to stress I’m opportune that i happened onto your internet announce! liver detoxification pathways

  31. Wayneved
    January 29th, 2020 at 05:01 | #31

    I from reading your snare locale. Thanks! http://fr.musclemass.space/fruit-et-legume-pour-musculation/

  32. January 29th, 2020 at 05:05 | #32

    I am really enjoying the theme/design of your weblog. Do you ever run into any web browser compatibility problems? A number of my blog audience have complained about my site not working correctly in Explorer but looks great in Chrome. Do you have any recommendations to help fix this issue? generic viagra 100mg

  33. Wayneved
    January 29th, 2020 at 09:29 | #33

    Your gluttonize is measure salutary. mejores suplementos para el gym

  34. Wayneved
    January 29th, 2020 at 13:54 | #34

    Many thanks! This a bizarre web after. http://zwickausuche.de/pennisvergroserung/

  35. Wayneved
    January 29th, 2020 at 18:23 | #35

    Through you so much for sharing this justly send down together webpage. http://nnet.it/i-peni-piu-lunghi/

Comment pages
  1. No trackbacks yet.

*