3 import businessLogic.ApplicationFacadeInterface;
5 import com.toedter.calendar.JCalendar;
8 import domain.RuralHouse;
12 import java.awt.event.*;
17 import java.text.DateFormat;
20 public class SearchOffersGUI extends JFrame {
22 private static final long serialVersionUID = 1L;
24 private JLabel jLabel1 = new JLabel();
25 private JComboBox jComboBox1;
26 private JLabel jLabel2 = new JLabel();
27 private JTextField jTextField2 = new JTextField();
28 private JLabel jLabel3 = new JLabel();
29 private JTextField jTextField3 = new JTextField();
30 private JButton jButton1 = new JButton();
31 private JButton jButton2 = new JButton();
33 private JCalendar jCalendar1 = new JCalendar();
34 private Calendar myCalendar = null;
35 private JLabel jLabel4 = new JLabel();
36 private JTextArea jTextArea1 = new JTextArea();
37 private JScrollPane scrollPane = new JScrollPane();
39 public SearchOffersGUI() {
48 private void jbInit() throws Exception {
49 ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
51 Vector<RuralHouse> rhs=facade.getAllRuralHouses();
52 jComboBox1 = new JComboBox(rhs);
54 this.getContentPane().setLayout(null);
55 this.setSize(new Dimension(440, 548));
56 this.setTitle("Search available rural houses");
57 jLabel1.setText("Rural house:");
58 jComboBox1.setBounds(new Rectangle(10, 10, 115, 25));
59 jLabel1.setBounds(new Rectangle(40, 20, 105, 25));
60 jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
61 jLabel2.setText("First day:");
62 jLabel2.setBounds(new Rectangle(40, 55, 75, 25));
63 jTextField2.setBounds(new Rectangle(190, 210, 155, 25));
64 jTextField2.setEditable(false);
65 jLabel3.setText("Number of nights:");
66 jLabel3.setBounds(new Rectangle(40, 250, 115, 25));
67 jTextField3.setBounds(new Rectangle(190, 250, 155, 25));
68 jTextField3.setText("0");
69 jButton1.setText("Accept");
70 jButton1.setBounds(new Rectangle(55, 455, 130, 30));
71 jButton1.addActionListener(new ActionListener() {
72 public void actionPerformed(ActionEvent e) {
73 jButton1_actionPerformed(e);
76 jButton2.setText("Close");
77 jButton2.setBounds(new Rectangle(230, 455, 130, 30));
79 jTextField3.addFocusListener(new FocusListener() {
80 public void focusGained(FocusEvent e) { }
81 public void focusLost(FocusEvent e) {
82 jTextField3_focusLost();
85 jButton2.addActionListener(new ActionListener() {
86 public void actionPerformed(ActionEvent e) {
87 jButton2_actionPerformed(e);
90 jLabel4.setBounds(new Rectangle(55, 300, 305, 30));
91 jLabel4.setForeground(Color.red);
92 jTextArea1.setEditable(false);
93 jCalendar1.setBounds(new Rectangle(190, 60, 225, 150));
94 scrollPane.setBounds(new Rectangle(45, 305, 320, 135));
95 jTextArea1.setText("");
96 scrollPane.getViewport().add(jTextArea1, null);
98 this.getContentPane().add(scrollPane, null);
99 this.getContentPane().add(jCalendar1, null);
100 this.getContentPane().add(jLabel4, null);
101 this.getContentPane().add(jButton2, null);
102 this.getContentPane().add(jButton1, null);
103 this.getContentPane().add(jTextField3, null);
104 this.getContentPane().add(jLabel3, null);
105 this.getContentPane().add(jTextField2, null);
106 this.getContentPane().add(jLabel2, null);
107 this.getContentPane().add(jComboBox1, null);
108 this.getContentPane().add(jLabel1, null);
110 // Code for JCalendar
111 this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() {
112 public void propertyChange(PropertyChangeEvent propertychangeevent) {
113 if (propertychangeevent.getPropertyName().equals("locale")) {
114 jCalendar1.setLocale((Locale) propertychangeevent.getNewValue());
115 DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale());
116 jTextField2.setText(dateformat.format(myCalendar.getTime()));
118 else if (propertychangeevent.getPropertyName().equals("calendar")) {
119 myCalendar = (Calendar) propertychangeevent.getNewValue();
120 DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
121 jTextField2.setText(dateformat1.format(myCalendar.getTime()));
122 jCalendar1.setCalendar(myCalendar);
129 private void jButton2_actionPerformed(ActionEvent e) {
130 this.setVisible(false);
133 private void jTextField3_focusLost() {
135 new Integer (jTextField3.getText());
138 catch (NumberFormatException ex) {
139 jLabel4.setText("Error: Please introduce a number");
143 private void jButton1_actionPerformed(ActionEvent e) {
145 RuralHouse rh=(RuralHouse)jComboBox1.getSelectedItem();
147 Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime());
148 //Remove the hour:minute:second:ms from the date
149 firstDay=Date.valueOf(firstDay.toString());
150 final long diams=1000*60*60*24;
151 long nights= diams * Integer.parseInt(jTextField3.getText());
153 Date lastDay= new Date((long)(firstDay.getTime()+nights));
154 jTextArea1.setText("");
156 ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
157 Vector<Offer> v=facade.getOffers(rh, firstDay, lastDay);
159 Enumeration<Offer> en=v.elements();
161 while (en.hasMoreElements()) {
163 firstDay= new Date(of.getFirstDay().getTime());
164 firstDay=Date.valueOf(firstDay.toString());
165 lastDay= new Date(of.getLastDay().getTime());
166 lastDay=Date.valueOf(lastDay.toString());
167 jTextArea1.append("Offer "+Integer.toString(of.getOfferNumber())+":from:"+firstDay+" to:"+lastDay+"\n");
170 //} catch (RemoteException e1) {
171 // e1.printStackTrace();
174 catch (Exception e1) {
175 e1.printStackTrace();