5 import java.text.DateFormat;
12 import java.awt.event.*;
14 import businessLogic.HouseManager;
15 import businessLogic.OfferManager;
17 import com.toedter.calendar.JCalendar;
19 import domain.Districs;
21 import domain.RuralHouse;
22 import exceptions.OverlappingOfferExists;
23 import exceptions.BadDates;
25 public class QueryAvailabilityGUI2 extends JFrame {
26 private static final long serialVersionUID = 1L;
28 private JComboBox jComboBox1;
29 private JLabel jLabel2 = new JLabel();
30 private JTextField jTextField1 = new JTextField();
31 private JLabel jLabel3 = new JLabel();
32 private JTextField jTextField2 = new JTextField();
33 private JLabel jLabel4 = new JLabel();
34 private JTextField jTextField3 = new JTextField();
35 private JButton jButton1 = new JButton();
38 private JCalendar jCalendar1 = new JCalendar();
39 private JCalendar jCalendar2 = new JCalendar();
40 private Calendar calendarInicio = null;
41 private Calendar calendarFin = null;
42 private JButton jButton2 = new JButton();
43 private JLabel jLabel5 = new JLabel();
44 private final JLabel lblNewLabel = new JLabel("");
45 private final JRadioButton ruralHouseName = new JRadioButton(
46 "Use RuralHouse name");
47 private final JRadioButton district = new JRadioButton("Use district name");
48 private final ButtonGroup buttonGroup = new ButtonGroup();
49 private final JMenuBar menuBar = new JMenuBar();
50 private final JMenu mnMoreOptions = new JMenu("Search Options");
51 private final JMenuItem PopUpM = new JMenuItem("More Filters");
52 private final JPopupMenu popupMenu = new JPopupMenu();
53 private final JLabel lblNewLabel_1 = new JLabel("Number of bedrooms:");
54 private JTextField nBedrooms;
55 private JTextField nKitchens;
56 private final JLabel lblExtraFeatures = new JLabel("EXTRA FEATURES");
57 private final JLabel lblNumberOfBaths = new JLabel("Number of baths:");
58 private final JTextField nBaths = new JTextField();
59 private final JLabel lblParkings = new JLabel("Parking slots:");
60 private final JTextField nParkings = new JTextField();
61 private HouseManager houseMan = new HouseManager();
62 private final JLabel lblNumberOfLivings = new JLabel("Number of Livings:");
63 private final JTextField nLivings = new JTextField();
65 public QueryAvailabilityGUI2() {
66 nLivings.setText("0");
67 nLivings.setColumns(10);
68 nParkings.setText("0");
69 nParkings.setColumns(10);
71 nBaths.setColumns(10);
74 } catch (Exception e) {
79 private void jbInit() throws Exception {
80 this.getContentPane().setLayout(null);
81 this.setSize(new Dimension(550, 500));
82 this.setTitle("Query Availability");
84 jComboBox1 = new JComboBox(new DefaultComboBoxModel(
85 Districs.longNames()));
86 jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
87 jLabel2.setText("First day :");
88 jLabel2.setBounds(new Rectangle(20, 134, 85, 25));
89 jTextField1.setBounds(new Rectangle(20, 350, 220, 25));
90 jTextField1.setEditable(false);
91 jLabel3.setText("Last day :");
92 jLabel3.setBounds(new Rectangle(281, 134, 75, 25));
93 jTextField2.setBounds(new Rectangle(281, 350, 220, 20));
94 jTextField2.setEditable(false);
95 jLabel4.setText("Rural House name:");
96 jLabel4.setBounds(new Rectangle(275, 30, 128, 20));
97 jTextField3.setEnabled(false);
98 jTextField3.setBounds(new Rectangle(413, 30, 115, 20));
99 jButton1.setText("Accept");
100 jButton1.setBounds(new Rectangle(60, 377, 165, 30));
101 jButton1.addActionListener(new ActionListener() {
102 public void actionPerformed(ActionEvent e) {
103 jButton1_actionPerformed(e);
106 jButton2.setText("Cancel");
107 jButton2.setBounds(new Rectangle(305, 377, 162, 30));
108 jButton2.addActionListener(new ActionListener() {
109 public void actionPerformed(ActionEvent e) {
110 jButton2_actionPerformed(e);
113 jLabel5.setBounds(new Rectangle(207, 600, 305, 20));
114 jLabel5.setForeground(Color.red);
115 jLabel5.setSize(new Dimension(305, 20));
116 jCalendar1.setBounds(new Rectangle(20, 184, 220, 165));
117 jCalendar2.setBounds(new Rectangle(281, 184, 220, 165));
119 // Code for JCalendar
120 this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() {
121 public void propertyChange(PropertyChangeEvent propertychangeevent) {
122 if (propertychangeevent.getPropertyName().equals("locale")) {
123 jCalendar1.setLocale((Locale) propertychangeevent
125 DateFormat dateformat = DateFormat.getDateInstance(1,
126 jCalendar1.getLocale());
127 jTextField1.setText(dateformat.format(calendarInicio
129 } else if (propertychangeevent.getPropertyName().equals(
131 calendarInicio = (Calendar) propertychangeevent
133 DateFormat dateformat1 = DateFormat.getDateInstance(1,
134 jCalendar1.getLocale());
135 jTextField1.setText(dateformat1.format(calendarInicio
137 jCalendar1.setCalendar(calendarInicio);
142 this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() {
143 public void propertyChange(PropertyChangeEvent propertychangeevent) {
144 if (propertychangeevent.getPropertyName().equals("locale")) {
145 jCalendar2.setLocale((Locale) propertychangeevent
147 DateFormat dateformat = DateFormat.getDateInstance(1,
148 jCalendar2.getLocale());
149 jTextField2.setText(dateformat.format(calendarFin.getTime()));
150 } else if (propertychangeevent.getPropertyName().equals(
152 calendarFin = (Calendar) propertychangeevent.getNewValue();
153 DateFormat dateformat1 = DateFormat.getDateInstance(1,
154 jCalendar2.getLocale());
155 jTextField2.setText(dateformat1.format(calendarFin
157 jCalendar2.setCalendar(calendarFin);
161 popupMenu.setBounds(75, 125, 58, 16);
163 addPopup(getContentPane(), popupMenu);
164 lblExtraFeatures.setHorizontalAlignment(SwingConstants.CENTER);
166 popupMenu.add(lblExtraFeatures);
168 popupMenu.add(lblNewLabel_1);
170 nBedrooms = new JTextField();
171 nBedrooms.setText("0");
172 popupMenu.add(nBedrooms);
173 nBedrooms.setColumns(10);
175 JLabel lblNumberOfKitchens = new JLabel("Number of kitchens:");
176 popupMenu.add(lblNumberOfKitchens);
178 nKitchens = new JTextField();
179 nKitchens.setText("0");
180 popupMenu.add(nKitchens);
181 nKitchens.setColumns(10);
183 popupMenu.add(lblNumberOfBaths);
185 popupMenu.add(nBaths);
187 popupMenu.add(lblParkings);
189 popupMenu.add(nParkings);
191 popupMenu.add(lblNumberOfLivings);
193 popupMenu.add(nLivings);
195 this.getContentPane().add(jCalendar2, null);
196 this.getContentPane().add(jCalendar1, null);
197 this.getContentPane().add(jLabel5, null);
198 this.getContentPane().add(jButton2, null);
199 this.getContentPane().add(jButton1, null);
200 this.getContentPane().add(jTextField3, null);
201 this.getContentPane().add(jLabel4, null);
202 this.getContentPane().add(jTextField2, null);
203 this.getContentPane().add(jLabel3, null);
204 this.getContentPane().add(jTextField1, null);
205 this.getContentPane().add(jLabel2, null);
206 this.getContentPane().add(jComboBox1, null);
207 lblNewLabel.setBounds(115, 301, 298, 38);
209 getContentPane().add(lblNewLabel);
211 district.setSelected(true);
213 district.setBounds(20, 69, 128, 20);
214 getContentPane().add(district);
215 buttonGroup.add(ruralHouseName);
216 buttonGroup.add(district);
217 ruralHouseName.setBounds(276, 60, 177, 38);
218 district.addItemListener(new ItemListener() {
220 public void itemStateChanged(ItemEvent e) {
221 int state = e.getStateChange();
222 if (state == ItemEvent.SELECTED) {
223 jComboBox1.setEnabled(true);
224 } else if (state == ItemEvent.DESELECTED) {
225 jComboBox1.setEnabled(false);
230 ruralHouseName.addItemListener(new ItemListener() {
232 public void itemStateChanged(ItemEvent e) {
233 int state = e.getStateChange();
234 if (state == ItemEvent.SELECTED) {
235 jTextField3.setEnabled(true);
236 } else if (state == ItemEvent.DESELECTED) {
237 jTextField3.setEnabled(false);
241 getContentPane().add(ruralHouseName);
243 JLabel lblNewLabel_2 = new JLabel("District name:");
244 lblNewLabel_2.setBounds(20, 30, 85, 17);
245 getContentPane().add(lblNewLabel_2);
247 setJMenuBar(menuBar);
249 menuBar.add(mnMoreOptions);
250 PopUpM.addActionListener(new ActionListener() {
251 public void actionPerformed(ActionEvent arg0) {
252 popupMenu.show(QueryAvailabilityGUI2.this, popupMenu.getX(),
257 mnMoreOptions.add(PopUpM);
260 private void jButton1_actionPerformed(ActionEvent e) {
261 if (this.district.isSelected()) {
262 Vector<RuralHouse> houses = houseMan.getHouses(jComboBox1
263 .getSelectedItem().toString(), Integer.parseInt(nBedrooms
264 .getText()), Integer.parseInt(nKitchens.getText()), Integer
265 .parseInt(nBaths.getText()), Integer.parseInt(nParkings
266 .getText()), Integer.parseInt(nLivings.getText()));
267 listOfHousesGUI list = new listOfHousesGUI(houses);
268 list.setVisible(true);
269 } else if (this.ruralHouseName.isSelected()) {
270 // show features of specific house
275 private void jButton2_actionPerformed(ActionEvent e) {
276 this.setVisible(false);
279 private static void addPopup(Component component, final JPopupMenu popup) {
280 component.addMouseListener(new MouseAdapter() {
281 public void mousePressed(MouseEvent e) {
282 if (e.isPopupTrigger()) {
287 public void mouseReleased(MouseEvent e) {
288 if (e.isPopupTrigger()) {
293 private void showMenu(MouseEvent e) {
294 popup.show(e.getComponent(), e.getX(), e.getY());