-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThumbnail.java
More file actions
82 lines (63 loc) · 2.1 KB
/
Thumbnail.java
File metadata and controls
82 lines (63 loc) · 2.1 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
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Thumbnail extends JButton implements ActionListener {
private Image cover;
private String name;
private Manga book;
private static int coverWidth = (int)(150 * 2);
private static int coverHeight = (int)(225 * 2);
public Thumbnail(String name, Image cover, Manga book) {
this.book = book;
this.name = name;
this.cover = cover;
setPreferredSize(new Dimension(coverWidth, coverHeight + 50));
setBackground(new Color(0, 0, 0, 0));
setOpaque(false);
addActionListener(this);
setBorder(null);
}
public static int getCoverWidth() {
return coverWidth;
}
public static int getCoverHeight() {
return coverHeight;
}
public void openBook() {
if(Library.instace.getCenter().getClass() == DetailView.class) {
new Reader(book).run();
return;
}
Library.instace.open(new DetailView(book));
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D graphics2D = (Graphics2D)g;
Dimension original = new Dimension(1500, 2250);
Dimension scaled = Tools.getScaledDimension(original, getSize());
graphics2D.setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON
);
int startX = (int)((getSize().getWidth() - scaled.getWidth()) / 2);
graphics2D.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22));
graphics2D.setColor(Color.WHITE);
graphics2D.drawString(name, startX, (int)scaled.getHeight() + 22);
graphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 18));
graphics2D.setColor(Color.WHITE);
graphics2D.drawString(book.getPages() + " Pages", startX, (int)scaled.getHeight() + 45);
graphics2D.drawImage(cover, startX, 0, (int)scaled.getWidth(), (int)scaled.getHeight(), getFocusCycleRootAncestor());
}
public String toString() {
return name;
}
public String getName() {
return name;
}
public Image getCover() {
return cover;
}
public void actionPerformed(ActionEvent e) {
openBook();
}
}