|
@@ -1,10 +1,14 @@ |
1 |
1 |
|
package gui; |
2 |
2 |
|
|
|
3 |
+ |
import java.awt.Color; |
|
4 |
+ |
import java.awt.Component; |
3 |
5 |
|
import java.awt.Font; |
4 |
6 |
|
import java.awt.Rectangle; |
5 |
7 |
|
import java.awt.event.ActionEvent; |
6 |
8 |
|
import java.awt.event.ActionListener; |
|
9 |
+ |
import java.rmi.Naming; |
7 |
10 |
|
import java.rmi.RemoteException; |
|
11 |
+ |
import java.util.Date; |
8 |
12 |
|
import java.util.Enumeration; |
9 |
13 |
|
import java.util.Vector; |
10 |
14 |
|
|
|
@@ -15,10 +19,12 @@ |
15 |
19 |
|
import javax.swing.JScrollPane; |
16 |
20 |
|
import javax.swing.JTable; |
17 |
21 |
|
import javax.swing.border.EmptyBorder; |
|
22 |
+ |
import javax.swing.table.DefaultTableCellRenderer; |
18 |
23 |
|
import javax.swing.table.DefaultTableModel; |
19 |
24 |
|
|
20 |
25 |
|
import common.BookingInterface; |
21 |
|
- |
|
|
26 |
+ |
import common.OfferInterface; |
|
27 |
+ |
import configuration.___IntNames; |
22 |
28 |
|
import domain.Booking; |
23 |
29 |
|
import domain.Offer; |
24 |
30 |
|
|
|
@@ -31,7 +37,7 @@ |
31 |
37 |
|
private JPanel contentPane; |
32 |
38 |
|
private JTable table; |
33 |
39 |
|
private Offer off; |
34 |
|
- |
private BookingInterface bookM =null; |
|
40 |
+ |
private BookingInterface bookM = null; |
35 |
41 |
|
private DefaultTableModel tableModel; |
36 |
42 |
|
private Vector<Booking> bookings = new Vector<Booking>(); |
37 |
43 |
|
|
|
@@ -56,8 +62,8 @@ |
56 |
62 |
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
57 |
63 |
|
setContentPane(contentPane); |
58 |
64 |
|
contentPane.setLayout(null); |
59 |
|
- |
|
60 |
|
- |
this.bookings= this.off.getBookings(); |
|
65 |
+ |
|
|
66 |
+ |
this.bookings = this.off.getBookings(); |
61 |
67 |
|
JLabel lblNewLabel = new JLabel(); |
62 |
68 |
|
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); |
63 |
69 |
|
lblNewLabel.setBounds(23, 41, 536, 33); |
|
@@ -80,18 +86,26 @@ |
80 |
86 |
|
}; |
81 |
87 |
|
}; |
82 |
88 |
|
scrollPane.setViewportView(table); |
83 |
|
- |
tableModel = new DefaultTableModel(null, new String[] { |
84 |
|
- |
"Booking Number", "Booking Date","Name","E-mail", "Telephone" }); |
|
89 |
+ |
tableModel = new DefaultTableModel(null, |
|
90 |
+ |
new String[] { "Booking Number", "Booking Date", "Name", |
|
91 |
+ |
"E-mail", "Telephone" }); |
85 |
92 |
|
|
86 |
|
- |
// Maybe there is a better way to avoid interaction. |
87 |
|
- |
// table.setEnabled(false); |
88 |
93 |
|
table.setModel(tableModel); |
89 |
94 |
|
|
90 |
95 |
|
JButton btnNewButton = new JButton("Confirm Booking"); |
91 |
96 |
|
btnNewButton.addActionListener(new ActionListener() { |
92 |
97 |
|
public void actionPerformed(ActionEvent e) { |
|
98 |
+ |
try { |
|
99 |
+ |
bookM = (BookingInterface) Naming |
|
100 |
+ |
.lookup(___IntNames.BookingManager); |
|
101 |
+ |
} catch (Exception e1) { |
|
102 |
+ |
System.out |
|
103 |
+ |
.println("Error accessing remote authentication: " |
|
104 |
+ |
+ e1.toString()); |
|
105 |
+ |
} |
93 |
106 |
|
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { |
94 |
|
- |
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { |
|
107 |
+ |
if (table.getRowCount() != 0 |
|
108 |
+ |
&& table.getSelectedRow() != -1) { |
95 |
109 |
|
Booking book = bookings.get(table.getSelectedRow()); |
96 |
110 |
|
try { |
97 |
111 |
|
bookM.acceptBooking(book); |
|
@@ -109,20 +123,29 @@ |
109 |
123 |
|
JButton btnDenyAddition = new JButton("Deny Booking"); |
110 |
124 |
|
btnDenyAddition.addActionListener(new ActionListener() { |
111 |
125 |
|
public void actionPerformed(ActionEvent arg0) { |
|
126 |
+ |
try { |
|
127 |
+ |
bookM = (BookingInterface) Naming |
|
128 |
+ |
.lookup(___IntNames.BookingManager); |
|
129 |
+ |
} catch (Exception e1) { |
|
130 |
+ |
System.out |
|
131 |
+ |
.println("Error accessing remote authentication: " |
|
132 |
+ |
+ e1.toString()); |
|
133 |
+ |
} |
112 |
134 |
|
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { |
113 |
135 |
|
Booking book = bookings.get(table.getSelectedRow()); |
114 |
136 |
|
try { |
115 |
|
- |
bookM.removeDenyBooking(book); |
|
137 |
+ |
bookM.denyBooking(book); |
116 |
138 |
|
} catch (RemoteException e) { |
117 |
139 |
|
e.printStackTrace(); |
118 |
140 |
|
} |
|
141 |
+ |
bookings.remove(book); |
119 |
142 |
|
|
120 |
143 |
|
} |
121 |
144 |
|
} |
122 |
145 |
|
}); |
123 |
146 |
|
btnDenyAddition.setBounds(390, 395, 169, 25); |
124 |
147 |
|
contentPane.add(btnDenyAddition); |
125 |
|
- |
|
|
148 |
+ |
|
126 |
149 |
|
Enumeration<Booking> en = this.bookings.elements(); |
127 |
150 |
|
Booking book; |
128 |
151 |
|
while (en.hasMoreElements()) { |
|
@@ -135,6 +158,38 @@ |
135 |
158 |
|
row.add(book.getClient().getTelephone()); |
136 |
159 |
|
tableModel.addRow(row); |
137 |
160 |
|
} |
|
161 |
+ |
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { |
|
162 |
+ |
/** |
|
163 |
+ |
* |
|
164 |
+ |
*/ |
|
165 |
+ |
private static final long serialVersionUID = 1L; |
138 |
166 |
|
|
|
167 |
+ |
public int daysBetween(Date d1, Date d2) { |
|
168 |
+ |
return (int) ((d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24)); |
|
169 |
+ |
} |
|
170 |
+ |
|
|
171 |
+ |
@Override |
|
172 |
+ |
public Component getTableCellRendererComponent(JTable table, |
|
173 |
+ |
Object value, boolean isSelected, boolean hasFocus, |
|
174 |
+ |
int row, int col) { |
|
175 |
+ |
|
|
176 |
+ |
super.getTableCellRendererComponent(table, value, isSelected, |
|
177 |
+ |
hasFocus, row, col); |
|
178 |
+ |
|
|
179 |
+ |
Date bookDay = (Date) table.getModel().getValueAt(row, 1); |
|
180 |
+ |
Date currentDay = new java.util.Date(System.currentTimeMillis()); |
|
181 |
+ |
|
|
182 |
+ |
if (daysBetween(bookDay, currentDay) > 3) { |
|
183 |
+ |
setBackground(Color.RED); |
|
184 |
+ |
setForeground(Color.BLACK); |
|
185 |
+ |
} else { |
|
186 |
+ |
setBackground(Color.GREEN); |
|
187 |
+ |
setForeground(Color.BLACK); |
|
188 |
+ |
} |
|
189 |
+ |
|
|
190 |
+ |
return this; |
|
191 |
+ |
} |
|
192 |
+ |
}); |
139 |
193 |
|
} |
|
194 |
+ |
|
140 |
195 |
|
} |