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.

ServerInfoDialog.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.lagdisplay;
  23. import com.dmdirc.Server;
  24. import com.dmdirc.ServerManager;
  25. import com.dmdirc.ServerState;
  26. import com.dmdirc.addons.ui_swing.MainFrame;
  27. import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPanel;
  28. import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow;
  29. import com.dmdirc.util.annotations.factory.Factory;
  30. import com.dmdirc.util.annotations.factory.Unbound;
  31. import java.util.List;
  32. import javax.swing.JLabel;
  33. import javax.swing.JPanel;
  34. import javax.swing.JSeparator;
  35. /**
  36. * Shows information about all connected servers.
  37. */
  38. @Factory(inject = true, singleton = true)
  39. public class ServerInfoDialog extends StatusbarPopupWindow {
  40. /**
  41. * A version number for this class. It should be changed whenever the class structure is changed
  42. * (or anything else that would prevent serialized objects being unserialized with the new
  43. * class).
  44. */
  45. private static final long serialVersionUID = 3;
  46. /** The lag display manager. */
  47. protected final LagDisplayManager manager;
  48. /** Swing main frame. */
  49. private final MainFrame mainFrame;
  50. /** Server manager to retrieve servers from. */
  51. private final ServerManager serverManager;
  52. /**
  53. * Creates a new ServerInfoDialog.
  54. *
  55. * @param manager The {@link LagDisplayManager} we're using for info
  56. * @param parent The {@link JPanel} to use for positioning
  57. * @param mainFrame The frame that will own this dialog.
  58. * @param serverManager The manager to use to iterate servers.
  59. */
  60. public ServerInfoDialog(
  61. final LagDisplayManager manager,
  62. @Unbound final StatusbarPanel<JLabel> parent,
  63. final MainFrame mainFrame,
  64. final ServerManager serverManager) {
  65. super(parent, mainFrame);
  66. this.manager = manager;
  67. this.mainFrame = mainFrame;
  68. this.serverManager = serverManager;
  69. }
  70. /** {@inheritDoc} */
  71. @Override
  72. protected void initContent(final JPanel panel) {
  73. final List<Server> servers = serverManager.getServers();
  74. if (servers.isEmpty()) {
  75. panel.add(new JLabel("No open servers."));
  76. } else {
  77. if (manager.shouldShowGraph()) {
  78. panel.add(new PingHistoryPanel(manager, mainFrame), "span, grow, wrap");
  79. panel.add(new JSeparator(), "span, grow, wrap");
  80. }
  81. for (final Server server : servers) {
  82. panel.add(new JLabel(server.getName()));
  83. panel.add(new JLabel(server.getState() == ServerState.CONNECTED
  84. ? server.getNetwork() : "---", JLabel.CENTER), "grow");
  85. panel.add(new JLabel(server.getState() == ServerState.CONNECTED
  86. ? manager.getTime(server) : "---", JLabel.RIGHT), "grow, wrap");
  87. }
  88. }
  89. }
  90. }