aboutsummaryrefslogtreecommitdiff
path: root/src/UI/Components/BookListItem.java
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2024-11-16 02:11:24 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2024-11-16 02:11:24 +0530
commited3e023d1da3465bc79a91d38950a167004911b2 (patch)
tree08fb4de9af501612ccb85c8ee2f6beb60779c1f2 /src/UI/Components/BookListItem.java
First Commit
Diffstat (limited to 'src/UI/Components/BookListItem.java')
-rw-r--r--src/UI/Components/BookListItem.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/UI/Components/BookListItem.java b/src/UI/Components/BookListItem.java
new file mode 100644
index 0000000..9042762
--- /dev/null
+++ b/src/UI/Components/BookListItem.java
@@ -0,0 +1,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));
+ }
+}
+