-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPage.java
More file actions
39 lines (28 loc) · 1.06 KB
/
Copy pathPage.java
File metadata and controls
39 lines (28 loc) · 1.06 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
import javax.swing.JPanel;
import java.awt.*;
public class Page extends JPanel {
private Image currentPage;
public Page(Image page) {
this.currentPage = page;
setSize(page.getWidth(null), getHeight());
setBackground(Color.BLACK);
((FlowLayout) getLayout()).setVgap(0);
}
public void updatePage(Image page) {
currentPage = page;
paint(getGraphics());
}
public int getPageWidth() {
return currentPage.getWidth(null);
}
public int getPageHeight() {
return currentPage.getHeight(null);
}
public void paint(Graphics g) {
super.paint(g);
Dimension original = new Dimension(currentPage.getWidth(getFocusCycleRootAncestor()), currentPage.getHeight(getFocusCycleRootAncestor()));
Dimension scaled = Tools.getScaledDimension(original, getSize());
int startX = (int)((getSize().getWidth() - scaled.getWidth()) / 2);
g.drawImage(currentPage, startX, 0, (int)scaled.getWidth(), (int)scaled.getHeight(), getFocusCycleRootAncestor());
}
}