3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.awt.event.ItemEvent;
6 import java.awt.event.ItemListener;
8 import javax.swing.GroupLayout;
9 import javax.swing.GroupLayout.Alignment;
10 import javax.swing.JButton;
11 import javax.swing.JComboBox;
12 import javax.swing.JFrame;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.JTextField;
16 import javax.swing.LayoutStyle.ComponentPlacement;
17 import javax.swing.SwingConstants;
18 import javax.swing.border.EmptyBorder;
20 import businessLogic.HouseManager;
22 import domain.RuralHouse;
24 public class ModifyHouseGUI extends JFrame {
29 private static final long serialVersionUID = 1L;
30 private JPanel contentPane;
32 private JLabel lblDistrict;
33 private JTextField District_f;
34 private JLabel lblDescription;
35 private JTextField description_f;
36 private JLabel lblKitchen;
37 private JTextField kitchens_f;
38 private JLabel lblRooms;
39 private JTextField rooms_f;
40 private JLabel lblLivings;
41 private JTextField lRooms_f;
42 private JLabel lblParkings;
43 private JTextField parkings_f;
44 private JLabel lblBaths;
45 private JTextField baths_f;
46 private JButton btnConfirm;
47 private JComboBox<RuralHouse> houseBox;
48 private RuralHouse rh;
54 public ModifyHouseGUI(Owner o) {
55 this.getContentPane().setLayout(null);
57 setBounds(100, 100, 500, 583);
58 contentPane = new JPanel();
59 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
60 setContentPane(contentPane);
62 JLabel lblCode = new JLabel("House Name:");
63 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
65 lblDistrict = new JLabel("District:");
66 lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
68 District_f = new JTextField();
69 District_f.setColumns(10);
71 lblDescription = new JLabel("Description:");
72 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
74 description_f = new JTextField();
75 description_f.setColumns(10);
77 lblKitchen = new JLabel("Kitchens:");
78 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
80 kitchens_f = new JTextField();
81 kitchens_f.setColumns(10);
83 lblRooms = new JLabel("Rooms:");
84 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
86 rooms_f = new JTextField();
87 rooms_f.setColumns(10);
89 lblLivings = new JLabel("Living rooms:");
90 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
92 lRooms_f = new JTextField();
93 lRooms_f.setColumns(10);
95 lblParkings = new JLabel("Parkings:");
96 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
98 parkings_f = new JTextField();
99 parkings_f.setColumns(10);
101 lblBaths = new JLabel("Baths:");
102 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
104 baths_f = new JTextField();
105 baths_f.setColumns(10);
107 btnConfirm = new JButton("Confirm");
108 btnConfirm.addActionListener(new ActionListener() {
109 public void actionPerformed(ActionEvent arg0) {
112 HouseManager hm = new HouseManager();
113 hm.removeHouse(rh, owner);
114 hm.registerNewHouse(rh.getHouseName(),
116 description_f.getText(),
117 District_f.getText(),
118 new Integer(rooms_f.getText()),
119 new Integer(kitchens_f.getText()),
120 new Integer(baths_f.getText()),
121 new Integer(lRooms_f.getText()),
122 new Integer(parkings_f.getText())
127 houseBox = new JComboBox<RuralHouse>(o.getRuralHouses());
129 houseBox.addItemListener(new ItemListener() {
131 public void itemStateChanged(ItemEvent e) {
132 rh = (RuralHouse)houseBox.getSelectedItem();
133 District_f.setText(rh.getDistrict());
134 description_f.setText(rh.getDescription());
135 kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens()));
136 rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
137 lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings()));
138 parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings()));
139 baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
144 GroupLayout gl_contentPane = new GroupLayout(contentPane);
145 gl_contentPane.setHorizontalGroup(
146 gl_contentPane.createParallelGroup(Alignment.LEADING)
147 .addGroup(gl_contentPane.createSequentialGroup()
148 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
149 .addGroup(gl_contentPane.createSequentialGroup()
151 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
152 .addGroup(gl_contentPane.createSequentialGroup()
153 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
155 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
156 .addGroup(gl_contentPane.createSequentialGroup()
157 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
159 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
160 .addGroup(gl_contentPane.createSequentialGroup()
161 .addComponent(lblCode)
162 .addPreferredGap(ComponentPlacement.UNRELATED)
163 .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE))
164 .addGroup(gl_contentPane.createSequentialGroup()
165 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
167 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
168 .addGroup(gl_contentPane.createSequentialGroup()
169 .addComponent(lblDistrict, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
171 .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
172 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
173 .addGroup(gl_contentPane.createSequentialGroup()
175 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
176 .addGroup(gl_contentPane.createSequentialGroup()
177 .addComponent(lblLivings)
179 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
180 .addGroup(gl_contentPane.createSequentialGroup()
181 .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
183 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
184 .addGroup(gl_contentPane.createSequentialGroup()
186 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
187 .addGroup(gl_contentPane.createSequentialGroup()
189 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE))
190 .addComponent(lblDescription, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)))))
191 .addGroup(gl_contentPane.createSequentialGroup()
193 .addComponent(btnConfirm)))
196 gl_contentPane.setVerticalGroup(
197 gl_contentPane.createParallelGroup(Alignment.LEADING)
198 .addGroup(gl_contentPane.createSequentialGroup()
200 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
201 .addGroup(gl_contentPane.createSequentialGroup()
203 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
204 .addComponent(lblCode)
205 .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
206 .addPreferredGap(ComponentPlacement.UNRELATED)
207 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
208 .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
209 .addComponent(lblDistrict)))
210 .addGroup(gl_contentPane.createSequentialGroup()
212 .addComponent(lblDescription)
213 .addPreferredGap(ComponentPlacement.UNRELATED)
214 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE)))
216 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
217 .addGroup(gl_contentPane.createSequentialGroup()
219 .addComponent(lblRooms))
220 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
221 .addGroup(gl_contentPane.createSequentialGroup()
223 .addComponent(lblKitchen))
224 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
226 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
227 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
228 .addGroup(gl_contentPane.createSequentialGroup()
230 .addComponent(lblBaths))
231 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
232 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
233 .addComponent(lblLivings)))
234 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
236 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
237 .addGroup(gl_contentPane.createSequentialGroup()
239 .addComponent(lblParkings))
240 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
242 .addComponent(btnConfirm)
245 contentPane.setLayout(gl_contentPane);