Browse Source

Merge pull request #711 from csmith/master

Extract interfaces for BackBuffer and IRCDocument.
pull/712/head
Greg Holmes 7 years ago
parent
commit
5a05e46ff5

src/main/java/com/dmdirc/events/DisplayPropertyMap.java → api/src/main/java/com/dmdirc/events/DisplayPropertyMap.java View File


+ 69
- 0
api/src/main/java/com/dmdirc/ui/messages/Document.java View File

@@ -0,0 +1,69 @@
1
+package com.dmdirc.ui.messages;
2
+
3
+import com.dmdirc.events.DisplayPropertyMap;
4
+import java.time.LocalDateTime;
5
+
6
+/**
7
+ * Models the content of a window, as a series of lines.
8
+ */
9
+public interface Document {
10
+
11
+    /**
12
+     * Returns the number of lines in this document.
13
+     *
14
+     * @return Number of lines
15
+     */
16
+    int getNumLines();
17
+
18
+    /**
19
+     * Returns the Line at the specified number.
20
+     *
21
+     * @param lineNumber Line number to retrieve
22
+     *
23
+     * @return Line at the specified number or null
24
+     */
25
+    Line getLine(int lineNumber);
26
+
27
+    /**
28
+     * Adds the stylised string to the canvas.
29
+     *
30
+     * @param timestamp The timestamp to show along with the text.
31
+     * @param displayPropertyMap The display properties to use
32
+     * @param text stylised string to add to the document
33
+     */
34
+    void addText(LocalDateTime timestamp, DisplayPropertyMap displayPropertyMap, String text);
35
+
36
+    /**
37
+     * Trims the document to the specified number of lines.
38
+     *
39
+     * @param numLines Number of lines to trim the document to
40
+     */
41
+    void trim(int numLines);
42
+
43
+    /** Clears all lines from the document. */
44
+    void clear();
45
+
46
+    /**
47
+     * Adds a DocumentListener to the listener list.
48
+     *
49
+     * @param listener Listener to add
50
+     */
51
+    void addIRCDocumentListener(DocumentListener listener);
52
+
53
+    /**
54
+     * Removes a DocumentListener from the listener list.
55
+     *
56
+     * @param listener Listener to remove
57
+     */
58
+    void removeIRCDocumentListener(DocumentListener listener);
59
+
60
+    /**
61
+     * Returns the line height of the specified.
62
+     *
63
+     * @param line Line
64
+     *
65
+     * @return Line height
66
+     */
67
+    int getLineHeight(int line);
68
+
69
+}

src/main/java/com/dmdirc/ui/messages/IRCDocumentListener.java → api/src/main/java/com/dmdirc/ui/messages/DocumentListener.java View File

@@ -25,9 +25,9 @@ package com.dmdirc.ui.messages;
25 25
 import java.util.EventListener;
26 26
 
27 27
 /**
28
- * Interface for IRCDocument listeners.
28
+ * Interface for document listeners.
29 29
  */
30
-public interface IRCDocumentListener extends EventListener {
30
+public interface DocumentListener extends EventListener {
31 31
 
32 32
     /**
33 33
      * A line has been added to the textpane.

+ 85
- 0
api/src/main/java/com/dmdirc/ui/messages/Line.java View File

@@ -0,0 +1,85 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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
+
23
+package com.dmdirc.ui.messages;
24
+
25
+import com.dmdirc.events.DisplayProperty;
26
+import java.util.Optional;
27
+
28
+/**
29
+ * Represents a line of text in IRC.
30
+ */
31
+public interface Line {
32
+
33
+    /**
34
+     * Returns the length of the specified line.
35
+     *
36
+     * @return Length of the line
37
+     */
38
+    int getLength();
39
+
40
+    /**
41
+     * Returns the height of the specified line.
42
+     *
43
+     * @return Line height
44
+     */
45
+    int getFontSize();
46
+
47
+    /**
48
+     * Sets the default font size for this line.
49
+     *
50
+     * @param fontSize New default font size
51
+     */
52
+    void setFontSize(final int fontSize);
53
+
54
+    /**
55
+     * Sets the default font name for this line.
56
+     *
57
+     * @param fontName New default font name
58
+     */
59
+    void setFontName(final String fontName);
60
+
61
+    /**
62
+     * Returns the Line text at the specified number.
63
+     *
64
+     * @return Line at the specified number or null
65
+     */
66
+    String getText();
67
+
68
+    /**
69
+     * Returns the Line text at the specified number.
70
+     *
71
+     * @return Line at the specified number or null
72
+     *
73
+     * @since 0.6.3m1
74
+     */
75
+    String getStyledText();
76
+
77
+    /**
78
+     * Converts a StyledDocument into an AttributedString.
79
+     *
80
+     * @return AttributedString representing the specified StyledDocument
81
+     */
82
+    <T> T getStyled(final StyledMessageMaker<T> maker);
83
+
84
+    <T> Optional<T> getDisplayableProperty(DisplayProperty<T> property);
85
+}

src/main/java/com/dmdirc/ui/messages/StyledMessageMaker.java → api/src/main/java/com/dmdirc/ui/messages/StyledMessageMaker.java View File


+ 3
- 2
src/main/java/com/dmdirc/FrameContainer.java View File

@@ -37,6 +37,7 @@ import com.dmdirc.interfaces.config.ConfigChangeListener;
37 37
 import com.dmdirc.parser.common.CompositionState;
38 38
 import com.dmdirc.ui.messages.BackBuffer;
39 39
 import com.dmdirc.ui.messages.BackBufferFactory;
40
+import com.dmdirc.ui.messages.BackBufferImpl;
40 41
 import com.dmdirc.ui.messages.UnreadStatusManager;
41 42
 
42 43
 import java.util.Collection;
@@ -72,7 +73,7 @@ public class FrameContainer implements WindowModel {
72 73
     /** The back buffer factory. */
73 74
     private final BackBufferFactory backBufferFactory;
74 75
     /** The back buffer for this container. */
75
-    private BackBuffer backBuffer;
76
+    private BackBufferImpl backBuffer;
76 77
     /** The input model for this container. */
77 78
     private Optional<InputModel> inputModel = Optional.empty();
78 79
     /** The connection associated with this model. */
@@ -208,7 +209,7 @@ public class FrameContainer implements WindowModel {
208 209
         eventBus.unsubscribe(unreadStatusManager);
209 210
         configManager.getBinder().unbind(unreadStatusManager);
210 211
         eventBus.publish(new FrameClosingEvent(this));
211
-        getBackBuffer().stopAddingEvents();
212
+        backBuffer.stopAddingEvents();
212 213
     }
213 214
 
214 215
     @Override

+ 4
- 76
src/main/java/com/dmdirc/ui/messages/BackBuffer.java View File

@@ -22,86 +22,14 @@
22 22
 
23 23
 package com.dmdirc.ui.messages;
24 24
 
25
-import com.dmdirc.events.DisplayProperty;
26
-import com.dmdirc.events.DisplayableEvent;
27
-import com.dmdirc.interfaces.EventBus;
28
-import com.dmdirc.interfaces.WindowModel;
29
-import com.dmdirc.util.EventUtils;
30
-
31
-import java.util.Arrays;
32
-
33
-import net.engio.mbassy.listener.Handler;
34
-
35 25
 /**
36 26
  * Models the history of a window in the client.
37 27
  */
38
-public class BackBuffer {
39
-
40
-    private final IRCDocument document;
41
-    private final Styliser styliser;
42
-    private final EventBus eventBus;
43
-    private final EventFormatter formatter;
44
-    private final WindowModel owner;
45
-
46
-    public BackBuffer(
47
-            final WindowModel owner,
48
-            final ColourManagerFactory colourManagerFactory,
49
-            final EventFormatter formatter) {
50
-        this.owner = owner;
51
-        this.styliser = new Styliser(
52
-                owner.getConnection().orElse(null),
53
-                owner.getConfigManager(),
54
-                colourManagerFactory.getColourManager(owner.getConfigManager()));
55
-        this.document = new IRCDocument(owner.getConfigManager(), styliser);
56
-        this.eventBus = owner.getEventBus();
57
-        this.formatter = formatter;
58
-    }
28
+public interface BackBuffer {
59 29
 
60
-    /**
61
-     * Starts adding events received on the event bus to this buffer's document.
62
-     */
63
-    public void startAddingEvents() {
64
-        eventBus.subscribe(this);
65
-    }
30
+    Document getDocument();
66 31
 
67
-    /**
68
-     * Stops adding events received on the event bus to this buffer's document.
69
-     */
70
-    public void stopAddingEvents() {
71
-        eventBus.unsubscribe(this);
72
-    }
73
-
74
-    /**
75
-     * Handles a displayable event received on the event bus.
76
-     *
77
-     * @param event The event to be displayed.
78
-     */
79
-    @Handler(priority = EventUtils.PRIORITY_DISPLAYABLE_EVENT_HANDLER)
80
-    private void handleDisplayableEvent(final DisplayableEvent event) {
81
-        if (shouldDisplay(event)) {
82
-            formatter.format(event).map(s -> s.split("\n")).map(Arrays::stream).ifPresent(
83
-                    t -> t.forEach(line -> document.addText(
84
-                            event.getTimestamp(), event.getDisplayProperties(), line)));
85
-        }
86
-    }
87
-
88
-    /**
89
-     * Determines if the specified event should be displayed in this backbuffer.
90
-     *
91
-     * @param event The event to check
92
-     * @return True if the event should be displayed, false otherwise.
93
-     */
94
-    private boolean shouldDisplay(final DisplayableEvent event) {
95
-        return event.getSource().equals(owner)
96
-                && !event.hasDisplayProperty(DisplayProperty.DO_NOT_DISPLAY);
97
-    }
98
-
99
-    public IRCDocument getDocument() {
100
-        return document;
101
-    }
102
-
103
-    public Styliser getStyliser() {
104
-        return styliser;
105
-    }
32
+    Styliser getStyliser();
106 33
 
107 34
 }
35
+

+ 2
- 2
src/main/java/com/dmdirc/ui/messages/BackBufferFactory.java View File

@@ -44,8 +44,8 @@ public class BackBufferFactory {
44 44
         this.formatter = formatter;
45 45
     }
46 46
 
47
-    public BackBuffer getBackBuffer(final WindowModel owner) {
48
-        return new BackBuffer(owner, colourManagerFactory, formatter);
47
+    public BackBufferImpl getBackBuffer(final WindowModel owner) {
48
+        return new BackBufferImpl(owner, colourManagerFactory, formatter);
49 49
     }
50 50
 
51 51
 }

+ 107
- 0
src/main/java/com/dmdirc/ui/messages/BackBufferImpl.java View File

@@ -0,0 +1,107 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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
+
23
+package com.dmdirc.ui.messages;
24
+
25
+import com.dmdirc.events.DisplayProperty;
26
+import com.dmdirc.events.DisplayableEvent;
27
+import com.dmdirc.interfaces.EventBus;
28
+import com.dmdirc.interfaces.WindowModel;
29
+import com.dmdirc.util.EventUtils;
30
+import java.util.Arrays;
31
+import net.engio.mbassy.listener.Handler;
32
+
33
+/**
34
+ * Models the history of a window in the client.
35
+ */
36
+public class BackBufferImpl implements BackBuffer {
37
+
38
+    private final Document document;
39
+    private final Styliser styliser;
40
+    private final EventBus eventBus;
41
+    private final EventFormatter formatter;
42
+    private final WindowModel owner;
43
+
44
+    public BackBufferImpl(
45
+            final WindowModel owner,
46
+            final ColourManagerFactory colourManagerFactory,
47
+            final EventFormatter formatter) {
48
+        this.owner = owner;
49
+        this.styliser = new Styliser(
50
+                owner.getConnection().orElse(null),
51
+                owner.getConfigManager(),
52
+                colourManagerFactory.getColourManager(owner.getConfigManager()));
53
+        this.document = new IRCDocument(owner.getConfigManager(), styliser);
54
+        this.eventBus = owner.getEventBus();
55
+        this.formatter = formatter;
56
+    }
57
+
58
+    /**
59
+     * Starts adding events received on the event bus to this buffer's document.
60
+     */
61
+    public void startAddingEvents() {
62
+        eventBus.subscribe(this);
63
+    }
64
+
65
+    /**
66
+     * Stops adding events received on the event bus to this buffer's document.
67
+     */
68
+    public void stopAddingEvents() {
69
+        eventBus.unsubscribe(this);
70
+    }
71
+
72
+    /**
73
+     * Handles a displayable event received on the event bus.
74
+     *
75
+     * @param event The event to be displayed.
76
+     */
77
+    @Handler(priority = EventUtils.PRIORITY_DISPLAYABLE_EVENT_HANDLER)
78
+    private void handleDisplayableEvent(final DisplayableEvent event) {
79
+        if (shouldDisplay(event)) {
80
+            formatter.format(event).map(s -> s.split("\n")).map(Arrays::stream).ifPresent(
81
+                    t -> t.forEach(line -> document.addText(
82
+                            event.getTimestamp(), event.getDisplayProperties(), line)));
83
+        }
84
+    }
85
+
86
+    /**
87
+     * Determines if the specified event should be displayed in this backbuffer.
88
+     *
89
+     * @param event The event to check
90
+     * @return True if the event should be displayed, false otherwise.
91
+     */
92
+    private boolean shouldDisplay(final DisplayableEvent event) {
93
+        return event.getSource().equals(owner)
94
+                && !event.hasDisplayProperty(DisplayProperty.DO_NOT_DISPLAY);
95
+    }
96
+
97
+    @Override
98
+    public Document getDocument() {
99
+        return document;
100
+    }
101
+
102
+    @Override
103
+    public Styliser getStyliser() {
104
+        return styliser;
105
+    }
106
+
107
+}

+ 2
- 2
src/main/java/com/dmdirc/ui/messages/CachingDocument.java View File

@@ -31,7 +31,7 @@ import com.dmdirc.util.collections.RollingList;
31 31
 public class CachingDocument<T> {
32 32
 
33 33
     /** The document to wrap and cache data from. */
34
-    private final IRCDocument document;
34
+    private final Document document;
35 35
     /** The maker to use to produce styled lines. */
36 36
     private final StyledMessageMaker<T> maker;
37 37
     /** Cached lines. */
@@ -39,7 +39,7 @@ public class CachingDocument<T> {
39 39
     /** Cached attributed strings. */
40 40
     private final RollingList<T> cachedStrings;
41 41
 
42
-    public CachingDocument(final IRCDocument document, final StyledMessageMaker<T> maker) {
42
+    public CachingDocument(final Document document, final StyledMessageMaker<T> maker) {
43 43
         this.document = document;
44 44
         this.maker = maker;
45 45
 

+ 21
- 55
src/main/java/com/dmdirc/ui/messages/IRCDocument.java View File

@@ -38,7 +38,7 @@ import javax.swing.UIManager;
38 38
 /**
39 39
  * Data contained in a TextPane.
40 40
  */
41
-public class IRCDocument implements Serializable, ConfigChangeListener {
41
+public class IRCDocument implements Serializable, ConfigChangeListener, Document {
42 42
 
43 43
     /** A version number for this class. */
44 44
     private static final long serialVersionUID = 4;
@@ -73,43 +73,27 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
73 73
         setCachedSettings();
74 74
     }
75 75
 
76
-    /**
77
-     * Returns the number of lines in this document.
78
-     *
79
-     * @return Number of lines
80
-     */
76
+    @Override
81 77
     public int getNumLines() {
82 78
         synchronized (lines) {
83 79
             return lines.size();
84 80
         }
85 81
     }
86 82
 
87
-    /**
88
-     * Returns the Line at the specified number.
89
-     *
90
-     * @param lineNumber Line number to retrieve
91
-     *
92
-     * @return Line at the specified number or null
93
-     */
83
+    @Override
94 84
     public Line getLine(final int lineNumber) {
95 85
         synchronized (lines) {
96 86
             return lines.get(lineNumber);
97 87
         }
98 88
     }
99 89
 
100
-    /**
101
-     * Adds the stylised string to the canvas.
102
-     *
103
-     * @param timestamp The timestamp to show along with the text.
104
-     * @param displayPropertyMap The display properties to use
105
-     * @param text stylised string to add to the document
106
-     */
90
+    @Override
107 91
     public void addText(final LocalDateTime timestamp, final DisplayPropertyMap displayPropertyMap,
108
-            final String text) {
92
+        final String text) {
109 93
         final int start;
110 94
         synchronized (lines) {
111 95
             start = lines.size();
112
-            lines.add(new Line(styliser, formatTimestamp(timestamp), text, displayPropertyMap,
96
+            lines.add(new IRCLine(styliser, formatTimestamp(timestamp), text, displayPropertyMap,
113 97
                     fontSize, fontName));
114 98
         }
115 99
         fireLinesAdded(start, 1);
@@ -119,11 +103,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
119 103
         return Formatter.formatMessage(configManager, "timestamp", timestamp);
120 104
     }
121 105
 
122
-    /**
123
-     * Trims the document to the specified number of lines.
124
-     *
125
-     * @param numLines Number of lines to trim the document to
126
-     */
106
+    @Override
127 107
     public void trim(final int numLines) {
128 108
         synchronized (lines) {
129 109
             if (frameBufferSize != null && frameBufferSize > 0) {
@@ -136,7 +116,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
136 116
         }
137 117
     }
138 118
 
139
-    /** Clears all lines from the document. */
119
+    @Override
140 120
     public void clear() {
141 121
         synchronized (lines) {
142 122
             lines.clear();
@@ -144,26 +124,18 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
144 124
         fireCleared();
145 125
     }
146 126
 
147
-    /**
148
-     * Adds a IRCDocumentListener to the listener list.
149
-     *
150
-     * @param listener Listener to add
151
-     */
152
-    public void addIRCDocumentListener(final IRCDocumentListener listener) {
127
+    @Override
128
+    public void addIRCDocumentListener(final DocumentListener listener) {
153 129
         if (listener == null) {
154 130
             return;
155 131
         }
156 132
 
157
-        listeners.add(IRCDocumentListener.class, listener);
133
+        listeners.add(DocumentListener.class, listener);
158 134
     }
159 135
 
160
-    /**
161
-     * Removes a IRCDocumentListener from the listener list.
162
-     *
163
-     * @param listener Listener to remove
164
-     */
165
-    public void removeIRCDocumentListener(final IRCDocumentListener listener) {
166
-        listeners.remove(IRCDocumentListener.class, listener);
136
+    @Override
137
+    public void removeIRCDocumentListener(final DocumentListener listener) {
138
+        listeners.remove(DocumentListener.class, listener);
167 139
     }
168 140
 
169 141
     /**
@@ -173,8 +145,8 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
173 145
      * @param size  Number of lines added
174 146
      */
175 147
     protected void fireLinesAdded(final int index, final int size) {
176
-        for (IRCDocumentListener listener
177
-                : listeners.get(IRCDocumentListener.class)) {
148
+        for (DocumentListener listener
149
+                : listeners.get(DocumentListener.class)) {
178 150
             listener.linesAdded(index, size, lines.size());
179 151
         }
180 152
         trim(frameBufferSize);
@@ -187,8 +159,8 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
187 159
      * @param trimmedLines Number of trimmed lines
188 160
      */
189 161
     protected void fireTrimmed(final int newSize, final int trimmedLines) {
190
-        for (IRCDocumentListener listener
191
-                : listeners.get(IRCDocumentListener.class)) {
162
+        for (DocumentListener listener
163
+                : listeners.get(DocumentListener.class)) {
192 164
             listener.trimmed(newSize, trimmedLines);
193 165
         }
194 166
     }
@@ -197,14 +169,14 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
197 169
      * fires the cleared method on all listeners.
198 170
      */
199 171
     protected void fireCleared() {
200
-        listeners.get(IRCDocumentListener.class).forEach(IRCDocumentListener::cleared);
172
+        listeners.get(DocumentListener.class).forEach(DocumentListener::cleared);
201 173
     }
202 174
 
203 175
     /**
204 176
      * fires the need repaint method on all listeners.
205 177
      */
206 178
     protected void fireRepaintNeeded() {
207
-        listeners.get(IRCDocumentListener.class).forEach(IRCDocumentListener::repaintNeeded);
179
+        listeners.get(DocumentListener.class).forEach(DocumentListener::repaintNeeded);
208 180
     }
209 181
 
210 182
     /**
@@ -218,13 +190,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
218 190
         return line.getFontSize();
219 191
     }
220 192
 
221
-    /**
222
-     * Returns the line height of the specified.
223
-     *
224
-     * @param line Line
225
-     *
226
-     * @return Line height
227
-     */
193
+    @Override
228 194
     public int getLineHeight(final int line) {
229 195
         return getLineHeight(getLine(line));
230 196
     }

+ 2
- 2
src/main/java/com/dmdirc/ui/messages/IRCDocumentSearcher.java View File

@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
33 33
 public class IRCDocumentSearcher {
34 34
 
35 35
     /** Document to search. */
36
-    private final IRCDocument document;
36
+    private final Document document;
37 37
     /** Phrase to search for. */
38 38
     private final String phrase;
39 39
     /** Textpane position. */
@@ -48,7 +48,7 @@ public class IRCDocumentSearcher {
48 48
      * @param document      Document to search
49 49
      * @param caseSensitive Whether or not this searcher is case sensitive
50 50
      */
51
-    public IRCDocumentSearcher(final String phrase, final IRCDocument document,
51
+    public IRCDocumentSearcher(final String phrase, final Document document,
52 52
             final boolean caseSensitive) {
53 53
         this.phrase = phrase;
54 54
         this.document = document;

src/main/java/com/dmdirc/ui/messages/Line.java → src/main/java/com/dmdirc/ui/messages/IRCLine.java View File

@@ -24,14 +24,13 @@ package com.dmdirc.ui.messages;
24 24
 
25 25
 import com.dmdirc.events.DisplayProperty;
26 26
 import com.dmdirc.events.DisplayPropertyMap;
27
-
28 27
 import java.util.Arrays;
29 28
 import java.util.Optional;
30 29
 
31 30
 /**
32 31
  * Represents a line of text in IRC.
33 32
  */
34
-public class Line {
33
+public class IRCLine implements Line {
35 34
 
36 35
     private final String timestamp;
37 36
     private final String text;
@@ -50,7 +49,7 @@ public class Line {
50 49
      * @param fontSize  The height for this line
51 50
      * @param fontName  The name of the font to use for this line
52 51
      */
53
-    public Line(final Styliser styliser, final String timestamp, final String text,
52
+    public IRCLine(final Styliser styliser, final String timestamp, final String text,
54 53
             final DisplayPropertyMap displayProperties, final int fontSize, final String fontName) {
55 54
         this.styliser = styliser;
56 55
         this.timestamp = timestamp; // TODO: Make this a long and convert further down the line
@@ -65,7 +64,7 @@ public class Line {
65 64
      *
66 65
      * @return Lines parts
67 66
      */
68
-    public String[] getLineParts() {
67
+    private String[] getLineParts() {
69 68
         if (displayProperties.get(DisplayProperty.NO_TIMESTAMPS).orElse(false)) {
70 69
             return new String[] { text };
71 70
         } else {
@@ -73,67 +72,37 @@ public class Line {
73 72
         }
74 73
     }
75 74
 
76
-    /**
77
-     * Returns the length of the specified line.
78
-     *
79
-     * @return Length of the line
80
-     */
75
+    @Override
81 76
     public int getLength() {
82 77
         return timestamp.length() + text.length();
83 78
     }
84 79
 
85
-    /**
86
-     * Returns the height of the specified line.
87
-     *
88
-     * @return Line height
89
-     */
80
+    @Override
90 81
     public int getFontSize() {
91 82
         return fontSize;
92 83
     }
93 84
 
94
-    /**
95
-     * Sets the default font size for this line.
96
-     *
97
-     * @param fontSize New default font size
98
-     */
85
+    @Override
99 86
     public void setFontSize(final int fontSize) {
100 87
         this.fontSize = fontSize;
101 88
     }
102 89
 
103
-    /**
104
-     * Sets the default font name for this line.
105
-     *
106
-     * @param fontName New default font name
107
-     */
90
+    @Override
108 91
     public void setFontName(final String fontName) {
109 92
         this.fontName = fontName;
110 93
     }
111 94
 
112
-    /**
113
-     * Returns the Line text at the specified number.
114
-     *
115
-     * @return Line at the specified number or null
116
-     */
95
+    @Override
117 96
     public String getText() {
118 97
         return Styliser.stipControlCodes(timestamp + text);
119 98
     }
120 99
 
121
-    /**
122
-     * Returns the Line text at the specified number.
123
-     *
124
-     * @return Line at the specified number or null
125
-     *
126
-     * @since 0.6.3m1
127
-     */
100
+    @Override
128 101
     public String getStyledText() {
129 102
         return timestamp + text;
130 103
     }
131 104
 
132
-    /**
133
-     * Converts a StyledDocument into an AttributedString.
134
-     *
135
-     * @return AttributedString representing the specified StyledDocument
136
-     */
105
+    @Override
137 106
     public <T> T getStyled(final StyledMessageMaker<T> maker) {
138 107
         maker.setDefaultFont(fontName, fontSize);
139 108
         final T styledString = styliser.getStyledString(getLineParts(), maker);
@@ -144,7 +113,7 @@ public class Line {
144 113
 
145 114
     @Override
146 115
     public boolean equals(final Object obj) {
147
-        return obj instanceof Line && Arrays.equals(((Line) obj).getLineParts(), getLineParts());
116
+        return obj instanceof Line && Arrays.equals(((IRCLine) obj).getLineParts(), getLineParts());
148 117
     }
149 118
 
150 119
     @Override
@@ -152,6 +121,7 @@ public class Line {
152 121
         return Arrays.hashCode(getLineParts());
153 122
     }
154 123
 
124
+    @Override
155 125
     public <T> Optional<T> getDisplayableProperty(final DisplayProperty<T> property) {
156 126
         return displayProperties.get(property);
157 127
     }

Loading…
Cancel
Save