4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
7 import javax.swing.GroupLayout;
8 import javax.swing.GroupLayout.Alignment;
9 import javax.swing.JButton;
10 import javax.swing.JFrame;
11 import javax.swing.JLabel;
12 import javax.swing.JPanel;
13 import javax.swing.JTextField;
14 import javax.swing.LayoutStyle.ComponentPlacement;
15 import javax.swing.SwingConstants;
16 import javax.swing.border.EmptyBorder;
18 import businessLogic.AdminManager;
19 import domain.HouseFeatures;
21 import domain.RuralHouse;
23 public class RequestNewHouseGUI extends JFrame {
28 private static final long serialVersionUID = 1L;
29 private JPanel contentPane;
31 private JLabel lblCode ;
32 private JTextField Code_f;
33 private JLabel lblTown;
34 private JTextField Town_f;
35 private JLabel lblDescription;
36 private JTextField description_f;
37 private JLabel lblKitchen;
38 private JTextField kitchens_f;
39 private JLabel lblRooms;
40 private JTextField rooms_f;
41 private JLabel lblLivings;
42 private JTextField lRooms_f;
43 private JLabel lblParkings;
44 private JTextField parkings_f;
45 private JLabel lblBaths;
46 private JTextField baths_f;
47 private JButton btnRegister;
48 private AdminManager am;
54 public RequestNewHouseGUI(Owner o) {
56 am = new AdminManager();
57 this.setTitle("New House");
58 setBackground(Color.WHITE);
59 this.getContentPane().setLayout(null);
61 setBounds(100, 100, 500, 583);
62 contentPane = new JPanel();
63 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
64 setContentPane(contentPane);
66 lblCode = new JLabel("House Code:");
67 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
69 Code_f = new JTextField();
70 Code_f.setColumns(10);
72 lblTown = new JLabel("Town:");
73 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
75 Town_f = new JTextField();
76 Town_f.setColumns(10);
78 lblDescription = new JLabel("Description(optional):");
79 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
81 description_f = new JTextField();
82 description_f.setToolTipText("");
83 description_f.setHorizontalAlignment(SwingConstants.LEFT);
84 description_f.setColumns(10);
86 lblKitchen = new JLabel("Kitchens:");
87 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
89 kitchens_f = new JTextField();
90 kitchens_f.setColumns(10);
92 lblRooms = new JLabel("Rooms:");
93 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
95 rooms_f = new JTextField();
96 rooms_f.setColumns(10);
98 lblLivings = new JLabel("Living rooms:");
99 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
101 lRooms_f = new JTextField();
102 lRooms_f.setColumns(10);
104 lblParkings = new JLabel("Parkings:");
105 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
107 parkings_f = new JTextField();
108 parkings_f.setColumns(10);
110 lblBaths = new JLabel("Baths:");
111 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
113 baths_f = new JTextField();
114 baths_f.setColumns(10);
116 btnRegister = new JButton("Request registration");
117 btnRegister.addActionListener(new ActionListener() {
118 public void actionPerformed(ActionEvent arg0) {
119 RuralHouse rh = null;
121 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
122 rh = new RuralHouse(Code_f.getText(),
123 owner, description_f.getText(),
124 Town_f.getText() ,new HouseFeatures(Integer.parseInt(rooms_f.getText()),
125 Integer.parseInt(kitchens_f.getText()),
126 Integer.parseInt(baths_f.getText()),
127 Integer.parseInt(lRooms_f.getText()),
128 Integer.parseInt(parkings_f.getText())) );
131 catch(NumberFormatException e ){
135 am.addAdditionRequest(rh);
138 GroupLayout gl_contentPane = new GroupLayout(contentPane);
139 gl_contentPane.setHorizontalGroup(
140 gl_contentPane.createParallelGroup(Alignment.LEADING)
141 .addGroup(gl_contentPane.createSequentialGroup()
142 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
143 .addGroup(gl_contentPane.createSequentialGroup()
145 .addComponent(btnRegister))
146 .addGroup(gl_contentPane.createSequentialGroup()
148 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
149 .addGroup(gl_contentPane.createSequentialGroup()
150 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
151 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
152 .addGroup(gl_contentPane.createSequentialGroup()
153 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
155 .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
156 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
157 .addGroup(gl_contentPane.createSequentialGroup()
158 .addComponent(lblLivings)
160 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
161 .addGroup(gl_contentPane.createSequentialGroup()
162 .addComponent(lblCode)
163 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
164 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
165 .addGroup(gl_contentPane.createSequentialGroup()
166 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
168 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
170 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
171 .addComponent(lblDescription)
172 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
173 .addGroup(gl_contentPane.createSequentialGroup()
174 .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
176 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
177 .addGroup(gl_contentPane.createSequentialGroup()
178 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
180 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
181 .addGroup(gl_contentPane.createSequentialGroup()
183 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
184 .addPreferredGap(ComponentPlacement.UNRELATED)
185 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
186 .addContainerGap(97, Short.MAX_VALUE))
188 gl_contentPane.setVerticalGroup(
189 gl_contentPane.createParallelGroup(Alignment.LEADING)
190 .addGroup(gl_contentPane.createSequentialGroup()
192 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
193 .addGroup(gl_contentPane.createSequentialGroup()
195 .addComponent(lblDescription)
196 .addPreferredGap(ComponentPlacement.RELATED)
197 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
198 .addGroup(gl_contentPane.createSequentialGroup()
200 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
201 .addComponent(lblCode)
202 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
203 .addPreferredGap(ComponentPlacement.UNRELATED)
204 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
205 .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
206 .addComponent(lblTown))
208 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
209 .addComponent(lblLivings)
210 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
212 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
213 .addGroup(gl_contentPane.createSequentialGroup()
215 .addComponent(lblRooms))
216 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
217 .addPreferredGap(ComponentPlacement.RELATED)
218 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
219 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
220 .addGroup(gl_contentPane.createSequentialGroup()
222 .addComponent(lblKitchen)))
223 .addPreferredGap(ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
224 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
225 .addGroup(gl_contentPane.createSequentialGroup()
227 .addComponent(lblBaths))
228 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
230 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
231 .addComponent(lblParkings)
232 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
234 .addComponent(btnRegister)
237 contentPane.setLayout(gl_contentPane);