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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.lagdisplay;
  18. import com.dmdirc.ServerState;
  19. import com.dmdirc.addons.ui_swing.MainFrame;
  20. import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPanel;
  21. import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow;
  22. import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
  23. import com.dmdirc.interfaces.Connection;
  24. import com.dmdirc.interfaces.ConnectionManager;
  25. import java.util.List;
  26. import javax.swing.JLabel;
  27. import javax.swing.JPanel;
  28. import javax.swing.JSeparator;
  29. import javax.swing.SwingConstants;
  30. /**
  31. * Shows information about all connected servers.
  32. */
  33. public class ServerInfoDialog extends StatusbarPopupWindow {
  34. /** A version number for this class. */
  35. private static final long serialVersionUID = 3;
  36. /** The lag display manager. */
  37. protected final LagDisplayManager manager;
  38. /** Server manager to retrieve servers from. */
  39. private final ConnectionManager connectionManager;
  40. /** The active window manager. */
  41. private final ActiveFrameManager activeFrameManager;
  42. /**
  43. * Creates a new ServerInfoDialog.
  44. *
  45. * @param manager The {@link LagDisplayManager} we're using for info
  46. * @param parent The {@link JPanel} to use for positioning
  47. * @param mainFrame The frame that will own this dialog.
  48. * @param connectionManager The manager to use to iterate servers.
  49. */
  50. public ServerInfoDialog(
  51. final LagDisplayManager manager,
  52. final StatusbarPanel<JLabel> parent,
  53. final MainFrame mainFrame,
  54. final ActiveFrameManager activeFrameManager,
  55. final ConnectionManager connectionManager) {
  56. super(parent, mainFrame);
  57. this.manager = manager;
  58. this.connectionManager = connectionManager;
  59. this.activeFrameManager = activeFrameManager;
  60. }
  61. @Override
  62. protected void initContent(final JPanel panel) {
  63. final List<Connection> connections = connectionManager.getConnections();
  64. if (connections.isEmpty()) {
  65. panel.add(new JLabel("No open servers."));
  66. } else {
  67. if (manager.shouldShowGraph()) {
  68. panel.add(new PingHistoryPanel(manager, activeFrameManager), "span, grow, wrap");
  69. panel.add(new JSeparator(), "span, grow, wrap");
  70. }
  71. for (Connection connection : connections) {
  72. panel.add(new JLabel(connection.getAddress()));
  73. panel.add(new JLabel(
  74. connection.getState() == ServerState.CONNECTED
  75. ? connection.getNetwork() : "---",
  76. SwingConstants.CENTER), "grow");
  77. panel.add(new JLabel(connection.getState() == ServerState.CONNECTED
  78. ? manager.getTime(connection) : "---", SwingConstants.RIGHT), "grow, wrap");
  79. }
  80. }
  81. }
  82. }