Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard
 
25898b619dd708c9f15a44200b545cac11404b73
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
package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.rmi.Naming;
import java.sql.Date;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import com.toedter.calendar.JCalendar;
import common.OfferInterface;

import configuration.___IntNames;
import domain.Offer;
import domain.RuralHouse;
import exceptions.BadDates;

public class ModifyOfferGUI extends JFrame {

	private static final long serialVersionUID = 1L;

	private JComboBox<RuralHouse> jComboBox1;
	private JLabel jLabel1 = new JLabel();
	private JLabel jLabel2 = new JLabel();
	private JTextField jTextField1 = new JTextField();
	private JLabel jLabel3 = new JLabel();
	private JTextField jTextField2 = new JTextField();
	private JLabel jLabel4 = new JLabel();
	private JTextField jTextField3 = new JTextField();
	private JButton jButton1 = new JButton();
	// Code for JCalendar
	private JCalendar jCalendar1 = new JCalendar();
	private JCalendar jCalendar2 = new JCalendar();
	private Calendar calendarInicio = null;
	private Calendar calendarFin = null;
	private JButton jButton2 = new JButton();
	private JLabel jLabel5 = new JLabel();
	private final JLabel jLabel1_o = new JLabel();
	private JComboBox<Offer> comboBox_o;

	public ModifyOfferGUI(Vector<RuralHouse> v) {
		try {
			jbInit(v);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void jbInit(Vector<RuralHouse> v) throws Exception {
		this.getContentPane().setLayout(null);
		this.setSize(new Dimension(513, 433));
		this.setTitle("Set availability");

		
		jComboBox1 = new JComboBox<RuralHouse>(v);

		comboBox_o = new JComboBox<Offer>(
				((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers());
		DateFormat dateformat1 = DateFormat.getDateInstance(1,
				jCalendar1.getLocale());
		if (!((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers()
				.isEmpty()) {
			jTextField1.setText(dateformat1.format(((Offer) comboBox_o
					.getSelectedItem()).getFirstDay()));
			jTextField2.setText(dateformat1.format(((Offer) comboBox_o
					.getSelectedItem()).getLastDay()));		
			jLabel4.setText(Float.toString(((Offer) comboBox_o
					.getSelectedItem()).getPrice()));
			jTextField3.setText(Float.toString(((Offer) comboBox_o
					.getSelectedItem()).getPrice()));
		} else {
			jLabel5.setText("There are no offers for the selected rural house");
			jCalendar1.setEnabled(false);
			jCalendar2.setEnabled(false);
			jButton1.setEnabled(false);
			comboBox_o.setEnabled(false);
			jTextField3.setEnabled(false);
		}
		jComboBox1.setBounds(new Rectangle(115, 12, 115, 20));
		jLabel1.setText("List of houses:");
		jLabel1.setBounds(new Rectangle(25, 12, 95, 20));
		jLabel2.setText("First day :");
		jLabel2.setBounds(new Rectangle(25, 75, 85, 25));
		jTextField1.setBounds(new Rectangle(25, 265, 220, 25));
		jTextField1.setEditable(false);
		jLabel3.setText("Last day :");
		jLabel3.setBounds(new Rectangle(260, 75, 75, 25));
		jTextField2.setBounds(new Rectangle(260, 265, 220, 25));
		jTextField2.setEditable(false);
		jLabel4.setText("Price:");
		jLabel4.setBounds(new Rectangle(260, 30, 75, 20));
		jTextField3.setBounds(new Rectangle(350, 30, 115, 20));
		jTextField3.setText("0");
		jButton1.setText("Accept");
		jButton1.setBounds(new Rectangle(100, 360, 130, 30));
		jTextField3.addFocusListener(new FocusListener() {
			public void focusGained(FocusEvent e) {
			}

			public void focusLost(FocusEvent e) {
				jTextField3_focusLost();
			}
		});

		jComboBox1.addItemListener(new ItemListener() {

			@Override
			public void itemStateChanged(ItemEvent arg0) {
				Vector<Offer> vo = ((RuralHouse) jComboBox1.getSelectedItem()).offers;
				comboBox_o.removeAllItems();
				if (!((RuralHouse) jComboBox1.getSelectedItem()).offers
						.isEmpty()) {
					jCalendar1.setEnabled(true);
					jCalendar2.setEnabled(true);
					jButton1.setEnabled(true);
					comboBox_o.setEnabled(true);
					jTextField3.setEnabled(true);
					jLabel5.setText("");
					for (Offer of : vo) {
						comboBox_o.addItem(of);
					}
				} else {
					jLabel5.setText("There are no offers for the selected rural house");
					jCalendar1.setEnabled(false);
					jCalendar2.setEnabled(false);
					jButton1.setEnabled(false);
					comboBox_o.setEnabled(false);
					jTextField3.setEnabled(false);
					
				}
			}

		});

		comboBox_o.addItemListener(new ItemListener() {

			@Override
			public void itemStateChanged(ItemEvent arg0) {
				if (arg0.getStateChange() == ItemEvent.SELECTED) {
					Offer of = (Offer) comboBox_o.getSelectedItem();
					DateFormat dateformat1 = DateFormat.getDateInstance(1,
							jCalendar1.getLocale());
					jTextField1.setText(dateformat1.format(of.getFirstDay()));
					jTextField2.setText(dateformat1.format(of.getLastDay()));
				}
			}

		});

		jButton1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jButton1_actionPerformed(e);
			}
		});
		jButton2.setText("Cancel");
		jButton2.setBounds(new Rectangle(270, 360, 130, 30));
		jButton2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jButton2_actionPerformed(e);
			}
		});
		jLabel5.setBounds(new Rectangle(100, 320, 300, 20));
		jLabel5.setForeground(Color.red);
		jLabel5.setSize(new Dimension(305, 20));
		jCalendar1.setBounds(new Rectangle(25, 100, 220, 165));
		jCalendar2.setBounds(new Rectangle(260, 100, 220, 165));

		// Code for JCalendar
		this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent propertychangeevent) {
				if (propertychangeevent.getPropertyName().equals("locale")) {
					jCalendar1.setLocale((Locale) propertychangeevent
							.getNewValue());
					DateFormat dateformat = DateFormat.getDateInstance(1,
							jCalendar1.getLocale());
					jTextField1.setText(dateformat.format(calendarInicio
							.getTime()));
				} else if (propertychangeevent.getPropertyName().equals(
						"calendar")) {
					calendarInicio = (Calendar) propertychangeevent
							.getNewValue();
					DateFormat dateformat1 = DateFormat.getDateInstance(1,
							jCalendar1.getLocale());
					jTextField1.setText(dateformat1.format(calendarInicio
							.getTime()));
					jCalendar1.setCalendar(calendarInicio);
				}
			}
		});

		this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent propertychangeevent) {
				if (propertychangeevent.getPropertyName().equals("locale")) {
					jCalendar2.setLocale((Locale) propertychangeevent
							.getNewValue());
					DateFormat dateformat = DateFormat.getDateInstance(1,
							jCalendar2.getLocale());
					jTextField2.setText(dateformat.format(calendarFin.getTime()));
				} else if (propertychangeevent.getPropertyName().equals(
						"calendar")) {
					calendarFin = (Calendar) propertychangeevent.getNewValue();
					DateFormat dateformat1 = DateFormat.getDateInstance(1,
							jCalendar2.getLocale());
					jTextField2.setText(dateformat1.format(calendarFin
							.getTime()));
					jCalendar2.setCalendar(calendarFin);
				}
			}
		});

		this.getContentPane().add(jCalendar2, null);
		this.getContentPane().add(jCalendar1, null);
		this.getContentPane().add(jLabel5, null);
		this.getContentPane().add(jButton2, null);
		this.getContentPane().add(jButton1, null);
		this.getContentPane().add(jTextField3, null);
		this.getContentPane().add(jLabel4, null);
		this.getContentPane().add(jTextField2, null);
		this.getContentPane().add(jLabel3, null);
		this.getContentPane().add(jTextField1, null);
		this.getContentPane().add(jLabel2, null);
		this.getContentPane().add(jLabel1, null);
		this.getContentPane().add(jComboBox1, null);
		jLabel1_o.setText("List of offers:");
		jLabel1_o.setBounds(new Rectangle(25, 30, 95, 20));
		jLabel1_o.setBounds(25, 44, 95, 20);

		getContentPane().add(jLabel1_o);
		comboBox_o.setBounds(new Rectangle(115, 30, 115, 20));
		comboBox_o.setBounds(115, 44, 115, 20);

		getContentPane().add(comboBox_o);
	}

	private void jButton1_actionPerformed(ActionEvent e) {
		RuralHouse ruralHouse = ((RuralHouse) jComboBox1.getSelectedItem());
		Date firstDay = new Date(jCalendar1.getCalendar().getTime().getTime());
		// Remove the hour:minute:second:ms from the date
		firstDay = Date.valueOf(firstDay.toString());
		Date lastDay = new Date(jCalendar2.getCalendar().getTime().getTime());
		// Remove the hour:minute:second:ms from the date
		lastDay = Date.valueOf(lastDay.toString());
		

		try {

			// It could be to trigger an exception if the introduced string is
			// not a number
			float price = Float.parseFloat(jTextField3.getText());

			// Obtain the business logic from a StartWindow class (local or
			// remote)
			OfferInterface offerM = null;
			try {
				offerM = (OfferInterface) Naming
						.lookup(___IntNames.OfferManager);
			} catch (Exception e1) {
				System.out.println("Error accessing remote authentication: "
						+ e1.toString());
			}
	  		
			offerM.deleteOffer(ruralHouse, (Offer) comboBox_o.getSelectedItem());
			offerM.createOffer(ruralHouse, firstDay, lastDay, price);

			jLabel5.setText("Offer modified");

		} catch (java.lang.NumberFormatException e1) {
			jLabel5.setText(jTextField3.getText() + " is not a valid price");
		} catch (BadDates e1) {
			jLabel5.setText("Last day is before first day in the offer");
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}

	private void jButton2_actionPerformed(ActionEvent e) {
		this.setVisible(false);
	}

	private void jTextField3_focusLost() {
		try {
			new Integer(jTextField3.getText());
			jLabel5.setText("");
		} catch (NumberFormatException ex) {
			jLabel5.setText("Error: Please introduce a number");
		}
	}
}

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

Diff revisions: vs.
Revision Author Commited Message
25898b ... Diff Diff camjan Mon 18 May, 2015 15:26:01 +0000

Account adding and deleting fixed

799949 ... Diff Diff epinzolas001 Mon 18 May, 2015 11:12:36 +0000

debugging

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

Merge conflicts solutioned