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.

WizardControlPanel.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. *
  3. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package com.dmdirc.installer.ui;
  24. import com.dmdirc.installer.ui.EtchedLineBorder.BorderSide;
  25. import java.awt.Dimension;
  26. import javax.swing.Box;
  27. import javax.swing.BoxLayout;
  28. import javax.swing.JButton;
  29. import javax.swing.JLabel;
  30. import javax.swing.JPanel;
  31. import javax.swing.border.EtchedBorder;
  32. /**
  33. * Simple Panel representing the control buttons for a wizard.
  34. */
  35. public class WizardControlPanel extends JPanel {
  36. private static final long serialVersionUID = 7903362315297158222L;
  37. private final JButton prev;
  38. private final JButton next;
  39. private final JLabel progress;
  40. private int total;
  41. private int step;
  42. /**
  43. * Instantiates a new wizard control panel.
  44. */
  45. public WizardControlPanel() {
  46. this(0);
  47. }
  48. /**
  49. * Instantiates a new wizard control panel using the specified number of
  50. * steps.
  51. *
  52. * @param total Total number of steps
  53. */
  54. public WizardControlPanel(final int total) {
  55. this.total = total;
  56. this.step = 0;
  57. prev = new JButton("\u00AB Previous");
  58. next = new JButton("Next \u00BB");
  59. progress = new JLabel();
  60. updateProgressLabel();
  61. prev.setPreferredSize(new Dimension(100, prev.getFont().getSize() + 2 * InstallerDialog.SMALL_GAP));
  62. next.setPreferredSize(new Dimension(100, next.getFont().getSize() + 2 * InstallerDialog.SMALL_GAP));
  63. setBorder(new EtchedLineBorder(EtchedBorder.LOWERED, BorderSide.TOP));
  64. setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
  65. add(progress);
  66. add(Box.createHorizontalGlue());
  67. add(prev);
  68. add(Box.createHorizontalStrut(InstallerDialog.SMALL_GAP));
  69. add(next);
  70. }
  71. /**
  72. * Returns the previous button.
  73. *
  74. * @return Previous button
  75. */
  76. public JButton getPrevButton() {
  77. return prev;
  78. }
  79. /**
  80. * Returns the next button.
  81. *
  82. * @return Next button
  83. */
  84. public JButton getNextButton() {
  85. return next;
  86. }
  87. /**
  88. * Returns the progress label.
  89. *
  90. * @return Progress Label
  91. */
  92. public JLabel getProgressLabel() {
  93. return progress;
  94. }
  95. /**
  96. * Updates the progress label.
  97. */
  98. public void updateProgressLabel() {
  99. progress.setText("Step " + step + " of " + total);
  100. }
  101. /**
  102. * Sets the new total number of steps.
  103. *
  104. * @param total New total number of steps
  105. */
  106. public void setTotal(final int total) {
  107. this.total = total;
  108. updateProgressLabel();
  109. }
  110. /**
  111. * Sets the current progress step.
  112. *
  113. * @param step Progress step
  114. */
  115. public void setProgress(final int step) {
  116. this.step = step + 1;
  117. updateProgressLabel();
  118. if (step + 1 == total) {
  119. next.setText("Finish");
  120. } else if (step == 0) {
  121. prev.setEnabled(false);
  122. } else if (step > 0) {
  123. prev.setEnabled(true);
  124. } else {
  125. next.setText("Next \u00BB");
  126. }
  127. }
  128. }