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.

InstallerWindow.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.components.addonbrowser;
  18. import com.dmdirc.addons.ui_swing.components.text.TextLabel;
  19. import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
  20. import java.awt.event.ActionEvent;
  21. import java.awt.event.ActionListener;
  22. import javax.swing.JDialog;
  23. import javax.swing.JProgressBar;
  24. import net.miginfocom.swing.MigLayout;
  25. /**
  26. * A window to show the progress whilst installing an addon.
  27. */
  28. public class InstallerWindow extends StandardDialog implements ActionListener {
  29. /** A version number for this class. */
  30. private static final long serialVersionUID = 1;
  31. /** Downloader progress bar. */
  32. private final JProgressBar jpb = new JProgressBar(0, 100);
  33. /** Parent window. */
  34. private final BrowserWindow parentWindow;
  35. /** Message label. */
  36. private final TextLabel label;
  37. /** Addon info. */
  38. private final AddonInfo info;
  39. /**
  40. * Instantiates a new installer window.
  41. *
  42. * @param parentWindow Parent window
  43. * @param info Associated addon info
  44. */
  45. public InstallerWindow(final BrowserWindow parentWindow, final AddonInfo info) {
  46. super(parentWindow, ModalityType.MODELESS);
  47. this.info = info;
  48. this.parentWindow = parentWindow;
  49. setTitle("Installing addon...");
  50. jpb.setIndeterminate(true);
  51. label = new TextLabel("Installing: " + info.getTitle());
  52. getOkButton().addActionListener(this);
  53. getCancelButton().addActionListener(this);
  54. setLayout(new MigLayout("fill, wrap 1"));
  55. add(label);
  56. add(jpb, "grow");
  57. add(getOkButton(), "split, right");
  58. getOkButton().setEnabled(false);
  59. setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
  60. setIconImages(parentWindow.getIconImages());
  61. }
  62. @Override
  63. public void actionPerformed(final ActionEvent ae) {
  64. dispose();
  65. }
  66. /**
  67. * Tells the window the installation has finished and displays the appropriate message to the
  68. * user.
  69. *
  70. * @param message Message to display (or an empty sting for success)
  71. */
  72. public void finished(final String message) {
  73. if (message.isEmpty()) {
  74. label.setText("Finished installing addon: " + info.getTitle());
  75. } else {
  76. label.setText("Error installing addon: " + info.getTitle() + "<br>"
  77. + message);
  78. }
  79. jpb.setIndeterminate(false);
  80. jpb.setValue(100);
  81. getOkButton().setEnabled(true);
  82. pack();
  83. parentWindow.loadData(false);
  84. }
  85. }