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.HouseManager;
29 import businessLogic.HouseManagerInterface;
31 public class NewHouseGUI extends JFrame {
36 private static final long serialVersionUID = 1L;
37 private JPanel contentPane;
39 private JLabel lblCode ;
40 private JTextField Code_f;
41 private JLabel lblTown;
42 private JTextField Town_f;
43 private JLabel lblDescription;
44 private JTextField description_f;
45 private JLabel lblKitchen;
46 private JTextField kitchens_f;
47 private JLabel lblRooms;
48 private JTextField rooms_f;
49 private JLabel lblLivings;
50 private JTextField lRooms_f;
51 private JLabel lblParkings;
52 private JTextField parkings_f;
53 private JLabel lblBaths;
54 private JTextField baths_f;
55 private JButton btnRegister;
61 public NewHouseGUI(Owner o) {
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 Code:");
72 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
74 Code_f = new JTextField();
75 Code_f.setColumns(10);
77 lblTown = new JLabel("Town:");
78 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
80 Town_f = new JTextField();
81 Town_f.setColumns(10);
83 lblDescription = new JLabel("Description(optional):");
84 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
86 description_f = new JTextField();
87 description_f.setToolTipText("");
88 description_f.setHorizontalAlignment(SwingConstants.LEFT);
89 description_f.setColumns(10);
91 lblKitchen = new JLabel("Kitchens:");
92 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
94 kitchens_f = new JTextField();
95 kitchens_f.setColumns(10);
97 lblRooms = new JLabel("Rooms:");
98 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
100 rooms_f = new JTextField();
101 rooms_f.setColumns(10);
103 lblLivings = new JLabel("Living rooms:");
104 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
106 lRooms_f = new JTextField();
107 lRooms_f.setColumns(10);
109 lblParkings = new JLabel("Parkings:");
110 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
112 parkings_f = new JTextField();
113 parkings_f.setColumns(10);
115 lblBaths = new JLabel("Baths:");
116 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
118 baths_f = new JTextField();
119 baths_f.setColumns(10);
121 btnRegister = new JButton("Register House");
122 btnRegister.addActionListener(new ActionListener() {
123 public void actionPerformed(ActionEvent arg0) {
125 HouseManagerInterface hm = new HouseManager();
126 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
127 hm.registerNewHouse(Code_f.getText(),
128 owner, description_f.getText(),
129 Town_f.getText() ,Integer.parseInt(rooms_f.getText()),
130 Integer.parseInt(kitchens_f.getText()),
131 Integer.parseInt(baths_f.getText()),
132 Integer.parseInt(lRooms_f.getText()),
133 Integer.parseInt(parkings_f.getText()) );
136 catch(NumberFormatException e ){
141 GroupLayout gl_contentPane = new GroupLayout(contentPane);
142 gl_contentPane.setHorizontalGroup(
143 gl_contentPane.createParallelGroup(Alignment.LEADING)
144 .addGroup(gl_contentPane.createSequentialGroup()
145 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
146 .addGroup(gl_contentPane.createSequentialGroup()
148 .addComponent(btnRegister))
149 .addGroup(gl_contentPane.createSequentialGroup()
151 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
152 .addGroup(gl_contentPane.createSequentialGroup()
153 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
154 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
155 .addGroup(gl_contentPane.createSequentialGroup()
156 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
158 .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
159 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
160 .addGroup(gl_contentPane.createSequentialGroup()
161 .addComponent(lblLivings)
163 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
164 .addGroup(gl_contentPane.createSequentialGroup()
165 .addComponent(lblCode)
166 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
167 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
168 .addGroup(gl_contentPane.createSequentialGroup()
169 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
171 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
173 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
174 .addComponent(lblDescription)
175 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
176 .addGroup(gl_contentPane.createSequentialGroup()
177 .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
179 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
180 .addGroup(gl_contentPane.createSequentialGroup()
181 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
183 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
184 .addGroup(gl_contentPane.createSequentialGroup()
186 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
187 .addPreferredGap(ComponentPlacement.UNRELATED)
188 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
189 .addContainerGap(97, Short.MAX_VALUE))
191 gl_contentPane.setVerticalGroup(
192 gl_contentPane.createParallelGroup(Alignment.LEADING)
193 .addGroup(gl_contentPane.createSequentialGroup()
195 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
196 .addGroup(gl_contentPane.createSequentialGroup()
198 .addComponent(lblDescription)
199 .addPreferredGap(ComponentPlacement.RELATED)
200 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
201 .addGroup(gl_contentPane.createSequentialGroup()
203 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
204 .addComponent(lblCode)
205 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
206 .addPreferredGap(ComponentPlacement.UNRELATED)
207 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
208 .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
209 .addComponent(lblTown))
211 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
212 .addComponent(lblLivings)
213 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
215 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
216 .addGroup(gl_contentPane.createSequentialGroup()
218 .addComponent(lblRooms))
219 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
220 .addPreferredGap(ComponentPlacement.RELATED)
221 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
222 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
223 .addGroup(gl_contentPane.createSequentialGroup()
225 .addComponent(lblKitchen)))
226 .addPreferredGap(ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
227 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
228 .addGroup(gl_contentPane.createSequentialGroup()
230 .addComponent(lblBaths))
231 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
233 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
234 .addComponent(lblParkings)
235 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
237 .addComponent(btnRegister)
240 contentPane.setLayout(gl_contentPane);