Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

SwingRestartDialog.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.dialogs.updater;
  18. import com.dmdirc.addons.ui_swing.components.text.TextLabel;
  19. import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
  20. import com.dmdirc.util.system.LifecycleController;
  21. import com.dmdirc.updater.components.LauncherComponent;
  22. import java.awt.Window;
  23. import java.awt.event.ActionEvent;
  24. import java.awt.event.ActionListener;
  25. import javax.swing.JButton;
  26. import net.miginfocom.swing.MigLayout;
  27. /**
  28. * Prompts the user to restart the client, and restarts the client.
  29. */
  30. public class SwingRestartDialog extends StandardDialog implements ActionListener {
  31. /** Serial version UID. */
  32. private static final long serialVersionUID = -7446499281414990074L;
  33. /** Life cycle controller. */
  34. private final LifecycleController lifecycleController;
  35. /** Informational label. */
  36. private TextLabel info;
  37. /** Info text. */
  38. private final String cause;
  39. /**
  40. * Dialog to restart the client.
  41. *
  42. * @param parentWindow Parent window
  43. * @param lifecycleController Life cycle controller, for restarting client
  44. * @param cause Reason for restart
  45. */
  46. public SwingRestartDialog(final Window parentWindow,
  47. final LifecycleController lifecycleController, final String cause) {
  48. super(parentWindow, ModalityType.APPLICATION_MODAL);
  49. this.cause = cause;
  50. this.lifecycleController = lifecycleController;
  51. setTitle("Restart needed");
  52. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  53. initComponents();
  54. layoutComponents();
  55. }
  56. /** Initialise components. */
  57. private void initComponents() {
  58. orderButtons(new JButton(), new JButton());
  59. if (LauncherComponent.isUsingLauncher()) {
  60. info = new TextLabel("Your client needs to be restarted to " + cause + ".");
  61. } else {
  62. info = new TextLabel("Your client needs to be restarted to " + cause
  63. + ", but as you do not seem to be using "
  64. + "the launcher you will have to restart the client "
  65. + "manually, do you wish to close the client?");
  66. }
  67. getOkButton().setText("Now");
  68. getCancelButton().setText("Later");
  69. getOkButton().addActionListener(this);
  70. getCancelButton().addActionListener(this);
  71. setResizable(false);
  72. }
  73. /** Layout Components. */
  74. private void layoutComponents() {
  75. setLayout(new MigLayout("fill, wrap 2, wmax " + getOwner().getSize().getWidth() + ", pack"));
  76. add(info, "grow, pushx, span 2");
  77. add(getLeftButton(), "split, right");
  78. add(getRightButton(), "right");
  79. pack();
  80. }
  81. @Override
  82. public void validate() {
  83. super.validate();
  84. setLocationRelativeTo(getOwner());
  85. }
  86. @Override
  87. public void actionPerformed(final ActionEvent e) {
  88. if (getOkButton().equals(e.getSource())) {
  89. lifecycleController.quit(42);
  90. }
  91. dispose();
  92. }
  93. }