Coverage Summary for Class: StudentButton (it.polimi.ingsw.Client.GUI.Components)
Class |
Method, %
|
Branch, %
|
Line, %
|
StudentButton |
0%
(0/1)
|
0%
(0/14)
|
0%
(0/24)
|
StudentButton$1 |
0%
(0/1)
|
0%
(0/1)
|
Total |
0%
(0/2)
|
0%
(0/14)
|
0%
(0/25)
|
1 package it.polimi.ingsw.Client.GUI.Components;
2
3 import it.polimi.ingsw.Model.Enums.PawnColour;
4
5 import javax.swing.*;
6 import java.awt.*;
7
8 import static it.polimi.ingsw.Client.GUI.IconLoader.*;
9
10 public class StudentButton extends JButton {
11 /**
12 * Create a new JButton with pawn as icon
13 *
14 * @param pawnColour pawn's colour
15 * @param amount pawns' multiplicity
16 * @param overrideTextColour force text's colour to black
17 */
18 public StudentButton(PawnColour pawnColour, int amount, boolean overrideTextColour) {
19 //remove borders and fill from StudentButton
20 this.setBorderPainted(false);
21 this.setContentAreaFilled(false);
22 this.setFocusPainted(false);
23 this.setOpaque(false);
24 //set icon basing on pawn's colour
25 switch (pawnColour) {
26 case BLUE -> this.setIcon(BlueStudent);
27 case YELLOW -> this.setIcon(YellowStudent);
28 case GREEN -> this.setIcon(GreenStudent);
29 case PINK -> this.setIcon(PinkStudent);
30 case RED -> this.setIcon(RedStudent);
31 }
32 //write eventual multiplicity beside the JButton
33 if (amount > 1) {
34 this.setText("x" + amount);
35 this.setHorizontalTextPosition(SwingConstants.RIGHT);
36 Font font = new Font("SansSerif", Font.BOLD, 13);
37 this.setFont(font);
38 //set text's colour
39 switch (pawnColour) {
40 case BLUE -> this.setForeground(new Color(0x27C3F2));
41 case YELLOW -> this.setForeground(new Color(0xFBAF2F));
42 case GREEN -> this.setForeground(new Color(0x1FB47F));
43 case PINK -> this.setForeground(new Color(0xDB5FA2));
44 case RED -> this.setForeground(new Color(0xEC1F23));
45 }
46 if (overrideTextColour) {
47 this.setForeground(Color.BLACK);
48 }
49 }
50 }
51 }