Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard
 
ad3773a09001cb5e9bac980f0500d8d6c787a3ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.rmi.Naming;
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import common.BookingInterface;

import configuration.___IntNames;
import domain.Booking;
import domain.Client;
import domain.Offer;
import domain.RuralHouse;

public class HouseFeaturesGUI extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JLabel lblDistrict;
	private JTextField District_f;
	private JLabel lblDescription;
	private JTextField description_f;
	private JLabel lblKitchen;
	private JTextField kitchens_f;
	private JLabel lblRooms;
	private JTextField rooms_f;
	private JLabel lblLivings;
	private JTextField lRooms_f;
	private JLabel lblParkings;
	private JTextField parkings_f;
	private JLabel lblBaths;
	private JTextField baths_f;
	private JTable table;
	private DefaultTableModel tableModel;
	private RuralHouse rh;
	private JTextField telIn;
	private int row;
	private JLabel labelPhone;
	private JLabel lblName;
	private JTextField nameField;
	private JLabel lblEmail;
	private JTextField mailField;

	/**
	 * Create the frame.
	 */

	public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay,
			final Date LastDay) {
		this.rh = RH;
		this.getContentPane().setLayout(null);
		setBounds(100, 100, 500, 700);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		lblDistrict = new JLabel("District:");
		lblDistrict.setBounds(23, 67, 70, 14);
		lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);

		District_f = new JTextField();
		District_f.setEditable(false);
		District_f.setBounds(103, 64, 86, 20);
		District_f.setColumns(10);

		lblDescription = new JLabel("Description:");
		lblDescription.setBounds(215, 67, 90, 14);
		lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);

		description_f = new JTextField();
		description_f.setEditable(false);
		description_f.setBounds(238, 99, 178, 129);
		description_f.setColumns(10);

		lblKitchen = new JLabel("Kitchens:");
		lblKitchen.setBounds(23, 211, 70, 14);
		lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);

		kitchens_f = new JTextField();
		kitchens_f.setEditable(false);
		kitchens_f.setBounds(103, 202, 86, 20);
		kitchens_f.setColumns(10);

		lblRooms = new JLabel("Rooms:");
		lblRooms.setBounds(23, 102, 70, 14);
		lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);

		rooms_f = new JTextField();
		rooms_f.setEditable(false);
		rooms_f.setBounds(103, 99, 86, 20);
		rooms_f.setColumns(10);

		lblLivings = new JLabel("Living rooms:");
		lblLivings.setBounds(30, 236, 63, 14);
		lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);

		lRooms_f = new JTextField();
		lRooms_f.setEditable(false);
		lRooms_f.setBounds(103, 233, 86, 20);
		lRooms_f.setColumns(10);

		lblParkings = new JLabel("Parkings:");
		lblParkings.setBounds(23, 174, 70, 14);
		lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);

		parkings_f = new JTextField();
		parkings_f.setEditable(false);
		parkings_f.setBounds(103, 171, 86, 20);
		parkings_f.setColumns(10);

		lblBaths = new JLabel("Baths:");
		lblBaths.setBounds(23, 143, 70, 14);
		lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);

		baths_f = new JTextField();
		baths_f.setEditable(false);
		baths_f.setBounds(103, 140, 86, 20);
		baths_f.setColumns(10);
		contentPane.setLayout(null);
		contentPane.add(lblParkings);
		contentPane.add(parkings_f);
		contentPane.add(lblRooms);
		contentPane.add(rooms_f);
		contentPane.add(lblBaths);
		contentPane.add(baths_f);
		contentPane.add(lblDistrict);
		contentPane.add(District_f);
		contentPane.add(lblLivings);
		contentPane.add(lRooms_f);
		contentPane.add(lblKitchen);
		contentPane.add(kitchens_f);
		contentPane.add(description_f);
		contentPane.add(lblDescription);
		parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings()));
		rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
		baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
		District_f.setText(rh.getDistrict());
		kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens()));
		description_f.setText(rh.getDescription());
		lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings()));
		JLabel lblAvailbleOffers = new JLabel("Availble Offers:");
		lblAvailbleOffers.setBounds(30, 286, 86, 14);
		contentPane.add(lblAvailbleOffers);
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(40, 311, 376, 183);
		contentPane.add(scrollPane);

		table = new JTable() {
			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int row, int column) {
				return false;
			};
		};
		tableModel = new DefaultTableModel(null, new String[] { "Offer #",
				"FirstDay", "LastDay", "Price" });
		table.setModel(tableModel);
		scrollPane.setViewportView(table);

		JButton btnBookSelected = new JButton("Book SelectedOffer");
		btnBookSelected.setBounds(238, 614, 178, 23);
		contentPane.add(btnBookSelected);

		btnBookSelected.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				jButton_ActionPerformed(arg0);
			}

		});

		JLabel lblNewLabel = new JLabel(
				"Green: Suit your dates. Red: Do not suit your dates");
		lblNewLabel.setEnabled(false);
		lblNewLabel.setBounds(170, 282, 261, 23);
		contentPane.add(lblNewLabel);

		JLabel lblNewLabel_1 = new JLabel("Telephone num:");
		lblNewLabel_1.setBounds(10, 618, 83, 14);
		contentPane.add(lblNewLabel_1);

		telIn = new JTextField();
		telIn.setBounds(103, 615, 129, 20);
		contentPane.add(telIn);
		telIn.setColumns(10);

		labelPhone = new JLabel("");
		labelPhone.setBounds(238, 252, 178, 14);
		contentPane.add(labelPhone);

		lblName = new JLabel("Name:");
		lblName.setBounds(10, 516, 46, 14);
		contentPane.add(lblName);

		nameField = new JTextField();
		nameField.setBounds(103, 513, 178, 20);
		contentPane.add(nameField);
		nameField.setColumns(10);

		lblEmail = new JLabel("E-mail:");
		lblEmail.setBounds(10, 565, 46, 14);
		contentPane.add(lblEmail);

		mailField = new JTextField();
		mailField.setBounds(103, 562, 178, 20);
		contentPane.add(mailField);
		mailField.setColumns(10);

		table.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				row = table.getSelectedRow();
			}
		});
		Enumeration<Offer> rhs = rh.getAllOffers().elements();
		while (rhs.hasMoreElements()) {
			Offer of = rhs.nextElement();
			if (of.getBookings() != null) {
				Vector<Object> row = new Vector<Object>();
				row.add(of.getOfferNumber());
				row.add(of.getFirstDay());
				row.add(of.getLastDay());
				row.add(of.getPrice());
				tableModel.addRow(row);
			}
		}
		table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public Component getTableCellRendererComponent(JTable table,
					Object value, boolean isSelected, boolean hasFocus,
					int row, int col) {

				super.getTableCellRendererComponent(table, value, isSelected,
						hasFocus, row, col);

				Date firstDay = (Date) table.getModel().getValueAt(row, 1);
				Date lastDay = (Date) table.getModel().getValueAt(row, 2);
				if (FirstDay != null && LastDay != null) {
					if (LastDay.before(lastDay) || FirstDay.after(firstDay)) {
						setBackground(Color.RED);
						setForeground(Color.BLACK);
					} else {
						setBackground(Color.GREEN);
						setForeground(Color.BLACK);
					}
				}
				return this;
			}
		});
	}

	private void jButton_ActionPerformed(ActionEvent arg0) {

		BookingInterface bookingM = null;
		try {
			bookingM = (BookingInterface) Naming
					.lookup(___IntNames.BookingManager);
		} catch (Exception e1) {
			System.out.println("Error accessing remote authentication: "
					+ e1.toString());
		}
  		
		if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")
				&& mailField
				.getText()
				.matches(
						"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
		&& !nameField.getText().isEmpty()) {
			labelPhone.setText("");
			Vector<Booking> book = null;
			try {
				if (table.getRowCount() != 0) {
					Client cl = new Client(nameField.getText(),
							mailField.getText(), telIn.getText());
					book = bookingM.createBooking(rh, rh.offers.get(row)
							.getFirstDay(), rh.offers.get(row).getLastDay(),cl);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (book != null) {
				BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
						book.lastElement());
				confirmWindow.setVisible(true);
			}
		} else {
			labelPhone.setText("Bad formatted data.");

		}
	}
}

Commits for RRRRHHHH_CoderuralHouses client/src/gui/HouseFeaturesGUI.java

Diff revisions: vs.
Revision Author Commited Message
ad3773 ... Diff Diff pinene picture pinene Tue 19 May, 2015 18:01:40 +0000

data now is gotten using queries

4f8bcc ... epinzolas001 Mon 18 May, 2015 09:49:54 +0000

Merge conflicts solutioned