-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArticle.java
64 lines (56 loc) · 2 KB
/
Article.java
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
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Vector;
public abstract class Article extends MaterialBlock{
Vector<String> article;
int height;
Color backgroundColor;
Color textColor;
boolean bordered;
Article(Vector<String> article) {
super(DPGenGUI.style);
this.article = article;
for (int i=0; i<article.size(); i++)
if (article.get(i).length() > 0 && article.get(i).charAt(0) == '.')
article.set(i, article.get(i).substring(2));
backgroundColor = DPGenGUI.backgroundColor;
textColor = DPGenGUI.textColor;
}
public void refreshArticleLines() {
LineCompacter compacter = new LineCompacter(DPGenGUI.lineSize);
Vector<String> newArticle = new Vector<String>();
for (String line : article) {
compacter.setLongLine(line);
compacter.compact();
newArticle.addAll(compacter.getLines());
}
article = newArticle;
}
public void trimArticle() {
String text = DPGenGUI.getStringFromStringVector(article, false);
LineCompacter compacter = new LineCompacter(DPGenGUI.lineSize);
compacter.setLongLine(text);
compacter.compact();
article = compacter.getLines();
}
int maximumLineWidthInPixels() {
BufferedImage image = new BufferedImage(DPGenGUI.width + 10, 50, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = (Graphics2D) image.getGraphics();
FontMetrics metrics = graphics2D.getFontMetrics();
int max = 0;
for (String line : article) {
int currWidth = metrics.stringWidth(line);
if (currWidth > max) max = currWidth;
}
return max;
}
void setBordered(boolean bordered) {
this.bordered = bordered;
}
void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
void setTextColor(Color textColor) {
this.textColor = textColor;
}
}