blob: 9042762fc52b91e78c89c363e7428192d1fd14bb (
plain)
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
|
package UI.Components;
import Client.Book;
import UI.MainWindow;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import java.awt.*;
public class BookListItem extends JPanel {
BookListItem(Book book) {
this.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(6, 10, 6, 10), new MatteBorder(0, 0, 1, 0, Color.BLACK)));
boolean issued = book.getIssuedBy() != 0;
JLabel titleLabel = new JLabel(book.getTitle());
titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, titleLabel.getFont().getSize() + 2));
this.add(titleLabel);
JPanel issueButtonPanel = new JPanel();
issueButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
if (!issued || book.getIssuedBy() == MainWindow.userId) {
JButton issueButton = new JButton(issued ? "Return Book" : "Issue Book");
issueButtonPanel.add(issueButton);
issueButton.addActionListener(e -> {
if (issued) {
book.returnBook();
} else {
book.issue();
}
});
} else {
issueButtonPanel.add(new JLabel("Book is Unavailable"));
}
this.add(issueButtonPanel);
JLabel authorLabel = new JLabel(book.getAuthor());
authorLabel.setForeground(Color.DARK_GRAY);
this.add(authorLabel);
this.setMaximumSize(new Dimension(650, 100));
this.setLayout(new GridLayout(2, 2));
}
}
|