package businessLogic;
-import java.sql.Date;
+import java.util.Date;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
//import java.util.Vector;
import java.rmi.RemoteException;
-import java.sql.Date;
+import java.util.Date;
import java.util.HashSet;
import java.util.ListIterator;
import java.util.Vector;
+++ /dev/null
-package gui;
-
-import businessLogic.BookingManager;
-import businessLogic.HouseManager;
-
-import com.toedter.calendar.*;
-
-import domain.Booking;
-import domain.RuralHouse;
-import exceptions.OfferCanNotBeBooked;
-
-import java.beans.*;
-import java.sql.Date;
-import java.text.*;
-import java.util.*;
-
-import javax.swing.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-
-
-public class BookRuralHouseGUI extends JFrame {
-private static final long serialVersionUID = 1L;
-public static final long MILLSECS_PER_DAY= 24 * 60 * 60 * 1000;
-
- private JLabel jLabel1 = new JLabel();
- private JComboBox jComboBox1;
- Vector<RuralHouse> ruralHouses;
- private JLabel jLabel2 = new JLabel();
- private JLabel jLabel3 = new JLabel();
- private JLabel jLabel4 = new JLabel();
- private JTextField jTextField2 = new JTextField();
- private JTextField jTextField3 = new JTextField();
- private JTextField jTextField4 = new JTextField();
- private JButton jButton2 = new JButton();
- private JButton jButton3 = new JButton();
-
- // Code for JCalendar
- private JCalendar jCalendar1 = new JCalendar();
- private Calendar calendarMio = null;
- private JLabel jLabel5 = new JLabel();
-
-
-
-public BookRuralHouseGUI()
- {
- try
- {
- jbInit();
-
-
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- public BookRuralHouseGUI(String houseName,Date firstDay,Date lastDay)
- {
- try
- {
- jbInit();
-
-
- // Put the "houseNumber", "firstDay" and "lastDay" in the graphical components of the user interface
- for (int i=0; i<ruralHouses.size();i++){
- if (((RuralHouse)ruralHouses.get(i)).getHouseName()==houseName) {
- jComboBox1.setSelectedIndex(i);
- break;
- }
- }
-
- Calendar c=new GregorianCalendar();
- c.setTime(firstDay);
- //jCalendar1.setCalendar(new GregorianCalendar(firstDay.getYear()+1900,firstDay.getMonth(),firstDay.getDate()));
- jCalendar1.setCalendar(c);
-
- long numberOfDays = (long) (lastDay.getTime()-firstDay.getTime()) / MILLSECS_PER_DAY;
- jTextField3.setText(Long.toString(numberOfDays));
-
-
-
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
-
- private void jbInit() throws Exception
- {
- this.getContentPane().setLayout(null);
- this.setSize(new Dimension(410, 413));
- this.setTitle("Book Rural House");
- jLabel1.setText("Rural house:");
- HouseManager houseM = new HouseManager();
- ruralHouses=houseM.getAllRuralHouses();
-
- jComboBox1 = new JComboBox(ruralHouses);
-
- jLabel1.setBounds(new Rectangle(15, 10, 115, 20));
- jComboBox1.setBounds(new Rectangle(120, 10, 175, 20));
-
-
- jTextField3.addFocusListener(new FocusListener()
- {
- public void focusGained(FocusEvent e)
- {
- }
-
- public void focusLost(FocusEvent e)
- {
- jTextField3_focusLost();
- }
- });
- jTextField4.addFocusListener(new FocusListener()
- {
- public void focusGained(FocusEvent e)
- {
- }
-
- public void focusLost(FocusEvent e)
- {
- jTextField4_focusLost();
- }
- });
- jLabel2.setText("Arrival day:");
- jLabel2.setBounds(new Rectangle(15, 40, 115, 20));
- jLabel3.setText("Number of nights:");
- jLabel3.setBounds(new Rectangle(15, 240, 115, 20));
- jLabel4.setText("Telephone contact number:");
- jLabel4.setBounds(new Rectangle(15, 270, 140, 20));
- jTextField2.setBounds(new Rectangle(155, 205, 140, 20));
- jTextField2.setEditable(false);
- jTextField3.setBounds(new Rectangle(155, 240, 140, 20));
- jTextField3.setText("0");
- jTextField4.setBounds(new Rectangle(155, 270, 140, 20));
- jTextField4.setText("0");
- jButton2.setText("Accept");
- jButton2.setBounds(new Rectangle(50, 345, 130, 30));
- jButton2.setSize(new Dimension(130, 30));
- jButton2.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- // House code
- RuralHouse house=(RuralHouse)jComboBox1.getSelectedItem();
- // Arrival date
- Date firstDay= new Date(jCalendar1.getCalendar().getTime().getTime());
-
- firstDay=Date.valueOf(firstDay.toString());
- // Last day
- // Number of days expressed in milliseconds
- long nights=1000*60*60*24* Integer.parseInt(jTextField3.getText());
- Date lastDay= new Date((long)(firstDay.getTime()+nights));
- // Telephone contact
- String telephone=jTextField4.getText();
- try {
-
- //Obtain the business logic from a StartWindow class (local or remote)
- BookingManager bookingM = new BookingManager();
-
- Booking book=bookingM.createBooking(house, firstDay, lastDay, telephone);
- if (book!=null) {
- BookRuralHouseConfirmationWindow confirmWindow=new BookRuralHouseConfirmationWindow(book);
- confirmWindow.setVisible(true);
- jLabel5.setText("Booking made");
-
- }
- else jLabel5.setText("There is not available offer for these dates");
- } catch (OfferCanNotBeBooked e1) {
- jLabel5.setText("Error: It is not possible to book");
- JFrame a = new QueryAvailabilityGUI();
- a.setVisible(true);
-
- } catch (Exception e1) {
-
- e1.printStackTrace();
- }}
- });
- jButton3.setText("Cancel");
- jButton3.setBounds(new Rectangle(220, 345, 130, 30));
- jButton3.setSize(new Dimension(130, 30));
- jButton3.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- jButton3_actionPerformed(e);
- }
- });
- jLabel5.setBounds(new Rectangle(50, 310, 300, 20));
- jLabel5.setForeground(Color.red);
- jCalendar1.setBounds(new Rectangle(155, 50, 235, 145));
- this.getContentPane().add(jCalendar1, null);
- this.getContentPane().add(jLabel5, null);
- this.getContentPane().add(jButton3, null);
- this.getContentPane().add(jButton2, null);
- this.getContentPane().add(jTextField4, null);
- this.getContentPane().add(jTextField3, null);
- this.getContentPane().add(jTextField2, null);
- this.getContentPane().add(jLabel4, null);
- this.getContentPane().add(jLabel3, null);
- this.getContentPane().add(jLabel2, null);
- this.getContentPane().add(jComboBox1, null);
- this.getContentPane().add(jLabel1, null);
-
- // Code for JCalendar
- this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener()
- {
- public void propertyChange(PropertyChangeEvent propertychangeevent)
- {
- if (propertychangeevent.getPropertyName().equals("locale"))
- {
- jCalendar1.setLocale((Locale) propertychangeevent.getNewValue());
- DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale());
- jTextField2.setText(dateformat.format(calendarMio.getTime()));
-
- }
- else if (propertychangeevent.getPropertyName().equals("calendar"))
- {
- calendarMio = (Calendar) propertychangeevent.getNewValue();
- DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
- jTextField2.setText(dateformat1.format(calendarMio.getTime()));
- jCalendar1.setCalendar(calendarMio);
- }
- }
- });
- }
-
-
- private void jButton3_actionPerformed(ActionEvent e)
- {
- this.setVisible(false);
- }
-
- public void setConfirmBooking(boolean b){
- if (b) jLabel5.setText("Booking made");
- }
-
- private void jTextField3_focusLost()
- {
- try
- {
- new Integer (jTextField3.getText());
- jLabel5.setText("");
- }
- catch (NumberFormatException ex)
- {
- jLabel5.setText("Error: Introduce a number");
- }
- }
-
- private void jTextField4_focusLost()
- {
- try
- {
- new Integer (jTextField4.getText());
- jLabel5.setText("");
- }
- catch (NumberFormatException ex)
- {
- jLabel5.setText("Error: Introduce a number");
- }
- }
-}
\ No newline at end of file
import java.awt.Color;
import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
+import businessLogic.BookingManager;
+import domain.Booking;
import domain.Offer;
import domain.RuralHouse;
-
-
+import exceptions.OfferCanNotBeBooked;
public class HouseFeaturesGUI extends JFrame {
private JTable table;
private DefaultTableModel tableModel;
private DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();
-
+ private RuralHouse rh;
+ private JTextField telIn;
+ private int row;
/**
* Create the frame.
*/
- public HouseFeaturesGUI(RuralHouse rh, Date FirstDay, Date LastDay) {
-
+ public HouseFeaturesGUI(RuralHouse RH, Date FirstDay, Date LastDay) {
+ this.rh = RH;
this.getContentPane().setLayout(null);
setBounds(100, 100, 500, 583);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
-
+
lblDistrict = new JLabel("District:");
lblDistrict.setBounds(23, 67, 70, 14);
lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
-
+
District_f = new JTextField();
District_f.setEditable(false);
District_f.setBounds(103, 64, 86, 20);
District_f.setColumns(10);
-
+
lblDescription = new JLabel("Description:");
lblDescription.setBounds(215, 67, 90, 14);
lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
-
+
description_f = new JTextField();
description_f.setEditable(false);
description_f.setBounds(238, 99, 178, 129);
description_f.setColumns(10);
-
+
lblKitchen = new JLabel("Kitchens:");
lblKitchen.setBounds(23, 211, 70, 14);
lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
-
+
kitchens_f = new JTextField();
kitchens_f.setEditable(false);
kitchens_f.setBounds(103, 202, 86, 20);
kitchens_f.setColumns(10);
-
+
lblRooms = new JLabel("Rooms:");
lblRooms.setBounds(23, 102, 70, 14);
lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
-
+
rooms_f = new JTextField();
rooms_f.setEditable(false);
rooms_f.setBounds(103, 99, 86, 20);
rooms_f.setColumns(10);
-
+
lblLivings = new JLabel("Living rooms:");
lblLivings.setBounds(30, 236, 63, 14);
lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
-
+
lRooms_f = new JTextField();
lRooms_f.setEditable(false);
lRooms_f.setBounds(103, 233, 86, 20);
lRooms_f.setColumns(10);
-
+
lblParkings = new JLabel("Parkings:");
lblParkings.setBounds(23, 174, 70, 14);
lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
-
+
parkings_f = new JTextField();
parkings_f.setEditable(false);
parkings_f.setBounds(103, 171, 86, 20);
parkings_f.setColumns(10);
-
+
lblBaths = new JLabel("Baths:");
lblBaths.setBounds(23, 143, 70, 14);
lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
-
+
baths_f = new JTextField();
baths_f.setEditable(false);
baths_f.setBounds(103, 140, 86, 20);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(40, 311, 376, 183);
contentPane.add(scrollPane);
-
- table = new JTable();
- tableModel = new DefaultTableModel(null,new String[] {"Offer #", "FirstDay", "LastDay", "Price"});
+
+ JTable table = new JTable() {
+ private static final long serialVersionUID = 1L;
+
+ public boolean isCellEditable(int row, int column) {
+ return false;
+ };
+ };
+ tableModel = new DefaultTableModel(null, new String[] { "Offer #",
+ "FirstDay", "LastDay", "Price" });
table.setModel(tableModel);
scrollPane.setViewportView(table);
-
+
JButton btnBookSelected = new JButton("Book SelectedOffer");
- btnBookSelected.setBounds(127, 511, 178, 23);
+ btnBookSelected.setBounds(238, 505, 178, 23);
contentPane.add(btnBookSelected);
-
- JLabel lblNewLabel = new JLabel("Green: Suit your dates. Red: Do not suit your dates");
+
+ btnBookSelected.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+
+ jButton_ActionPerformed(arg0);
+ }
+
+ });
+
+ JLabel lblNewLabel = new JLabel(
+ "Green: Suit your dates. Red: Do not suit your dates");
lblNewLabel.setEnabled(false);
lblNewLabel.setBounds(152, 277, 261, 23);
contentPane.add(lblNewLabel);
+
+ JLabel lblNewLabel_1 = new JLabel("Telephone num:");
+ lblNewLabel_1.setBounds(10, 509, 83, 14);
+ contentPane.add(lblNewLabel_1);
+
+ telIn = new JTextField();
+ telIn.setBounds(99, 505, 129, 20);
+ contentPane.add(telIn);
+ telIn.setColumns(10);
+ table.addMouseListener( new MouseAdapter(){
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ row = table.getSelectedRow();
+ }
+ });
Enumeration<Offer> rhs = rh.getAllOffers().elements();
- while(rhs.hasMoreElements()){
+ while (rhs.hasMoreElements()) {
Offer of = rhs.nextElement();
Vector<Object> row = new Vector<Object>();
row.add(of.getOfferNumber());
row.add(of.getLastDay());
row.add(of.getPrice());
tableModel.addRow(row);
-
-
+
}
- table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer(){
- @Override
- public Component getTableCellRendererComponent(JTable table,
- Object value, boolean isSelected, boolean hasFocus, int row, int col) {
-
- super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
-
- Date firstDay = (Date) table.getModel().getValueAt(row, 1);
- Date lastDay = (Date) table.getModel().getValueAt(row, 2);
- if (FirstDay.before(firstDay)&&LastDay.after(lastDay)) {
- setBackground(Color.GREEN);
- setForeground(Color.BLACK);
- } else {
- setBackground(Color.RED);
- setForeground(Color.BLACK);
- }
- return this;
- }
+ table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+ @Override
+ public Component getTableCellRendererComponent(JTable table,
+ Object value, boolean isSelected, boolean hasFocus,
+ int row, int col) {
+
+ super.getTableCellRendererComponent(table, value, isSelected,
+ hasFocus, row, col);
+
+ Date firstDay = (Date) table.getModel().getValueAt(row, 1);
+ Date lastDay = (Date) table.getModel().getValueAt(row, 2);
+ if (FirstDay != null && LastDay != null) {
+ if (FirstDay.before(firstDay) || FirstDay.equals(firstDay)
+ && LastDay.after(lastDay)
+ || LastDay.equals(lastDay)) {
+ setBackground(Color.GREEN);
+ setForeground(Color.BLACK);
+ } else {
+ setBackground(Color.RED);
+ setForeground(Color.BLACK);
+ }
+ }
+ return this;
+ }
});
}
+
+ private void jButton_ActionPerformed(ActionEvent arg0) {
+ BookingManager bookingM = new BookingManager();
+ //RegExp to see if telephone number is correct??TODO
+ Booking book = null;
+ try {
+ book = bookingM.createBooking(rh, rh.offers.get(row).getFirstDay(), rh.offers.get(row).getLastDay(), telIn.getText());
+ } catch (OfferCanNotBeBooked e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (book != null) {
+ BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
+ book);
+ confirmWindow.setVisible(true);
+ }
+ }
}
* @author willCodeForFood
*/
import exceptions.DB4oManagerCreationException;
-import gui.BookRuralHouseGUI;
import javax.swing.*;
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
- private JButton boton1 = null;
private JButton boton2 = null;
private JButton boton3 = null;
private static configuration.ConfigXML c;
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
- GridLayout gridLayout = new GridLayout();
- gridLayout.setRows(4);
- gridLayout.setColumns(1);
jContentPane = new JPanel();
- jContentPane.setLayout(gridLayout);
+ jContentPane.setLayout(null);
jContentPane.add(getLblNewLabel());
- jContentPane.add(getBoton2(), null);
- jContentPane.add(getBoton3(), null);
- jContentPane.add(getBoton1(), null);
+ jContentPane.add(getBoton2());
+ jContentPane.add(getBoton3());
}
return jContentPane;
}
- /**
- * This method initializes boton1
- *
- * @return javax.swing.JButton
- */
- private JButton getBoton1() {
- if (boton1 == null) {
- boton1 = new JButton();
- boton1.setText("Book rural house");
- boton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- // C?digo cedido por la univerdad
- JFrame a = new BookRuralHouseGUI();
- a.setVisible(true);
- }
- });
- }
- return boton1;
- }
-
/**
* This method initializes boton2
*
private JButton getBoton2() {
if (boton2 == null) {
boton2 = new JButton();
+ boton2.setBounds(0, 74, 479, 93);
boton2.setText("Login");
boton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
private JButton getBoton3() {
if (boton3 == null) {
boton3 = new JButton();
+ boton3.setBounds(0, 165, 479, 87);
boton3.setText("Query availability");
boton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
private JLabel getLblNewLabel() {
if (lblNewLabel == null) {
lblNewLabel = new JLabel("Select option:");
+ lblNewLabel.setBounds(0, 0, 479, 63);
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 13));
lblNewLabel.setForeground(Color.BLACK);
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
import javax.swing.table.DefaultTableModel;
import java.awt.Component;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.sql.Date;
import java.util.Enumeration;
import java.util.LinkedList;
private JPanel contentPane;
private JTable table;
private DefaultTableModel tableModel;
-
- /**
+ private Vector<RuralHouse> houses;
+ /**
* Create the frame.
*/
- public listOfHousesGUI(Vector<RuralHouse> houses) {
+ public listOfHousesGUI(Vector<RuralHouse> rhs) {
try {
- init(houses);
+ this.houses=rhs;
+ init();
} catch (Exception e) {
e.printStackTrace();
}
}
- private void init(Vector<RuralHouse> houses) throws Exception {
+ private void init() throws Exception {
setBounds(100, 100, 600, 450);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
scrollPane.setBounds(23, 113, 536, 271);
contentPane.add(scrollPane);
- table = new JTable();
+ JTable table = new JTable() {
+ private static final long serialVersionUID = 1L;
+
+ public boolean isCellEditable(int row, int column) {
+ return false;
+ };
+ };
scrollPane.setViewportView(table);
tableModel = new DefaultTableModel(null, new String[] {
"House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
"Livings" });
+
//Maybe there is a better way to avoid interaction.
//table.setEnabled(false);
table.setModel(tableModel);
Enumeration<RuralHouse> en = houses.elements();
RuralHouse rh;
-
+ table.addMouseListener( new MouseAdapter(){
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ int row = table.getSelectedRow();
+ HouseFeaturesGUI feat = new HouseFeaturesGUI(houses.get(row),null,null);
+ feat.setVisible(true);
+ }
+ });
while (en.hasMoreElements()) {
rh = en.nextElement();
Vector<Object> row = new Vector<Object>();