Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (c) 2006-2013 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.serverlistdialog;
  23. import com.dmdirc.addons.ui_swing.UIUtilities;
  24. import com.dmdirc.addons.serverlists.ServerGroupItem;
  25. import com.dmdirc.addons.ui_swing.components.text.TextLabel;
  26. import com.dmdirc.ui.core.util.URLHandler;
  27. import java.net.URI;
  28. import java.util.Map.Entry;
  29. import javax.swing.JPanel;
  30. import javax.swing.JScrollPane;
  31. import javax.swing.event.HyperlinkEvent;
  32. import javax.swing.event.HyperlinkEvent.EventType;
  33. import javax.swing.event.HyperlinkListener;
  34. import net.miginfocom.swing.MigLayout;
  35. /**
  36. * Panel for showing server group item information.
  37. */
  38. public class Info extends JPanel implements HyperlinkListener,
  39. ServerListListener {
  40. /**
  41. * A version number for this class. It should be changed whenever the class
  42. * structure is changed (or anything else that would prevent serialized
  43. * objects being unserialized with the new class).
  44. */
  45. private static final long serialVersionUID = 2;
  46. /** Info pane. */
  47. private final TextLabel infoLabel;
  48. /** Link label. */
  49. private final TextLabel linkLabel;
  50. /** Server list model. */
  51. private final ServerListModel model;
  52. /** Info scroll panel. */
  53. private final JScrollPane sp;
  54. /** URL Handler to use to open links. */
  55. private final URLHandler urlHandler;
  56. /**
  57. * Creates a new info panel.
  58. *
  59. * @param model Model to pull information from
  60. * @param urlHandler A {@link URLHandler} to use to open links
  61. */
  62. public Info(final ServerListModel model, final URLHandler urlHandler) {
  63. super();
  64. this.urlHandler = urlHandler;
  65. this.model = model;
  66. infoLabel = new TextLabel();
  67. linkLabel = new TextLabel();
  68. sp = new JScrollPane(infoLabel);
  69. setLayout(new MigLayout("fill, ins 0"));
  70. add(sp, "grow, push");
  71. add(linkLabel, "grow");
  72. addListeners();
  73. serverGroupChanged(model.getSelectedItem());
  74. }
  75. /**
  76. * Adds required listeners.
  77. */
  78. private void addListeners() {
  79. linkLabel.addHyperlinkListener(this);
  80. model.addServerListListener(this);
  81. }
  82. /** {@inheritDoc} */
  83. @Override
  84. public void hyperlinkUpdate(final HyperlinkEvent e) {
  85. if (e.getEventType() == EventType.ACTIVATED) {
  86. urlHandler.launchApp(e.getURL());
  87. }
  88. }
  89. /** {@inheritDoc} */
  90. @Override
  91. public void serverGroupChanged(final ServerGroupItem item) {
  92. setVisible(false);
  93. infoLabel.setVisible(false);
  94. linkLabel.setVisible(false);
  95. if (item == null) {
  96. infoLabel.setText("");
  97. linkLabel.setText("");
  98. } else {
  99. final StringBuilder sb = new StringBuilder();
  100. sb.append("<html><b>");
  101. sb.append(item.getPath());
  102. sb.append("</b><br>");
  103. if (item.getGroup() == null) {
  104. sb.append("");
  105. } else {
  106. sb.append(item.getGroup().getDescription());
  107. }
  108. sb.append("</html>");
  109. infoLabel.setText(sb.toString());
  110. sb.setLength(0);
  111. for (Entry<String, URI> entry : item.getGroup().getLinks()
  112. .entrySet()) {
  113. if (sb.length() != 0) {
  114. sb.append("<br>");
  115. }
  116. sb.append("<a href=\"");
  117. sb.append(entry.getValue().toString());
  118. sb.append("\">");
  119. sb.append(entry.getKey());
  120. sb.append("</a>");
  121. }
  122. linkLabel.setText(sb.toString());
  123. }
  124. UIUtilities.resetScrollPane(sp);
  125. infoLabel.setVisible(true);
  126. linkLabel.setVisible(true);
  127. setVisible(true);
  128. }
  129. /** {@inheritDoc} */
  130. @Override
  131. public void dialogClosed(final boolean save) {
  132. //Ignore
  133. }
  134. /** {@inheritDoc} */
  135. @Override
  136. public void serverGroupAdded(final ServerGroupItem parent,
  137. final ServerGroupItem group) {
  138. //Ignore
  139. }
  140. /** {@inheritDoc} */
  141. @Override
  142. public void serverGroupRemoved(final ServerGroupItem parent,
  143. final ServerGroupItem group) {
  144. //Ignore
  145. }
  146. }