Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

NicklistRenderer.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.ui_swing.components.renderers;
  23. import com.dmdirc.ChannelClientProperty;
  24. import com.dmdirc.interfaces.ConfigChangeListener;
  25. import com.dmdirc.config.ConfigManager;
  26. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  27. import java.awt.Color;
  28. import java.awt.Component;
  29. import java.util.Map;
  30. import javax.swing.BorderFactory;
  31. import javax.swing.DefaultListCellRenderer;
  32. import javax.swing.JList;
  33. /** Renders the nicklist. */
  34. public final class NicklistRenderer extends DefaultListCellRenderer implements
  35. ConfigChangeListener {
  36. /**
  37. * A version number for this class. It should be changed whenever the class
  38. * structure is changed (or anything else that would prevent serialized
  39. * objects being unserialized with the new class).
  40. */
  41. private static final long serialVersionUID = 5;
  42. /** Config manager. */
  43. private final ConfigManager config;
  44. /** Nicklist alternate background colour. */
  45. private Color altBackgroundColour;
  46. /** Show nick colours. */
  47. private boolean showColours;
  48. /** The list that we're using for the nicklist. */
  49. private final JList nicklist;
  50. /**
  51. * Creates a new instance of NicklistRenderer.
  52. *
  53. * @param config ConfigManager for the associated channel
  54. * @param nicklist The nicklist that we're rendering for.
  55. */
  56. public NicklistRenderer(final ConfigManager config, final JList nicklist) {
  57. super();
  58. this.config = config;
  59. this.nicklist = nicklist;
  60. config.addChangeListener("ui", "shownickcoloursinnicklist", this);
  61. config.addChangeListener("ui", "nicklistbackgroundcolour", this);
  62. config.addChangeListener("ui", "backgroundcolour", this);
  63. config.addChangeListener("ui", "nickListAltBackgroundColour", this);
  64. altBackgroundColour = config.getOptionColour(
  65. "ui", "nickListAltBackgroundColour",
  66. "ui", "nicklistbackgroundcolour",
  67. "ui", "backgroundcolour");
  68. showColours = config.getOptionBool("ui", "shownickcoloursinnicklist");
  69. }
  70. /** {@inheritDoc} */
  71. @Override
  72. public Component getListCellRendererComponent(final JList list,
  73. final Object value, final int index, final boolean isSelected,
  74. final boolean cellHasFocus) {
  75. super.getListCellRendererComponent(list, value, index, isSelected,
  76. cellHasFocus);
  77. if (!isSelected && (index & 1) == 1) {
  78. setBackground(altBackgroundColour);
  79. }
  80. final Map map = ((ChannelClientInfo) value).getMap();
  81. if (showColours && map != null) {
  82. if (map.containsKey(ChannelClientProperty.NICKLIST_FOREGROUND)) {
  83. setForeground((Color) map.get(ChannelClientProperty.NICKLIST_FOREGROUND));
  84. }
  85. if (map.containsKey(ChannelClientProperty.NICKLIST_BACKGROUND)) {
  86. setBackground((Color) map.get(ChannelClientProperty.NICKLIST_BACKGROUND));
  87. }
  88. }
  89. setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
  90. return this;
  91. }
  92. /** {@inheritDoc} */
  93. @Override
  94. public void configChanged(final String domain, final String key) {
  95. if ("shownickcoloursinnicklist".equals(key)) {
  96. showColours = config.getOptionBool("ui", "shownickcoloursinnicklist");
  97. } else {
  98. altBackgroundColour =
  99. config.getOptionColour(
  100. "ui", "nickListAltBackgroundColour",
  101. "ui", "nicklistbackgroundcolour",
  102. "ui", "backgroundcolour");
  103. }
  104. nicklist.repaint();
  105. }
  106. }