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.

SwingFirstRunWizard.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.firstrun;
  18. import com.dmdirc.addons.ui_swing.components.IconManager;
  19. import com.dmdirc.addons.ui_swing.dialogs.profile.ProfileManagerDialog;
  20. import com.dmdirc.addons.ui_swing.injection.DialogProvider;
  21. import com.dmdirc.addons.ui_swing.injection.MainWindow;
  22. import com.dmdirc.addons.ui_swing.wizard.WizardDialog;
  23. import com.dmdirc.addons.ui_swing.wizard.WizardListener;
  24. import com.dmdirc.config.UserConfig;
  25. import com.dmdirc.config.provider.ConfigProvider;
  26. import com.dmdirc.interfaces.ui.FirstRunWizard;
  27. import com.dmdirc.plugins.CorePluginExtractor;
  28. import java.awt.Dialog.ModalityType;
  29. import java.awt.Dimension;
  30. import java.awt.Window;
  31. import java.util.ArrayList;
  32. import javax.inject.Inject;
  33. import javax.inject.Singleton;
  34. /** First run wizard, used to initially setup the client for the user. */
  35. @Singleton
  36. public class SwingFirstRunWizard implements WizardListener, FirstRunWizard {
  37. /** Wizard dialog. */
  38. private final WizardDialog wizardDialog;
  39. /** Global config. */
  40. private final ConfigProvider config;
  41. /** Extractor to use for core plugins. */
  42. private final CorePluginExtractor corePluginExtractor;
  43. /** Provider to use to obtain PMDs. */
  44. private final DialogProvider<ProfileManagerDialog> profileDialogProvider;
  45. /**
  46. * Instantiate the wizard.
  47. *
  48. * @param parentWindow Parent window
  49. * @param config Global config
  50. * @param pluginExtractor Plugin extractor to use.
  51. * @param iconManager Manager to use to find icons.
  52. * @param profileDialogProvider Provider to use to obtain PMDs.
  53. */
  54. @Inject
  55. public SwingFirstRunWizard(@MainWindow final Window parentWindow,
  56. @UserConfig final ConfigProvider config,
  57. final CorePluginExtractor pluginExtractor, final IconManager iconManager,
  58. final DialogProvider<ProfileManagerDialog> profileDialogProvider) {
  59. this.corePluginExtractor = pluginExtractor;
  60. this.config = config;
  61. this.profileDialogProvider = profileDialogProvider;
  62. wizardDialog = new WizardDialog("Setup wizard", new ArrayList<>(), parentWindow,
  63. ModalityType.APPLICATION_MODAL);
  64. wizardDialog.setIconImage(iconManager.getImage("icon"));
  65. wizardDialog.addWizardListener(this);
  66. wizardDialog.setMinimumSize(new Dimension(400, 500));
  67. }
  68. @Override
  69. public void wizardFinished() {
  70. if (((ExtractionStep) wizardDialog.getStep(0)).getPluginsState()) {
  71. extractPlugins();
  72. }
  73. config.setOption("updater", "enable",
  74. ((CommunicationStep) wizardDialog.getStep(1)).checkUpdates());
  75. config.setOption("general", "submitErrors",
  76. ((CommunicationStep) wizardDialog.getStep(1)).checkErrors());
  77. if (((ProfileStep) wizardDialog.getStep(2)).getProfileManagerState()) {
  78. profileDialogProvider.displayOrRequestFocus();
  79. }
  80. wizardDialog.dispose();
  81. }
  82. @Override
  83. public void wizardCancelled() {
  84. wizardDialog.dispose();
  85. }
  86. @Override
  87. public void extractPlugins() {
  88. corePluginExtractor.extractCorePlugins(null);
  89. }
  90. @Override
  91. public void display() {
  92. wizardDialog.addStep(new FirstRunExtractionStep());
  93. wizardDialog.addStep(new CommunicationStep());
  94. wizardDialog.addStep(new ProfileStep());
  95. wizardDialog.display();
  96. }
  97. /**
  98. * Returns the dialog associated with this wizard.
  99. *
  100. * @return Associated wizard dialog
  101. */
  102. public WizardDialog getWizardDialog() {
  103. return wizardDialog;
  104. }
  105. }