CardTextData.java
5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package fi.codecrew.moya.model;
import java.awt.Color;
import java.awt.Font;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.enums.CardTextAlignment;
import fi.codecrew.moya.enums.CardTextDataType;
import fi.codecrew.moya.enums.CardTextStyle;
@Entity
@Table(name = "card_text_data")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class CardTextData extends GenericEntity{
private static final long serialVersionUID = 307145499023412008L;
@Column(name="card_text_data_type", nullable=false)
@Enumerated(EnumType.STRING)
private CardTextDataType textDataType = CardTextDataType.UNKNOWN;
@Column(name = "text_alignment", nullable = false)
@Enumerated(EnumType.STRING)
private CardTextAlignment textAlignment;
@Column(name = "x", nullable = false)
private int x;
@Column(name = "y", nullable = false)
private int y;
@Column(name = "size", nullable = false, precision = 5, scale = 2)
private BigDecimal size;
@Column(name = "font_color_r", nullable = false)
private int fontColorR;
@Column(name = "font_color_g", nullable = false)
private int fontColorG;
@Column(name = "font_color_b", nullable = false)
private int fontColorB;
@Column(name = "font_name", nullable = false)
private String fontName;
@Column(name = "font_style", nullable = false)
@Enumerated(EnumType.STRING)
private CardTextStyle fontStyle;
@Column(name = "text", nullable = true)
private String text;
@Column(name = "z_index", nullable = false)
private int zIndex;
@ManyToOne
@JoinColumn(nullable = false, name = "card_templates_id")
private CardTemplate cardTemplate;
public boolean isTypeStatic() {
if(this.textDataType == CardTextDataType.STATIC)
return true;
return false;
}
public void setTextDataType(CardTextDataType field) {
this.textDataType = field;
}
public CardTextDataType getTextDataType() {
return this.textDataType;
}
public void setX(int x) {
this.x = x;
}
public int getX() {
return this.x;
}
public void setY(int y) {
this.y = y;
}
public int getY() {
return this.y;
}
public void setSize(BigDecimal size) {
this.size = size;
}
public BigDecimal getSize() {
return this.size;
}
public void setFontName(String font) {
this.fontName = font;
}
public String getFontName() {
return this.fontName;
}
public void setFontStyle(CardTextStyle fontStyle) {
this.fontStyle = fontStyle;
}
public CardTextStyle getFontStyle() {
return this.fontStyle;
}
public void setText(String text) {
this.text = text;
}
public String getText() {
return this.text;
}
public int getzIndex() {
return zIndex;
}
public void setzIndex(int zIndex) {
this.zIndex = zIndex;
}
public CardTextAlignment getTextAlignment() {
return textAlignment;
}
public void setTextAlignment(CardTextAlignment textAlignment) {
this.textAlignment = textAlignment;
}
public void setFont(Font font) {
//this.font = font;
this.fontName = font.getFontName();
this.size = new BigDecimal(font.getSize());
if(font.isBold() && font.isItalic())
this.fontStyle = CardTextStyle.BOLDITALIC;
else if(font.isItalic())
this.fontStyle = CardTextStyle.ITALIC;
else if(font.isPlain())
this.fontStyle = CardTextStyle.PLAIN;
}
public Font getFont() {
if(this.fontStyle == CardTextStyle.BOLD)
return new Font(this.fontName, Font.BOLD, this.size.intValue());
else if(this.fontStyle == CardTextStyle.ITALIC)
return new Font(this.fontName, Font.ITALIC, this.size.intValue());
else if(this.fontStyle == CardTextStyle.PLAIN)
return new Font(this.fontName, Font.PLAIN, this.size.intValue());
else
return new Font(this.fontName, Font.PLAIN, this.size.intValue());
}
public void setCardTemplate(CardTemplate template) {
this.cardTemplate = template;
}
public CardTemplate getCardTemplate() {
return this.cardTemplate;
}
public LanEvent getEvent() {
if(cardTemplate != null)
return cardTemplate.getEvent();
else
return null;
}
public int getFontColorR() {
return fontColorR;
}
public void setFontColorR(int fontColorR) {
this.fontColorR = fontColorR;
}
public int getFontColorG() {
return fontColorG;
}
public void setFontColorG(int fontColorG) {
this.fontColorG = fontColorG;
}
public int getFontColorB() {
return fontColorB;
}
public void setFontColorB(int fontColorB) {
this.fontColorB = fontColorB;
}
public void setFontColor(int r, int g, int b) {
this.fontColorR = r;
this.fontColorG = g;
this.fontColorB = b;
}
public String getColorHexCode() {
String r = Integer.toHexString(fontColorR);
String g = Integer.toHexString(fontColorG);
String b = Integer.toHexString(fontColorB);
return r + g + b;
}
public void setColorHexCode(String colorHexCode) {
Color color = null;
try {
color = Color.decode("#"+colorHexCode);
fontColorR = color.getRed();
fontColorG = color.getGreen();
fontColorB = color.getBlue();
}catch(Exception ex) {
}
}
}