|
@@ -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
|
+}
|