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.

InvitePopup.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.Invite;
  19. import com.dmdirc.interfaces.Connection;
  20. import com.dmdirc.util.DateUtils;
  21. import java.awt.Window;
  22. import java.util.Optional;
  23. import javax.swing.JLabel;
  24. import javax.swing.JPanel;
  25. import javax.swing.SwingConstants;
  26. /**
  27. * Shows information about received invites.
  28. *
  29. * @since 0.6.3m1
  30. */
  31. public class InvitePopup extends StatusbarPopupWindow {
  32. /** A version number for this class. */
  33. private static final long serialVersionUID = 1;
  34. /** The connection to show invites for. */
  35. private final Optional<Connection> connection;
  36. /**
  37. * Creates a new InvitePopup for the specified panel and connection.
  38. *
  39. * @param parent The parent of this popup
  40. * @param connection The connection to show invites for
  41. * @param parentWindow Parent window
  42. */
  43. public InvitePopup(final JPanel parent,
  44. final Optional<Connection> connection, final Window parentWindow) {
  45. super(parent, parentWindow);
  46. this.connection = connection;
  47. }
  48. @Override
  49. protected void initContent(final JPanel panel) {
  50. if (connection.isPresent()) {
  51. for (final Invite invite : connection.get().getInviteManager().getInvites()) {
  52. panel.add(new JLabel(invite.getChannel()), "growx, pushx");
  53. panel.add(new JLabel(invite.getSource().getNickname(), SwingConstants.CENTER),
  54. "growx, pushx, al center");
  55. panel.add(new JLabel(DateUtils.formatDuration(
  56. (int) (System.currentTimeMillis() - invite.getTimestamp()) / 1000)
  57. + " ago", SwingConstants.RIGHT),
  58. "growx, pushx, al right, wrap");
  59. }
  60. }
  61. }
  62. }