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;
13 import javax.swing.JButton;
14 import javax.swing.JFrame;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17 import javax.swing.JScrollPane;
18 import javax.swing.JTable;
19 import javax.swing.JTextField;
20 import javax.swing.SwingConstants;
21 import javax.swing.border.EmptyBorder;
22 import javax.swing.table.DefaultTableCellRenderer;
23 import javax.swing.table.DefaultTableModel;
25 import businessLogic.BookingManager;
26 import domain.Booking;
28 import domain.RuralHouse;
30 public class HouseFeaturesGUI extends JFrame {
35 private static final long serialVersionUID = 1L;
36 private JPanel contentPane;
37 private JLabel lblDistrict;
38 private JTextField District_f;
39 private JLabel lblDescription;
40 private JTextField description_f;
41 private JLabel lblKitchen;
42 private JTextField kitchens_f;
43 private JLabel lblRooms;
44 private JTextField rooms_f;
45 private JLabel lblLivings;
46 private JTextField lRooms_f;
47 private JLabel lblParkings;
48 private JTextField parkings_f;
49 private JLabel lblBaths;
50 private JTextField baths_f;
52 private DefaultTableModel tableModel;
53 private RuralHouse rh;
54 private JTextField telIn;
56 private JLabel phoneNum;
62 public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay, final Date LastDay) {
64 this.getContentPane().setLayout(null);
65 setBounds(100, 100, 500, 583);
66 contentPane = new JPanel();
67 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
68 setContentPane(contentPane);
70 lblDistrict = new JLabel("District:");
71 lblDistrict.setBounds(23, 67, 70, 14);
72 lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
74 District_f = new JTextField();
75 District_f.setEditable(false);
76 District_f.setBounds(103, 64, 86, 20);
77 District_f.setColumns(10);
79 lblDescription = new JLabel("Description:");
80 lblDescription.setBounds(215, 67, 90, 14);
81 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
83 description_f = new JTextField();
84 description_f.setEditable(false);
85 description_f.setBounds(238, 99, 178, 129);
86 description_f.setColumns(10);
88 lblKitchen = new JLabel("Kitchens:");
89 lblKitchen.setBounds(23, 211, 70, 14);
90 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
92 kitchens_f = new JTextField();
93 kitchens_f.setEditable(false);
94 kitchens_f.setBounds(103, 202, 86, 20);
95 kitchens_f.setColumns(10);
97 lblRooms = new JLabel("Rooms:");
98 lblRooms.setBounds(23, 102, 70, 14);
99 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
101 rooms_f = new JTextField();
102 rooms_f.setEditable(false);
103 rooms_f.setBounds(103, 99, 86, 20);
104 rooms_f.setColumns(10);
106 lblLivings = new JLabel("Living rooms:");
107 lblLivings.setBounds(30, 236, 63, 14);
108 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
110 lRooms_f = new JTextField();
111 lRooms_f.setEditable(false);
112 lRooms_f.setBounds(103, 233, 86, 20);
113 lRooms_f.setColumns(10);
115 lblParkings = new JLabel("Parkings:");
116 lblParkings.setBounds(23, 174, 70, 14);
117 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
119 parkings_f = new JTextField();
120 parkings_f.setEditable(false);
121 parkings_f.setBounds(103, 171, 86, 20);
122 parkings_f.setColumns(10);
124 lblBaths = new JLabel("Baths:");
125 lblBaths.setBounds(23, 143, 70, 14);
126 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
128 baths_f = new JTextField();
129 baths_f.setEditable(false);
130 baths_f.setBounds(103, 140, 86, 20);
131 baths_f.setColumns(10);
132 contentPane.setLayout(null);
133 contentPane.add(lblParkings);
134 contentPane.add(parkings_f);
135 contentPane.add(lblRooms);
136 contentPane.add(rooms_f);
137 contentPane.add(lblBaths);
138 contentPane.add(baths_f);
139 contentPane.add(lblDistrict);
140 contentPane.add(District_f);
141 contentPane.add(lblLivings);
142 contentPane.add(lRooms_f);
143 contentPane.add(lblKitchen);
144 contentPane.add(kitchens_f);
145 contentPane.add(description_f);
146 contentPane.add(lblDescription);
147 parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings()));
148 rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
149 baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
150 District_f.setText(rh.getDistrict());
151 kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens()));
152 description_f.setText(rh.getDescription());
153 lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings()));
154 JLabel lblAvailbleOffers = new JLabel("Availble Offers:");
155 lblAvailbleOffers.setBounds(30, 286, 86, 14);
156 contentPane.add(lblAvailbleOffers);
157 JScrollPane scrollPane = new JScrollPane();
158 scrollPane.setBounds(40, 311, 376, 183);
159 contentPane.add(scrollPane);
161 table = new JTable() {
162 private static final long serialVersionUID = 1L;
164 public boolean isCellEditable(int row, int column) {
168 tableModel = new DefaultTableModel(null, new String[] { "Offer #",
169 "FirstDay", "LastDay", "Price" });
170 table.setModel(tableModel);
171 scrollPane.setViewportView(table);
173 JButton btnBookSelected = new JButton("Book SelectedOffer");
174 btnBookSelected.setBounds(238, 505, 178, 23);
175 contentPane.add(btnBookSelected);
177 btnBookSelected.addActionListener(new ActionListener() {
178 public void actionPerformed(ActionEvent arg0) {
180 jButton_ActionPerformed(arg0);
185 JLabel lblNewLabel = new JLabel(
186 "Green: Suit your dates. Red: Do not suit your dates");
187 lblNewLabel.setEnabled(false);
188 lblNewLabel.setBounds(170, 282, 261, 23);
189 contentPane.add(lblNewLabel);
191 JLabel lblNewLabel_1 = new JLabel("Telephone num:");
192 lblNewLabel_1.setBounds(10, 509, 83, 14);
193 contentPane.add(lblNewLabel_1);
195 telIn = new JTextField();
196 telIn.setBounds(99, 505, 129, 20);
197 contentPane.add(telIn);
198 telIn.setColumns(10);
200 phoneNum = new JLabel("");
201 phoneNum.setBounds(215, 255, 201, 15);
202 contentPane.add(phoneNum);
203 table.addMouseListener( new MouseAdapter(){
205 public void mouseClicked(MouseEvent arg0) {
206 row = table.getSelectedRow();
209 Enumeration<Offer> rhs = rh.getAllOffers().elements();
210 while (rhs.hasMoreElements()) {
211 Offer of = rhs.nextElement();
212 Vector<Object> row = new Vector<Object>();
213 row.add(of.getOfferNumber());
214 row.add(of.getFirstDay());
215 row.add(of.getLastDay());
216 row.add(of.getPrice());
217 tableModel.addRow(row);
220 table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
224 private static final long serialVersionUID = 1L;
227 public Component getTableCellRendererComponent(JTable table,
228 Object value, boolean isSelected, boolean hasFocus,
231 super.getTableCellRendererComponent(table, value, isSelected,
234 Date firstDay = (Date) table.getModel().getValueAt(row, 1);
235 Date lastDay = (Date) table.getModel().getValueAt(row, 2);
236 if (FirstDay != null && LastDay != null) {
237 if (LastDay.before(lastDay) || FirstDay.after(firstDay)) {
238 setBackground(Color.RED);
239 setForeground(Color.BLACK);
241 setBackground(Color.GREEN);
242 setForeground(Color.BLACK);
250 private void jButton_ActionPerformed(ActionEvent arg0) {
251 BookingManager bookingM = new BookingManager();
252 //RegExp to see if telephone number is correct??TODO
253 if (!telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")){
254 phoneNum.setText("Wrong phone format");
256 phoneNum.setText("");
260 if (table.getRowCount()!=0)
261 book = bookingM.createBooking(rh, rh.offers.get(row).getFirstDay(), rh.offers.get(row).getLastDay(), telIn.getText());
262 } catch (Exception e) {
263 // TODO Auto-generated catch block
267 BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
269 confirmWindow.setVisible(true);