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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.ui_swing.components.renderers;
  23. import com.dmdirc.addons.ui_swing.EDTInvocation;
  24. import com.dmdirc.addons.ui_swing.UIUtilities;
  25. import com.dmdirc.config.ConfigBinding;
  26. import com.dmdirc.events.DisplayProperty;
  27. import com.dmdirc.interfaces.GroupChatUser;
  28. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  29. import com.dmdirc.ui.messages.ColourManager;
  30. import java.awt.Color;
  31. import javax.swing.JLabel;
  32. import javax.swing.JList;
  33. import javax.swing.ListCellRenderer;
  34. /** Renders the nicklist. */
  35. public final class NicklistRenderer extends DMDircListCellRenderer<GroupChatUser> {
  36. /** Config manager. */
  37. private final AggregateConfigProvider config;
  38. /** Nicklist alternate background colour. */
  39. private Color altBackgroundColour;
  40. /** Show nick colours. */
  41. private boolean showColours;
  42. /** The list that we're using for the nicklist. */
  43. private final JList<GroupChatUser> nicklist;
  44. /** Colour manager to use to resolve colours. */
  45. private final ColourManager colourManager;
  46. /**
  47. * Creates a new instance of NicklistRenderer.
  48. *
  49. * @param config ConfigManager for the associated channel
  50. * @param nicklist The nicklist that we're rendering for.
  51. * @param colourManager Colour manager to use to resolve colours.
  52. */
  53. public NicklistRenderer(final ListCellRenderer<? super GroupChatUser> renderer,
  54. final AggregateConfigProvider config,
  55. final JList<GroupChatUser> nicklist,
  56. final ColourManager colourManager) {
  57. super(renderer);
  58. this.config = config;
  59. this.nicklist = nicklist;
  60. this.colourManager = colourManager;
  61. config.getBinder().bind(this, NicklistRenderer.class);
  62. }
  63. @Override
  64. protected void renderValue(final JLabel label, final GroupChatUser value, final int index,
  65. final boolean isSelected, final boolean hasFocus) {
  66. if (!isSelected && (index & 1) == 1) {
  67. label.setBackground(altBackgroundColour);
  68. }
  69. if (showColours) {
  70. value.getDisplayProperty(DisplayProperty.FOREGROUND_COLOUR).ifPresent(
  71. c -> label.setForeground(UIUtilities.convertColour(c)));
  72. value.getDisplayProperty(DisplayProperty.BACKGROUND_COLOUR).ifPresent(
  73. c -> label.setForeground(UIUtilities.convertColour(c)));
  74. }
  75. label.setText(value.getImportantMode() + value.getNickname());
  76. }
  77. @ConfigBinding(domain = "ui", key = "shownickcoloursinnicklist",
  78. invocation = EDTInvocation.class)
  79. public void handleShowColoursInNickList(final String value) {
  80. showColours = config.getOptionBool("ui", "shownickcoloursinnicklist");
  81. nicklist.repaint();
  82. }
  83. @ConfigBinding(domain = "ui", key = "nickListAltBackgroundColour",
  84. fallbacks = {"ui", "nicklistbackgroundcolour", "ui", "backgroundcolour"},
  85. invocation = EDTInvocation.class)
  86. public void handleColours(final String value) {
  87. altBackgroundColour = UIUtilities.convertColour(
  88. colourManager.getColourFromString(value, null));
  89. nicklist.repaint();
  90. }
  91. }