4 import java.awt.Component;
6 import java.awt.Rectangle;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.rmi.Naming;
10 import java.rmi.RemoteException;
11 import java.util.Date;
12 import java.util.Enumeration;
13 import java.util.Vector;
15 import javax.swing.JButton;
16 import javax.swing.JFrame;
17 import javax.swing.JLabel;
18 import javax.swing.JPanel;
19 import javax.swing.JScrollPane;
20 import javax.swing.JTable;
21 import javax.swing.border.EmptyBorder;
22 import javax.swing.table.DefaultTableCellRenderer;
23 import javax.swing.table.DefaultTableModel;
25 import common.BookingInterface;
26 import common.OfferInterface;
27 import configuration.___IntNames;
28 import domain.Booking;
31 public class listOfBookingRequestsGUI extends JFrame {
36 private static final long serialVersionUID = 1L;
37 private JPanel contentPane;
40 private BookingInterface bookM = null;
41 private DefaultTableModel tableModel;
42 private Vector<Booking> bookings = new Vector<Booking>();
47 public listOfBookingRequestsGUI(Offer of) {
48 setTitle("Adding requests");
54 } catch (Exception e) {
59 private void init() throws Exception {
60 setBounds(100, 100, 600, 500);
61 contentPane = new JPanel();
62 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
63 setContentPane(contentPane);
64 contentPane.setLayout(null);
66 this.bookings = this.off.getBookings();
67 JLabel lblNewLabel = new JLabel();
68 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
69 lblNewLabel.setBounds(23, 41, 536, 33);
70 contentPane.add(lblNewLabel);
71 if (bookings.isEmpty())
73 .setText("There are not bookings to be confirmed or denied");
75 lblNewLabel.setText("List of bookings:");
76 JScrollPane scrollPane = new JScrollPane();
77 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
78 scrollPane.setBounds(23, 113, 536, 271);
79 contentPane.add(scrollPane);
81 table = new JTable() {
82 private static final long serialVersionUID = 1L;
84 public boolean isCellEditable(int row, int column) {
88 scrollPane.setViewportView(table);
89 tableModel = new DefaultTableModel(null,
90 new String[] { "Booking Number", "Booking Date", "Name",
91 "E-mail", "Telephone" });
93 table.setModel(tableModel);
95 JButton btnNewButton = new JButton("Confirm Booking");
96 btnNewButton.addActionListener(new ActionListener() {
97 public void actionPerformed(ActionEvent e) {
99 bookM = (BookingInterface) Naming
100 .lookup(___IntNames.BookingManager);
101 } catch (Exception e1) {
103 .println("Error accessing remote authentication: "
106 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
107 if (table.getRowCount() != 0
108 && table.getSelectedRow() != -1) {
109 Booking book = bookings.get(table.getSelectedRow());
111 bookM.acceptBooking(book);
112 } catch (RemoteException e1) {
113 e1.printStackTrace();
120 btnNewButton.setBounds(33, 396, 169, 25);
121 contentPane.add(btnNewButton);
123 JButton btnDenyAddition = new JButton("Deny Booking");
124 btnDenyAddition.addActionListener(new ActionListener() {
125 public void actionPerformed(ActionEvent arg0) {
127 bookM = (BookingInterface) Naming
128 .lookup(___IntNames.BookingManager);
129 } catch (Exception e1) {
131 .println("Error accessing remote authentication: "
134 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
135 Booking book = bookings.get(table.getSelectedRow());
137 bookM.denyBooking(book);
138 } catch (RemoteException e) {
141 bookings.remove(book);
146 btnDenyAddition.setBounds(390, 395, 169, 25);
147 contentPane.add(btnDenyAddition);
149 Enumeration<Booking> en = this.bookings.elements();
151 while (en.hasMoreElements()) {
152 book = en.nextElement();
153 Vector<Object> row = new Vector<Object>();
154 row.add(book.getBookNumber());
155 row.add(book.getBookDate());
156 row.add(book.getClient().getName());
157 row.add(book.getClient().getMailAccount());
158 row.add(book.getClient().getTelephone());
159 tableModel.addRow(row);
161 table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
165 private static final long serialVersionUID = 1L;
167 public int daysBetween(Date d1, Date d2) {
168 return (int) ((d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
172 public Component getTableCellRendererComponent(JTable table,
173 Object value, boolean isSelected, boolean hasFocus,
176 super.getTableCellRendererComponent(table, value, isSelected,
179 Date bookDay = (Date) table.getModel().getValueAt(row, 1);
180 Date currentDay = new java.util.Date(System.currentTimeMillis());
182 if (daysBetween(bookDay, currentDay) > 3) {
183 setBackground(Color.RED);
184 setForeground(Color.BLACK);
186 setBackground(Color.GREEN);
187 setForeground(Color.BLACK);