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.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 java.util.List;
  30. import javax.swing.JLabel;
  31. import javax.swing.JPanel;
  32. import javax.swing.JSeparator;
  33. import javax.swing.SwingConstants;
  34. /**
  35. * Shows information about all connected servers.
  36. */
  37. public class ServerInfoDialog extends StatusbarPopupWindow {
  38. /** A version number for this class. */
  39. private static final long serialVersionUID = 3;
  40. /** The lag display manager. */
  41. protected final LagDisplayManager manager;
  42. /** Swing main frame. */
  43. private final MainFrame mainFrame;
  44. /** Server manager to retrieve servers from. */
  45. private final ServerManager serverManager;
  46. /**
  47. * Creates a new ServerInfoDialog.
  48. *
  49. * @param manager The {@link LagDisplayManager} we're using for info
  50. * @param parent The {@link JPanel} to use for positioning
  51. * @param mainFrame The frame that will own this dialog.
  52. * @param serverManager The manager to use to iterate servers.
  53. */
  54. public ServerInfoDialog(
  55. final LagDisplayManager manager,
  56. final StatusbarPanel<JLabel> parent,
  57. final MainFrame mainFrame,
  58. final ServerManager serverManager) {
  59. super(parent, mainFrame);
  60. this.manager = manager;
  61. this.mainFrame = mainFrame;
  62. this.serverManager = serverManager;
  63. }
  64. @Override
  65. protected void initContent(final JPanel panel) {
  66. final List<Server> servers = serverManager.getServers();
  67. if (servers.isEmpty()) {
  68. panel.add(new JLabel("No open servers."));
  69. } else {
  70. if (manager.shouldShowGraph()) {
  71. panel.add(new PingHistoryPanel(manager, mainFrame), "span, grow, wrap");
  72. panel.add(new JSeparator(), "span, grow, wrap");
  73. }
  74. for (final Server server : servers) {
  75. panel.add(new JLabel(server.getName()));
  76. panel.add(new JLabel(server.getState() == ServerState.CONNECTED
  77. ? server.getNetwork() : "---", SwingConstants.CENTER), "grow");
  78. panel.add(new JLabel(server.getState() == ServerState.CONNECTED
  79. ? manager.getTime(server) : "---", SwingConstants.RIGHT), "grow, wrap");
  80. }
  81. }
  82. }
  83. }