76b2465f67a08e3cad312f8bc87c6676e508965f
[RRRRHHHH_Code] / ruralHouses / src / gui / RequestNewHouseGUI.java
1 package gui;
2
3 import java.awt.Color;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6
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;
19
20 import businessLogic.AdminManager;
21 import domain.Districs;
22 import domain.HouseFeatures;
23 import domain.Owner;
24 import domain.RuralHouse;
25
26 public class RequestNewHouseGUI extends JFrame {
27
28         /**
29          * 
30          */
31         private static final long serialVersionUID = 1L;
32         private JPanel contentPane;
33         private Owner owner;
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;
53
54
55         /**
56          * Create the frame.
57          */
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);
65                 owner = o;
66                 setBounds(100, 100, 500, 583);
67                 contentPane = new JPanel();
68                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
69                 setContentPane(contentPane);
70                 
71                 lblCode = new JLabel("House Name:");
72                 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
73                 
74                 Code_f = new JTextField();
75                 Code_f.setColumns(10);
76                 
77                 lblTown = new JLabel("District:");
78                 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
79                 
80                 lblDescription = new JLabel("Description(optional):");
81                 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
82                 
83                 description_f = new JTextField();
84                 description_f.setToolTipText("");
85                 description_f.setHorizontalAlignment(SwingConstants.LEFT);
86                 description_f.setColumns(10);
87                 
88                 lblKitchen = new JLabel("Kitchens:");
89                 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
90                 
91                 kitchens_f = new JTextField();
92                 kitchens_f.setColumns(10);
93                 
94                 lblRooms = new JLabel("Rooms:");
95                 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
96                 
97                 rooms_f = new JTextField();
98                 rooms_f.setColumns(10);
99                 
100                 lblLivings = new JLabel("Living rooms:");
101                 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
102                 
103                 lRooms_f = new JTextField();
104                 lRooms_f.setColumns(10);
105                 
106                 lblParkings = new JLabel("Parkings:");
107                 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
108                 
109                 parkings_f = new JTextField();
110                 parkings_f.setColumns(10);
111                 
112                 lblBaths = new JLabel("Baths:");
113                 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
114                 
115                 baths_f = new JTextField();
116                 baths_f.setColumns(10);
117                 
118                 btnRegister = new JButton("Request registration");
119                 btnRegister.addActionListener(new ActionListener() {
120                         public void actionPerformed(ActionEvent arg0) {
121                                 RuralHouse rh = null;
122                                 try {
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())) );
131                                 
132                                 }
133                                 catch(NumberFormatException e){
134                                         e.printStackTrace();
135                                 }
136                                 
137                                 if(am.addAdditionRequest(rh)){
138                                         feedback.setText("Request sended");
139                                 }else{
140                                         feedback.setText("Request cannot be sended(Already added)");
141                                 }
142                         }
143                 });
144                 
145                 
146                 
147                 
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()
154                                                         .addContainerGap()
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)
161                                                                                                 .addGap(18)
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)
166                                                                                                         .addGap(18)
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)
174                                                                                         .addGap(18)
175                                                                                         .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
176                                                                         .addGap(29)
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)
182                                                                         .addGap(18)
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)
186                                                                         .addGap(18)
187                                                                         .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
188                                                 .addGroup(gl_contentPane.createSequentialGroup()
189                                                         .addGap(18)
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()
194                                                         .addGap(140)
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))
199                 );
200                 gl_contentPane.setVerticalGroup(
201                         gl_contentPane.createParallelGroup(Alignment.LEADING)
202                                 .addGroup(gl_contentPane.createSequentialGroup()
203                                         .addGap(20)
204                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
205                                                 .addGroup(gl_contentPane.createSequentialGroup()
206                                                         .addGap(63)
207                                                         .addComponent(lblDescription)
208                                                         .addPreferredGap(ComponentPlacement.RELATED)
209                                                         .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
210                                                 .addGroup(gl_contentPane.createSequentialGroup()
211                                                         .addGap(60)
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))
219                                                         .addGap(18)
220                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
221                                                                 .addComponent(lblLivings)
222                                                                 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
223                                         .addGap(63)
224                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
225                                                 .addGroup(gl_contentPane.createSequentialGroup()
226                                                         .addGap(3)
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()
233                                                         .addGap(3)
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()
238                                                         .addGap(3)
239                                                         .addComponent(lblBaths))
240                                                 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
241                                         .addGap(45)
242                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
243                                                 .addComponent(lblParkings)
244                                                 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
245                                         .addGap(41)
246                                         .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
247                                         .addPreferredGap(ComponentPlacement.UNRELATED)
248                                         .addComponent(btnRegister)
249                                         .addGap(54))
250                 );
251                 contentPane.setLayout(gl_contentPane);
252         }
253 }