4 import java.awt.Component;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.awt.event.MouseAdapter;
8 import java.awt.event.MouseEvent;
9 import java.rmi.Naming;
10 import java.util.Date;
11 import java.util.Enumeration;
12 import java.util.Vector;
14 import javax.swing.JButton;
15 import javax.swing.JFrame;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18 import javax.swing.JScrollPane;
19 import javax.swing.JTable;
20 import javax.swing.JTextField;
21 import javax.swing.SwingConstants;
22 import javax.swing.border.EmptyBorder;
23 import javax.swing.table.DefaultTableCellRenderer;
24 import javax.swing.table.DefaultTableModel;
26 import common.BookingInterface;
28 import configuration.___IntNames;
29 import domain.Booking;
32 import domain.RuralHouse;
34 public class HouseFeaturesGUI extends JFrame {
39 private static final long serialVersionUID = 1L;
40 private JPanel contentPane;
41 private JLabel lblDistrict;
42 private JTextField District_f;
43 private JLabel lblDescription;
44 private JTextField description_f;
45 private JLabel lblKitchen;
46 private JTextField kitchens_f;
47 private JLabel lblRooms;
48 private JTextField rooms_f;
49 private JLabel lblLivings;
50 private JTextField lRooms_f;
51 private JLabel lblParkings;
52 private JTextField parkings_f;
53 private JLabel lblBaths;
54 private JTextField baths_f;
56 private DefaultTableModel tableModel;
57 private RuralHouse rh;
58 private JTextField telIn;
60 private JLabel labelPhone;
61 private JLabel lblName;
62 private JTextField nameField;
63 private JLabel lblEmail;
64 private JTextField mailField;
70 public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay,
73 this.getContentPane().setLayout(null);
74 setBounds(100, 100, 500, 700);
75 contentPane = new JPanel();
76 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
77 setContentPane(contentPane);
79 lblDistrict = new JLabel("District:");
80 lblDistrict.setBounds(23, 67, 70, 14);
81 lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
83 District_f = new JTextField();
84 District_f.setEditable(false);
85 District_f.setBounds(103, 64, 86, 20);
86 District_f.setColumns(10);
88 lblDescription = new JLabel("Description:");
89 lblDescription.setBounds(215, 67, 90, 14);
90 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
92 description_f = new JTextField();
93 description_f.setEditable(false);
94 description_f.setBounds(238, 99, 178, 129);
95 description_f.setColumns(10);
97 lblKitchen = new JLabel("Kitchens:");
98 lblKitchen.setBounds(23, 211, 70, 14);
99 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
101 kitchens_f = new JTextField();
102 kitchens_f.setEditable(false);
103 kitchens_f.setBounds(103, 202, 86, 20);
104 kitchens_f.setColumns(10);
106 lblRooms = new JLabel("Rooms:");
107 lblRooms.setBounds(23, 102, 70, 14);
108 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
110 rooms_f = new JTextField();
111 rooms_f.setEditable(false);
112 rooms_f.setBounds(103, 99, 86, 20);
113 rooms_f.setColumns(10);
115 lblLivings = new JLabel("Living rooms:");
116 lblLivings.setBounds(30, 236, 63, 14);
117 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
119 lRooms_f = new JTextField();
120 lRooms_f.setEditable(false);
121 lRooms_f.setBounds(103, 233, 86, 20);
122 lRooms_f.setColumns(10);
124 lblParkings = new JLabel("Parkings:");
125 lblParkings.setBounds(23, 174, 70, 14);
126 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
128 parkings_f = new JTextField();
129 parkings_f.setEditable(false);
130 parkings_f.setBounds(103, 171, 86, 20);
131 parkings_f.setColumns(10);
133 lblBaths = new JLabel("Baths:");
134 lblBaths.setBounds(23, 143, 70, 14);
135 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
137 baths_f = new JTextField();
138 baths_f.setEditable(false);
139 baths_f.setBounds(103, 140, 86, 20);
140 baths_f.setColumns(10);
141 contentPane.setLayout(null);
142 contentPane.add(lblParkings);
143 contentPane.add(parkings_f);
144 contentPane.add(lblRooms);
145 contentPane.add(rooms_f);
146 contentPane.add(lblBaths);
147 contentPane.add(baths_f);
148 contentPane.add(lblDistrict);
149 contentPane.add(District_f);
150 contentPane.add(lblLivings);
151 contentPane.add(lRooms_f);
152 contentPane.add(lblKitchen);
153 contentPane.add(kitchens_f);
154 contentPane.add(description_f);
155 contentPane.add(lblDescription);
156 parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings()));
157 rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
158 baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
159 District_f.setText(rh.getDistrict());
160 kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens()));
161 description_f.setText(rh.getDescription());
162 lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings()));
163 JLabel lblAvailbleOffers = new JLabel("Availble Offers:");
164 lblAvailbleOffers.setBounds(30, 286, 86, 14);
165 contentPane.add(lblAvailbleOffers);
166 JScrollPane scrollPane = new JScrollPane();
167 scrollPane.setBounds(40, 311, 376, 183);
168 contentPane.add(scrollPane);
170 table = new JTable() {
171 private static final long serialVersionUID = 1L;
173 public boolean isCellEditable(int row, int column) {
177 tableModel = new DefaultTableModel(null, new String[] { "Offer #",
178 "FirstDay", "LastDay", "Price" });
179 table.setModel(tableModel);
180 scrollPane.setViewportView(table);
182 JButton btnBookSelected = new JButton("Book SelectedOffer");
183 btnBookSelected.setBounds(238, 614, 178, 23);
184 contentPane.add(btnBookSelected);
186 btnBookSelected.addActionListener(new ActionListener() {
187 public void actionPerformed(ActionEvent arg0) {
189 jButton_ActionPerformed(arg0);
194 JLabel lblNewLabel = new JLabel(
195 "Green: Suit your dates. Red: Do not suit your dates");
196 lblNewLabel.setEnabled(false);
197 lblNewLabel.setBounds(170, 282, 261, 23);
198 contentPane.add(lblNewLabel);
200 JLabel lblNewLabel_1 = new JLabel("Telephone num:");
201 lblNewLabel_1.setBounds(10, 618, 83, 14);
202 contentPane.add(lblNewLabel_1);
204 telIn = new JTextField();
205 telIn.setBounds(103, 615, 129, 20);
206 contentPane.add(telIn);
207 telIn.setColumns(10);
209 labelPhone = new JLabel("");
210 labelPhone.setBounds(238, 252, 178, 14);
211 contentPane.add(labelPhone);
213 lblName = new JLabel("Name:");
214 lblName.setBounds(10, 516, 46, 14);
215 contentPane.add(lblName);
217 nameField = new JTextField();
218 nameField.setBounds(103, 513, 178, 20);
219 contentPane.add(nameField);
220 nameField.setColumns(10);
222 lblEmail = new JLabel("E-mail:");
223 lblEmail.setBounds(10, 565, 46, 14);
224 contentPane.add(lblEmail);
226 mailField = new JTextField();
227 mailField.setBounds(103, 562, 178, 20);
228 contentPane.add(mailField);
229 mailField.setColumns(10);
231 table.addMouseListener(new MouseAdapter() {
233 public void mouseClicked(MouseEvent arg0) {
234 row = table.getSelectedRow();
238 Enumeration<Offer> rhs = rh.getAllOffers().elements();
239 while (rhs.hasMoreElements()) {
240 Offer of = rhs.nextElement();
241 if (of.getBookings() != null) {
242 Vector<Object> row = new Vector<Object>();
243 row.add(of.getOfferNumber());
244 row.add(of.getFirstDay());
245 row.add(of.getLastDay());
246 row.add(of.getPrice());
247 tableModel.addRow(row);
250 table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
254 private static final long serialVersionUID = 1L;
257 public Component getTableCellRendererComponent(JTable table,
258 Object value, boolean isSelected, boolean hasFocus,
261 super.getTableCellRendererComponent(table, value, isSelected,
264 Date firstDay = (Date) table.getModel().getValueAt(row, 1);
265 Date lastDay = (Date) table.getModel().getValueAt(row, 2);
266 if (FirstDay != null && LastDay != null) {
267 if (LastDay.before(lastDay) || FirstDay.after(firstDay)) {
268 setBackground(Color.RED);
269 setForeground(Color.BLACK);
271 setBackground(Color.GREEN);
272 setForeground(Color.BLACK);
280 private void jButton_ActionPerformed(ActionEvent arg0) {
282 BookingInterface bookingM = null;
284 bookingM = (BookingInterface) Naming
285 .lookup(___IntNames.BookingManager);
286 } catch (Exception e1) {
287 System.out.println("Error accessing remote authentication: "
291 if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")
295 "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
296 && !nameField.getText().isEmpty()) {
297 labelPhone.setText("");
298 Vector<Booking> book = null;
300 if (table.getRowCount() != 0) {
301 Client cl = new Client(nameField.getText(),
302 mailField.getText(), telIn.getText());
303 book = bookingM.createBooking(rh, rh.offers.get(row)
304 .getFirstDay(), rh.offers.get(row).getLastDay(),cl);
306 } catch (Exception e) {
310 BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
312 confirmWindow.setVisible(true);
315 labelPhone.setText("Bad formatted data.");