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;
10 import java.util.Enumeration;
11 import java.util.Vector;
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import javax.swing.JScrollPane;
17 import javax.swing.JTable;
18 import javax.swing.JTextField;
19 import javax.swing.SwingConstants;
20 import javax.swing.border.EmptyBorder;
21 import javax.swing.table.DefaultTableCellRenderer;
22 import javax.swing.table.DefaultTableModel;
24 import businessLogic.BookingManager;
25 import domain.Booking;
27 import domain.RuralHouse;
29 public class HouseFeaturesGUI extends JFrame {
34 private static final long serialVersionUID = 1L;
35 private JPanel contentPane;
36 private JLabel lblDistrict;
37 private JTextField District_f;
38 private JLabel lblDescription;
39 private JTextField description_f;
40 private JLabel lblKitchen;
41 private JTextField kitchens_f;
42 private JLabel lblRooms;
43 private JTextField rooms_f;
44 private JLabel lblLivings;
45 private JTextField lRooms_f;
46 private JLabel lblParkings;
47 private JTextField parkings_f;
48 private JLabel lblBaths;
49 private JTextField baths_f;
51 private DefaultTableModel tableModel;
52 private RuralHouse rh;
53 private JTextField telIn;
55 private JLabel labelPhone;
61 public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay, final Date LastDay) {
63 this.getContentPane().setLayout(null);
64 setBounds(100, 100, 500, 583);
65 contentPane = new JPanel();
66 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
67 setContentPane(contentPane);
69 lblDistrict = new JLabel("District:");
70 lblDistrict.setBounds(23, 67, 70, 14);
71 lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
73 District_f = new JTextField();
74 District_f.setEditable(false);
75 District_f.setBounds(103, 64, 86, 20);
76 District_f.setColumns(10);
78 lblDescription = new JLabel("Description:");
79 lblDescription.setBounds(215, 67, 90, 14);
80 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
82 description_f = new JTextField();
83 description_f.setEditable(false);
84 description_f.setBounds(238, 99, 178, 129);
85 description_f.setColumns(10);
87 lblKitchen = new JLabel("Kitchens:");
88 lblKitchen.setBounds(23, 211, 70, 14);
89 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
91 kitchens_f = new JTextField();
92 kitchens_f.setEditable(false);
93 kitchens_f.setBounds(103, 202, 86, 20);
94 kitchens_f.setColumns(10);
96 lblRooms = new JLabel("Rooms:");
97 lblRooms.setBounds(23, 102, 70, 14);
98 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
100 rooms_f = new JTextField();
101 rooms_f.setEditable(false);
102 rooms_f.setBounds(103, 99, 86, 20);
103 rooms_f.setColumns(10);
105 lblLivings = new JLabel("Living rooms:");
106 lblLivings.setBounds(30, 236, 63, 14);
107 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
109 lRooms_f = new JTextField();
110 lRooms_f.setEditable(false);
111 lRooms_f.setBounds(103, 233, 86, 20);
112 lRooms_f.setColumns(10);
114 lblParkings = new JLabel("Parkings:");
115 lblParkings.setBounds(23, 174, 70, 14);
116 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
118 parkings_f = new JTextField();
119 parkings_f.setEditable(false);
120 parkings_f.setBounds(103, 171, 86, 20);
121 parkings_f.setColumns(10);
123 lblBaths = new JLabel("Baths:");
124 lblBaths.setBounds(23, 143, 70, 14);
125 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
127 baths_f = new JTextField();
128 baths_f.setEditable(false);
129 baths_f.setBounds(103, 140, 86, 20);
130 baths_f.setColumns(10);
131 contentPane.setLayout(null);
132 contentPane.add(lblParkings);
133 contentPane.add(parkings_f);
134 contentPane.add(lblRooms);
135 contentPane.add(rooms_f);
136 contentPane.add(lblBaths);
137 contentPane.add(baths_f);
138 contentPane.add(lblDistrict);
139 contentPane.add(District_f);
140 contentPane.add(lblLivings);
141 contentPane.add(lRooms_f);
142 contentPane.add(lblKitchen);
143 contentPane.add(kitchens_f);
144 contentPane.add(description_f);
145 contentPane.add(lblDescription);
146 parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings()));
147 rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
148 baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
149 District_f.setText(rh.getDistrict());
150 kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens()));
151 description_f.setText(rh.getDescription());
152 lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings()));
153 JLabel lblAvailbleOffers = new JLabel("Availble Offers:");
154 lblAvailbleOffers.setBounds(30, 286, 86, 14);
155 contentPane.add(lblAvailbleOffers);
156 JScrollPane scrollPane = new JScrollPane();
157 scrollPane.setBounds(40, 311, 376, 183);
158 contentPane.add(scrollPane);
160 table = new JTable() {
161 private static final long serialVersionUID = 1L;
163 public boolean isCellEditable(int row, int column) {
167 tableModel = new DefaultTableModel(null, new String[] { "Offer #",
168 "FirstDay", "LastDay", "Price" });
169 table.setModel(tableModel);
170 scrollPane.setViewportView(table);
172 JButton btnBookSelected = new JButton("Book SelectedOffer");
173 btnBookSelected.setBounds(238, 505, 178, 23);
174 contentPane.add(btnBookSelected);
176 btnBookSelected.addActionListener(new ActionListener() {
177 public void actionPerformed(ActionEvent arg0) {
179 jButton_ActionPerformed(arg0);
184 JLabel lblNewLabel = new JLabel(
185 "Green: Suit your dates. Red: Do not suit your dates");
186 lblNewLabel.setEnabled(false);
187 lblNewLabel.setBounds(152, 277, 261, 23);
188 contentPane.add(lblNewLabel);
190 JLabel lblNewLabel_1 = new JLabel("Telephone num:");
191 lblNewLabel_1.setBounds(10, 509, 83, 14);
192 contentPane.add(lblNewLabel_1);
194 telIn = new JTextField();
195 telIn.setBounds(99, 505, 129, 20);
196 contentPane.add(telIn);
197 telIn.setColumns(10);
199 labelPhone = new JLabel("");
200 labelPhone.setBounds(238, 252, 178, 14);
201 contentPane.add(labelPhone);
202 table.addMouseListener( new MouseAdapter(){
204 public void mouseClicked(MouseEvent arg0) {
205 row = table.getSelectedRow();
208 Enumeration<Offer> rhs = rh.getAllOffers().elements();
209 while (rhs.hasMoreElements()) {
210 Offer of = rhs.nextElement();
211 Vector<Object> row = new Vector<Object>();
212 row.add(of.getOfferNumber());
213 row.add(of.getFirstDay());
214 row.add(of.getLastDay());
215 row.add(of.getPrice());
216 tableModel.addRow(row);
219 table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
223 private static final long serialVersionUID = 1L;
226 public Component getTableCellRendererComponent(JTable table,
227 Object value, boolean isSelected, boolean hasFocus,
230 super.getTableCellRendererComponent(table, value, isSelected,
233 Date firstDay = (Date) table.getModel().getValueAt(row, 1);
234 Date lastDay = (Date) table.getModel().getValueAt(row, 2);
235 if (FirstDay != null && LastDay != null) {
236 if (LastDay.before(lastDay) || FirstDay.after(firstDay)) {
237 setBackground(Color.RED);
238 setForeground(Color.BLACK);
240 setBackground(Color.GREEN);
241 setForeground(Color.BLACK);
249 private void jButton_ActionPerformed(ActionEvent arg0) {
250 BookingManager bookingM = new BookingManager();
251 //RegExp to see if telephone number is correct??TODO
252 if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")) {
255 if (table.getRowCount()!=0)
256 book = bookingM.createBooking(rh, rh.offers.get(row).getFirstDay(), rh.offers.get(row).getLastDay(), telIn.getText());
257 } catch (Exception e) {
261 BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
263 confirmWindow.setVisible(true);
266 labelPhone.setText("Phone format is wrong");