aboutsummaryrefslogtreecommitdiff
path: root/src/UI/Components
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
First Commit
Diffstat (limited to 'src/UI/Components')
-rw-r--r--src/UI/Components/BookListItem.java47
-rw-r--r--src/UI/Components/BooksList.java38
-rw-r--r--src/UI/Components/InputBox.java39
-rw-r--r--src/UI/Components/LoginPanel.java55
4 files changed, 179 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));
+ }
+}
+
diff --git a/src/UI/Components/BooksList.java b/src/UI/Components/BooksList.java
new file mode 100644
index 0000000..05a2f5f
--- /dev/null
+++ b/src/UI/Components/BooksList.java
@@ -0,0 +1,38 @@
+package UI.Components;
+
+import Client.Book;
+
+import javax.swing.*;
+import java.util.ArrayList;
+
+public class BooksList extends JPanel {
+ private static JPanel listPanel;
+
+ public BooksList() {
+ listPanel = new JPanel();
+ listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS));
+
+ JScrollPane scrollPane = new JScrollPane(listPanel);
+ scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
+
+ this.add(scrollPane);
+
+ this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ }
+
+ public static void refreshBooks(ArrayList<Book> books) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ listPanel.removeAll();
+
+ for (Book book : books) {
+ listPanel.add(new BookListItem(book));
+ }
+
+ listPanel.revalidate();
+ listPanel.repaint();
+ }
+ }).start();
+ }
+}
diff --git a/src/UI/Components/InputBox.java b/src/UI/Components/InputBox.java
new file mode 100644
index 0000000..c15381e
--- /dev/null
+++ b/src/UI/Components/InputBox.java
@@ -0,0 +1,39 @@
+package UI.Components;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class InputBox extends JPanel {
+ JLabel label;
+ JTextField textField;
+
+ public InputBox(String label) {
+ this.label = new JLabel(label);
+ this.label.setPreferredSize(new Dimension(70, 30));
+ this.add(this.label);
+
+ this.add(Box.createHorizontalGlue());
+
+ this.textField = new JTextField(20);
+ this.add(this.textField);
+
+ this.setLayout(new FlowLayout(FlowLayout.CENTER));
+ }
+
+ public String getLabel() {
+ return this.label.getText();
+ }
+
+ public String getValue() {
+ return this.textField.getText();
+ }
+
+ public void setLabel(String label) {
+ this.label.setText(label);
+ }
+
+ public void setValue(String value) {
+ this.textField.setText(value);
+ this.textField.repaint();
+ }
+}
diff --git a/src/UI/Components/LoginPanel.java b/src/UI/Components/LoginPanel.java
new file mode 100644
index 0000000..e79326b
--- /dev/null
+++ b/src/UI/Components/LoginPanel.java
@@ -0,0 +1,55 @@
+package UI.Components;
+
+import UI.MainWindow;
+import UI.SettingsPopupWindow;
+
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import java.awt.*;
+
+public class LoginPanel extends JPanel {
+ public JButton loginButton;
+ private SettingsPopupWindow settingsPopupWindow;
+
+ public InputBox usernameInput;
+ public InputBox passwordInput;
+
+ public LoginPanel() {
+ usernameInput = new InputBox("Username:");
+ usernameInput.setBorder(new EmptyBorder(140, 100, 0, 100));
+ this.add(usernameInput);
+
+ passwordInput = new InputBox("Password:");
+ passwordInput.setBorder(new EmptyBorder(10, 100, 10, 100));
+ this.add(passwordInput);
+
+ JPanel buttonPanel = new JPanel();
+ buttonPanel.add(Box.createRigidArea(new Dimension(140, 0)));
+
+ JButton settingsButton = new JButton("Settings");
+ settingsButton.addActionListener(_ -> {
+ if (settingsPopupWindow == null) {
+ settingsPopupWindow = new SettingsPopupWindow();
+ settingsPopupWindow.saveButton.addActionListener(_ -> {
+ MainWindow.url = settingsPopupWindow.hostnameInput.getValue();
+ settingsPopupWindow.setVisible(false);
+ });
+ }
+
+ settingsPopupWindow.hostnameInput.setValue(MainWindow.url);
+
+ settingsPopupWindow.setVisible(true);
+ });
+ buttonPanel.add(settingsButton);
+
+ buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
+
+ loginButton = new JButton("Login");
+ buttonPanel.add(loginButton);
+
+ buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
+ this.add(buttonPanel);
+
+ this.setMaximumSize(new Dimension(350, 200));
+ }
+}