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.DefaultComboBoxModel;
10 import javax.swing.JButton;
11 import javax.swing.JFrame;
12 import javax.swing.JLabel;
13 import javax.swing.JPanel;
14 import javax.swing.JTextField;
15 import javax.swing.LayoutStyle.ComponentPlacement;
16 import javax.swing.SwingConstants;
17 import javax.swing.border.EmptyBorder;
19 import businessLogic.AdminManager;
20 import domain.Districs;
21 import domain.HouseFeatures;
23 import domain.RuralHouse;
25 import javax.swing.JComboBox;
27 public class RequestNewHouseGUI extends JFrame {
32 private static final long serialVersionUID = 1L;
33 private JPanel contentPane;
35 private JLabel lblCode ;
36 private JLabel feedback = new JLabel("");
37 private JTextField Code_f;
38 private JLabel lblTown;
39 private JLabel lblDescription;
40 private JTextField description_f;
41 private JLabel lblKitchen;
42 private JTextField kitchens_f;
43 private JLabel lblRooms;
44 private JTextField rooms_f;
45 private JLabel lblLivings;
46 private JTextField lRooms_f;
47 private JLabel lblParkings;
48 private JTextField parkings_f;
49 private JLabel lblBaths;
50 private JTextField baths_f;
51 private JButton btnRegister;
52 private AdminManager am;
53 private JComboBox comboBox;
59 public RequestNewHouseGUI(Owner o) {
60 JComboBox<String> comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
61 Districs.longNames()));
62 am = new AdminManager();
63 this.setTitle("New House");
64 setBackground(Color.WHITE);
65 this.getContentPane().setLayout(null);
67 setBounds(100, 100, 500, 583);
68 contentPane = new JPanel();
69 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
70 setContentPane(contentPane);
72 lblCode = new JLabel("House Name:");
73 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
75 Code_f = new JTextField();
76 Code_f.setColumns(10);
78 lblTown = new JLabel("District:");
79 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
81 lblDescription = new JLabel("Description(optional):");
82 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
84 description_f = new JTextField();
85 description_f.setToolTipText("");
86 description_f.setHorizontalAlignment(SwingConstants.LEFT);
87 description_f.setColumns(10);
89 lblKitchen = new JLabel("Kitchens:");
90 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
92 kitchens_f = new JTextField();
93 kitchens_f.setColumns(10);
95 lblRooms = new JLabel("Rooms:");
96 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
98 rooms_f = new JTextField();
99 rooms_f.setColumns(10);
101 lblLivings = new JLabel("Living rooms:");
102 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
104 lRooms_f = new JTextField();
105 lRooms_f.setColumns(10);
107 lblParkings = new JLabel("Parkings:");
108 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
110 parkings_f = new JTextField();
111 parkings_f.setColumns(10);
113 lblBaths = new JLabel("Baths:");
114 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
116 baths_f = new JTextField();
117 baths_f.setColumns(10);
119 btnRegister = new JButton("Request registration");
120 btnRegister.addActionListener(new ActionListener() {
121 public void actionPerformed(ActionEvent arg0) {
122 RuralHouse rh = null;
124 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
125 rh = new RuralHouse(Code_f.getText(),
126 owner, description_f.getText(),
127 (String) comboBox.getSelectedItem() ,new HouseFeatures(Integer.parseInt(rooms_f.getText()),
128 Integer.parseInt(kitchens_f.getText()),
129 Integer.parseInt(baths_f.getText()),
130 Integer.parseInt(lRooms_f.getText()),
131 Integer.parseInt(parkings_f.getText())) );
134 catch(NumberFormatException e ){
138 if(am.addAdditionRequest(rh)){
139 feedback.setText("Request sended");
141 feedback.setText("Request cannot be sended(Already added)");
149 GroupLayout gl_contentPane = new GroupLayout(contentPane);
150 gl_contentPane.setHorizontalGroup(
151 gl_contentPane.createParallelGroup(Alignment.LEADING)
152 .addGroup(gl_contentPane.createSequentialGroup()
153 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
154 .addGroup(gl_contentPane.createSequentialGroup()
156 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
157 .addGroup(gl_contentPane.createSequentialGroup()
158 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
159 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
160 .addGroup(gl_contentPane.createSequentialGroup()
161 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
163 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
164 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
165 .addGroup(gl_contentPane.createSequentialGroup()
166 .addComponent(lblLivings)
168 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
169 .addGroup(gl_contentPane.createSequentialGroup()
170 .addComponent(lblCode)
171 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
172 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
173 .addGroup(gl_contentPane.createSequentialGroup()
174 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
176 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
178 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
179 .addComponent(lblDescription)
180 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
181 .addGroup(gl_contentPane.createSequentialGroup()
182 .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
184 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
185 .addGroup(gl_contentPane.createSequentialGroup()
186 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
188 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
189 .addGroup(gl_contentPane.createSequentialGroup()
191 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
192 .addPreferredGap(ComponentPlacement.UNRELATED)
193 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
194 .addGroup(gl_contentPane.createSequentialGroup()
196 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
197 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
198 .addComponent(btnRegister))))
199 .addContainerGap(97, Short.MAX_VALUE))
201 gl_contentPane.setVerticalGroup(
202 gl_contentPane.createParallelGroup(Alignment.LEADING)
203 .addGroup(gl_contentPane.createSequentialGroup()
205 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
206 .addGroup(gl_contentPane.createSequentialGroup()
208 .addComponent(lblDescription)
209 .addPreferredGap(ComponentPlacement.RELATED)
210 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
211 .addGroup(gl_contentPane.createSequentialGroup()
213 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
214 .addComponent(lblCode)
215 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
216 .addPreferredGap(ComponentPlacement.UNRELATED)
217 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
218 .addComponent(lblTown)
219 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
221 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
222 .addComponent(lblLivings)
223 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
225 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
226 .addGroup(gl_contentPane.createSequentialGroup()
228 .addComponent(lblRooms))
229 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
230 .addPreferredGap(ComponentPlacement.RELATED)
231 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
232 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
233 .addGroup(gl_contentPane.createSequentialGroup()
235 .addComponent(lblKitchen)))
236 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
237 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
238 .addGroup(gl_contentPane.createSequentialGroup()
240 .addComponent(lblBaths))
241 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
243 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
244 .addComponent(lblParkings)
245 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
247 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
248 .addPreferredGap(ComponentPlacement.UNRELATED)
249 .addComponent(btnRegister)
252 contentPane.setLayout(gl_contentPane);