Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ServerEntry.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.serverlists;
  23. import com.dmdirc.ServerManager;
  24. import com.dmdirc.interfaces.config.IdentityController;
  25. import java.net.URI;
  26. /**
  27. * Describes an entry for a server within a {@link ServerGroup}.
  28. *
  29. * @since 0.6.4
  30. * @author chris
  31. */
  32. public class ServerEntry extends ServerGroupItemBase {
  33. /** The address of the server in question. */
  34. private URI address;
  35. /** The group that owns this entry. */
  36. private final ServerGroup group;
  37. /** The manager to use to create new servers. */
  38. private final ServerManager serverManager;
  39. /**
  40. * Creates a new server entry.
  41. *
  42. * @param identityController The controller to read/write settings with.
  43. * @param serverManager The server manager to connect to servers with.
  44. * @param group The group that owns this entry
  45. * @param name The name of this server
  46. * @param address The address of this server
  47. * @param profile The name of the profile to be used by this server
  48. */
  49. public ServerEntry(
  50. final IdentityController identityController,
  51. final ServerManager serverManager,
  52. final ServerGroup group, final String name,
  53. final URI address, final String profile) {
  54. super(identityController);
  55. this.serverManager = serverManager;
  56. setName(name);
  57. setProfile(profile);
  58. this.address = address;
  59. this.group = group;
  60. }
  61. /** {@inheritDoc} */
  62. @Override
  63. public ServerGroup getGroup() {
  64. return group;
  65. }
  66. /** {@inheritDoc} */
  67. @Override
  68. protected ServerGroup getParent() {
  69. return getGroup();
  70. }
  71. /**
  72. * Retrieves the address used by this server.
  73. *
  74. * @return This server's address
  75. */
  76. @Override
  77. public URI getAddress() {
  78. return address;
  79. }
  80. /**
  81. * Sets the address for this server entry.
  82. *
  83. * @param address The new address for this entry
  84. */
  85. public void setAddress(final URI address) {
  86. setModified(true);
  87. this.address = address;
  88. }
  89. /** {@inheritDoc} */
  90. @Override
  91. public void connect() {
  92. serverManager.connectToAddress(address, getProfileIdentity());
  93. }
  94. /** {@inheritDoc} */
  95. @Override
  96. public String toString() {
  97. return "[" + getName() + ": address: " + getAddress() + "]";
  98. }
  99. }