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;
22 import java.awt.Color;
23 import java.awt.event.ActionListener;
24 import java.awt.event.ActionEvent;
26 import javax.swing.JTextPane;
28 import businessLogic.AdminManager;
29 import businessLogic.HouseManager;
30 import businessLogic.HouseManagerInterface;
32 public class RequestNewHouseGUI extends JFrame {
37 private static final long serialVersionUID = 1L;
38 private JPanel contentPane;
40 private JLabel lblCode ;
41 private JTextField Code_f;
42 private JLabel lblTown;
43 private JTextField Town_f;
44 private JLabel lblDescription;
45 private JTextField description_f;
46 private JLabel lblKitchen;
47 private JTextField kitchens_f;
48 private JLabel lblRooms;
49 private JTextField rooms_f;
50 private JLabel lblLivings;
51 private JTextField lRooms_f;
52 private JLabel lblParkings;
53 private JTextField parkings_f;
54 private JLabel lblBaths;
55 private JTextField baths_f;
56 private JButton btnRegister;
57 private AdminManager am;
63 public RequestNewHouseGUI(Owner o) {
65 am = new AdminManager();
66 this.setTitle("New House");
67 setBackground(Color.WHITE);
68 this.getContentPane().setLayout(null);
70 setBounds(100, 100, 500, 583);
71 contentPane = new JPanel();
72 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
73 setContentPane(contentPane);
75 lblCode = new JLabel("House Code:");
76 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
78 Code_f = new JTextField();
79 Code_f.setColumns(10);
81 lblTown = new JLabel("Town:");
82 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
84 Town_f = new JTextField();
85 Town_f.setColumns(10);
87 lblDescription = new JLabel("Description(optional):");
88 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
90 description_f = new JTextField();
91 description_f.setToolTipText("");
92 description_f.setHorizontalAlignment(SwingConstants.LEFT);
93 description_f.setColumns(10);
95 lblKitchen = new JLabel("Kitchens:");
96 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
98 kitchens_f = new JTextField();
99 kitchens_f.setColumns(10);
101 lblRooms = new JLabel("Rooms:");
102 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
104 rooms_f = new JTextField();
105 rooms_f.setColumns(10);
107 lblLivings = new JLabel("Living rooms:");
108 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
110 lRooms_f = new JTextField();
111 lRooms_f.setColumns(10);
113 lblParkings = new JLabel("Parkings:");
114 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
116 parkings_f = new JTextField();
117 parkings_f.setColumns(10);
119 lblBaths = new JLabel("Baths:");
120 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
122 baths_f = new JTextField();
123 baths_f.setColumns(10);
125 btnRegister = new JButton("Request registration");
126 btnRegister.addActionListener(new ActionListener() {
127 public void actionPerformed(ActionEvent arg0) {
128 RuralHouse rh = null;
130 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
131 rh = new RuralHouse(Code_f.getText(),
132 owner, description_f.getText(),
133 Town_f.getText() ,new HouseFeatures(Integer.parseInt(rooms_f.getText()),
134 Integer.parseInt(kitchens_f.getText()),
135 Integer.parseInt(baths_f.getText()),
136 Integer.parseInt(lRooms_f.getText()),
137 Integer.parseInt(parkings_f.getText())) );
140 catch(NumberFormatException e ){
144 am.addAdditionRequest(rh);
147 GroupLayout gl_contentPane = new GroupLayout(contentPane);
148 gl_contentPane.setHorizontalGroup(
149 gl_contentPane.createParallelGroup(Alignment.LEADING)
150 .addGroup(gl_contentPane.createSequentialGroup()
151 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
152 .addGroup(gl_contentPane.createSequentialGroup()
154 .addComponent(btnRegister))
155 .addGroup(gl_contentPane.createSequentialGroup()
157 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
158 .addGroup(gl_contentPane.createSequentialGroup()
159 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
160 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
161 .addGroup(gl_contentPane.createSequentialGroup()
162 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
164 .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
165 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
166 .addGroup(gl_contentPane.createSequentialGroup()
167 .addComponent(lblLivings)
169 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
170 .addGroup(gl_contentPane.createSequentialGroup()
171 .addComponent(lblCode)
172 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
173 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
174 .addGroup(gl_contentPane.createSequentialGroup()
175 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
177 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
179 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
180 .addComponent(lblDescription)
181 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
182 .addGroup(gl_contentPane.createSequentialGroup()
183 .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
185 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
186 .addGroup(gl_contentPane.createSequentialGroup()
187 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
189 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
190 .addGroup(gl_contentPane.createSequentialGroup()
192 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
193 .addPreferredGap(ComponentPlacement.UNRELATED)
194 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
195 .addContainerGap(97, Short.MAX_VALUE))
197 gl_contentPane.setVerticalGroup(
198 gl_contentPane.createParallelGroup(Alignment.LEADING)
199 .addGroup(gl_contentPane.createSequentialGroup()
201 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
202 .addGroup(gl_contentPane.createSequentialGroup()
204 .addComponent(lblDescription)
205 .addPreferredGap(ComponentPlacement.RELATED)
206 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
207 .addGroup(gl_contentPane.createSequentialGroup()
209 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
210 .addComponent(lblCode)
211 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
212 .addPreferredGap(ComponentPlacement.UNRELATED)
213 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
214 .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
215 .addComponent(lblTown))
217 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
218 .addComponent(lblLivings)
219 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
221 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
222 .addGroup(gl_contentPane.createSequentialGroup()
224 .addComponent(lblRooms))
225 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
226 .addPreferredGap(ComponentPlacement.RELATED)
227 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
228 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
229 .addGroup(gl_contentPane.createSequentialGroup()
231 .addComponent(lblKitchen)))
232 .addPreferredGap(ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
233 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
234 .addGroup(gl_contentPane.createSequentialGroup()
236 .addComponent(lblBaths))
237 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
239 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
240 .addComponent(lblParkings)
241 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
243 .addComponent(btnRegister)
246 contentPane.setLayout(gl_contentPane);