Browse Source

Make highlight colours configurable.

pull/338/head
Chris Smith 9 years ago
parent
commit
a63f70b05c

+ 2
- 0
res/com/dmdirc/config/defaults/default/defaults View File

@@ -174,6 +174,8 @@ ui:
174 174
   miscellaneousNotificationColour=3
175 175
   messageNotificationColour=12
176 176
   highlightNotificationColour=4
177
+  highlightLineBackgroundColour=F9C4BB
178
+  highlightLineForegroundColour=
177 179
 
178 180
 treeview:
179 181
   dragSelection=true

+ 5
- 1
src/com/dmdirc/Server.java View File

@@ -55,6 +55,7 @@ import com.dmdirc.ui.core.components.WindowComponent;
55 55
 import com.dmdirc.ui.input.TabCompleterFactory;
56 56
 import com.dmdirc.ui.input.TabCompletionType;
57 57
 import com.dmdirc.ui.messages.BackBufferFactory;
58
+import com.dmdirc.ui.messages.ColourManager;
58 59
 import com.dmdirc.ui.messages.Formatter;
59 60
 import com.dmdirc.ui.messages.HighlightManager;
60 61
 import com.dmdirc.ui.messages.sink.MessageSinkManager;
@@ -239,7 +240,9 @@ public class Server extends FrameContainer implements Connection {
239 240
         getConfigManager().addChangeListener("formatter", "serverName", configListener);
240 241
         getConfigManager().addChangeListener("formatter", "serverTitle", configListener);
241 242
 
242
-        this.highlightManager = new HighlightManager();
243
+        this.highlightManager = new HighlightManager(getConfigManager(),
244
+                new ColourManager(getConfigManager(), getEventBus()));
245
+        highlightManager.init();
243 246
         getEventBus().subscribe(highlightManager);
244 247
     }
245 248
 
@@ -852,6 +855,7 @@ public class Server extends FrameContainer implements Connection {
852 855
         synchronized (myStateLock) {
853 856
             eventHandler.unregisterCallbacks();
854 857
             getConfigManager().removeListener(configListener);
858
+            highlightManager.stop();
855 859
             getEventBus().unsubscribe(highlightManager);
856 860
             executorService.shutdown();
857 861
 

+ 56
- 6
src/com/dmdirc/ui/messages/HighlightManager.java View File

@@ -22,16 +22,21 @@
22 22
 
23 23
 package com.dmdirc.ui.messages;
24 24
 
25
+import com.dmdirc.config.ConfigBinding;
25 26
 import com.dmdirc.events.BaseChannelTextEvent;
26 27
 import com.dmdirc.events.BaseQueryTextEvent;
27 28
 import com.dmdirc.events.ChannelHighlightEvent;
28 29
 import com.dmdirc.events.DisplayProperty;
30
+import com.dmdirc.events.DisplayableEvent;
29 31
 import com.dmdirc.events.QueryHighlightEvent;
30 32
 import com.dmdirc.events.ServerConnectedEvent;
31 33
 import com.dmdirc.events.ServerNickchangeEvent;
32 34
 import com.dmdirc.interfaces.User;
35
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
33 36
 import com.dmdirc.util.colours.Colour;
34 37
 
38
+import com.google.common.base.Strings;
39
+
35 40
 import java.util.ArrayList;
36 41
 import java.util.Collection;
37 42
 import java.util.Optional;
@@ -48,35 +53,80 @@ public class HighlightManager {
48 53
             "(\\p{Space}|\\p{Punct}|$).*";
49 54
 
50 55
     private final Collection<Pattern> patterns = new ArrayList<>();
56
+    private final AggregateConfigProvider configProvider;
57
+    private final ColourManager colourManager;
51 58
 
52 59
     private Optional<Pattern> nicknamePattern = Optional.empty();
53 60
 
61
+    private Optional<Colour> backgroundColour = Optional.of(Colour.RED);
62
+    private Optional<Colour> foregroundColour = Optional.empty();
63
+
64
+    public HighlightManager(
65
+            final AggregateConfigProvider configProvider,
66
+            final ColourManager colourManager) {
67
+        this.configProvider = configProvider;
68
+        this.colourManager = colourManager;
69
+    }
70
+
71
+    public void init() {
72
+        configProvider.getBinder().bind(this, HighlightManager.class);
73
+    }
74
+
75
+    public void stop() {
76
+        configProvider.getBinder().unbind(this);
77
+    }
78
+
54 79
     @Handler
55
-    public void handleChannelMessage(final BaseChannelTextEvent event) {
80
+    void handleChannelMessage(final BaseChannelTextEvent event) {
56 81
         if (patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
57
-            event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, Colour.RED);
82
+            setColours(event);
58 83
             event.getChannel().getEventBus().publishAsync(new ChannelHighlightEvent(event));
59 84
         }
60 85
     }
61 86
 
62 87
     @Handler
63
-    public void handleQueryMessage(final BaseQueryTextEvent event) {
88
+    void handleQueryMessage(final BaseQueryTextEvent event) {
64 89
         if (patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
65
-            event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, Colour.RED);
90
+            setColours(event);
66 91
             event.getQuery().getEventBus().publishAsync(new QueryHighlightEvent(event));
67 92
         }
68 93
     }
69 94
 
70 95
     @Handler
71
-    public void handleNickChange(final ServerNickchangeEvent event) {
96
+    void handleNickChange(final ServerNickchangeEvent event) {
72 97
         setNickname(event.getNewNick());
73 98
     }
74 99
 
75 100
     @Handler
76
-    public void handleConnected(final ServerConnectedEvent event) {
101
+    void handleConnected(final ServerConnectedEvent event) {
77 102
         event.getConnection().getLocalUser().map(User::getNickname).ifPresent(this::setNickname);
78 103
     }
79 104
 
105
+    @ConfigBinding(domain = "ui", key = "highlightLineForegroundColour")
106
+    void handleForegroundColour(final String value) {
107
+        if (Strings.isNullOrEmpty(value)) {
108
+            foregroundColour = Optional.empty();
109
+        } else {
110
+            foregroundColour = Optional.ofNullable(colourManager.getColourFromString(value, null));
111
+        }
112
+    }
113
+
114
+    @ConfigBinding(domain = "ui", key = "highlightLineBackgroundColour")
115
+    void handleBackgroundColour(final String value) {
116
+        if (Strings.isNullOrEmpty(value)) {
117
+            backgroundColour = Optional.empty();
118
+        } else {
119
+            backgroundColour = Optional.ofNullable(colourManager.getColourFromString(value, null));
120
+        }
121
+    }
122
+
123
+    private void setColours(final DisplayableEvent event) {
124
+        backgroundColour.ifPresent(
125
+                c -> event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, c));
126
+        foregroundColour.ifPresent(
127
+                c -> event.setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, c));
128
+    }
129
+
80 130
     private void setNickname(final String newNick) {
81 131
         nicknamePattern.ifPresent(patterns::remove);
82 132
         nicknamePattern = Optional.of(compile(newNick));

Loading…
Cancel
Save