You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WizardFrame.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.wizard;
  23. import com.dmdirc.ui.CoreUIUtils;
  24. import java.util.List;
  25. import javax.swing.JFrame;
  26. /**
  27. * Basic wizard container.
  28. */
  29. public class WizardFrame extends JFrame {
  30. /**
  31. * A version number for this class. It should be changed whenever the class structure is changed
  32. * (or anything else that would prevent serialized objects being unserialized with the new
  33. * class).
  34. */
  35. private static final long serialVersionUID = 2;
  36. /** Wizard. */
  37. private final WizardPanel wizard;
  38. /**
  39. * Creates a new instance of WizardFrame that requires a mainframe.
  40. *
  41. * @param title Title for the wizard
  42. * @param steps Steps for the wizard
  43. */
  44. public WizardFrame(final String title, final List<Step> steps) {
  45. super();
  46. setTitle(title);
  47. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  48. this.wizard = new WizardPanel(title, steps);
  49. layoutComponents();
  50. }
  51. /** Lays out the components. */
  52. private void layoutComponents() {
  53. setContentPane(wizard);
  54. }
  55. /** Displays the wizard. */
  56. public void display() {
  57. wizard.display();
  58. CoreUIUtils.centreWindow(this);
  59. setResizable(false);
  60. setVisible(true);
  61. }
  62. /** {@inheritDoc} */
  63. @Override
  64. public void validate() {
  65. super.validate();
  66. CoreUIUtils.centreWindow(this);
  67. }
  68. /**
  69. * Adds a step to the wizard.
  70. *
  71. * @param step Step to add
  72. */
  73. public void addStep(final Step step) {
  74. wizard.addStep(step);
  75. }
  76. /**
  77. * Returns the step at the specified index.
  78. *
  79. * @param stepNumber step number
  80. *
  81. * @return Specified step.
  82. */
  83. public Step getStep(final int stepNumber) {
  84. return wizard.getStep(stepNumber);
  85. }
  86. /**
  87. * Returns the current step.
  88. *
  89. * @return Current step number
  90. */
  91. public int getCurrentStep() {
  92. return wizard.getCurrentStep();
  93. }
  94. /**
  95. * Enables or disables the "next step" button.
  96. *
  97. * @param newValue boolean true to make "next" button enabled, else false
  98. */
  99. public void enableNextStep(final boolean newValue) {
  100. wizard.enableNextStep(newValue);
  101. }
  102. /**
  103. * Enables or disables the "previous step" button.
  104. *
  105. * @param newValue boolean true to make "previous" button enabled, else false
  106. */
  107. public void enablePreviousStep(final boolean newValue) {
  108. wizard.enablePreviousStep(newValue);
  109. }
  110. /**
  111. * Adds a step listener to the list.
  112. *
  113. * @param listener Listener to add
  114. */
  115. public void addStepListener(final StepListener listener) {
  116. wizard.addStepListener(listener);
  117. }
  118. /**
  119. * Removes a step listener from the list.
  120. *
  121. * @param listener Listener to remove
  122. */
  123. public void removeStepListener(final StepListener listener) {
  124. wizard.removeStepListener(listener);
  125. }
  126. /**
  127. * Adds a wizard listener to the list.
  128. *
  129. * @param listener Listener to add
  130. */
  131. public void addWizardListener(final WizardListener listener) {
  132. wizard.addWizardListener(listener);
  133. }
  134. /**
  135. * Removes a wizard listener from the list.
  136. *
  137. * @param listener Listener to remove
  138. */
  139. public void removeWizardListener(final WizardListener listener) {
  140. wizard.removeWizardListener(listener);
  141. }
  142. }