-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanelCredits.java
More file actions
130 lines (114 loc) · 4.36 KB
/
Copy pathPanelCredits.java
File metadata and controls
130 lines (114 loc) · 4.36 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
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
/**
* Credits screen
*/
@SuppressWarnings("serial")
public class PanelCredits extends JPanel {
/**
* The JFrame this panel is drawn upon
*/
final private Window owner;
/**
* Height of GUI window
*/
private int height;
/**
* Width of GUI window
*/
private int width;
/**
* Panel for the back button
*/
private PanelBack backButtonLayout;
/**
* Creates a new PanelCredits on the JFrame owner with the given width and height.
* @param owner JFrame window
* @param width Width of window
* @param height Height of window
*/
public PanelCredits(Window owner, int width, int height) {
this.width = width;
this.height = height;
this.owner = owner;
createGUI();
}
/**
* Draws background.
*/
public void paintComponent(Graphics g) {
g.setColor(Driver.bgColor);
g.fillRect(0, 0, width, height);
}
/**
* Sets all text and hyperlinks for Github pages.
* Also sets key bindings.
*/
private void createGUI() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
// Import fonts so that they can be used in HTML
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(Driver.fontRegular);
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(Driver.fontBold);
backButtonLayout = new PanelBack();
backButtonLayout.backButton.addActionListener(event -> {
SwingUtilities.invokeLater(() -> owner.showView(new PanelHome(owner, Driver.width, Driver.height)));
});
add(backButtonLayout);
JTextPane textPane = new JTextPane();
textPane.setBackground(Driver.bgColor);
String creditsContent =
"<html>" +
"<body style=\"font-family: 'Rubik'; font-size: 20px;\">" +
"<br>" +
"<p style=\"font-family: 'Rubik Medium'; font-size: 30px;\">CREDITS</p>" +
"<p>Akash Bhave </p><a href=\"https://github.com/AkashBhave\">(@AkashBhave)</a>" +
"<p>Avik Rao </p><a href=\"https://github.com/acidepicice\">(@acidepicice)</a>" +
"<p>Nathan Stephenson </p><a href=\"https://github.com/nathanstep55\">(@nathanstep55)</a>" +
"</body>" +
"</html>";
textPane.setContentType("text/html");
textPane.setText(creditsContent);
textPane.setFont(Driver.standardFont);
textPane.setEditable(false);
textPane.setMargin(new Insets(50, 20, 0, 20));
textPane.addHyperlinkListener(e -> {
if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(e.getURL().toURI());
} catch (Exception linkException) {
linkException.printStackTrace();
}
}
});
StyledDocument styledDoc = textPane.getStyledDocument();
SimpleAttributeSet centerStyle = new SimpleAttributeSet();
StyleConstants.setAlignment(centerStyle, StyleConstants.ALIGN_CENTER);
styledDoc.setParagraphAttributes(0, styledDoc.getLength(), centerStyle, false);
add(textPane);
// key bindings
int backMap = JComponent.WHEN_IN_FOCUSED_WINDOW;
InputMap imap = this.getInputMap(backMap);
KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
imap.put(escape, "return");
ActionMap amap = this.getActionMap();
amap.put("return", new BackAction() );
owner.requestFocus();
}
/**
* Returns to PanelHome if the escape key is pressed.
*/
@SuppressWarnings("serial")
private class BackAction extends AbstractAction {
public void actionPerformed (ActionEvent e) {
backButtonLayout.backButton.doClick();
}
}
}