4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
7 import javax.swing.DefaultComboBoxModel;
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.AdminManager;
21 import domain.Districs;
22 import domain.HouseFeatures;
24 import domain.RuralHouse;
26 public class RequestNewHouseGUI extends JFrame {
31 private static final long serialVersionUID = 1L;
32 private JPanel contentPane;
34 private JLabel lblCode ;
35 private JLabel feedback = new JLabel("");
36 private JTextField Code_f;
37 private JLabel lblTown;
38 private JLabel lblDescription;
39 private JTextField description_f;
40 private JLabel lblKitchen;
41 private JTextField kitchens_f;
42 private JLabel lblRooms;
43 private JTextField rooms_f;
44 private JLabel lblLivings;
45 private JTextField lRooms_f;
46 private JLabel lblParkings;
47 private JTextField parkings_f;
48 private JLabel lblBaths;
49 private JTextField baths_f;
50 private JButton btnRegister;
51 private AdminManager am;
52 private JComboBox<String> comboBox;
58 public RequestNewHouseGUI(Owner o) {
59 comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
60 Districs.longNames()));
61 am = new AdminManager();
62 this.setTitle("New House");
63 setBackground(Color.WHITE);
64 this.getContentPane().setLayout(null);
66 setBounds(100, 100, 500, 583);
67 contentPane = new JPanel();
68 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
69 setContentPane(contentPane);
71 lblCode = new JLabel("House Name:");
72 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
74 Code_f = new JTextField();
75 Code_f.setColumns(10);
77 lblTown = new JLabel("District:");
78 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
80 lblDescription = new JLabel("Description(optional):");
81 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
83 description_f = new JTextField();
84 description_f.setToolTipText("");
85 description_f.setHorizontalAlignment(SwingConstants.LEFT);
86 description_f.setColumns(10);
88 lblKitchen = new JLabel("Kitchens:");
89 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
91 kitchens_f = new JTextField();
92 kitchens_f.setColumns(10);
94 lblRooms = new JLabel("Rooms:");
95 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
97 rooms_f = new JTextField();
98 rooms_f.setColumns(10);
100 lblLivings = new JLabel("Living rooms:");
101 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
103 lRooms_f = new JTextField();
104 lRooms_f.setColumns(10);
106 lblParkings = new JLabel("Parkings:");
107 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
109 parkings_f = new JTextField();
110 parkings_f.setColumns(10);
112 lblBaths = new JLabel("Baths:");
113 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
115 baths_f = new JTextField();
116 baths_f.setColumns(10);
118 btnRegister = new JButton("Request registration");
119 btnRegister.addActionListener(new ActionListener() {
120 public void actionPerformed(ActionEvent arg0) {
121 RuralHouse rh = null;
123 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
124 rh = new RuralHouse(Code_f.getText(),
125 owner, description_f.getText(),
126 (String) comboBox.getSelectedItem() ,new HouseFeatures(Integer.parseInt(rooms_f.getText()),
127 Integer.parseInt(kitchens_f.getText()),
128 Integer.parseInt(baths_f.getText()),
129 Integer.parseInt(lRooms_f.getText()),
130 Integer.parseInt(parkings_f.getText())) );
133 catch(NumberFormatException e ){
137 if(am.addAdditionRequest(rh)){
138 feedback.setText("Request sended");
140 feedback.setText("Request cannot be sended(Already added)");
148 GroupLayout gl_contentPane = new GroupLayout(contentPane);
149 gl_contentPane.setHorizontalGroup(
150 gl_contentPane.createParallelGroup(Alignment.LEADING)
151 .addGroup(gl_contentPane.createSequentialGroup()
152 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
153 .addGroup(gl_contentPane.createSequentialGroup()
155 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
156 .addGroup(gl_contentPane.createSequentialGroup()
157 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
158 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
159 .addGroup(gl_contentPane.createSequentialGroup()
160 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
162 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
163 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
164 .addGroup(gl_contentPane.createSequentialGroup()
165 .addComponent(lblLivings)
167 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
168 .addGroup(gl_contentPane.createSequentialGroup()
169 .addComponent(lblCode)
170 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
171 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
172 .addGroup(gl_contentPane.createSequentialGroup()
173 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
175 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
177 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
178 .addComponent(lblDescription)
179 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, 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()
185 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
187 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
188 .addGroup(gl_contentPane.createSequentialGroup()
190 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
191 .addPreferredGap(ComponentPlacement.UNRELATED)
192 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
193 .addGroup(gl_contentPane.createSequentialGroup()
195 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
196 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
197 .addComponent(btnRegister))))
198 .addContainerGap(97, Short.MAX_VALUE))
200 gl_contentPane.setVerticalGroup(
201 gl_contentPane.createParallelGroup(Alignment.LEADING)
202 .addGroup(gl_contentPane.createSequentialGroup()
204 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
205 .addGroup(gl_contentPane.createSequentialGroup()
207 .addComponent(lblDescription)
208 .addPreferredGap(ComponentPlacement.RELATED)
209 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
210 .addGroup(gl_contentPane.createSequentialGroup()
212 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
213 .addComponent(lblCode)
214 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
215 .addPreferredGap(ComponentPlacement.UNRELATED)
216 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
217 .addComponent(lblTown)
218 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
220 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
221 .addComponent(lblLivings)
222 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
224 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
225 .addGroup(gl_contentPane.createSequentialGroup()
227 .addComponent(lblRooms))
228 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
229 .addPreferredGap(ComponentPlacement.RELATED)
230 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
231 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
232 .addGroup(gl_contentPane.createSequentialGroup()
234 .addComponent(lblKitchen)))
235 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
236 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
237 .addGroup(gl_contentPane.createSequentialGroup()
239 .addComponent(lblBaths))
240 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
242 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
243 .addComponent(lblParkings)
244 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
246 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
247 .addPreferredGap(ComponentPlacement.UNRELATED)
248 .addComponent(btnRegister)
251 contentPane.setLayout(gl_contentPane);