-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInformationPanel.java
More file actions
102 lines (83 loc) · 3.27 KB
/
Copy pathInformationPanel.java
File metadata and controls
102 lines (83 loc) · 3.27 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
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.*;
/**
* An information panel that displays information to users
*
* @Team MAGA
* @Author Gajun Young - 16440714
* @Author Royal Thomas - 16326926
* @Author Richard Otroshchenko - 16353416
*/
public class InformationPanel extends JPanel {
private static final long serialVersionUID = 1L;
private static final int HEIGHT = 30;
private static final int WIDTH = 24;
private JTextArea infoArea = new JTextArea("", HEIGHT, WIDTH);
private static JPanel remainingCards = new JPanel();
//Constructor
public InformationPanel() {
JScrollPane scroll = new JScrollPane(infoArea);
setPreferredSize(new Dimension(300, 690));
//border style
setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Information Panel"));
//Ensures text area doesn't expand to the right, but pushes text downwards
infoArea.setLineWrap(true);
infoArea.setEditable(false); //Non editable, so players can't text here
infoArea.setMaximumSize(infoArea.getPreferredSize());
add(scroll);
remainingCards.add(new JLabel("Undealt Cards:"));
try {
remainingCards.add(CluedoUI.imageToResizedLabel("empty.png", 45, 70));
remainingCards.add(CluedoUI.imageToResizedLabel("empty.png", 45, 70));
remainingCards.add(CluedoUI.imageToResizedLabel("empty.png", 45, 70));
}catch(IOException ex){
}
add(remainingCards);
}
/**
* A method that updates the content on the information panel that is displayed to everyone
*
* @param value - The string of text to be displayed
*/
public void updateContent(String value) {
// Add string below current value.
infoArea.append(value + "\n");
// Auto scroll down to current position.
infoArea.setCaretPosition(infoArea.getDocument().getLength());
}
/**
* Method to clear information area
*/
public void clearContent(){
infoArea.setText("");
}
/**
* Updates the UI to show the cards that are not dealt to the players
*
* @param cards An ArrayList of cards that are not dealt to the players
* @return Nothing
*/
public static void updateRemainingCards(ArrayList<Card> cards) {
if (!cards.isEmpty()) {
remainingCards.removeAll(); // Clean it up
remainingCards.add(new JLabel("Undealt Cards:"));
for (Card c : cards) { // Add each card to the panel one by one
try {
// Fetch the image based on the card by removing spaces and
// making it lower case
String cardName = c.getName().toLowerCase().replaceAll(" ", "")
+ ".jpg";
remainingCards.add(CluedoUI.imageToResizedLabel(cardName, 45, 70)); // Add it to the panel
} catch (IOException ex) {
System.out.println("Unable to locate files for undealt cards.");
}
}
remainingCards.updateUI(); // Refresh the UI to show changes.
}
}
}