3 import java.awt.BorderLayout;
4 import java.awt.EventQueue;
6 import javax.swing.JFrame;
7 import javax.swing.JPanel;
8 import javax.swing.border.EmptyBorder;
9 import javax.swing.GroupLayout;
10 import javax.swing.GroupLayout.Alignment;
12 import domain.HouseFeatures;
14 import domain.RuralHouse;
16 import javax.swing.JLabel;
17 import javax.swing.JTextField;
18 import javax.swing.LayoutStyle.ComponentPlacement;
19 import javax.swing.SwingConstants;
20 import javax.swing.JButton;
21 import javax.swing.JComboBox;
23 import businessLogic.HouseManager;
25 import java.awt.event.ActionListener;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ItemEvent;
28 import java.awt.event.ItemListener;
30 public class ModifyHouseGUI extends JFrame {
35 private static final long serialVersionUID = 1L;
36 private JPanel contentPane;
38 private JLabel lblDistrict;
39 private JTextField District_f;
40 private JLabel lblDescription;
41 private JTextField description_f;
42 private JLabel lblKitchen;
43 private JTextField kitchens_f;
44 private JLabel lblRooms;
45 private JTextField rooms_f;
46 private JLabel lblLivings;
47 private JTextField lRooms_f;
48 private JLabel lblParkings;
49 private JTextField parkings_f;
50 private JLabel lblBaths;
51 private JTextField baths_f;
52 private JButton btnConfirm;
53 private JComboBox<RuralHouse> houseBox;
54 private RuralHouse rh;
60 public ModifyHouseGUI(Owner o) {
61 this.getContentPane().setLayout(null);
63 setBounds(100, 100, 500, 583);
64 contentPane = new JPanel();
65 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
66 setContentPane(contentPane);
68 JLabel lblCode = new JLabel("House Code:");
69 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
71 lblDistrict = new JLabel("District:");
72 lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
74 District_f = new JTextField();
75 District_f.setColumns(10);
77 lblDescription = new JLabel("Description:");
78 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
80 description_f = new JTextField();
81 description_f.setColumns(10);
83 lblKitchen = new JLabel("Kitchens:");
84 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
86 kitchens_f = new JTextField();
87 kitchens_f.setColumns(10);
89 lblRooms = new JLabel("Rooms:");
90 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
92 rooms_f = new JTextField();
93 rooms_f.setColumns(10);
95 lblLivings = new JLabel("Living rooms:");
96 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
98 lRooms_f = new JTextField();
99 lRooms_f.setColumns(10);
101 lblParkings = new JLabel("Parkings:");
102 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
104 parkings_f = new JTextField();
105 parkings_f.setColumns(10);
107 lblBaths = new JLabel("Baths:");
108 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
110 baths_f = new JTextField();
111 baths_f.setColumns(10);
113 btnConfirm = new JButton("Confirm");
114 btnConfirm.addActionListener(new ActionListener() {
115 public void actionPerformed(ActionEvent arg0) {
118 HouseManager hm = new HouseManager();
119 hm.removeHouse(rh, owner);
120 hm.registerNewHouse(rh.getHouseName(),
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())
133 houseBox = new JComboBox<RuralHouse>(o.getRuralHouses());
135 houseBox.addItemListener(new ItemListener() {
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()));
150 GroupLayout gl_contentPane = new GroupLayout(contentPane);
151 gl_contentPane.setHorizontalGroup(
152 gl_contentPane.createParallelGroup(Alignment.LEADING)
153 .addGroup(gl_contentPane.createSequentialGroup()
154 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
155 .addGroup(gl_contentPane.createSequentialGroup()
157 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
158 .addGroup(gl_contentPane.createSequentialGroup()
159 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
161 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
162 .addGroup(gl_contentPane.createSequentialGroup()
163 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
165 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
166 .addGroup(gl_contentPane.createSequentialGroup()
167 .addComponent(lblCode)
168 .addPreferredGap(ComponentPlacement.UNRELATED)
169 .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE))
170 .addGroup(gl_contentPane.createSequentialGroup()
171 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
173 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
174 .addGroup(gl_contentPane.createSequentialGroup()
175 .addComponent(lblDistrict, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
177 .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
178 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
179 .addGroup(gl_contentPane.createSequentialGroup()
181 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
182 .addGroup(gl_contentPane.createSequentialGroup()
183 .addComponent(lblLivings)
185 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
186 .addGroup(gl_contentPane.createSequentialGroup()
187 .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
189 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
190 .addGroup(gl_contentPane.createSequentialGroup()
192 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
193 .addGroup(gl_contentPane.createSequentialGroup()
195 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE))
196 .addComponent(lblDescription, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)))))
197 .addGroup(gl_contentPane.createSequentialGroup()
199 .addComponent(btnConfirm)))
202 gl_contentPane.setVerticalGroup(
203 gl_contentPane.createParallelGroup(Alignment.LEADING)
204 .addGroup(gl_contentPane.createSequentialGroup()
206 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
207 .addGroup(gl_contentPane.createSequentialGroup()
209 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
210 .addComponent(lblCode)
211 .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
212 .addPreferredGap(ComponentPlacement.UNRELATED)
213 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
214 .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
215 .addComponent(lblDistrict)))
216 .addGroup(gl_contentPane.createSequentialGroup()
218 .addComponent(lblDescription)
219 .addPreferredGap(ComponentPlacement.UNRELATED)
220 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE)))
222 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
223 .addGroup(gl_contentPane.createSequentialGroup()
225 .addComponent(lblRooms))
226 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
227 .addGroup(gl_contentPane.createSequentialGroup()
229 .addComponent(lblKitchen))
230 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
232 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
233 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
234 .addGroup(gl_contentPane.createSequentialGroup()
236 .addComponent(lblBaths))
237 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
238 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
239 .addComponent(lblLivings)))
240 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
242 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
243 .addGroup(gl_contentPane.createSequentialGroup()
245 .addComponent(lblParkings))
246 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
248 .addComponent(btnConfirm)
251 contentPane.setLayout(gl_contentPane);