Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

UpdaterLabel.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.statusbar;
  18. import com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog;
  19. import com.dmdirc.addons.ui_swing.dialogs.updater.SwingUpdaterDialog;
  20. import com.dmdirc.addons.ui_swing.injection.DialogModule.ForUpdates;
  21. import com.dmdirc.addons.ui_swing.injection.DialogProvider;
  22. import com.dmdirc.addons.ui_swing.injection.MainWindow;
  23. import com.dmdirc.addons.ui_swing.components.IconManager;
  24. import com.dmdirc.updater.manager.CachingUpdateManager;
  25. import com.dmdirc.updater.manager.UpdateManager;
  26. import com.dmdirc.updater.manager.UpdateManagerListener;
  27. import com.dmdirc.updater.manager.UpdateManagerStatus;
  28. import java.awt.Window;
  29. import java.awt.event.MouseEvent;
  30. import javax.inject.Inject;
  31. import javax.swing.BorderFactory;
  32. import javax.swing.JLabel;
  33. /**
  34. * Updater label is responsible for handling the display of updates in the status bar.
  35. */
  36. public class UpdaterLabel extends StatusbarPopupPanel<JLabel> implements UpdateManagerListener {
  37. /** A version number for this class. */
  38. private static final long serialVersionUID = 1;
  39. /** The manager to use to retrieve icons. */
  40. private final IconManager iconManager;
  41. /** The parent that will own any popup windows. */
  42. private final Window parentWindow;
  43. /** The update manager to use to retrieve information. */
  44. private final CachingUpdateManager updateManager;
  45. /** Provider of updater dialogs. */
  46. private final DialogProvider<SwingUpdaterDialog> updaterDialogProvider;
  47. /** Provider of restart dialogs. */
  48. private final DialogProvider<SwingRestartDialog> restartDialogProvider;
  49. /**
  50. * Instantiates a new updater label, handles showing updates on the status bar.
  51. *
  52. * @param iconManager The manager to use to retrieve icons.
  53. * @param parentWindow The parent that will own any popup windows.
  54. * @param updateManager The manager to use to retrieve information.
  55. * @param updaterDialogProvider Provider of updater dialogs.
  56. * @param restartDialogProvider Provider of restart dialogs.
  57. */
  58. @Inject
  59. public UpdaterLabel(
  60. final IconManager iconManager,
  61. @MainWindow final Window parentWindow,
  62. final CachingUpdateManager updateManager,
  63. final DialogProvider<SwingUpdaterDialog> updaterDialogProvider,
  64. @ForUpdates final DialogProvider<SwingRestartDialog> restartDialogProvider) {
  65. super(new JLabel());
  66. this.iconManager = iconManager;
  67. this.parentWindow = parentWindow;
  68. this.updateManager = updateManager;
  69. this.updaterDialogProvider = updaterDialogProvider;
  70. this.restartDialogProvider = restartDialogProvider;
  71. setBorder(BorderFactory.createEtchedBorder());
  72. updateManager.addUpdateManagerListener(this);
  73. setVisible(false);
  74. label.setText(null);
  75. }
  76. @Override
  77. public void mouseReleased(final MouseEvent mouseEvent) {
  78. super.mouseReleased(mouseEvent);
  79. if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
  80. if (updateManager.getManagerStatus() == UpdateManagerStatus.IDLE_RESTART_NEEDED) {
  81. closeDialog();
  82. restartDialogProvider.displayOrRequestFocus();
  83. } else {
  84. updaterDialogProvider.displayOrRequestFocus();
  85. }
  86. }
  87. }
  88. @Override
  89. protected StatusbarPopupWindow getWindow() {
  90. return new UpdaterPopup(updateManager, this, parentWindow);
  91. }
  92. @Override
  93. public void updateManagerStatusChanged(final UpdateManager manager,
  94. final UpdateManagerStatus status) {
  95. if (status == UpdateManagerStatus.IDLE) {
  96. setVisible(false);
  97. } else {
  98. setVisible(true);
  99. }
  100. if (status == UpdateManagerStatus.WORKING) {
  101. label.setIcon(iconManager.getIcon("hourglass"));
  102. } else if (status == UpdateManagerStatus.IDLE_UPDATE_AVAILABLE) {
  103. label.setIcon(iconManager.getIcon("update"));
  104. } else if (status == UpdateManagerStatus.IDLE_RESTART_NEEDED) {
  105. label.setIcon(iconManager.getIcon("restart-needed"));
  106. }
  107. }
  108. }