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.

InstallerListener.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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;
  24. import com.dmdirc.installer.Installer.ShortcutType;
  25. import com.dmdirc.installer.ui.InstallerDialog;
  26. /**
  27. * Listeners to all wizard and step changes and responds accordingly.
  28. */
  29. public class InstallerListener implements WizardListener, StepListener {
  30. private Main main;
  31. /**
  32. * Instantiates a new installer listener.
  33. *
  34. * @param main Installer entry point
  35. */
  36. public InstallerListener(final Main main) {
  37. this.main = main;
  38. }
  39. /** {@inheritDoc} */
  40. @Override
  41. public void wizardFinished() {
  42. main.disposeOfInstaller();
  43. Main.getWizardFrame().dispose();
  44. }
  45. /** {@inheritDoc} */
  46. @Override
  47. public void wizardCancelled() {
  48. if (!"Install".equals(Main.getWizardFrame().getCurrentStepName()) && Main.getWizardFrame().
  49. showCancelConfirmation()) {
  50. Main.getWizardFrame().dispose();
  51. }
  52. }
  53. /** {@inheritDoc} */
  54. @Override
  55. public void stepAboutToDisplay(final Step step) {
  56. if ("Install".equals(step.getStepName())) {
  57. installerToBeDisplayed(step);
  58. } else if ("Confirm".equals(step.getStepName())) {
  59. confirmToBeDisplayed(step);
  60. }
  61. }
  62. /** {@inheritDoc} */
  63. @Override
  64. public void stepHidden(final Step step) {
  65. //Ignore
  66. }
  67. private void installerToBeDisplayed(final Step step) {
  68. final InstallerDialog dialog = Main.getWizardFrame();
  69. dialog.enableNextStep(false);
  70. dialog.enablePreviousStep(false);
  71. Main.getInstaller().setInstallStep((TextStep) dialog.getStep("Install"));
  72. Main.getInstaller().start();
  73. }
  74. private void confirmToBeDisplayed(final Step step) {
  75. String shortcutText = "";
  76. final Settings settings = (Settings) Main.getWizardFrame().getStep(1);
  77. if (Main.getInstaller().supportsShortcut(ShortcutType.MENU) && settings.
  78. getShortcutMenuState()) {
  79. shortcutText = shortcutText + " - Create " + Main.getInstaller().
  80. getMenuName() + " shortcut\n";
  81. }
  82. if (Main.getInstaller().supportsShortcut(ShortcutType.DESKTOP)
  83. && settings.getShortcutDesktopState()) {
  84. shortcutText = shortcutText + " - Create desktop shortcut\n";
  85. }
  86. if (Main.getInstaller().supportsShortcut(ShortcutType.QUICKLAUNCH)
  87. && settings.getShortcutQuickState()) {
  88. shortcutText = shortcutText + " - Create Quick Launch shortcut\n";
  89. }
  90. if (Main.getInstaller().supportsShortcut(ShortcutType.PROTOCOL)
  91. && settings.getShortcutProtocolState()) {
  92. shortcutText = shortcutText + " - Make DMDirc handle irc:// links\n";
  93. }
  94. final String installLocation = settings.getInstallLocation();
  95. if (step instanceof TextStep) {
  96. final TextStep textStep = (TextStep) step;
  97. if (installLocation.isEmpty()) {
  98. textStep.setText(
  99. "You have chosen an invalid install location\n\n"
  100. + "Please press the \"Previous\" button to go back and correct it.");
  101. Main.getWizardFrame().enableNextStep(false);
  102. } else {
  103. textStep.setText(
  104. "Please review your chosen settings:\n\n"
  105. + " - Install Location:\n" + " " + installLocation
  106. + "\n" + shortcutText + "\n" + "If you wish to change "
  107. + "any of these settings, press the \"Previous\" "
  108. + "button, otherwise click \"Next\" to begin the installation");
  109. Main.getWizardFrame().enableNextStep(true);
  110. }
  111. }
  112. }
  113. }