|
@@ -9,7 +9,10 @@ |
9 |
9 |
|
import javax.swing.GroupLayout; |
10 |
10 |
|
import javax.swing.GroupLayout.Alignment; |
11 |
11 |
|
|
|
12 |
+ |
import domain.HouseFeatures; |
12 |
13 |
|
import domain.Owner; |
|
14 |
+ |
import domain.RuralHouse; |
|
15 |
+ |
|
13 |
16 |
|
import javax.swing.JLabel; |
14 |
17 |
|
import javax.swing.JTextField; |
15 |
18 |
|
import javax.swing.LayoutStyle.ComponentPlacement; |
|
@@ -17,6 +20,13 @@ |
17 |
20 |
|
import javax.swing.JButton; |
18 |
21 |
|
import javax.swing.JComboBox; |
19 |
22 |
|
|
|
23 |
+ |
import businessLogic.HouseManager; |
|
24 |
+ |
|
|
25 |
+ |
import java.awt.event.ActionListener; |
|
26 |
+ |
import java.awt.event.ActionEvent; |
|
27 |
+ |
import java.awt.event.ItemEvent; |
|
28 |
+ |
import java.awt.event.ItemListener; |
|
29 |
+ |
|
20 |
30 |
|
public class ModifyHouseGUI extends JFrame { |
21 |
31 |
|
|
22 |
32 |
|
/** |
|
@@ -25,8 +35,8 @@ |
25 |
35 |
|
private static final long serialVersionUID = 1L; |
26 |
36 |
|
private JPanel contentPane; |
27 |
37 |
|
private Owner owner; |
28 |
|
- |
private JLabel lblTown; |
29 |
|
- |
private JTextField Town_f; |
|
38 |
+ |
private JLabel lblDistrict; |
|
39 |
+ |
private JTextField District_f; |
30 |
40 |
|
private JLabel lblDescription; |
31 |
41 |
|
private JTextField description_f; |
32 |
42 |
|
private JLabel lblKitchen; |
|
@@ -39,9 +49,9 @@ |
39 |
49 |
|
private JTextField parkings_f; |
40 |
50 |
|
private JLabel lblBaths; |
41 |
51 |
|
private JTextField baths_f; |
42 |
|
- |
private JButton btnRegister; |
43 |
|
- |
private JComboBox comboBox; |
44 |
|
- |
|
|
52 |
+ |
private JButton btnConfirm; |
|
53 |
+ |
private JComboBox<RuralHouse> houseBox; |
|
54 |
+ |
private RuralHouse rh; |
45 |
55 |
|
|
46 |
56 |
|
|
47 |
57 |
|
/** |
|
@@ -58,11 +68,11 @@ |
58 |
68 |
|
JLabel lblCode = new JLabel("House Code:"); |
59 |
69 |
|
lblCode.setHorizontalAlignment(SwingConstants.RIGHT); |
60 |
70 |
|
|
61 |
|
- |
lblTown = new JLabel("Town:"); |
62 |
|
- |
lblTown.setHorizontalAlignment(SwingConstants.RIGHT); |
|
71 |
+ |
lblDistrict = new JLabel("District:"); |
|
72 |
+ |
lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT); |
63 |
73 |
|
|
64 |
|
- |
Town_f = new JTextField(); |
65 |
|
- |
Town_f.setColumns(10); |
|
74 |
+ |
District_f = new JTextField(); |
|
75 |
+ |
District_f.setColumns(10); |
66 |
76 |
|
|
67 |
77 |
|
lblDescription = new JLabel("Description:"); |
68 |
78 |
|
lblDescription.setHorizontalAlignment(SwingConstants.RIGHT); |
|
@@ -100,9 +110,43 @@ |
100 |
110 |
|
baths_f = new JTextField(); |
101 |
111 |
|
baths_f.setColumns(10); |
102 |
112 |
|
|
103 |
|
- |
btnRegister = new JButton("Register House"); |
|
113 |
+ |
btnConfirm = new JButton("Confirm"); |
|
114 |
+ |
btnConfirm.addActionListener(new ActionListener() { |
|
115 |
+ |
public void actionPerformed(ActionEvent arg0) { |
|
116 |
+ |
|
|
117 |
+ |
|
|
118 |
+ |
HouseManager hm = new HouseManager(); |
|
119 |
+ |
hm.removeHouse(rh, owner); |
|
120 |
+ |
hm.registerNewHouse(rh.getHouseName(), |
|
121 |
+ |
owner, |
|
122 |
+ |
description_f.getText(), |
|
123 |
+ |
District_f.getText(), |
|
124 |
+ |
new Integer(rooms_f.getText()), |
|
125 |
+ |
new Integer(kitchens_f.getText()), |
|
126 |
+ |
new Integer(baths_f.getText()), |
|
127 |
+ |
new Integer(lRooms_f.getText()), |
|
128 |
+ |
new Integer(parkings_f.getText()) |
|
129 |
+ |
); |
|
130 |
+ |
} |
|
131 |
+ |
}); |
|
132 |
+ |
|
|
133 |
+ |
houseBox = new JComboBox<RuralHouse>(o.getRuralHouses()); |
|
134 |
+ |
|
|
135 |
+ |
houseBox.addItemListener(new ItemListener() { |
|
136 |
+ |
@Override |
|
137 |
+ |
public void itemStateChanged(ItemEvent e) { |
|
138 |
+ |
rh = (RuralHouse)houseBox.getSelectedItem(); |
|
139 |
+ |
District_f.setText(rh.getDistrict()); |
|
140 |
+ |
description_f.setText(rh.getDescription()); |
|
141 |
+ |
kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens())); |
|
142 |
+ |
rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); |
|
143 |
+ |
lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings())); |
|
144 |
+ |
parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings())); |
|
145 |
+ |
baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); |
|
146 |
+ |
|
|
147 |
+ |
} |
|
148 |
+ |
}); |
104 |
149 |
|
|
105 |
|
- |
comboBox = new JComboBox(); |
106 |
150 |
|
GroupLayout gl_contentPane = new GroupLayout(contentPane); |
107 |
151 |
|
gl_contentPane.setHorizontalGroup( |
108 |
152 |
|
gl_contentPane.createParallelGroup(Alignment.LEADING) |
|
@@ -122,15 +166,15 @@ |
122 |
166 |
|
.addGroup(gl_contentPane.createSequentialGroup() |
123 |
167 |
|
.addComponent(lblCode) |
124 |
168 |
|
.addPreferredGap(ComponentPlacement.UNRELATED) |
125 |
|
- |
.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)) |
|
169 |
+ |
.addComponent(houseBox, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)) |
126 |
170 |
|
.addGroup(gl_contentPane.createSequentialGroup() |
127 |
171 |
|
.addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) |
128 |
172 |
|
.addGap(18) |
129 |
173 |
|
.addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) |
130 |
174 |
|
.addGroup(gl_contentPane.createSequentialGroup() |
131 |
|
- |
.addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) |
|
175 |
+ |
.addComponent(lblDistrict, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) |
132 |
176 |
|
.addGap(18) |
133 |
|
- |
.addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) |
|
177 |
+ |
.addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) |
134 |
178 |
|
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) |
135 |
179 |
|
.addGroup(gl_contentPane.createSequentialGroup() |
136 |
180 |
|
.addGap(17) |
|
@@ -152,7 +196,7 @@ |
152 |
196 |
|
.addComponent(lblDescription, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE))))) |
153 |
197 |
|
.addGroup(gl_contentPane.createSequentialGroup() |
154 |
198 |
|
.addGap(140) |
155 |
|
- |
.addComponent(btnRegister))) |
|
199 |
+ |
.addComponent(btnConfirm))) |
156 |
200 |
|
.addContainerGap()) |
157 |
201 |
|
); |
158 |
202 |
|
gl_contentPane.setVerticalGroup( |
|
@@ -164,11 +208,11 @@ |
164 |
208 |
|
.addGap(60) |
165 |
209 |
|
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) |
166 |
210 |
|
.addComponent(lblCode) |
167 |
|
- |
.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) |
|
211 |
+ |
.addComponent(houseBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) |
168 |
212 |
|
.addPreferredGap(ComponentPlacement.UNRELATED) |
169 |
213 |
|
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) |
170 |
|
- |
.addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) |
171 |
|
- |
.addComponent(lblTown))) |
|
214 |
+ |
.addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) |
|
215 |
+ |
.addComponent(lblDistrict))) |
172 |
216 |
|
.addGroup(gl_contentPane.createSequentialGroup() |
173 |
217 |
|
.addGap(63) |
174 |
218 |
|
.addComponent(lblDescription) |
|
@@ -201,7 +245,7 @@ |
201 |
245 |
|
.addComponent(lblParkings)) |
202 |
246 |
|
.addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) |
203 |
247 |
|
.addGap(41) |
204 |
|
- |
.addComponent(btnRegister) |
|
248 |
+ |
.addComponent(btnConfirm) |
205 |
249 |
|
.addGap(54)) |
206 |
250 |
|
); |
207 |
251 |
|
contentPane.setLayout(gl_contentPane); |