[qdwizard] 03/08: Imported Upstream version 5.0.1
Felix Natter
fnatter-guest at moszumanska.debian.org
Sun Mar 6 09:04:50 UTC 2016
This is an automated email from the git hooks/post-receive script.
fnatter-guest pushed a commit to branch master
in repository qdwizard.
commit fdeeffe793230adb1dadd7b418fc3cdf6705383a
Author: Felix Natter <fnatter at gmx.net>
Date: Sun Mar 6 09:54:59 2016 +0100
Imported Upstream version 5.0.1
---
.classpath | 8 +
.gitignore | 8 +
.project | 17 +
README.md | 194 ++++++++
lgpl-2.1.txt | 502 ++++++++++++++++++++
pom.xml | 120 +++++
qdwizard.jpeg | Bin 0 -> 59456 bytes
src/main/java/org/qdwizard/ActionsPanel.java | 190 ++++++++
src/main/java/org/qdwizard/ClearPoint.java | 34 ++
src/main/java/org/qdwizard/Header.java | 118 +++++
src/main/java/org/qdwizard/Langpack.java | 117 +++++
src/main/java/org/qdwizard/Screen.java | 258 ++++++++++
src/main/java/org/qdwizard/ScreenState.java | 157 ++++++
src/main/java/org/qdwizard/Utils.java | 58 +++
src/main/java/org/qdwizard/Wizard.java | 681 +++++++++++++++++++++++++++
src/test/java/org/qdwizard/LangpackTest.java | 54 +++
16 files changed, 2516 insertions(+)
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..49a9848
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1e709af
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+*.class
+
+# Package Files #
+*.jar
+*.war
+*.ear
+target
+/bin
diff --git a/.project b/.project
new file mode 100644
index 0000000..579d012
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>qdwizard</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7e26529
--- /dev/null
+++ b/README.md
@@ -0,0 +1,194 @@
+# QDWizard
+**_Why should it be more complicated ?_**
+* QDWizard is a dead simple API for creating Swing wizards with a learning curve of less than 15 minutes.
+* It is released under the [LGPL V2.1](http://www.gnu.org/licenses/lgpl-2.1.html) license
+* This library follows [semantic versioning scheme](http://semver.org/) from version 4.0.0
+
+
+
+# Download
+* Zipped source, javadoc and jar are available from the [Maven central repository](http://search.maven.org/#search|ga|1|a%3A%22qdwizard%22)
+
+# Features
+* Designed to minimize required code. Only few methods to implement.
+* Simple design, only two classes visible to the programmer.
+* None dependency.
+* Maven powered : QDWizard is available from Maven central repository as artifact (net.sf.qdwizard:qdwizard).
+* I18n support for action buttons.
+> see [this class](https://github.com/bflorat/qdwizard/blob/master/src/main/java/org/qdwizard/Langpack.java) to get the list of natively supported languages. It is still possible to add manually your own langpack.
+* Full branching support, can implement any wizard navigation.
+* Error management using the simple setProblem() method.
+* Supports Wizard images natively and resizes image automatically.
+* Ultra light API: only few KB.
+* Actively supported by the Jajuk team.
+* Learning curve of 15 minutes maximum.
+* Real world samples provided, see [jajuk classes](https://github.com/jajuk-team/jajuk/blob/master/jajuk/src/main/java/org/jajuk/ui/wizard/digital_dj/DigitalDJWizard.java).
+
+#Requirements
+* To use QDWizard, just add the qdwizard-[release].jar to your CLASSPATH
+* JRE 1.5 and above.
+
+#Manual
+## Concepts
+* A wizard is build of several screens.
+ * The wizard provides the screens cinematic (by setting the screen that's after or before each screen) and the code to be run at the end of the wizard (through `finish()` method).
+ * The screens contains the GUI code and the business logic (can we go next ? for instance).
+* Previous and next screens decision is taken by the wizard class.
+* Wizard data is stored in a map named 'data'. It is accessible from Wizard and Screen class. Store and get options selected by the user here.
+
+### Wizard creation
+* Create a class that extends Wizard. You'll have to implement `getPreviousScreen()`, `getNextScreen()` and `finish()` abstract methods.
+* Instantiate the wizard using its fluent builder (only the constructor arguments of the Builder class are mandatory, all the others methods like `icon()` are optional):
+````java
+MyWizard wizard = new Wizard(new Wizard.Builder("wizard name", ActionSelectionPanel.class,window)
+ .hSize(600).vSize(500).locale(LocaleManager.getLocale()).icon(anIcon)
+ .headerBackgroundImage(backgroundImage).leftSideImage(leftSideImage));
+````
+* The builder arguments are :
+ * [mandatory] The wizard name displayed as title of the dialog
+ * [mandatory] The initial screen class
+ * [mandatory] The parent window
+ * `hSize()` method set the horizontal size (in pixels). Default is 700.
+ * `vSize()` method set the vertical size (in pixels). Default is 500.
+ * `locale()` method set the locale to use. If provided locale is not supported, English is used.
+ * `icon()` method set the header left-side icon
+ * `headerBackgroundImage()` adds an auto-resized image as header's background
+ * `leftSideImage()` adds an image to be displayed as a left side panel. This image is automatically extended to fit all the available space. To avoid letting users to see this image being resized at first display, make sure to create an image than has the right dimension out of the box.
+* `finish()` method implements the actions to be done at the end of the wizard.
+* `getPreviousScreen()` and `getNextScreen()` have to return previous or next screen class :
+
+````java
+public Class getNextScreen(Class screen) {
+ if (ActionSelectionPanel.class.equals(getCurrentScreen())){
+ if (...){
+ return TypeSelectionPanel.class;
+ }
+ else {
+ return RemovePanel.class;
+ }
+ }
+}
+````
+* `show()` displays the wizard.
+
+### Screen creation
+* For each wizard page, create a public Screen class. You have to implement `initUI()`, `getDescription()` and `getName()` abstract methods.
+* `getName()` method should return the step name and getDescription() the step description (return `null` if none description required).
+* `initUI()` method contains graphical code for your screen. This method is automatically called from screen constructor, don't call it by yourself.
+
+### Data sharing between screens and wizard
+Get and set wizard data using the `data` map available from wizard and screen classes. This is a `HashMap<Object,Object>` so you can use anything as a key or a value.
+A good practice is to create an enum in the Wizard class and use to enum entry as key for the data map :
+````java
+public Class MyWizard extends Wizard {
+ enum Variable {VARIABLE_1,VARIABLE_2}
+ ...
+ void someMethod(){
+ data.put(Variable.VARIABLE1,"a String");
+ }
+}
+
+public Class MyScreen extends Screen {
+ void someMethod(){
+ String var1 = data.get(Variable.VARIABLE_1);
+ }
+}
+````
+## General use
+* It is a good practice to create wizards and their associated screens in the same package. It's also better to implement screens in different java files.
+* Set errors using the `setProblem(String)` method. The error will be displayed in red at the bottom of the screen. When error is fixed, use a `setProblem(null)` to remove it.
+* Use `setCanFinish(true)` method in a screen to state the fact that this screen is the last one (user can click on Finish button).
+
+##Advanced topics
+* The Screen class contains two empty methods `onEnter()` and `onLeave()` which are called by the wizard respectively on entering and before leaving the screen. You can override them to add specific behaviors. Note that this happens only in forward mode, which means that `onEnter()` won't be called when you return to a screen via the previous button and that `onLeave()` won't be called when you leave the screen via the previous button.
+* By default, QDwizard keeps the screens (and its widgets models) into memory so user can go previous or next and keep typed values. If you want to clear this cache, use the `ClearPoint` annotation against your screen(s) classes. When user reaches a screen that use this annotation, the screens cache is cleaned up and the screens `initUI()` is called.
+* By default, the Cancel button just close the wizard window. You can implement a `Wizard.onCancel()` method which will be called when the user presses the Cancel button. This method should should return true to close the window or false if you want to keep it opened.
+* You can come with you own langpack if it is not provided natively by QDWizard or you can override an existing langpack using the `Langpack.addLocale()` method.
+* [from 4.2.0] You can call the `Screen.setCanGoNext(boolean)`, `Screen.setCanGoPrevious(boolean)`,`Screen.setCanCancel(boolean)` and `Screen.setCanFinish(boolean)` from your screen class as a way to force disabling of "Previous","Next", "Cancel" or "Finish" buttons on certain events.
+* [from 4.2.0] You can call the `Wizard.forceNextScreen()`, `Wizard.forcePreviousScreen()`, `Wizard.forceCancel()` and `Wizard.forceFinish()` to force programmatically the screen actions (without actual user clicking on the buttons). Beware that this action still follows the state of the screen (canGoNext, canGoPrev, canCancel, canFinish) and will have no effect if this condition is not fulfilled. The same methods are available from the `Screen` classes.
+
+##Samples
+Have a look at [the Jajuk DJ wizard](https://github.com/jajuk-team/jajuk/blob/master/jajuk/src/main/java/org/jajuk/ui/wizard/digital_dj/DigitalDJWizard.java)
+
+##Javadoc
+Check http://bflorat.github.io/qdwizard/apidocs/
+
+# History
+* 2016/03/05: [5.0.1] (some methods removed)
+ * Fixed license in source (LGPL, not GPL) + added a LGPL license notice along with the sources
+* 2015/04/10: [5.0.0] (some methods removed)
+ * Several bugfixes, check https://github.com/bflorat/qdwizard/issues
+ * Added programmatical actions on wizards and screens like `forceNextScreen()` (thx Boformer)
+ * `setCanGoNext()` and `setCanGoPrevious()` methods are now public and be overriden in screens (thx Boformer)
+ * `Screen.onCancelled()` and `Screen.onFinished()` methods removed (should use `Wizard.onCancel()` and `Wizard.finish()` instead))
+ * `Screen.onNext()` method has been replaced by the `onLeave()` method.
+* 2014/03/28: [4.1.0] (backward compatible)
+ * It is now possible to add or override a langpack using the `Langpack.addLocale()` method
+* 2014/03/28: [4.0.0] (backward compatibility slightly broken at runtime only)
+ * The Wizard.setScreen() method now throws an `IllegalArgumentException` if provided screen is wrong or not accessible
+ * javadoc augmentation and fixes
+ * Version update due to semantic versioning compliance from this version
+* 2014/03/28: [3.1.2] (backward compatible)
+ * data is now a `HashMap<Object,Object>`, no more a `HashMap<String,Object>` to allow using enums as data entries
+ * Code and javadoc cleanup
+* 2014/03/25: [3.1.1] (backward compatible)
+ * Fixes a regression on the clearpoint annotation that has been broken in 3.1
+ * 2014/03/25: [3.1] (backward compatibility slightly broken)
+ * `ClearPoint` interface is now an annotation
+* 2013/07/14: [3.0] (backward compatibility broken)
+ * Builder pattern to build a wizard to make the instantiation much easier and cleaner
+ * Moved the project to GitHub
+ * Code cleanup
+* 2009/02/22: [2.1] Enhancements and fixes
+ * Fixed an issue preventing right previous/next buttons state display
+ * Added a `setHeaderIcon()` method that allow to display an icon at the right upper side of the header
+ * Code cleanup
+ * Removed deprecated methods `Wizard.cancel()` and `Screen.onLeave()` methods
+ * Fixed painting issues with some look and feels (like substance)
+* 2008/03/26: [2.0.4] Cleanup
+ * Code spelling and formatting
+ * Fixed a potential flaw in `ScreenStatus` class
+* 2008/03/18: [2.0.3] Enhancements
+ * Added Galician support
+* 2007/12/22: [2.0.2] Fixes
+ * Fixed ant script that depends on my own path
+ * Added Russian support
+* 2007/12/21: [2.0.1] Fixes
+ * Fixed broken compatibility with previous Wizard constructors to ensure upward compatibility
+ * Improved javadoc documentation, especially in classes headers
+ * Code cleanup
+* 2007/12/20: [2.0] Enhancements
+ * QDWizard as maven project
+ * New project website
+ * More stack traces for debug
+* 2007/01/02: [1.9] Fixes
+ * Timer should be stopped when pressing finish or cancel
+ * Code cleanup
+* 2006/09/04: [1.7] Fixes and enhancements
+ * Zip Packaging fix (extract to a qdwizard directory)
+ * Header thinner
+ * Wizard is now displayed using an external `show()` call
+* 2006/08/09: [1.6] Enhancements
+ * i18n with property resource bundles
+ * New notification methods `onEnter()` and `onLeave()` in Screen class
+* 2006/07/24: [1.5] Enhancements
+ * Wizards are now fully resizable (including left-side picture)
+ * No more dependencies to TableLayout
+* 2006/07/08: [1.4] Fixes and enhancements
+ * German langpack fixes
+ * Renamed WizardCleaner interface to `ClearPoint`
+ * Added arrows in Next and Previous buttons
+ * QDWizard project is now fully autonomous from Jajuk
+* 2006/06/22: [1.3] Fixes and enhancements
+ * Keep screens memory
+ * Added WizardClearer stuff to reset screens history
+* 2006/05/22: [1.2] Fixes and enhancements
+ * Screens are no more cached to allow user value changes
+ * Locale can now be set explicitly (no more uses only the default locale)
+ * Doc screenshot fix
+* 2006/05/19: [1.1] Fixes
+ * [FATAL] Fixed wrong jajuk Main class dependency
+ * Fixed wizard size issue if screen too small
+ * Do not display 'null' if screen description is not provided
+ * Fixed documentation and javadoc
+* 2006/05/14: [1.0] Initial release
diff --git a/lgpl-2.1.txt b/lgpl-2.1.txt
new file mode 100644
index 0000000..4362b49
--- /dev/null
+++ b/lgpl-2.1.txt
@@ -0,0 +1,502 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..7ae47e1
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>net.sf.qdwizard</groupId>
+ <artifactId>qdwizard</artifactId>
+ <name>QDWizard</name>
+ <packaging>jar</packaging>
+ <version>5.0.1</version>
+ <url>http://github.com/bflorat/qdwizard</url>
+ <licenses>
+ <license>
+ <name>GNU Lesser General Public License, version 2.1</name>
+ <url>http://www.gnu.org/licenses/lgpl-2.1.html</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <description>QDWizard is a dead simple API for creating Swing wizards</description>
+ <developers>
+ <developer>
+ <id>bflorat</id>
+ <name>Bertrand Florat</name>
+ <roles>
+ <role>Project Manager</role>
+ <role>Developer</role>
+ </roles>
+ <timezone>+2</timezone>
+ </developer>
+ <developer>
+ <id>maiapopa</id>
+ <name>Ana Oleski</name>
+ <roles>
+ <role>Project Manager</role>
+ <role>Developer</role>
+ </roles>
+ <timezone>+2</timezone>
+ </developer>
+ <developer>
+ <id>jonks</id>
+ <name>Jonks</name>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ </developers>
+ <scm>
+ <connection>scm:git:git://github.com/bflorat/qdwizard.git</connection>
+ <developerConnection>scm:git:git at github.com:bflorat/qdwizard.git</developerConnection>
+ <url>http://github.com/bflorat/qdwizard</url>
+ </scm>
+ <properties>
+ <github.global.server>github</github.global.server>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.5</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.3</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.github.github</groupId>
+ <artifactId>site-maven-plugin</artifactId>
+ <version>0.11</version>
+ <configuration>
+ <message>Creating site for ${project.version}</message>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>site</goal>
+ </goals>
+ <phase>site</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.10.3</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <sourceEncoding>utf-8</sourceEncoding>
+ <targetJdk>1.5</targetJdk>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>taglist-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/qdwizard.jpeg b/qdwizard.jpeg
new file mode 100644
index 0000000..a17a4b3
Binary files /dev/null and b/qdwizard.jpeg differ
diff --git a/src/main/java/org/qdwizard/ActionsPanel.java b/src/main/java/org/qdwizard/ActionsPanel.java
new file mode 100644
index 0000000..96ea508
--- /dev/null
+++ b/src/main/java/org/qdwizard/ActionsPanel.java
@@ -0,0 +1,190 @@
+/*
+ * QDWizard
+ * Copyright (C) Bertrand Florat and others
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.qdwizard;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.GridLayout;
+import java.awt.RenderingHints;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRootPane;
+import javax.swing.SwingConstants;
+
+/**
+ * Action panel
+ * <p>
+ * Contains a message area where problems are displayed and a buttons area
+ * (Previous, Next, Finish, Cancel).
+ * </p>
+ */
+class ActionsPanel extends JPanel {
+ private static final long serialVersionUID = 1L;
+ /** Problem text area. */
+ private JLabel jlProblem;
+ private JButton jbPrevious;
+ private JButton jbNext;
+ private JButton jbFinish;
+ private JButton jbCancel;
+ private Color backgroundColor;
+ private Color backgroundColorProblem;
+
+ /**
+ * The Constructor.
+ *
+ * @param al
+ * associated action listener
+ */
+ public ActionsPanel(ActionListener al) {
+ backgroundColor = Color.WHITE;
+ backgroundColorProblem = Color.WHITE;
+ // Problem panel
+ jlProblem = new JLabel();
+ jlProblem.setForeground(Color.RED);
+ jlProblem.setFont(new Font("Dialog", Font.BOLD, 12));
+ jlProblem.setHorizontalAlignment(SwingConstants.CENTER);
+ // Action buttons
+ JPanel jpButtons = new JPanel();
+ jpButtons.setLayout(new BoxLayout(jpButtons, BoxLayout.X_AXIS));
+ Dimension dimButtons = new Dimension(150, 20);
+ jbPrevious = new JButton("< " + Langpack.getMessage("Previous"));
+ jbPrevious.setPreferredSize(dimButtons);
+ jbPrevious.addActionListener(al);
+ jbPrevious.setActionCommand("Prev");
+ jbNext = new JButton(Langpack.getMessage("Next") + " >");
+ jbNext.addActionListener(al);
+ jbNext.setActionCommand("Next");
+ jbNext.setPreferredSize(dimButtons);
+ jbFinish = new JButton(Langpack.getMessage("Finish"));
+ jbFinish.addActionListener(al);
+ jbFinish.setActionCommand("Finish");
+ jbFinish.setPreferredSize(dimButtons);
+ jbCancel = new JButton(Langpack.getMessage("Cancel"));
+ jbCancel.addActionListener(al);
+ jbCancel.setActionCommand("Cancel");
+ jbCancel.setPreferredSize(dimButtons);
+ jpButtons.add(Box.createHorizontalStrut(10));
+ jpButtons.add(Box.createHorizontalGlue());
+ jpButtons.add(jbPrevious);
+ jpButtons.add(Box.createHorizontalStrut(5));
+ jpButtons.add(jbNext);
+ jpButtons.add(Box.createHorizontalStrut(10));
+ jpButtons.add(jbFinish);
+ jpButtons.add(Box.createHorizontalStrut(20));
+ jpButtons.add(jbCancel);
+ jpButtons.add(Box.createHorizontalStrut(10));
+ jpButtons.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
+ jpButtons.setOpaque(false);
+ jlProblem.setOpaque(false);
+ setOpaque(false);
+ // Main panel
+ setLayout(new GridLayout(2, 1));
+ add(jlProblem);
+ add(jpButtons);
+ }
+
+ /**
+ * Set buttons states.
+ *
+ * @param bPrevious
+ * @param bNext
+ * @param bFinish
+ * @param bCancel
+ */
+ void setState(boolean bPrevious, boolean bNext, boolean bFinish, boolean bCancel) {
+ jbPrevious.setEnabled(bPrevious);
+ jbFinish.setEnabled(bFinish);
+ jbNext.setEnabled(bNext);
+ jbCancel.setEnabled(bCancel);
+ }
+
+ /**
+ * Sets the problem.
+ *
+ * @param problem
+ * the new problem
+ */
+ void setProblem(String problem) {
+ String sProblem = problem;
+ jlProblem.setText(sProblem);
+ }
+
+ /**
+ * Set the background color of the ActionPanel.
+ *
+ * @param color
+ */
+ public void setBackgroundColor(Color color) {
+ this.backgroundColor = color;
+ }
+
+ /**
+ * Set the background color of the ActionPanel Problem notification area.
+ *
+ * @param color
+ */
+ public void setProblemBackgroundColor(Color color) {
+ this.backgroundColorProblem = color;
+ }
+
+ /**
+ * Set the "next" button as default button
+ *
+ * @param rootPane
+ * the wizard root pane
+ */
+ public void setNextAsDefaultButtonInPanel(JRootPane rootPane) {
+ rootPane.setDefaultButton(jbNext);
+ }
+
+ /**
+ * Set the background color of the ActionPanel Problem notification area.
+ *
+ * @param color
+ */
+ public void setProblemTextColor(Color color) {
+ jlProblem.setForeground(color);
+ }
+
+ @Override
+ public void paint(java.awt.Graphics g) {
+ Graphics2D g2D = (Graphics2D) g;
+ g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ java.awt.Rectangle rect = getBounds();
+ g2D.setColor(backgroundColor);
+ g2D.fillRect(0, 0, rect.width, rect.height);
+ if (jlProblem != null && jlProblem.getText() != null && jlProblem.getText().length() > 0) {
+ rect = jlProblem.getBounds();
+ g2D.setColor(backgroundColorProblem);
+ g2D.fillRect(rect.x, rect.y, rect.width, rect.height);
+ }
+ super.paint(g);
+ g2D.setColor(Color.LIGHT_GRAY);
+ g2D.drawLine(rect.x, 0, rect.width, 0);
+ }
+}
diff --git a/src/main/java/org/qdwizard/ClearPoint.java b/src/main/java/org/qdwizard/ClearPoint.java
new file mode 100644
index 0000000..2182112
--- /dev/null
+++ b/src/main/java/org/qdwizard/ClearPoint.java
@@ -0,0 +1,34 @@
+/*
+ * QDWizard
+ * Copyright (C) Bertrand Florat and others
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.qdwizard;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Screens needing to clear wizard cache (values filled up in different screens)
+ * should use this annotation.
+ */
+ at Target(ElementType.TYPE)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ClearPoint {
+}
diff --git a/src/main/java/org/qdwizard/Header.java b/src/main/java/org/qdwizard/Header.java
new file mode 100644
index 0000000..54a03e7
--- /dev/null
+++ b/src/main/java/org/qdwizard/Header.java
@@ -0,0 +1,118 @@
+/*
+ * QDWizard
+ * Copyright (C) Bertrand Florat and others
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.qdwizard;
+
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.GridLayout;
+import java.awt.Image;
+import java.awt.RenderingHints;
+
+import javax.swing.ImageIcon;
+import javax.swing.JPanel;
+
+/**
+ * Screen Header
+ * <p>
+ * Contains a wizard title, a subtitle used to display the name of the current
+ * screen and an optional background image
+ * </p>.
+ */
+ at SuppressWarnings("serial")
+class Header extends JPanel {
+ private JPanel panel;
+ private Image backgroundImage;
+ private ImageIcon icon;
+ private String title;
+ private String subtitle;
+
+ /**
+ * Build a header
+ */
+ public Header() {
+ setLayout(new GridLayout());
+ panel = new JPanel();
+ panel.setOpaque(true);
+ panel.setPreferredSize(new Dimension(0, 70));
+ add(panel);
+ }
+
+ /**
+ * Set the header Image.
+ *
+ * @param img
+ */
+ public void setBackgroundImage(Image img) {
+ backgroundImage = img;
+ }
+
+ /**
+ * Set the header title. The title is the screen name.
+ *
+ * @param title the title
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ * Set the header subtitle text. It is a text that can be changed at will among screens.
+ *
+ * @param subtitle the subtitle
+ */
+ public void setSubtitle(String subtitle) {
+ this.subtitle = subtitle;
+ }
+
+ /**
+ * Set the header right-side icon.
+ *
+ * @param icon
+ */
+ public void setIcon(ImageIcon icon) {
+ this.icon = icon;
+ }
+
+ @Override
+ public void paint(java.awt.Graphics g) {
+ super.paint(g);
+ Graphics2D g2D = (Graphics2D) g;
+ java.awt.Rectangle rect = getBounds();
+ g2D.setColor(java.awt.Color.WHITE);
+ g2D.fillRect(rect.x, rect.y, rect.width, rect.height);
+ if (backgroundImage != null) {
+ g2D.drawImage(backgroundImage, 0, 0, rect.width, rect.height, this);
+ }
+ if (icon != null) {
+ int h = icon.getIconHeight();
+ int w = icon.getIconWidth();
+ g2D.drawImage(icon.getImage(), rect.width - w - 10, (rect.height - h) / 2, w, h, this);
+ }
+ g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2D.setColor(java.awt.Color.BLACK);
+ g2D.setFont(new Font("Dialog", Font.BOLD, 14));
+ g2D.drawString(title, 20, 25);
+ g2D.setFont(new Font("Dialog", Font.PLAIN, 13));
+ g2D.drawString(subtitle, 20, 50);
+ g2D.setColor(java.awt.Color.BLACK);
+ g2D.drawLine(rect.x, rect.height - 1, rect.width, rect.height - 1);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/qdwizard/Langpack.java b/src/main/java/org/qdwizard/Langpack.java
new file mode 100644
index 0000000..6954431
--- /dev/null
+++ b/src/main/java/org/qdwizard/Langpack.java
@@ -0,0 +1,117 @@
+/*
+ * QDWizard
+ * Copyright (C) Bertrand Florat and others
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.qdwizard;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * This class includes all langpacks strings. Note that we don't use
+ * ResourceBundle here to ease translation tasks (properties doesn't support
+ * non-latin1 characters) and because QDwizard comes with a very low number of
+ * strings
+ */
+public class Langpack {
+ private static List<String> defaults = Arrays.asList("Finish", "Cancel", "Previous", "Next");
+ // Strings content : "Finish", "Cancel", "Previous", "Next"
+ static private Map<Locale, List<String>> strings = new HashMap<Locale, List<String>>(20);
+ /** static set of strings, can contain non-ISO8859 chars * */
+ static {
+ strings.put(new Locale("ca"),
+ Arrays.asList("Finalitzar", "Cancelar", "Anterior", "Següent"));
+ strings.put(new Locale("cs"), Arrays.asList("Dokončit", "Storno", "Předchozí", "Další"));
+ strings.put(new Locale("de"), Arrays.asList("Fertig", "Abbrechen", "Zurück", "Weiter"));
+ strings.put(new Locale("en"), defaults);
+ strings.put(new Locale("es"),
+ Arrays.asList("Finalizar", "Cancelar", "Anterior", "Siguiente"));
+ strings.put(new Locale("el"), Arrays.asList("Τέλος", "Ακύρωση", "Προηγούμενο", "Επόμενο"));
+ strings.put(new Locale("fr"), Arrays.asList("Terminé", "Annuler", "Précédent", "Suivant"));
+ strings.put(new Locale("gl"), Arrays.asList("Rematar", "Cancelar", "Anterior", "Seguinte"));
+ strings.put(new Locale("nl"),
+ Arrays.asList("Afgerond", "Annuleren", "Vooropgaand", "Aanstaande"));
+ strings.put(new Locale("ru"), Arrays.asList("Готово", "Отмена", "Назад", "Дальше"));
+ strings.put(new Locale("pt"), Arrays.asList("Terminar", "Cancelar", "Anterior", "Seguinte"));
+ strings.put(new Locale("zh"), Arrays.asList("完成", "取消", "上一步", "下一步"));
+ }
+ /** Used locale for the wizard buttons, use English as a default *. */
+ private static Locale locale = new Locale("en");
+
+ /**
+ * private constructor for utility class with only static methods.
+ */
+ private Langpack() {
+ super();
+ }
+
+ /**
+ * Set the QDwizard locale.
+ *
+ * @param locale
+ * the locale to set
+ */
+ public static void setLocale(Locale locale) {
+ Langpack.locale = locale;
+ }
+
+ /**
+ * Add a QDwizard locale and associated labels. This can be used as well to
+ * override the langpacks provided with QDWizard.
+ *
+ * @param locale
+ * the locale to add.
+ * @param labels
+ * the labels associated with the locale. It should contain 4
+ * strings translating "Finish", "Cancel", "Previous", "Next".
+ * @throws IllegalArgumentException
+ * if provided locale is null or if labels is null or has the
+ * wrong size.
+ */
+ public static void addLocale(Locale locale, List<String> labels) {
+ if (locale == null || labels == null) {
+ throw new IllegalArgumentException("locale and labels can't be null");
+ }
+ if (labels.size() != defaults.size()) {
+ throw new IllegalArgumentException("Provided labels should have this size : "
+ + defaults.size());
+ }
+ strings.put(locale, labels);
+ }
+
+ /**
+ * Return label for given key or null if not matching key is found.
+ *
+ * @param key
+ * the key as a string using the default locale
+ *
+ * @return label for given key or null if not matching key is found
+ */
+ public static String getMessage(String key) {
+ List<String> labels = strings.get(locale);
+ // If the local is unknown, use default one
+ if (labels == null) {
+ labels = defaults;
+ }
+ int index = defaults.indexOf(key);
+ return labels.get(index);
+ }
+}
diff --git a/src/main/java/org/qdwizard/Screen.java b/src/main/java/org/qdwizard/Screen.java
new file mode 100644
index 0000000..1915f6a
--- /dev/null
+++ b/src/main/java/org/qdwizard/Screen.java
@@ -0,0 +1,258 @@
+/*
+ * QDWizard
+ * Copyright (C) Bertrand Florat and others
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.qdwizard;
+
+import java.util.Map;
+
+import javax.swing.JPanel;
+
+/**
+ * A wizard screen
+ * <ul>
+ * <li>For each wizard page, create a public Screen class. You have to implement
+ * initUI(), getDescription() and getName() abstract mandatory methods.</li>
+ * <li>{@code getName()} method should return the step name and
+ * {@code getDescription()} the step description (can return null if no
+ * description is required).</li>
+ * <li>{@code initUI()} method contains graphical code for your screen. This
+ * method is automatically called from screen constructor, you shouldn't call it
+ * directly.</li>
+ * </ul>
+ */
+public abstract class Screen extends JPanel {
+ /** Generated serialVersionUID. */
+ private static final long serialVersionUID = 1L;
+ /** The state of the screen */
+ private final ScreenState state;
+ /** Data is shared with wizard scope */
+ public Map<Object, Object> data;
+
+ /**
+ * Construct a screen.
+ */
+ public Screen() {
+ state = new ScreenState(true, true, true, false, null);
+ }
+
+ /**
+ * Set the data map from the wizard
+ *
+ * @param data
+ * the data map
+ */
+ void setData(Map<Object, Object> data) {
+ this.data = data;
+ }
+
+ /**
+ * Give here the step name.
+ *
+ * @return screen name
+ */
+ @Override
+ abstract public String getName();
+
+ /**
+ * Give here the screen description (can be null)
+ *
+ * @return screen description
+ */
+ abstract public String getDescription();
+
+ /**
+ * Can finish.
+ *
+ *
+ * @return true if this is the last screen.
+ */
+ boolean canFinish() {
+ // Can finish only if none problem
+ return state.getCanFinish() && state.getProblem() == null;
+ }
+
+ /**
+ * Set whether the finish button should be enabled.
+ *
+ * @param b
+ * set whether we can finish from this screen
+ */
+ protected void setCanFinish(boolean b) {
+ state.setCanFinish(b);
+ notifyGUI();
+ }
+
+ /**
+ * Can go next.
+ *
+ *
+ * @return true if we can go next from this screen
+ */
+ boolean canGoNext() {
+ // if screen is last one, cannot go further
+ return state.getCanGoNext() && !state.getCanFinish() && state.getProblem() == null;
+ }
+
+ /**
+ * Can cancel.
+ *
+ *
+ * @return true if we can cancel from this screen
+ */
+ boolean canCancel() {
+ return state.getCanCancel();
+ }
+
+ /**
+ * Can go previous.
+ *
+ *
+ * @return true if we can go to the previous screen from this screen
+ */
+ boolean canGoPrevious() {
+ return state.getCanGoPrevious();
+ }
+
+ /**
+ * Set whether the next button should be enabled.
+ *
+ * @param b
+ * set whether we can go to the next screen from this screen
+ */
+ protected void setCanGoNext(boolean b) {
+ state.setCanGoNext(b);
+ notifyGUI();
+ }
+
+ /**
+ * Set whether the previous button should be enabled.
+ *
+ * @param b
+ * set whether we can go to the previous screen from this screen
+ */
+ protected void setCanGoPrevious(boolean b) {
+ state.setCanGoPrevious(b);
+ notifyGUI();
+ }
+
+ /**
+ * Set whether the cancel (or System menu close) button should be enabled.
+ *
+ * @param b
+ * set whether we can cancel from this screen
+ */
+ protected void setCanCancel(boolean b) {
+ state.setCanCancel(b);
+ notifyGUI();
+ }
+
+ /**
+ * Set a problem (set to null if problem is fixed).
+ *
+ * @param sProblem
+ * Problem string or null if no more problem
+ */
+ public void setProblem(String sProblem) {
+ state.setProblem(sProblem);
+ notifyGUI();
+ }
+
+ /**
+ * Get current problem if any (or null if none problem)
+ *
+ * @return the current problem
+ */
+ public String getProblem() {
+ return state.getProblem();
+ }
+
+ /**
+ * UI creation.
+ */
+ abstract public void initUI();
+
+ /**
+ * Called by wizard before the screen is displayed. This happens only in
+ * forward mode, which means {@code onEnter()} won't be called when you
+ * return to a screen via the previous button.
+ */
+ public void onEnter() {
+ // Do nothing by default
+ }
+
+ /**
+ * Programmatical switch to the next screen.
+ *
+ */
+ public void forceNextScreen() {
+ synchronized (data) {
+ this.data.put(Utils.RESERVED_DATA.FORCED_NEXT_SCREEN, true);
+ }
+ }
+
+ /**
+ * Programmatical switch to the previous screen.
+ *
+ */
+ public void forcePreviousScreen() {
+ synchronized (data) {
+ this.data.put(Utils.RESERVED_DATA.FORCED_PREV_SCREEN, true);
+ }
+ }
+
+ /**
+ * Programmatical cancel.
+ *
+ */
+ public void forceCancel() {
+ synchronized (data) {
+ this.data.put(Utils.RESERVED_DATA.FORCED_CANCEL, true);
+ }
+ }
+
+ /**
+ * Programmatical finish.
+ *
+ */
+ public void forceFinish() {
+ synchronized (data) {
+ this.data.put(Utils.RESERVED_DATA.FORCED_FINISH, true);
+ }
+ }
+
+ /**
+ * Called by wizard before the screen is left. This happens only in forward
+ * mode, which means {@code onLeave()} won't be called when you leave the
+ * screen via the previous button.
+ *
+ */
+ public void onLeave() {
+ // Does nothing by default
+ }
+
+ /**
+ * Ask for a GUI refresh
+ *
+ */
+ private void notifyGUI() {
+ synchronized (data) {
+ this.data.put(Utils.RESERVED_DATA.UPDATE_GUI, true);
+ }
+ }
+}
diff --git a/src/main/java/org/qdwizard/ScreenState.java b/src/main/java/org/qdwizard/ScreenState.java
new file mode 100644
index 0000000..0f93ac1
--- /dev/null
+++ b/src/main/java/org/qdwizard/ScreenState.java
@@ -0,0 +1,157 @@
+/*
+ * QDWizard
+ * Copyright (C) Bertrand Florat and others
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.qdwizard;
+
+/**
+ * A screen state:
+ * <ul>
+ * <li>can cancel ?</li>
+ * <li>can finish ?</li>
+ * <li>can go next ?</li>
+ * <li>can go previous ?</li>
+ * </ul>.
+ */
+class ScreenState {
+ private boolean bCanFinish;
+ /** Can Go Next. */
+ private boolean bCanGoNext;
+ /** Can Go Previous. */
+ private boolean bCanGoPrevious;
+ /** Can Cancel. */
+ private boolean bCanCancel;
+ /** Problem. */
+ private String sProblem;
+
+ /**
+ * Construct a ScreenState.
+ */
+ public ScreenState() {
+ this(false, false, false, false, null);
+ }
+
+ /**
+ * Construct a ScreenState.
+ *
+ * @param bCanGoNext next button is enabled
+ * @param bCanGoPrevious previous button is enabled
+ * @param bCanCancel cancel button is enabled
+ * @param bCanFinish cancel button is enabled
+ * @param sProblem problem text
+ */
+ public ScreenState(boolean bCanGoNext, boolean bCanGoPrevious, boolean bCanCancel,
+ boolean bCanFinish, String sProblem) {
+ this.bCanGoNext = bCanGoNext;
+ this.bCanGoPrevious = bCanGoPrevious;
+ this.bCanCancel = bCanCancel;
+ this.bCanFinish = bCanFinish;
+ this.sProblem = sProblem;
+ }
+
+ /**
+ * Gets the can finish.
+ *
+ * @return Finish button enabled
+ */
+ public boolean getCanFinish() {
+ return bCanFinish;
+ }
+
+ /**
+ * Set whether the finish button should be enabled.
+ *
+ * @param bCanFinish
+ */
+ public void setCanFinish(boolean bCanFinish) {
+ this.bCanFinish = bCanFinish;
+ }
+
+ /**
+ * Gets the can go next.
+ *
+ * @return Next button enabled
+ */
+ public boolean getCanGoNext() {
+ return bCanGoNext;
+ }
+
+ /**
+ * Set whether the next button should be enabled.
+ *
+ * @param bCanGoNext
+ */
+ public void setCanGoNext(boolean bCanGoNext) {
+ this.bCanGoNext = bCanGoNext;
+ }
+
+ /**
+ * Gets the can go previous.
+ *
+ * @return Previous button enabled
+ */
+ public boolean getCanGoPrevious() {
+ return bCanGoPrevious;
+ }
+
+ /**
+ * Set whether the previous button should be enabled.
+ *
+ * @param bCanGoPrevious
+ */
+ public void setCanGoPrevious(boolean bCanGoPrevious) {
+ this.bCanGoPrevious = bCanGoPrevious;
+ }
+
+ /**
+ * Gets the can cancel.
+ *
+ * @return Cancel button enabled
+ */
+ public boolean getCanCancel() {
+ return bCanCancel;
+ }
+
+ /**
+ * Set whether the cancel (or System menu close) button should be enabled.
+ *
+ * @param bCanCancel
+ */
+ public void setCanCancel(boolean bCanCancel) {
+ this.bCanCancel = bCanCancel;
+ }
+
+ /**
+ * Gets the problem.
+ *
+ * @return Problem button enabled
+ */
+ public String getProblem() {
+ return sProblem;
+ }
+
+ /**
+ * Set a problem (set to null if problem is fixed).
+ *
+ * @param sProblem Problem string or null if no more problem
+ */
+ public void setProblem(String sProblem) {
+ this.sProblem = sProblem;
+ setCanGoNext(sProblem == null);
+ }
+}
diff --git a/src/main/java/org/qdwizard/Utils.java b/src/main/java/org/qdwizard/Utils.java
new file mode 100644
index 0000000..8084953
--- /dev/null
+++ b/src/main/java/org/qdwizard/Utils.java
@@ -0,0 +1,58 @@
+/*
+ * QDWizard
+ * Copyright (C) Bertrand Florat and others
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.qdwizard;
+
+import java.awt.Image;
+
+import javax.swing.ImageIcon;
+
+/**
+ * Various internal utilities
+ */
+class Utils {
+
+ /** List of reserved data types */
+ enum RESERVED_DATA{
+ /** Request for GUI refresh, maps a boolean*/
+ UPDATE_GUI,
+ /** Request for a programmatical next screen action */
+ FORCED_NEXT_SCREEN,
+ /** Request for a programmatical previous screen action */
+ FORCED_PREV_SCREEN,
+ /** Request for a programmatical cancel action */
+ FORCED_CANCEL,
+ /** Request for a programmatical finish action */
+ FORCED_FINISH,
+
+ }
+
+
+ /**
+ * Image resizes
+ */
+ static ImageIcon getResizedImage(Image img, int iNewWidth, int iNewHeight) {
+ if (img == null) {
+ return null;
+ }
+ ImageIcon iiNew = new ImageIcon();
+ Image scaleImg = img.getScaledInstance(iNewWidth, iNewHeight, Image.SCALE_AREA_AVERAGING);
+ iiNew.setImage(scaleImg);
+ return iiNew;
+ }
+}
diff --git a/src/main/java/org/qdwizard/Wizard.java b/src/main/java/org/qdwizard/Wizard.java
new file mode 100644
index 0000000..fcf2cb0
--- /dev/null
+++ b/src/main/java/org/qdwizard/Wizard.java
@@ -0,0 +1,681 @@
+/*
+ * QDWizard
+ * Copyright (C) Bertrand Florat and others
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+package org.qdwizard;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Frame;
+import java.awt.Image;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.swing.BorderFactory;
+import javax.swing.ImageIcon;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.Timer;
+import javax.swing.WindowConstants;
+
+/**
+ * A Wizard dialog displaying one or more screens
+ * <p>
+ * Create a class that extends Wizard. You have to implement
+ * getPreviousScreen(), getNextScreen() and finish() abstract methods
+ * </p>
+ * Displaying the wizard:
+ *
+ * <pre>
+ * {
+ * @code
+ * MyWizard wizard = new Wizard(new Wizard.Builder("wizard name", ActionSelectionPanel.class,
+ * window).hSize(600).vSize(500).locale(LocaleManager.getLocale()).icon(anIcon));
+ * wizard.show();
+ * }
+ * </pre>
+ *
+ * <p>
+ * {@code finish()} method implements actions to be done at the end of the
+ * wizard
+ * </p>
+ * <p>
+ * {@code getPreviousScreen()} and {@code getNextScreen()} have to return
+ * previous or next screen class. Example:
+ * </p>
+ *
+ * <pre>
+ * {@code
+ * public Class getNextScreen(Class screen) {
+ * if (ActionSelectionPanel.class.equals(getCurrentScreen())) {
+ * String sAction = (String) data.get(KEY_ACTION);
+ * if (ActionSelectionPanel.ACTION_CREATION.equals(sAction)) {
+ * return TypeSelectionPanel.class;
+ * }
+ * else if (ActionSelectionPanel.ACTION_DELETE.equals(sAction)) {
+ * return RemovePanel.class;
+ * }
+ * }
+ * }
+ * }
+ * </pre>
+ *
+ * <p>
+ * Get and set wizard data using the 'data' map available from wizard and screen
+ * classes. This is a {@code HashMap<Object,Object>} so you can use anything as
+ * a key.
+ * </p>
+ * <p>
+ * A good practice is to create an enum in the Wizard class and use to enum
+ * entry as key for the data map :
+ * </p>
+ *
+ * <pre>
+ * {@code
+ * public Class MyWizard extends Wizard {
+ * enum Variable {VARIABLE_1,VARIABLE_2}
+ * ...
+ * void someMethod(){
+ * data.put(Variable.VARIABLE1,"a fine example String");
+ * }
+ * }
+ *
+ * public Class MyScreen extends Screen {
+ * void someMethod(){
+ * String var1 = data.get(Variable.VARIABLE_1);
+ * }
+ * }
+ * }
+ * </pre>
+ *
+ */
+public abstract class Wizard extends WindowAdapter implements ActionListener {
+ private static final String FINISH_ACTION = "Finish";
+ private static final String CANCEL_ACTION = "Cancel";
+ private static final String NEXT_ACTION = "Next";
+ private static final String PREV_ACTION = "Prev";
+ private final String name;
+ private Screen current;
+ private final Class<? extends Screen> initial;
+ /** Wizard data. */
+ protected final Map<Object, Object> data = new HashMap<Object, Object>(10);
+ /** Wizard header. */
+ private Header header;
+ /** Wizard action Panel. */
+ private ActionsPanel actions;
+ /** Wizard dialog. */
+ private JDialog dialog;
+ private final Image leftSideImage;
+ private final Frame parentWindow;
+ private final int horizontalSize;
+ private final int verticalSize;
+ private final Logger logger = Logger.getAnonymousLogger();
+ /** Screens instance repository. */
+ private final Map<Class<? extends Screen>, Screen> hmClassScreens = new HashMap<Class<? extends Screen>, Screen>(
+ 10);
+ /** Default Wizard size. */
+ protected static final int DEFAULT_H_SIZE = 700;
+ /** The Constant DEFAULT_V_SIZE. */
+ protected static final int DEFAULT_V_SIZE = 500;
+ /** Default horizontal padding. */
+ protected static final int DEFAULT_H_LAYOUT_PADDING = 5;
+ /** Default vertical padding. */
+ protected static final int DEFAULT_V_LAYOUT_PADDING = 5;
+ /** Was the Wizard Canceled?. */
+ private boolean bCancelled;
+ private final int layoutHPadding;
+ private final int layoutVPadding;
+ /** Timer delay */
+ private static final int REFRESH_TIMER_INTERVAL_MILLIS = 100;
+
+ /** This timer perform actions required by setting the RESERVED_DATA flags */
+ private Timer refreshGUITimer = new Timer(REFRESH_TIMER_INTERVAL_MILLIS, new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ synchronized (data) {
+ Boolean updateGui = (Boolean) data.get(Utils.RESERVED_DATA.UPDATE_GUI);
+ if (updateGui != null && updateGui) {
+ updateGUIState();
+ data.put(Utils.RESERVED_DATA.UPDATE_GUI, false);
+ // Only one single action at each loop, we return
+ return;
+ }
+ Boolean nextScreen = (Boolean) data.get(Utils.RESERVED_DATA.FORCED_NEXT_SCREEN);
+ if (nextScreen != null && nextScreen) {
+ forceNextScreen();
+ data.put(Utils.RESERVED_DATA.FORCED_NEXT_SCREEN, false);
+ return;
+ }
+ Boolean prevScreen = (Boolean) data.get(Utils.RESERVED_DATA.FORCED_PREV_SCREEN);
+ if (prevScreen != null && prevScreen) {
+ forcePreviousScreen();
+ data.put(Utils.RESERVED_DATA.FORCED_PREV_SCREEN, false);
+ return;
+ }
+ Boolean cancel = (Boolean) data.get(Utils.RESERVED_DATA.FORCED_CANCEL);
+ if (cancel != null && cancel) {
+ forceCancel();
+ data.put(Utils.RESERVED_DATA.FORCED_CANCEL, false);
+ return;
+ }
+ Boolean finish = (Boolean) data.get(Utils.RESERVED_DATA.FORCED_FINISH);
+ if (finish != null && finish) {
+ forceFinish();
+ data.put(Utils.RESERVED_DATA.FORCED_FINISH, false);
+ return;
+ }
+ }
+ }
+ });
+
+ /**
+ * Fluent-API style Wizard Builder
+ */
+ public static class Builder {
+ // Mandatory fields
+ private final String name;
+ /** Initial screen class */
+ private final Class<? extends Screen> initial;
+ /** Parent window. */
+ private final Frame parentWindow;
+ // Optional fields
+ private ImageIcon icon;
+ private Image headerBackgroundImage;
+ private Image leftSideImage;
+ private int horizontalSize = -1;
+ private int verticalSize = -1;
+ private int layoutHPadding = -1;
+ private int layoutVPadding = -1;
+ private Locale locale;
+
+ /**
+ *
+ * @param name
+ * Wizard name displayed in the frame title
+ * @param initial
+ * initial screen to display
+ * @param parentWindow
+ * wizard parent window
+ */
+ public Builder(String name, Class<? extends Screen> initial, Frame parentWindow) {
+ this.name = name;
+ this.initial = initial;
+ this.parentWindow = parentWindow;
+ }
+
+ /**
+ * Set the header left-side icon
+ *
+ * @param icon
+ * header left-side icon
+ * @return the wizard builder
+ */
+ public Builder icon(ImageIcon icon) {
+ this.icon = icon;
+ return this;
+ }
+
+ /**
+ * Set the background image
+ *
+ * @param image
+ * image displayed in the header
+ * @return the wizard builder
+ */
+ public Builder headerBackgroundImage(Image image) {
+ this.headerBackgroundImage = image;
+ return this;
+ }
+
+ /**
+ * Set the left-side image
+ *
+ * @param image
+ * -side image displayed in the wizard body
+ * @return the wizard builder
+ */
+ public Builder leftSideImage(Image image) {
+ this.leftSideImage = image;
+ return this;
+ }
+
+ /**
+ * Set the locale. If provided locale is not supported, English is used.
+ *
+ * @param locale
+ * locale (language) of the wizard
+ * @return the wizard builder
+ */
+ public Builder locale(Locale locale) {
+ this.locale = locale;
+ return this;
+ }
+
+ /**
+ * Set the vertical size
+ *
+ * @param verticalSize
+ * vertical size in pixel of the wizard
+ * @return the wizard builder
+ */
+ public Builder vSize(int verticalSize) {
+ this.verticalSize = verticalSize;
+ return this;
+ }
+
+ /**
+ * Set the horizontal size. Default is 700.
+ *
+ * @param horizontalSize
+ * horizontal size in pixel of the wizard
+ * @return the wizard builder
+ */
+ public Builder hSize(int horizontalSize) {
+ this.horizontalSize = horizontalSize;
+ return this;
+ }
+
+ /**
+ * Set the vertical padding. Default is 500.
+ *
+ * @param layoutVPadding
+ * vertical padding in pixel between header and body
+ * @return the wizard builder
+ */
+ public Builder vPadding(int layoutVPadding) {
+ this.layoutVPadding = layoutVPadding;
+ return this;
+ }
+
+ /**
+ * Set the horizontal padding
+ *
+ * @param layoutHPadding
+ * horizontal padding in pixel between left side image and
+ * body
+ * @return the wizard builder
+ */
+ public Builder hPadding(int layoutHPadding) {
+ this.layoutHPadding = layoutHPadding;
+ return this;
+ }
+ }
+
+ /**
+ * Wizard constructor.
+ *
+ * @param builder
+ * Wizard builder
+ */
+ public Wizard(Builder builder) {
+ bCancelled = false;
+ this.name = builder.name;
+ this.parentWindow = builder.parentWindow;
+ Langpack.setLocale((builder.locale == null) ? Locale.getDefault() : builder.locale);
+ this.header = new Header();
+ header.setIcon(builder.icon);
+ header.setBackgroundImage(builder.headerBackgroundImage);
+ this.layoutHPadding = builder.layoutHPadding >= 0 ? builder.layoutHPadding
+ : DEFAULT_H_LAYOUT_PADDING;
+ this.layoutVPadding = builder.layoutVPadding >= 0 ? builder.layoutVPadding
+ : DEFAULT_V_LAYOUT_PADDING;
+ this.initial = builder.initial;
+ this.leftSideImage = builder.leftSideImage;
+ this.horizontalSize = builder.horizontalSize >= 0 ? builder.horizontalSize : DEFAULT_H_SIZE;
+ this.verticalSize = builder.verticalSize >= 0 ? builder.verticalSize : DEFAULT_V_SIZE;
+ }
+
+ /**
+ * Show the wizard *
+ */
+ public void show() {
+ createDialog();
+ setScreen(initial);
+ current.onEnter();
+ refreshGUITimer.start();
+ dialog.setVisible(true);
+ }
+
+ /**
+ * access to the JDialog of the wizard, in case we need it (for instance to
+ * set a glass pane when waiting).
+ *
+ * @return the wizard dialog
+ */
+ public JDialog getDialog() {
+ return dialog;
+ }
+
+ /**
+ * UI manager.
+ */
+ private void createDialog() {
+ dialog = new JDialog(parentWindow, true);// modal
+ // Set default size
+ dialog.setSize(this.horizontalSize == 0 ? DEFAULT_H_SIZE : horizontalSize,
+ this.verticalSize == 0 ? DEFAULT_V_SIZE : verticalSize);
+ dialog.setTitle(name);
+ actions = new ActionsPanel(this);
+ dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ dialog.addWindowListener(this);
+ dialog.setLocationRelativeTo(parentWindow);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ dialog.setCursor(new Cursor(Cursor.WAIT_CURSOR));
+ try {
+ // Previous required. Note that the previous button is enabled only
+ // if the user can go previous
+ if (PREV_ACTION.equals(ae.getActionCommand())) {
+ setScreen(getPreviousScreen(current.getClass()));
+ } else if (NEXT_ACTION.equals(ae.getActionCommand())) {
+ // only go to next screen if onNext() of current screen
+ // returns true
+ current.onLeave();
+ setScreen(getNextScreen(current.getClass()));
+ current.onEnter();
+ } else if (CANCEL_ACTION.equals(ae.getActionCommand())) {
+ data.clear();
+ bCancelled = true;
+ onCancel();
+ dialog.dispose();
+ } else if (FINISH_ACTION.equals(ae.getActionCommand())) {
+ finish();
+ dialog.dispose();
+ }
+ } finally {
+ dialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ /**
+ * Programmatical switch to the next screen.
+ *
+ * @return true if successful
+ */
+ public boolean forceNextScreen() {
+ Class<? extends Screen> nextScreen = getNextScreen(current.getClass());
+ // We still test if the switch is legal
+ if (nextScreen == null || !current.canGoNext()) {
+ return false;
+ }
+ // regular next
+ actionPerformed(new ActionEvent(this, 0, NEXT_ACTION));
+ return true;
+ }
+
+ /**
+ * Programmatical canceling.
+ *
+ * @return true if successful
+ */
+ public boolean forceCancel() {
+ if (!current.canCancel()) {
+ return false;
+ }
+ // regular cancel
+ actionPerformed(new ActionEvent(this, 0, CANCEL_ACTION));
+ return true;
+ }
+
+ /**
+ * Programmatical finishing.
+ *
+ * @return true if successful
+ */
+ public boolean forceFinish() {
+ if (!current.canFinish()) {
+ return false;
+ }
+ // regular finish
+ actionPerformed(new ActionEvent(this, 0, FINISH_ACTION));
+ return true;
+ }
+
+ /**
+ * Programmatical switch to the previous screen.
+ *
+ * @return true if successful
+ */
+ public boolean forcePreviousScreen() {
+ Class<? extends Screen> previousScreen = getPreviousScreen(current.getClass());
+ // We still test if the switch is legal
+ if (previousScreen == null || !current.canGoPrevious()) {
+ return false;
+ }
+ actionPerformed(new ActionEvent(this, 0, PREV_ACTION));
+ return true;
+ }
+
+ /**
+ * Set the screen to display a class.
+ *
+ * @param screenClass
+ * screen class to set. Note that this class must be public or
+ * you'll get an IllegalArgumentException.
+ * @throw {@link IllegalArgumentException} if the screen class doesn't exist
+ * or is not accessible
+ */
+ private void setScreen(Class<? extends Screen> screenClass) throws IllegalArgumentException {
+ Screen screen = null;
+ // If the class is an clear point, we clean up all previous screens
+ if (screenClass.isAnnotationPresent(ClearPoint.class)) {
+ resetScreens();
+ }
+ // Try to get a screen from buffer or create it if needed
+ if (hmClassScreens.containsKey(screenClass)) {
+ screen = hmClassScreens.get(screenClass);
+ } else {
+ try {
+ screen = screenClass.newInstance();
+ } catch (InstantiationException e) {
+ logger.log(Level.SEVERE, "Cannot instanciate the screen", e);
+ throw new IllegalArgumentException("Cannot instanciate the screen", e);
+ } catch (IllegalAccessException e) {
+ logger.log(Level.SEVERE, "Cannot instanciate the screen", e);
+ throw new IllegalArgumentException("Cannot instanciate the screen", e);
+ }
+ screen.setData(this.data);
+ screen.initUI();
+ hmClassScreens.put(screenClass, screen);
+ }
+ current = screen;
+ current.setCanGoPrevious(getPreviousScreen(screenClass) != null);
+ current.setCanGoNext(getNextScreen(screenClass) != null);
+ String sDesc = screen.getDescription();
+ if (sDesc != null) {
+ header.setTitle(screen.getName());
+ header.setSubtitle(sDesc);
+ } else {
+ header.setTitle(screen.getName());
+ header.setSubtitle("");
+ }
+ refreshGUI();
+ }
+
+ /**
+ * Called at each screen refresh.
+ */
+ private void refreshGUI() {
+ ((JPanel) dialog.getContentPane()).removeAll();
+ dialog.setLayout(new BorderLayout(layoutHPadding, layoutVPadding));
+ if (leftSideImage != null) {
+ final JLabel jlIcon = new JLabel(new ImageIcon(leftSideImage));
+ dialog.add(jlIcon, BorderLayout.WEST);
+ // Add a listener to resize left side image if wizard window is
+ // resized
+ jlIcon.addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ jlIcon.setIcon(Utils.getResizedImage(leftSideImage, jlIcon.getWidth(),
+ jlIcon.getHeight()));
+ jlIcon.setVisible(true);
+ }
+ });
+ }
+ dialog.add(actions, BorderLayout.SOUTH);
+ JScrollPane jsp = new JScrollPane(header);
+ jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+ jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+ jsp.setBorder(BorderFactory.createEmptyBorder());
+ dialog.add(jsp, BorderLayout.NORTH);
+ if (current != null) {
+ dialog.add(current, BorderLayout.CENTER);
+ }
+ actions.setNextAsDefaultButtonInPanel(dialog.getRootPane());
+ ((JPanel) dialog.getContentPane()).revalidate();
+ dialog.getContentPane().repaint();
+ }
+
+ /**
+ * Set the header image.
+ *
+ * @param img
+ * image to set as header
+ */
+ public void setHeaderImage(Image img) {
+ header.setBackgroundImage(img);
+ }
+
+ /**
+ * Set the header icon.
+ *
+ * @param icon
+ * icon to set as header
+ */
+ public void setHeaderIcon(ImageIcon icon) {
+ header.setIcon(icon);
+ }
+
+ /**
+ * Set the background color of the ActionPanel.
+ *
+ * @param color
+ * background color to set
+ */
+ public void setActionsBackgroundColor(Color color) {
+ actions.setBackgroundColor(color);
+ }
+
+ /**
+ * Set the background color of the ActionPanel's Problem notification area.
+ *
+ * @param color
+ * problems panel background color to set
+ */
+ public void setProblemBackgroundColor(Color color) {
+ actions.setProblemBackgroundColor(color);
+ }
+
+ /**
+ * Gets the previous screen class.
+ *
+ * @param screen
+ * reference screen for which we want the previous screen class.
+ *
+ * @return previous screen class relatively to <code>screen</code> or null
+ * if there is no screen before <code>screen</code>.
+ */
+ abstract public Class<? extends Screen> getPreviousScreen(Class<? extends Screen> screen);
+
+ /**
+ * Clear screens history, all screens are dropped along with their data and
+ * will be recreated in future use.
+ */
+ public final void resetScreens() {
+ hmClassScreens.clear();
+ }
+
+ /**
+ * Gets the next screen class.
+ *
+ * @param screen
+ * reference screen for which we want the next screen class.
+ *
+ * @return next screen class relatively to <code>screen</code> or null if
+ * there is no screen after <code>screen</code>.
+ */
+ abstract public Class<? extends Screen> getNextScreen(Class<? extends Screen> screen);
+
+ /**
+ * Get current screen.
+ *
+ * @return current screen class
+ */
+ public Class<? extends Screen> getCurrentScreen() {
+ return this.current.getClass();
+ }
+
+ /**
+ * Refresh buttons and problems. Called asynchronously by the screens or by
+ * the wizard itself.
+ */
+ public void updateGUIState() {
+ boolean bPrevious = current.canGoPrevious();
+ boolean bNext = current.canGoNext();
+ boolean bFinish = current.canFinish();
+ boolean bCancel = current.canCancel();
+ actions.setState(bPrevious, bNext, bFinish, bCancel);
+ actions.setProblem(current.getProblem());
+ }
+
+ /**
+ * Finish action. Called when user clicks on "finish"
+ */
+ abstract public void finish();
+
+ /**
+ * Called when user clicks on "cancel". Override it if you want to do
+ * something in cancel such as display a confirmation dialog.
+ * <p>
+ *
+ * @return return true if the Wizard should continue to close return false
+ * if the Wizard should abort the cancellation
+ */
+ public boolean onCancel() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void windowClosing(WindowEvent windowEvent) {
+ // if cancel is disabled, then don't call the onCancel function and
+ // don't dispose
+ if (current.canCancel() && onCancel()) {
+ bCancelled = true;
+ dialog.dispose();
+ }
+ }
+
+}
diff --git a/src/test/java/org/qdwizard/LangpackTest.java b/src/test/java/org/qdwizard/LangpackTest.java
new file mode 100644
index 0000000..bb0c330
--- /dev/null
+++ b/src/test/java/org/qdwizard/LangpackTest.java
@@ -0,0 +1,54 @@
+/*
+ * Jajuk
+ * Copyright (C) 2003 "Bertrand Florat <bertrand at florat.net>"
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * $Revision$
+ */
+
+package org.qdwizard;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.Locale;
+
+import org.junit.Test;
+
+public class LangpackTest {
+
+ @Test
+ public void testAddLocaleOK() throws Exception {
+ Langpack.addLocale(new Locale("is"), Arrays.asList("a", "b", "c", "d"));
+ Langpack.setLocale(new Locale("is"));
+ assertEquals("c", Langpack.getMessage("Previous"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testAddLocaleNullLocale() throws Exception {
+ Langpack.addLocale(null, Arrays.asList("a", "b", "c", "d"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testAddLocaleNullLabels() throws Exception {
+ Langpack.addLocale(new Locale("is"), null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testAddLocaleWrongLabelSize() throws Exception {
+ Langpack.addLocale(new Locale("is"), Arrays.asList("a", "b", "c"));
+ }
+
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/qdwizard.git
More information about the pkg-java-commits
mailing list