5 import java.text.DateFormat;
11 import java.awt.event.*;
13 import businessLogic.HouseManager;
14 import businessLogic.OfferManager;
16 import com.toedter.calendar.JCalendar;
19 import domain.RuralHouse;
20 import exceptions.OverlappingOfferExists;
21 import exceptions.BadDates;
23 public class QueryAvailabilityGUI2 extends JFrame {
24 private static final long serialVersionUID = 1L;
26 private JComboBox jComboBox1;
27 private JLabel jLabel2 = new JLabel();
28 private JTextField jTextField1 = new JTextField();
29 private JLabel jLabel3 = new JLabel();
30 private JTextField jTextField2 = new JTextField();
31 private JLabel jLabel4 = new JLabel();
32 private JTextField jTextField3 = new JTextField();
33 private JButton jButton1 = new JButton();
36 private JCalendar jCalendar1 = new JCalendar();
37 private JCalendar jCalendar2 = new JCalendar();
38 private Calendar calendarInicio = null;
39 private Calendar calendarFin = null;
40 private JButton jButton2 = new JButton();
41 private JLabel jLabel5 = new JLabel();
42 private final JLabel lblNewLabel = new JLabel("");
43 private final JRadioButton ruralHouseName = new JRadioButton(
44 "Use RuralHouse name");
45 private final JRadioButton district = new JRadioButton("Use district name");
46 private final ButtonGroup buttonGroup = new ButtonGroup();
47 private final JMenuBar menuBar = new JMenuBar();
48 private final JMenu mnMoreOptions = new JMenu("Search Options");
49 private final JMenuItem PopUpM = new JMenuItem("More Filters");
50 private final JPopupMenu popupMenu = new JPopupMenu();
51 private final JLabel lblNewLabel_1 = new JLabel("Number of bedrooms:");
52 private JTextField nBedrooms;
53 private JTextField nKitchens;
54 private final JLabel lblExtraFeatures = new JLabel("EXTRA FEATURES");
55 private final JLabel lblNumberOfBaths = new JLabel("Number of baths:");
56 private final JTextField nBaths = new JTextField();
57 private final JLabel lblParkings = new JLabel("Parking slots:");
58 private final JTextField nParkings = new JTextField();
59 private HouseManager houseMan = new HouseManager();
61 public QueryAvailabilityGUI2() {
62 nParkings.setText("");
63 nParkings.setColumns(10);
64 nBaths.setColumns(10);
67 } catch (Exception e) {
72 private void jbInit() throws Exception {
73 this.getContentPane().setLayout(null);
74 this.setSize(new Dimension(550, 500));
75 this.setTitle("Set availability");
77 //TODO here we should add the districts of villatripas this is just for testing purposes
78 jComboBox1 = new JComboBox(this.houseMan.getAllRuralHouses());
79 jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
80 jLabel2.setText("First day :");
81 jLabel2.setBounds(new Rectangle(20, 134, 85, 25));
82 jTextField1.setBounds(new Rectangle(20, 350, 220, 25));
83 jTextField1.setEditable(false);
84 jLabel3.setText("Last day :");
85 jLabel3.setBounds(new Rectangle(281, 134, 75, 25));
86 jTextField2.setBounds(new Rectangle(281, 350, 220, 20));
87 jTextField2.setEditable(false);
88 jLabel4.setText("Rural House name:");
89 jLabel4.setBounds(new Rectangle(275, 30, 128, 20));
90 jTextField3.setEnabled(false);
91 jTextField3.setBounds(new Rectangle(413, 30, 115, 20));
92 jButton1.setText("Accept");
93 jButton1.setBounds(new Rectangle(60, 377, 165, 30));
94 jButton1.addActionListener(new ActionListener() {
95 public void actionPerformed(ActionEvent e) {
96 jButton1_actionPerformed(e);
99 jButton2.setText("Cancel");
100 jButton2.setBounds(new Rectangle(305, 377, 162, 30));
101 jButton2.addActionListener(new ActionListener() {
102 public void actionPerformed(ActionEvent e) {
103 jButton2_actionPerformed(e);
106 jLabel5.setBounds(new Rectangle(207, 600, 305, 20));
107 jLabel5.setForeground(Color.red);
108 jLabel5.setSize(new Dimension(305, 20));
109 jCalendar1.setBounds(new Rectangle(20, 184, 220, 165));
110 jCalendar2.setBounds(new Rectangle(281, 184, 220, 165));
112 // Code for JCalendar
113 this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() {
114 public void propertyChange(PropertyChangeEvent propertychangeevent) {
115 if (propertychangeevent.getPropertyName().equals("locale")) {
116 jCalendar1.setLocale((Locale) propertychangeevent
118 DateFormat dateformat = DateFormat.getDateInstance(1,
119 jCalendar1.getLocale());
120 jTextField1.setText(dateformat.format(calendarInicio
122 } else if (propertychangeevent.getPropertyName().equals(
124 calendarInicio = (Calendar) propertychangeevent
126 DateFormat dateformat1 = DateFormat.getDateInstance(1,
127 jCalendar1.getLocale());
128 jTextField1.setText(dateformat1.format(calendarInicio
130 jCalendar1.setCalendar(calendarInicio);
135 this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() {
136 public void propertyChange(PropertyChangeEvent propertychangeevent) {
137 if (propertychangeevent.getPropertyName().equals("locale")) {
138 jCalendar2.setLocale((Locale) propertychangeevent
140 DateFormat dateformat = DateFormat.getDateInstance(1,
141 jCalendar2.getLocale());
142 jTextField2.setText(dateformat.format(calendarFin.getTime()));
143 } else if (propertychangeevent.getPropertyName().equals(
145 calendarFin = (Calendar) propertychangeevent.getNewValue();
146 DateFormat dateformat1 = DateFormat.getDateInstance(1,
147 jCalendar2.getLocale());
148 jTextField2.setText(dateformat1.format(calendarFin
150 jCalendar2.setCalendar(calendarFin);
154 popupMenu.setBounds(75, 125, 58, 16);
156 addPopup(getContentPane(), popupMenu);
157 lblExtraFeatures.setHorizontalAlignment(SwingConstants.CENTER);
159 popupMenu.add(lblExtraFeatures);
161 popupMenu.add(lblNewLabel_1);
163 nBedrooms = new JTextField();
164 popupMenu.add(nBedrooms);
165 nBedrooms.setColumns(10);
167 JLabel lblNumberOfKitchens = new JLabel("Number of kitchens:");
168 popupMenu.add(lblNumberOfKitchens);
170 nKitchens = new JTextField();
171 popupMenu.add(nKitchens);
172 nKitchens.setColumns(10);
174 popupMenu.add(lblNumberOfBaths);
176 popupMenu.add(nBaths);
178 popupMenu.add(lblParkings);
180 popupMenu.add(nParkings);
182 this.getContentPane().add(jCalendar2, null);
183 this.getContentPane().add(jCalendar1, null);
184 this.getContentPane().add(jLabel5, null);
185 this.getContentPane().add(jButton2, null);
186 this.getContentPane().add(jButton1, null);
187 this.getContentPane().add(jTextField3, null);
188 this.getContentPane().add(jLabel4, null);
189 this.getContentPane().add(jTextField2, null);
190 this.getContentPane().add(jLabel3, null);
191 this.getContentPane().add(jTextField1, null);
192 this.getContentPane().add(jLabel2, null);
193 this.getContentPane().add(jComboBox1, null);
194 lblNewLabel.setBounds(115, 301, 298, 38);
196 getContentPane().add(lblNewLabel);
198 district.setSelected(true);;
199 district.setBounds(20, 69, 128, 20);
200 getContentPane().add(district);
201 buttonGroup.add(ruralHouseName);
202 buttonGroup.add(district);
203 ruralHouseName.setBounds(276, 60, 177, 38);
204 district.addItemListener(new ItemListener() {
206 public void itemStateChanged(ItemEvent e) {
207 int state = e.getStateChange();
208 if (state == ItemEvent.SELECTED) {
209 jComboBox1.setEnabled(true);
210 } else if (state == ItemEvent.DESELECTED) {
211 jComboBox1.setEnabled(false);
216 ruralHouseName.addItemListener(new ItemListener() {
218 public void itemStateChanged(ItemEvent e) {
219 int state = e.getStateChange();
220 if (state == ItemEvent.SELECTED) {
221 jTextField3.setEnabled(true);
222 } else if (state == ItemEvent.DESELECTED) {
223 jTextField3.setEnabled(false);
227 getContentPane().add(ruralHouseName);
229 JLabel lblNewLabel_2 = new JLabel("District name:");
230 lblNewLabel_2.setBounds(20, 30, 85, 17);
231 getContentPane().add(lblNewLabel_2);
233 setJMenuBar(menuBar);
235 menuBar.add(mnMoreOptions);
236 PopUpM.addActionListener(new ActionListener() {
237 public void actionPerformed(ActionEvent arg0) {
238 popupMenu.show(QueryAvailabilityGUI2.this,popupMenu.getX(), popupMenu.getY());
242 mnMoreOptions.add(PopUpM);
245 private void jButton1_actionPerformed(ActionEvent e) {
246 if(this.district.isSelected()){
247 //show list of houses GUI
249 else if(this.ruralHouseName.isSelected()){
250 //show features of specific house
254 private void jButton2_actionPerformed(ActionEvent e) {
255 this.setVisible(false);
257 private static void addPopup(Component component, final JPopupMenu popup) {
258 component.addMouseListener(new MouseAdapter() {
259 public void mousePressed(MouseEvent e) {
260 if (e.isPopupTrigger()) {
264 public void mouseReleased(MouseEvent e) {
265 if (e.isPopupTrigger()) {
269 private void showMenu(MouseEvent e) {
270 popup.show(e.getComponent(), e.getX(), e.getY());