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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.ServerState;
  24. import com.dmdirc.addons.ui_swing.MainFrame;
  25. import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPanel;
  26. import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow;
  27. import com.dmdirc.interfaces.Connection;
  28. import com.dmdirc.interfaces.ConnectionManager;
  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 ConnectionManager connectionManager;
  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 connectionManager 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 ConnectionManager connectionManager) {
  59. super(parent, mainFrame);
  60. this.manager = manager;
  61. this.mainFrame = mainFrame;
  62. this.connectionManager = connectionManager;
  63. }
  64. @Override
  65. protected void initContent(final JPanel panel) {
  66. final List<Connection> connections = connectionManager.getConnections();
  67. if (connections.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 (Connection connection : connections) {
  75. panel.add(new JLabel(connection.getAddress()));
  76. panel.add(new JLabel(
  77. connection.getState() == ServerState.CONNECTED
  78. ? connection.getNetwork() : "---",
  79. SwingConstants.CENTER), "grow");
  80. panel.add(new JLabel(connection.getState() == ServerState.CONNECTED
  81. ? manager.getTime(connection) : "---", SwingConstants.RIGHT), "grow, wrap");
  82. }
  83. }
  84. }
  85. }