Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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 final class WizardFrame extends JFrame {
  30. /**
  31. * A version number for this class. It should be changed whenever the class
  32. * structure is changed (or anything else that would prevent serialized
  33. * objects being unserialized with the new 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. * @param wizard Wizard to inform of changes
  44. */
  45. public WizardFrame(final String title, final List<Step> steps,
  46. final WizardListener wizard) {
  47. super();
  48. setTitle(title);
  49. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  50. this.wizard = new WizardPanel(title, steps, wizard);
  51. layoutComponents();
  52. }
  53. /** Lays out the components. */
  54. private void layoutComponents() {
  55. setContentPane(wizard);
  56. }
  57. /** Displays the wizard. */
  58. public void display() {
  59. wizard.display();
  60. CoreUIUtils.centreWindow(this);
  61. setResizable(false);
  62. setVisible(true);
  63. }
  64. /** {@inheritDoc} */
  65. @Override
  66. public void validate() {
  67. super.validate();
  68. CoreUIUtils.centreWindow(this);
  69. }
  70. /**
  71. * Adds a step to the wizard.
  72. *
  73. * @param step Step to add
  74. */
  75. public void addStep(final Step step) {
  76. wizard.addStep(step);
  77. }
  78. /**
  79. * Returns the step at the specified index.
  80. *
  81. * @param stepNumber step number
  82. *
  83. * @return Specified step.
  84. */
  85. public Step getStep(final int stepNumber) {
  86. return wizard.getStep(stepNumber);
  87. }
  88. /**
  89. * Returns the current step.
  90. *
  91. * @return Current step number
  92. */
  93. public int getCurrentStep() {
  94. return wizard.getCurrentStep();
  95. }
  96. /**
  97. * Enables or disables the "next step" button.
  98. *
  99. * @param newValue boolean true to make "next" button enabled, else false
  100. */
  101. public void enableNextStep(final boolean newValue) {
  102. wizard.enableNextStep(newValue);
  103. }
  104. /**
  105. * Enables or disables the "previous step" button.
  106. *
  107. * @param newValue boolean true to make "previous" button enabled, else false
  108. */
  109. public void enablePreviousStep(final boolean newValue) {
  110. wizard.enablePreviousStep(newValue);
  111. }
  112. /**
  113. * Adds a step listener to the list.
  114. *
  115. * @param listener
  116. */
  117. public void addStepListener(final StepListener listener) {
  118. wizard.addStepListener(listener);
  119. }
  120. /**
  121. * Removes a step listener from the list.
  122. *
  123. * @param listener
  124. */
  125. public void removeStepListener(final StepListener listener) {
  126. wizard.removeStepListener(listener);
  127. }
  128. /**
  129. * Adds a wizard listener to the list.
  130. *
  131. * @param listener
  132. */
  133. public void addWizardListener(final WizardListener listener) {
  134. wizard.addWizardListener(listener);
  135. }
  136. /**
  137. * Removes a wizard listener from the list.
  138. *
  139. * @param listener
  140. */
  141. public void removeWizardListener(final WizardListener listener) {
  142. wizard.removeWizardListener(listener);
  143. }
  144. }