4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.rmi.Naming;
7 import java.rmi.RemoteException;
9 import javax.swing.DefaultComboBoxModel;
10 import javax.swing.GroupLayout;
11 import javax.swing.GroupLayout.Alignment;
12 import javax.swing.JButton;
13 import javax.swing.JComboBox;
14 import javax.swing.JFrame;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17 import javax.swing.JTextField;
18 import javax.swing.LayoutStyle.ComponentPlacement;
19 import javax.swing.SwingConstants;
20 import javax.swing.border.EmptyBorder;
22 import common.AdminInterface;
24 import configuration.___IntNames;
25 import domain.Districs;
26 import domain.HouseFeatures;
28 import domain.RuralHouse;
30 public class RequestNewHouseGUI extends JFrame {
35 private static final long serialVersionUID = 1L;
36 private JPanel contentPane;
38 private JLabel lblCode ;
39 private JLabel feedback = new JLabel("");
40 private JTextField Code_f;
41 private JLabel lblTown;
42 private JLabel lblDescription;
43 private JTextField description_f;
44 private JLabel lblKitchen;
45 private JTextField kitchens_f;
46 private JLabel lblRooms;
47 private JTextField rooms_f;
48 private JLabel lblLivings;
49 private JTextField lRooms_f;
50 private JLabel lblParkings;
51 private JTextField parkings_f;
52 private JLabel lblBaths;
53 private JTextField baths_f;
54 private JButton btnRegister;
55 private AdminInterface am = null;
56 private JComboBox<String> comboBox;
62 public RequestNewHouseGUI(Owner o) {
63 comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
64 Districs.longNames()));
66 am = (AdminInterface) Naming
67 .lookup(___IntNames.AdminManager);
68 } catch (Exception e1) {
69 System.out.println("Error accessing remote authentication: "
72 this.setTitle("New House");
73 setBackground(Color.WHITE);
74 this.getContentPane().setLayout(null);
76 setBounds(100, 100, 500, 583);
77 contentPane = new JPanel();
78 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
79 setContentPane(contentPane);
81 lblCode = new JLabel("House Name:");
82 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
84 Code_f = new JTextField();
85 Code_f.setColumns(10);
87 lblTown = new JLabel("District:");
88 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
90 lblDescription = new JLabel("Description(optional):");
91 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
93 description_f = new JTextField();
94 description_f.setToolTipText("");
95 description_f.setHorizontalAlignment(SwingConstants.LEFT);
96 description_f.setColumns(10);
98 lblKitchen = new JLabel("Kitchens:");
99 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
101 kitchens_f = new JTextField();
102 kitchens_f.setColumns(10);
104 lblRooms = new JLabel("Rooms:");
105 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
107 rooms_f = new JTextField();
108 rooms_f.setColumns(10);
110 lblLivings = new JLabel("Living rooms:");
111 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
113 lRooms_f = new JTextField();
114 lRooms_f.setColumns(10);
116 lblParkings = new JLabel("Parkings:");
117 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
119 parkings_f = new JTextField();
120 parkings_f.setColumns(10);
122 lblBaths = new JLabel("Baths:");
123 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
125 baths_f = new JTextField();
126 baths_f.setColumns(10);
128 btnRegister = new JButton("Request registration");
129 btnRegister.addActionListener(new ActionListener() {
130 public void actionPerformed(ActionEvent arg0) {
131 RuralHouse rh = null;
133 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
134 rh = new RuralHouse(Code_f.getText(),
135 owner, description_f.getText(),
136 (String) comboBox.getSelectedItem(), new HouseFeatures(Integer.parseInt(rooms_f.getText()),
137 Integer.parseInt(kitchens_f.getText()),
138 Integer.parseInt(baths_f.getText()),
139 Integer.parseInt(lRooms_f.getText()),
140 Integer.parseInt(parkings_f.getText())) );
143 catch(NumberFormatException e){
148 if(am.addAdditionRequest(rh)){
150 feedback.setText("Request sended");
152 feedback.setText("Request cannot be sended(Already added)");
154 } catch (RemoteException e) {
155 // TODO Auto-generated catch block
164 GroupLayout gl_contentPane = new GroupLayout(contentPane);
165 gl_contentPane.setHorizontalGroup(
166 gl_contentPane.createParallelGroup(Alignment.LEADING)
167 .addGroup(gl_contentPane.createSequentialGroup()
168 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
169 .addGroup(gl_contentPane.createSequentialGroup()
171 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
172 .addGroup(gl_contentPane.createSequentialGroup()
173 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
174 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
175 .addGroup(gl_contentPane.createSequentialGroup()
176 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
178 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
179 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
180 .addGroup(gl_contentPane.createSequentialGroup()
181 .addComponent(lblLivings)
183 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
184 .addGroup(gl_contentPane.createSequentialGroup()
185 .addComponent(lblCode)
186 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
187 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
188 .addGroup(gl_contentPane.createSequentialGroup()
189 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
191 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
193 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
194 .addComponent(lblDescription)
195 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
196 .addGroup(gl_contentPane.createSequentialGroup()
197 .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
199 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
200 .addGroup(gl_contentPane.createSequentialGroup()
201 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
203 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
204 .addGroup(gl_contentPane.createSequentialGroup()
206 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
207 .addPreferredGap(ComponentPlacement.UNRELATED)
208 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
209 .addGroup(gl_contentPane.createSequentialGroup()
211 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
212 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
213 .addComponent(btnRegister))))
214 .addContainerGap(97, Short.MAX_VALUE))
216 gl_contentPane.setVerticalGroup(
217 gl_contentPane.createParallelGroup(Alignment.LEADING)
218 .addGroup(gl_contentPane.createSequentialGroup()
220 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
221 .addGroup(gl_contentPane.createSequentialGroup()
223 .addComponent(lblDescription)
224 .addPreferredGap(ComponentPlacement.RELATED)
225 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
226 .addGroup(gl_contentPane.createSequentialGroup()
228 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
229 .addComponent(lblCode)
230 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
231 .addPreferredGap(ComponentPlacement.UNRELATED)
232 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
233 .addComponent(lblTown)
234 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
236 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
237 .addComponent(lblLivings)
238 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
240 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
241 .addGroup(gl_contentPane.createSequentialGroup()
243 .addComponent(lblRooms))
244 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
245 .addPreferredGap(ComponentPlacement.RELATED)
246 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
247 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
248 .addGroup(gl_contentPane.createSequentialGroup()
250 .addComponent(lblKitchen)))
251 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
252 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
253 .addGroup(gl_contentPane.createSequentialGroup()
255 .addComponent(lblBaths))
256 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
258 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
259 .addComponent(lblParkings)
260 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
262 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
263 .addPreferredGap(ComponentPlacement.UNRELATED)
264 .addComponent(btnRegister)
267 contentPane.setLayout(gl_contentPane);