blob: 1204f7605fee4e7b2871095b93dccf618a7f4530 (
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
48
|
package UI.Components;
import Store.Book;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import java.awt.*;
import java.sql.SQLException;
import java.util.Objects;
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)));
JLabel titleLabel = new JLabel(book.getTitle());
titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, titleLabel.getFont().getSize() + 2));
this.add(titleLabel);
JPanel deleteButtonPanel = new JPanel();
JButton deleteButton = new JButton("Delete Book");
deleteButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
deleteButtonPanel.add(deleteButton);
this.add(deleteButtonPanel);
deleteButton.addActionListener(e -> {
try {
book.delete();
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
});
JLabel authorLabel = new JLabel(book.getAuthor());
authorLabel.setForeground(Color.DARK_GRAY);
this.add(authorLabel);
JPanel issuedByLabelPanel = new JPanel();
JLabel issuedByLabel = new JLabel(!Objects.equals(book.getIssuedByName(), null) ? "Issued by user " + book.getIssuedByName() : "Available");
issuedByLabelPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
issuedByLabelPanel.add(issuedByLabel);
this.add(issuedByLabelPanel);
this.setMaximumSize(new Dimension(650, 100));
this.setLayout(new GridLayout(2, 2));
}
}
|