選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

WizardFrame.java 4.2KB

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