Ver código fonte

Extract an interface for Line.

pull/711/head
Chris Smith 7 anos atrás
pai
commit
89a09f4760

src/main/java/com/dmdirc/events/DisplayPropertyMap.java → api/src/main/java/com/dmdirc/events/DisplayPropertyMap.java Ver arquivo


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

@@ -31,8 +31,7 @@ public interface Document {
31 31
      * @param displayPropertyMap The display properties to use
32 32
      * @param text stylised string to add to the document
33 33
      */
34
-    void addText(LocalDateTime timestamp, DisplayPropertyMap displayPropertyMap,
35
-        String text);
34
+    void addText(LocalDateTime timestamp, DisplayPropertyMap displayPropertyMap, String text);
36 35
 
37 36
     /**
38 37
      * Trims the document to the specified number of lines.

+ 1
- 1
src/main/java/com/dmdirc/ui/messages/IRCDocument.java Ver arquivo

@@ -93,7 +93,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener, Document
93 93
         final int start;
94 94
         synchronized (lines) {
95 95
             start = lines.size();
96
-            lines.add(new Line(styliser, formatTimestamp(timestamp), text, displayPropertyMap,
96
+            lines.add(new IRCLine(styliser, formatTimestamp(timestamp), text, displayPropertyMap,
97 97
                     fontSize, fontName));
98 98
         }
99 99
         fireLinesAdded(start, 1);

+ 129
- 0
src/main/java/com/dmdirc/ui/messages/IRCLine.java Ver arquivo

@@ -0,0 +1,129 @@
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.DisplayPropertyMap;
27
+import java.util.Arrays;
28
+import java.util.Optional;
29
+
30
+/**
31
+ * Represents a line of text in IRC.
32
+ */
33
+public class IRCLine implements Line {
34
+
35
+    private final String timestamp;
36
+    private final String text;
37
+    private final Styliser styliser;
38
+    private final DisplayPropertyMap displayProperties;
39
+    private int fontSize;
40
+    private String fontName;
41
+
42
+    /**
43
+     * Creates a new line with a specified height.
44
+     *
45
+     * @param styliser  The styliser to use to style this line
46
+     * @param timestamp The textual timestamp to use for the line
47
+     * @param text      The textual content of the line
48
+     * @param displayProperties The properties to use when displaying the line.
49
+     * @param fontSize  The height for this line
50
+     * @param fontName  The name of the font to use for this line
51
+     */
52
+    public IRCLine(final Styliser styliser, final String timestamp, final String text,
53
+            final DisplayPropertyMap displayProperties, final int fontSize, final String fontName) {
54
+        this.styliser = styliser;
55
+        this.timestamp = timestamp; // TODO: Make this a long and convert further down the line
56
+        this.text = text;
57
+        this.displayProperties = displayProperties;
58
+        this.fontName = fontName;
59
+        this.fontSize = fontSize;
60
+    }
61
+
62
+    /**
63
+     * Returns the line parts of this line.
64
+     *
65
+     * @return Lines parts
66
+     */
67
+    private String[] getLineParts() {
68
+        if (displayProperties.get(DisplayProperty.NO_TIMESTAMPS).orElse(false)) {
69
+            return new String[] { text };
70
+        } else {
71
+            return new String[] { timestamp, text };
72
+        }
73
+    }
74
+
75
+    @Override
76
+    public int getLength() {
77
+        return timestamp.length() + text.length();
78
+    }
79
+
80
+    @Override
81
+    public int getFontSize() {
82
+        return fontSize;
83
+    }
84
+
85
+    @Override
86
+    public void setFontSize(final int fontSize) {
87
+        this.fontSize = fontSize;
88
+    }
89
+
90
+    @Override
91
+    public void setFontName(final String fontName) {
92
+        this.fontName = fontName;
93
+    }
94
+
95
+    @Override
96
+    public String getText() {
97
+        return Styliser.stipControlCodes(timestamp + text);
98
+    }
99
+
100
+    @Override
101
+    public String getStyledText() {
102
+        return timestamp + text;
103
+    }
104
+
105
+    @Override
106
+    public <T> T getStyled(final StyledMessageMaker<T> maker) {
107
+        maker.setDefaultFont(fontName, fontSize);
108
+        final T styledString = styliser.getStyledString(getLineParts(), maker);
109
+        fontSize = maker.getMaximumFontSize();
110
+        maker.clear();
111
+        return styledString;
112
+    }
113
+
114
+    @Override
115
+    public boolean equals(final Object obj) {
116
+        return obj instanceof Line && Arrays.equals(((IRCLine) obj).getLineParts(), getLineParts());
117
+    }
118
+
119
+    @Override
120
+    public int hashCode() {
121
+        return Arrays.hashCode(getLineParts());
122
+    }
123
+
124
+    @Override
125
+    public <T> Optional<T> getDisplayableProperty(final DisplayProperty<T> property) {
126
+        return displayProperties.get(property);
127
+    }
128
+
129
+}

+ 9
- 83
src/main/java/com/dmdirc/ui/messages/Line.java Ver arquivo

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

Carregando…
Cancelar
Salvar