Ver código fonte

Store display properties in Line.

pull/228/head
Chris Smith 9 anos atrás
pai
commit
2e45dfbbe0

+ 3
- 1
src/com/dmdirc/FrameContainer.java Ver arquivo

@@ -24,6 +24,7 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.commandparser.parsers.CommandParser;
26 26
 import com.dmdirc.events.ClientLineAddedEvent;
27
+import com.dmdirc.events.DisplayPropertyMap;
27 28
 import com.dmdirc.events.FrameClosingEvent;
28 29
 import com.dmdirc.events.FrameComponentAddedEvent;
29 30
 import com.dmdirc.events.FrameComponentRemovedEvent;
@@ -493,7 +494,8 @@ public abstract class FrameContainer {
493 494
      */
494 495
     public void addLine(final String line, final Date timestamp) {
495 496
         for (final String myLine : line.split("\n")) {
496
-            getBackBuffer().getDocument().addText(timestamp.getTime(), myLine);
497
+            getBackBuffer().getDocument().addText(
498
+                    timestamp.getTime(), DisplayPropertyMap.EMPTY, myLine);
497 499
             eventBus.publishAsync(new ClientLineAddedEvent(this, myLine));
498 500
         }
499 501
     }

+ 5
- 0
src/com/dmdirc/events/ChannelDisplayableEvent.java Ver arquivo

@@ -65,4 +65,9 @@ public abstract class ChannelDisplayableEvent extends ChannelEvent implements Di
65 65
         return properties.get(property);
66 66
     }
67 67
 
68
+    @Override
69
+    public DisplayPropertyMap getDisplayProperties() {
70
+        return properties;
71
+    }
72
+
68 73
 }

+ 9
- 0
src/com/dmdirc/events/DisplayPropertyMap.java Ver arquivo

@@ -31,6 +31,8 @@ import java.util.concurrent.ConcurrentSkipListMap;
31 31
  */
32 32
 public class DisplayPropertyMap {
33 33
 
34
+    public static final DisplayPropertyMap EMPTY = new ReadOnlyDisplayPropertyMap();
35
+
34 36
     private final Map<DisplayProperty<?>, Object> properties = new ConcurrentSkipListMap<>();
35 37
 
36 38
     /**
@@ -56,4 +58,11 @@ public class DisplayPropertyMap {
56 58
         properties.put(property, value);
57 59
     }
58 60
 
61
+    private static class ReadOnlyDisplayPropertyMap extends DisplayPropertyMap {
62
+        @Override
63
+        public <T> void put(final DisplayProperty<T> property, final T value) {
64
+            throw new UnsupportedOperationException("Read only");
65
+        }
66
+    }
67
+
59 68
 }

+ 7
- 1
src/com/dmdirc/events/DisplayableEvent.java Ver arquivo

@@ -61,11 +61,17 @@ public interface DisplayableEvent {
61 61
      */
62 62
     <T> Optional<T> getDisplayProperty(DisplayProperty<T> property);
63 63
 
64
+    /**
65
+     * Gets the map of all display properties.
66
+     *
67
+     * @return The map of display properties.
68
+     */
69
+    DisplayPropertyMap getDisplayProperties();
70
+
64 71
     /**
65 72
      * Gets the timestamp at which the event occurred.
66 73
      *
67 74
      * @return The timestamp the event occurred at.
68 75
      */
69 76
     long getTimestamp();
70
-
71 77
 }

+ 4
- 0
src/com/dmdirc/events/QueryDisplayableEvent.java Ver arquivo

@@ -66,4 +66,8 @@ public abstract class QueryDisplayableEvent extends QueryEvent implements
66 66
         return properties.get(property);
67 67
     }
68 68
 
69
+    @Override
70
+    public DisplayPropertyMap getDisplayProperties() {
71
+        return properties;
72
+    }
69 73
 }

+ 5
- 0
src/com/dmdirc/events/ServerDisplayableEvent.java Ver arquivo

@@ -66,4 +66,9 @@ public abstract class ServerDisplayableEvent extends ServerEvent implements Disp
66 66
         return properties.get(property);
67 67
     }
68 68
 
69
+    @Override
70
+    public DisplayPropertyMap getDisplayProperties() {
71
+        return properties;
72
+    }
73
+
69 74
 }

+ 5
- 0
src/com/dmdirc/events/UnknownCommandEvent.java Ver arquivo

@@ -90,4 +90,9 @@ public class UnknownCommandEvent extends DMDircEvent implements DisplayableEvent
90 90
         return properties.get(property);
91 91
     }
92 92
 
93
+    @Override
94
+    public DisplayPropertyMap getDisplayProperties() {
95
+        return properties;
96
+    }
97
+
93 98
 }

+ 2
- 1
src/com/dmdirc/ui/messages/BackBuffer.java Ver arquivo

@@ -84,7 +84,8 @@ public class BackBuffer {
84 84
     @Handler
85 85
     public void handleDisplayableEvent(final DisplayableEvent event) {
86 86
         if (enabled && !event.getDisplayProperty(DisplayProperty.HANDLED).isPresent()) {
87
-            formatter.format(event).ifPresent(t -> document.addText(event.getTimestamp(), t));
87
+            formatter.format(event).ifPresent(
88
+                    t -> document.addText(event.getTimestamp(), event.getDisplayProperties(), t));
88 89
             event.setDisplayProperty(DisplayProperty.HANDLED, Boolean.TRUE);
89 90
         }
90 91
     }

+ 6
- 2
src/com/dmdirc/ui/messages/IRCDocument.java Ver arquivo

@@ -24,6 +24,7 @@ package com.dmdirc.ui.messages;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.events.AppErrorEvent;
27
+import com.dmdirc.events.DisplayPropertyMap;
27 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
28 29
 import com.dmdirc.interfaces.config.ConfigChangeListener;
29 30
 import com.dmdirc.logger.ErrorLevel;
@@ -117,13 +118,16 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
117 118
      * Adds the stylised string to the canvas.
118 119
      *
119 120
      * @param timestamp The timestamp to show along with the text.
121
+     * @param displayPropertyMap The display properties to use
120 122
      * @param text stylised string to add to the document
121 123
      */
122
-    public void addText(final long timestamp, final String text) {
124
+    public void addText(final long timestamp, final DisplayPropertyMap displayPropertyMap,
125
+            final String text) {
123 126
         final int start;
124 127
         synchronized (lines) {
125 128
             start = lines.size();
126
-            lines.add(new Line(styliser, formatTimestamp(timestamp), text, fontSize, fontName));
129
+            lines.add(new Line(styliser, formatTimestamp(timestamp), text, displayPropertyMap,
130
+                    fontSize, fontName));
127 131
         }
128 132
         fireLinesAdded(start, 1);
129 133
     }

+ 5
- 1
src/com/dmdirc/ui/messages/Line.java Ver arquivo

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.messages;
24 24
 
25
+import com.dmdirc.events.DisplayPropertyMap;
25 26
 import com.dmdirc.ui.core.util.ExtendedAttributedString;
26 27
 import com.dmdirc.ui.core.util.Utils;
27 28
 
@@ -38,6 +39,7 @@ public class Line {
38 39
     private final String timestamp;
39 40
     private final String text;
40 41
     private final Styliser styliser;
42
+    private final DisplayPropertyMap displayProperties;
41 43
     private int fontSize;
42 44
     private String fontName;
43 45
 
@@ -47,14 +49,16 @@ public class Line {
47 49
      * @param styliser  The styliser to use to style this line
48 50
      * @param timestamp The textual timestamp to use for the line
49 51
      * @param text      The textual content of the line
52
+     * @param displayProperties The properties to use when displaying the line.
50 53
      * @param fontSize  The height for this line
51 54
      * @param fontName  The name of the font to use for this line
52 55
      */
53 56
     public Line(final Styliser styliser, final String timestamp, final String text,
54
-            final int fontSize, final String fontName) {
57
+            final DisplayPropertyMap displayProperties, final int fontSize, final String fontName) {
55 58
         this.styliser = styliser;
56 59
         this.timestamp = timestamp; // TODO: Make this a long and convert further down the line
57 60
         this.text = text;
61
+        this.displayProperties = displayProperties;
58 62
         this.fontName = fontName;
59 63
         this.fontSize = fontSize;
60 64
     }

Carregando…
Cancelar
Salvar