Given code uploaded
authorunknown <jcampos004@ikasle.ehu.es>
Thu, 26 Feb 2015 19:24:02 +0000 (20:24 +0100)
committerunknown <jcampos004@ikasle.ehu.es>
Thu, 26 Feb 2015 19:24:02 +0000 (20:24 +0100)
21 files changed:
aa.txt [deleted file]
ruralHouses/.classpath [new file with mode: 0644]
ruralHouses/.project [new file with mode: 0644]
ruralHouses/src/businessLogic/ApplicationFacadeInterface.java [new file with mode: 0644]
ruralHouses/src/businessLogic/BookingManager.java [new file with mode: 0644]
ruralHouses/src/businessLogic/FacadeImplementation.java [new file with mode: 0644]
ruralHouses/src/businessLogic/OfferManager.java [new file with mode: 0644]
ruralHouses/src/businessLogic/RemoteServer.java [new file with mode: 0644]
ruralHouses/src/configuration/Config.java [new file with mode: 0644]
ruralHouses/src/dataAccess/DB4oManager.java [new file with mode: 0644]
ruralHouses/src/domain/Booking.java [new file with mode: 0644]
ruralHouses/src/domain/Offer.java [new file with mode: 0644]
ruralHouses/src/domain/Owner.java [new file with mode: 0644]
ruralHouses/src/domain/RuralHouse.java [new file with mode: 0644]
ruralHouses/src/exceptions/OfferCanNotBeBooked.java [new file with mode: 0644]
ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java [new file with mode: 0644]
ruralHouses/src/gui/BookRuralHouseGUI.java [new file with mode: 0644]
ruralHouses/src/gui/IntroduceOffer2GUI.java [new file with mode: 0644]
ruralHouses/src/gui/IntroduceOfferGUI.java [new file with mode: 0644]
ruralHouses/src/gui/SearchOffersGUI.java [new file with mode: 0644]
ruralHouses/src/gui/StartWindow.java [new file with mode: 0644]

diff --git a/aa.txt b/aa.txt
deleted file mode 100644 (file)
index 7c4a013..0000000
--- a/aa.txt
+++ /dev/null
@@ -1 +0,0 @@
-aaa
\ No newline at end of file
diff --git a/ruralHouses/.classpath b/ruralHouses/.classpath
new file mode 100644 (file)
index 0000000..421f8bf
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/jcalendar.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/bloat-1.0.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/db4o-7.4.106.13438-instrumentation.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/db4o-7.4.106.13438-java5.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/db4o-7.4.106.13438-taj.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/db4o-sql-r27-db4o-7.4-java5.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/forms-1.0.7.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/looks-2.0.4.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/objectmanager-api.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/xpp3_min-1.1.3.4.O.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Jesus/Desktop/RuralHouses/Aidanez/additionalLibs/db4o/lib/xstream-1.2.1.jar"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/ruralHouses/.project b/ruralHouses/.project
new file mode 100644 (file)
index 0000000..d76d534
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>ruralHouses</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/ruralHouses/src/businessLogic/ApplicationFacadeInterface.java b/ruralHouses/src/businessLogic/ApplicationFacadeInterface.java
new file mode 100644 (file)
index 0000000..a438bee
--- /dev/null
@@ -0,0 +1,71 @@
+package businessLogic;
+
+import java.rmi.*;
+
+import java.util.Vector;
+import java.util.Date;
+
+import domain.Booking;
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+
+import exceptions.OfferCanNotBeBooked; 
+
+public interface ApplicationFacadeInterface extends Remote {
+
+       /**
+        * This method obtains an owner's rural houses 
+        * 
+        * @param owner object
+        *            
+        * @return a vector of Rural Houses
+        */
+       Vector<RuralHouse> getRuralHouses(Owner owner)
+                       throws RemoteException;
+
+       /**
+        * This method creates an offer with a house number, first day, last day and price
+        * 
+        * @param House
+        *            number, start day, last day and price
+        * @return None
+        */
+
+       Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
+                       float price) throws RemoteException, Exception;
+
+       /**
+        * This method creates a book with a corresponding parameters
+        * 
+        * @param First
+        *            day, last day, house number and telephone
+        * @return a book
+        */
+       Booking createBooking(RuralHouse ruralHouse, Date firstDay, Date lastDay,
+                       String telephoneNumber) throws RemoteException, OfferCanNotBeBooked;
+
+       /**
+        * This method obtains available offers for a concrete house in a certain period 
+        * 
+        * @param houseNumber, the house number where the offers must be obtained 
+        * @param firstDay, first day in a period range 
+        * @param lastDay, last day in a period range
+        * @return a vector of offers(Offer class)  available  in this period
+        */
+       Vector<Offer> getOffers(RuralHouse houseNumber, Date firstDay, Date lastDay) 
+                       throws RemoteException, Exception;
+       
+       /**
+        * This method finds existing  owners 
+        * 
+        */
+       public Vector<Owner> getOwners() throws RemoteException,
+                       Exception;
+       
+       public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
+       Exception;
+       
+       public void close() throws RemoteException;
+       
+}
\ No newline at end of file
diff --git a/ruralHouses/src/businessLogic/BookingManager.java b/ruralHouses/src/businessLogic/BookingManager.java
new file mode 100644 (file)
index 0000000..18670e1
--- /dev/null
@@ -0,0 +1,49 @@
+package businessLogic;
+
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+
+import dataAccess.DB4oManager;
+
+
+public final class BookingManager {
+
+       private int bookingNumber = 0;
+       dataAccess.DB4oManager dbMngr;
+
+       private static BookingManager theBookingManager;
+
+       private BookingManager() {}
+       
+       /**
+        * This method returns the next Booking number 
+        * 
+        * @return the book number
+        */
+    public static int getNumber(){
+               ObjectContainer db=DB4oManager.getContainer();
+       BookingManager b=getInstance();
+       b.bookingNumber++;
+       db.store(b);
+       db.commit();
+       return b.bookingNumber;
+    }
+       
+       /**
+        * This method returns the instance of the BookingManager class 
+        * 
+        * @return the booking manager
+        */
+       public static BookingManager getInstance()  {
+               ObjectContainer db=DB4oManager.getContainer();
+           BookingManager b = new BookingManager();
+           ObjectSet result = db.queryByExample(b);
+           if (!result.hasNext()){
+               theBookingManager = new BookingManager();
+               db.store(theBookingManager);
+               db.commit();
+           } else theBookingManager=(BookingManager)result.next();
+               return theBookingManager;
+       }
+       
+}
\ No newline at end of file
diff --git a/ruralHouses/src/businessLogic/FacadeImplementation.java b/ruralHouses/src/businessLogic/FacadeImplementation.java
new file mode 100644 (file)
index 0000000..c4670bb
--- /dev/null
@@ -0,0 +1,96 @@
+package businessLogic;
+
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+
+import java.util.Date;
+import java.util.Vector;
+
+import java.sql.SQLException;
+
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+import configuration.Config;
+
+import dataAccess.DB4oManager;
+
+import domain.Booking;
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+
+import exceptions.OfferCanNotBeBooked;
+
+public class FacadeImplementation extends UnicastRemoteObject implements ApplicationFacadeInterface {
+
+       private static final long serialVersionUID = 1L;
+       DB4oManager dbMngr;
+
+       public FacadeImplementation() throws RemoteException, InstantiationException,
+       IllegalAccessException, ClassNotFoundException, SQLException {
+               dbMngr = DB4oManager.getInstance();
+       }
+
+       /**
+        * This method obtains an owner's rural houses 
+        * 
+        * @param owner object
+        *            
+        * @return a vector of Rural Houses
+        */
+       public Vector<RuralHouse> getRuralHouses(Owner owner)
+                       throws RemoteException {
+               return owner.getRuralHouses();          
+       }
+
+       public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
+                       float price) throws RemoteException, Exception {                 
+               return dbMngr.createOffer(ruralHouse, firstDay, lastDay, price);
+       }
+
+       /**
+        * This method obtains available offers for a concrete house in a certain period 
+        * 
+        * @param houseNumber, the house number where the offers must be obtained 
+        * @param firstDay, first day in a period range 
+        * @param lastDay, last day in a period range
+        * @return a vector of offers(Offer class)  available  in this period
+        */
+       public Vector<Offer> getOffers(RuralHouse house,Date firstDay, Date lastDay) throws RemoteException,
+       Exception {             
+               return house.getOffers(firstDay, lastDay);
+
+       }
+       /**
+        * This method finds all existing  owners 
+        * 
+        */
+       public Vector<Owner> getOwners() throws RemoteException,
+       Exception {
+               return dbMngr.getOwners();
+       } 
+
+       public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
+       Exception {             
+               return dbMngr.getAllRuralHouses();              
+       }
+
+       public void close() throws RemoteException{
+               DB4oManager.close();
+       }
+
+       public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
+                       throws OfferCanNotBeBooked {
+               try {
+                       RuralHouse rh=dbMngr.getRuralHouse(ruralHouse);
+                       Offer offer = rh.findOffer(firstDate, lastDate);
+                       Booking b=dbMngr.createBooking(offer,bookTelephoneNumber);
+                       return b;
+               } catch (Exception exc) {
+                       exc.printStackTrace();
+                       return null;
+               }
+       }
+
+}
+
diff --git a/ruralHouses/src/businessLogic/OfferManager.java b/ruralHouses/src/businessLogic/OfferManager.java
new file mode 100644 (file)
index 0000000..3c00ca5
--- /dev/null
@@ -0,0 +1,41 @@
+package businessLogic;
+
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+
+import dataAccess.DB4oManager;
+
+public final class OfferManager {
+
+       private int offerNumber = 0;
+       dataAccess.DB4oManager dbMngr;
+       private static OfferManager theOfferManager;
+
+       private OfferManager() {}
+
+       public static int getNumber() {
+               ObjectContainer db=DB4oManager.getContainer();
+               OfferManager o=getInstance();
+               o.offerNumber++;
+               db.store(o);
+               db.commit();
+               return o.offerNumber;
+       }
+
+       /**
+        * This method returns the instance of the OfferManager class 
+        * 
+        * @return the offer manager
+        */
+       public static OfferManager getInstance()  {
+               ObjectContainer db=DB4oManager.getContainer();
+               OfferManager b = new OfferManager();
+               ObjectSet result = db.queryByExample(b);
+               if (!result.hasNext()){
+                       theOfferManager = new OfferManager();
+                       db.store(theOfferManager);
+                       db.commit();
+               } else theOfferManager=(OfferManager)result.next();
+               return theOfferManager;
+       }
+}
diff --git a/ruralHouses/src/businessLogic/RemoteServer.java b/ruralHouses/src/businessLogic/RemoteServer.java
new file mode 100644 (file)
index 0000000..3e1f473
--- /dev/null
@@ -0,0 +1,42 @@
+package businessLogic;
+
+import java.rmi.Naming;
+import java.rmi.RMISecurityManager;
+
+import configuration.Config;
+import dataAccess.DB4oManager;
+
+public class RemoteServer {
+
+       public static void main(String[] args) {
+               Config c=Config.getInstance();
+
+               System.setProperty("java.security.policy", c.getJavaPolicyPath());
+
+               //System.setSecurityManager(new RMISecurityManager());
+
+               try {
+                       java.rmi.registry.LocateRegistry.createRegistry(Integer.parseInt(c.getPortRMI()));
+                       // Create RMIREGISTRY
+               } catch (Exception e) {
+                       System.out.println(e.toString() + "RMIregistry already running.");
+               }
+
+               try {
+                       System.setProperty("java.security.policy", c.getJavaPolicyPath());
+
+                       ApplicationFacadeInterface server = new FacadeImplementation();
+
+                       String service= "//"+c.getServerRMI() +":"+ c.getPortRMI()+"/"+c.getServiceRMI();
+
+                       //Register the remote server
+                       Naming.rebind(service, server);
+                       System.out.println("Running service at:\n\t" + service);
+                       //This operation removes the actual database and initializes it with some predefined values
+
+               } catch (Exception e) {
+                       System.out.println(e.toString());
+               }
+       }
+       
+}
diff --git a/ruralHouses/src/configuration/Config.java b/ruralHouses/src/configuration/Config.java
new file mode 100644 (file)
index 0000000..1588ee3
--- /dev/null
@@ -0,0 +1,52 @@
+package configuration;
+
+public class Config {
+
+       private final String serverRMI = "localhost";
+
+       private final String portRMI = "1099";
+
+       private final String serviceRMI = "RuralHouses";
+       
+       //private final String javaPolicyPath="/Users/joniturrioz/Asignaturas/gradoISO/CasaRuralSG/java.policy";
+       private final String javaPolicyPath="C://Users/Jesus/Desktop/RuralHouses/Aidanez/java.policy";
+       
+       //final static String db4oFilename = "/Users/joniturrioz/DB/ruralHouses.db4o";
+       private final  String db4oFilename = "C://Users/Jesus/Desktop/RuralHouses/DBjibanez008.yap";
+
+       //Two possible values: "open" or "initialize"
+       private final String dataBaseOpenMode="initialize";
+
+       private static Config theInstance = new Config();
+   
+       private Config(){}
+    
+       public static Config getInstance() { 
+               return theInstance; 
+       }
+
+       public String getServerRMI() {
+               return serverRMI; 
+       }
+
+       public String getPortRMI() { 
+               return portRMI; 
+       }
+
+       public String getServiceRMI() {
+               return serviceRMI;
+       }
+
+       public String getDb4oFilename() {
+               return db4oFilename; 
+       }
+
+       public String getJavaPolicyPath() {
+               return javaPolicyPath;
+       }
+
+       public String getDataBaseOpenMode(){
+               return dataBaseOpenMode;
+       }
+
+}
diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java
new file mode 100644 (file)
index 0000000..0049a4e
--- /dev/null
@@ -0,0 +1,164 @@
+package dataAccess;
+
+import java.io.File;
+import java.rmi.RemoteException;
+import java.util.Date;
+import java.util.Vector;
+//import java.util.Enumeration;
+//import java.util.Vector;
+
+import businessLogic.BookingManager;
+
+import com.db4o.*;
+
+import configuration.Config;
+
+import domain.Booking;
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+import exceptions.OfferCanNotBeBooked;
+
+public class DB4oManager { 
+
+       private static ObjectContainer db;
+       private static DB4oManager theDB4oManager=new DB4oManager();
+
+       private DB4oManager() {
+               Config c=Config.getInstance();
+               String dataBaseOpenMode=c.getDataBaseOpenMode();
+               DB4oManager.openDatabase(dataBaseOpenMode);
+       }
+
+       public static void openDatabase(String mode) {
+               Config c=Config.getInstance();
+               String db4oFileName=c.getDb4oFilename();
+               if (mode.compareTo("open")==0) {
+                       db=Db4o.openFile(Db4o.newConfiguration(), db4oFileName);
+                       db.ext().configure().updateDepth(5);
+                       System.out.println("DataBase Opened");
+
+               } else if (mode.compareTo("initialize")==0){
+                       new File(db4oFileName).delete();
+                       db=Db4o.openFile(Db4o.newConfiguration(), db4oFileName);
+                       db.ext().configure().updateDepth(5);
+                       Owner jon = new Owner("Jon", "userJon", "passJon");
+                       Owner alfredo = new Owner("Alfredo","userAlfredo", "passAlfredo");
+                       jon.addRuralHouse(1, "Ezkioko etxea","Ezkio");
+                       jon.addRuralHouse(2, "Eskiatzeko etxea","Jaca");
+                       jon.setBankAccount("1349 5677 21 2133567777");
+                       alfredo.addRuralHouse(3, "Casa del abuelo","Pitillas");
+                       alfredo.addRuralHouse(4, "Refugio","Murgia");
+                       alfredo.setBankAccount("4144 0087 23 9700002133");
+
+                       db.store(jon);
+                       db.store(alfredo);
+                       db.commit();
+                       System.out.println("DataBase Initialized");
+               }
+       }
+
+       public  static ObjectContainer getContainer() {
+               return db;
+       }
+       public static void close(){
+               db.close();
+               System.out.println("DataBase closed");
+       }
+       
+       /**
+        * This method finds all existing  owners 
+        * 
+        */
+       public Vector<Owner> getOwners() throws RemoteException,
+       Exception {
+               ObjectContainer db=DB4oManager.getContainer();
+
+               try {
+                       Owner proto = new Owner(null,null,null,null);
+                       ObjectSet result = db.queryByExample(proto);
+                       Vector<Owner> owners=new Vector<Owner>();
+                       while(result.hasNext())                          
+                               owners.add((Owner)result.next());
+                       return owners;
+               } finally {
+                       //db.close();
+               }
+       } 
+
+       public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
+       Exception {
+               ObjectContainer db=DB4oManager.getContainer();
+               try {
+                       RuralHouse proto = new RuralHouse(0,null,null,null);
+                       ObjectSet result = db.queryByExample(proto);
+                       Vector<RuralHouse> ruralHouses=new Vector<RuralHouse>();
+                       while(result.hasNext()) 
+                               ruralHouses.add((RuralHouse)result.next());
+                       return ruralHouses;
+               } finally {
+                       //db.close();
+               }
+       }
+
+       /**
+        * This method creates an offer with a house number, first day, last day and price
+        * precondition: There are no overlapping offers
+        * @param House
+        *            number, start day, last day and price
+        * @return None
+        */
+       public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
+                       float price) throws RemoteException, Exception {
+               ObjectContainer db=DB4oManager.getContainer();
+               RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(), null, 
+                               ruralHouse.getDescription(), ruralHouse.getTown());
+               ObjectSet result = db.queryByExample(proto);
+               RuralHouse rh=(RuralHouse)result.next();
+               Offer o=rh.createOffer(firstDay, lastDay, price);
+               db.store(o);
+               db.commit(); 
+               return o;
+       }
+
+       public RuralHouse getRuralHouse(RuralHouse rh){
+               try {
+                       ObjectContainer db=DB4oManager.getContainer();
+                       RuralHouse proto = new RuralHouse(rh.getHouseNumber(), null,
+                                       rh.getDescription(), rh.getTown());
+                       ObjectSet result = db.queryByExample(proto);
+                       return  rh=(RuralHouse)result.next();
+               } catch (Exception exc) {
+                       exc.printStackTrace();
+                       return null;
+               }
+       }
+
+       public Booking createBooking(Offer offer, String clientTelephoneNumber)
+                       throws OfferCanNotBeBooked {
+               try {
+                       Booking b=null;
+                       if (offer!=null) {
+                               b=offer.createBook(clientTelephoneNumber);
+                               db.store(b);
+                               db.store(offer);
+                               db.commit();
+                       }
+                       return b;
+               } catch (Exception exc) {
+                       exc.printStackTrace();
+                       return null;
+               }
+       }
+
+       /**
+        * This method returns the instance of the DB4oManager class 
+        * 
+        * @return the db4o manager
+        */
+       public static DB4oManager getInstance()  {
+               return theDB4oManager;
+       }
+
+}
+
diff --git a/ruralHouses/src/domain/Booking.java b/ruralHouses/src/domain/Booking.java
new file mode 100644 (file)
index 0000000..64a3152
--- /dev/null
@@ -0,0 +1,82 @@
+package domain;
+
+import java.io.*;
+import java.util.Date;
+
+import businessLogic.BookingManager;
+
+@SuppressWarnings("serial")
+public class Booking implements Serializable {
+       private int bookingNumber;
+       private boolean isPaid;
+       private Date bookingDate;
+       private String telephone;
+       private Offer offer;
+       
+       public Booking() {
+       }
+
+       public Booking(String telephone, Offer offer) {
+               
+               this.bookingNumber = BookingManager.getNumber();
+               this.telephone=telephone;
+               this.offer = offer;
+               //this.price = price;
+               //Booking date is assigned to actual date
+               this.bookingDate= new java.util.Date(System.currentTimeMillis());
+               this.isPaid=false;
+       }
+       
+       public void imprimete(){
+               System.out.println(bookingNumber);
+               System.out.println(isPaid);
+               System.out.println(bookingDate);
+               System.out.println(telephone);
+               System.out.println(offer);              
+       }
+
+       public int getBookNumber() {
+               return this.bookingNumber;
+       }
+
+       public void setOffer(Offer offer) {
+               this.offer = offer;
+       }
+
+       public Offer getOffer() {
+               return this.offer;
+       }
+
+       public float getPrice() {
+               return this.offer.getPrice();
+       }
+       
+       public void setBookDate(Date bookDate) {
+               this.bookingDate = bookDate;
+       }
+
+       public Date getBookDate() {
+               return this.bookingDate;
+       }
+       
+       public void setTelephone(String telephone) {
+               this.telephone = telephone;
+       }
+
+       public String getTelephone() {
+               return this.telephone;
+       }
+       
+       public void paid() {
+               this.isPaid = true;
+       }
+
+       public void notPaid() {
+               this.isPaid=false;
+       }
+
+       public boolean isPaid() {
+               return isPaid;
+       }
+       
+}
\ No newline at end of file
diff --git a/ruralHouses/src/domain/Offer.java b/ruralHouses/src/domain/Offer.java
new file mode 100644 (file)
index 0000000..36b7037
--- /dev/null
@@ -0,0 +1,77 @@
+package domain;
+
+import java.io.*;
+//import java.util.Vector;
+import java.util.Date;
+import businessLogic.OfferManager;
+import com.db4o.ObjectContainer;
+import dataAccess.DB4oManager;
+
+@SuppressWarnings("serial")
+public class Offer implements Serializable {
+       
+       private int offerNumber;
+       private Date firstDay;
+       private Date lastDay;
+       private float price;
+       private Booking booking;
+       private RuralHouse ruralHouse;
+       
+       public Offer(RuralHouse ruralHouse, Date firstDay, Date lastDay, float price) {
+                 this.firstDay=firstDay;
+                 this.lastDay=lastDay;
+                 this.price=price;
+                 this.ruralHouse=ruralHouse;
+                 this.offerNumber=OfferManager.getNumber();
+       }
+
+       public RuralHouse getRuralHouse() {
+               return this.ruralHouse;
+       }
+
+       public void setRuralHouse(RuralHouse ruralHouse) {
+               this.ruralHouse = ruralHouse;
+       }
+
+       public int getOfferNumber() {
+               return this.offerNumber;
+       }
+
+       public Date getFirstDay() {
+               return this.firstDay;
+       }
+
+       public void setFirstDay(Date firstDay) {
+               this.firstDay = firstDay;
+       }
+
+       public Date getLastDay() {
+               return this.lastDay;
+       }
+
+       public void setLastDay(Date lastDay) {
+               this.lastDay = lastDay;
+       }
+
+       public float getPrice() {
+               return this.price;
+       }
+
+       public void setPrice(float price) {
+               this.price = price;
+       }
+
+       public Booking getBooking() {
+               return this.booking;
+       }
+
+       public void setBooking(Booking booking) {
+               this.booking = booking;
+       }
+       
+       public Booking createBook(String bookTelephoneNumber) {
+               Booking b=new Booking(bookTelephoneNumber, this);
+               booking=b;
+               return booking;                 
+       }
+}
\ No newline at end of file
diff --git a/ruralHouses/src/domain/Owner.java b/ruralHouses/src/domain/Owner.java
new file mode 100644 (file)
index 0000000..34255f8
--- /dev/null
@@ -0,0 +1,76 @@
+package domain;
+
+import java.io.Serializable;
+import java.util.Vector;
+
+@SuppressWarnings("serial")
+public class Owner implements Serializable {
+
+       private String bankAccount = "";
+       private String name="";
+       private String username="";
+       private String password="";
+       private Vector<RuralHouse> ruralHouses;
+
+       public Owner(String name,String login, String password) {
+               this.name=name;
+               this.username=login;
+               this.password=password;
+               ruralHouses=new Vector<RuralHouse>();           
+       }
+
+       public Owner(String name,String login, String password, String bankAccount) {
+               this.bankAccount=bankAccount;
+               this.name=name;
+               this.username=login;
+               this.password=password;
+               ruralHouses=new Vector<RuralHouse>();           
+       }
+
+       public String getName() {
+               return this.name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public String getBankAccount() {
+               return this.bankAccount;
+       }
+
+       public void setBankAccount(String bankAccount) {
+               this.bankAccount = bankAccount;
+       }
+
+       public String getUsername() {
+               return this.username;
+       }
+
+       public void setUsername(String username) {
+               this.username = username;
+       }
+
+       public String getPassword() {
+               return this.password;
+       }
+
+       public void setPassword(String password) {
+               this.password = password;
+       }
+
+       public Vector<RuralHouse> getRuralHouses() {
+               return ruralHouses;
+       }
+
+       public RuralHouse addRuralHouse(int houseNumber, String description, String city) {
+               RuralHouse rh=new RuralHouse(houseNumber,  this,  description,  city);
+               ruralHouses.add(rh);
+               return rh;
+       }
+       
+       public String toString(){
+               return name;
+       }
+
+}
\ No newline at end of file
diff --git a/ruralHouses/src/domain/RuralHouse.java b/ruralHouses/src/domain/RuralHouse.java
new file mode 100644 (file)
index 0000000..13a751d
--- /dev/null
@@ -0,0 +1,144 @@
+package domain;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Vector;
+
+public class RuralHouse implements Serializable {
+
+       private static final long serialVersionUID = 1L;
+
+       private int houseNumber;
+       private String description;
+       private Owner owner;
+       private String town; 
+       public Vector<Offer> offers;
+       
+       public RuralHouse() {
+               super();
+       }
+
+       public RuralHouse(int houseNumber, Owner owner, String description, String town) {
+               this.houseNumber = houseNumber;
+               this.description = description;
+               this.owner = owner;
+               this.town = town;
+               offers=new Vector<Offer>();
+       }
+
+       public int getHouseNumber() {
+               return houseNumber;
+       }
+
+       public void setHouseNumber(int houseNumber) {
+               this.houseNumber = houseNumber;
+       }
+
+       public String getDescription() {
+               return description;
+       }
+       
+       public void setDescription(String description) {
+               this.description=description;
+       }
+
+       public Owner getOwner() {
+               return owner;
+       }
+
+       public void setOwner(Owner owner) {
+               this.owner=owner;
+       }
+       
+       public String getTown() {
+               return town;
+       }
+       
+       public void setTown(String town) {
+               this.town=town;
+       }
+       
+       public String toString() {
+               return this.houseNumber + ": " + this.town;
+       }
+       
+       public Offer createOffer(Date firstDay, Date lastDay, float price) {
+        Offer off=new Offer(this, firstDay, lastDay, price);
+        offers.add(off);
+        return off;
+       }
+
+       @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + houseNumber;
+               return result;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+               RuralHouse other = (RuralHouse) obj;
+               if (houseNumber != other.houseNumber)
+                       return false;
+               return true;
+       }
+       
+       public String getAccountNumber(int houseNumber) {
+               /*try {
+                       dbMngr=DBManager.getInstance();
+                       return dbMngr.getOwner(houseNumber).getBankAccount();
+
+               } catch (Exception e) {
+                       System.out.println("Error, accessing to DB Manager: "
+                                       + e.toString());
+                       return null;
+               }*/ return null;
+       }
+       
+       /**
+        * This method obtains available offers for a concrete house in a certain period 
+        * 
+        * @param houseNumber, the house number where the offers must be obtained 
+        * @param firstDay, first day in a period range 
+        * @param lastDay, last day in a period range
+        * @return a vector of offers(Offer class)  available  in this period
+        */
+       public Vector<Offer> getOffers( Date firstDay,  Date lastDay) {
+               Vector<Offer> availableOffers=new Vector<Offer>();
+               Iterator<Offer> e=offers.iterator();
+               Offer offer;
+               while (e.hasNext()){
+                       offer=e.next();
+                       if ( (offer.getFirstDay().compareTo(firstDay)>=0) && (offer.getLastDay().compareTo(lastDay)<=0) && (offer.getBooking()==null) )
+                               availableOffers.add(offer);
+               }
+               return availableOffers;
+       }
+       
+       /**
+        * This method obtains the offer that match exactly with a given dates that has not been booked
+        * 
+        * @param firstDay, first day in a period range 
+        * @param lastDay, last day in a period range
+        * @return the  offer(Offer class)  available  for a this period
+        */
+       public Offer findOffer( Date firstDay,  Date lastDay) {         
+               Iterator<Offer> e=offers.iterator();
+               Offer offer=null;
+               while (e.hasNext()){
+                       offer=e.next();
+                       if ( (offer.getFirstDay().compareTo(firstDay)==0) && (offer.getLastDay().compareTo(lastDay)==0) && (offer.getBooking()==null) )
+                               return offer;
+               }
+               return null;            
+       }
+
+}
diff --git a/ruralHouses/src/exceptions/OfferCanNotBeBooked.java b/ruralHouses/src/exceptions/OfferCanNotBeBooked.java
new file mode 100644 (file)
index 0000000..b4539d0
--- /dev/null
@@ -0,0 +1,17 @@
+package exceptions;
+public class OfferCanNotBeBooked extends Exception {
+       private static final long serialVersionUID = 1L;
+
+       public OfferCanNotBeBooked() {
+               super();
+       }
+       
+       /**This exception is triggered if an offer cannot be booked 
+        *@param String
+        *@return None
+        */
+       public OfferCanNotBeBooked(String s)
+       {
+               super(s);
+       }
+}
\ No newline at end of file
diff --git a/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java b/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java
new file mode 100644 (file)
index 0000000..a80006f
--- /dev/null
@@ -0,0 +1,87 @@
+package gui;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+import domain.Booking;
+
+public class BookRuralHouseConfirmationWindow extends JFrame {
+
+       private static final long serialVersionUID = 1L;
+       private JLabel jLabel1 = new JLabel();
+       private JTextField jTextField1 = new JTextField();
+       private JLabel jLabel2 = new JLabel();
+       private JTextField jTextField2 = new JTextField();
+       private JLabel jLabel3 = new JLabel();
+       private JButton jButton1 = new JButton();
+       private JLabel jLabel4 = new JLabel();
+       private JLabel jLabel5 = new JLabel();
+       private JTextField jTextField3 = new JTextField();
+       private JTextField jTextField4 = new JTextField();
+
+       public BookRuralHouseConfirmationWindow(Booking booking) {
+               try {
+                       jbInit(booking);
+               }
+               catch(Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void jbInit(Booking booking) throws Exception {
+
+               this.getContentPane().setLayout(null);
+               this.setSize(new Dimension(416, 316));
+               this.setTitle("Confirm Booking");
+               this.setResizable(false);
+               jLabel1.setText("Owner Bank account number:");
+               jLabel1.setBounds(new Rectangle(20, 20, 200, 25));
+               jTextField1.setBounds(new Rectangle(225, 20, 165, 25));
+               jTextField1.setEditable(false);
+               jTextField1.setText(booking.getOffer().getRuralHouse().getOwner().getBankAccount());
+
+               jLabel2.setText("Booking number:");
+               jLabel2.setBounds(new Rectangle(20, 60, 130, 25));
+               jTextField2.setBounds(new Rectangle(225, 60, 165, 25));
+               jTextField2.setEditable(false);
+
+               jTextField2.setText(Integer.toString(booking.getBookNumber()));
+
+               jLabel3.setText("You ought to transfer 20% of the total price of the booking in the next three days.");
+               jLabel3.setBounds(new Rectangle(20, 105, 370, 25));
+               jButton1.setText("Accept");
+               jButton1.setBounds(new Rectangle(135, 235, 130, 30));
+               jButton1.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton1_actionPerformed(e);
+                       }
+               });
+               jLabel4.setText("Total:");
+               jLabel4.setBounds(new Rectangle(70, 140, 85, 25));
+               jLabel5.setText("Deposit amount:");
+               jLabel5.setBounds(new Rectangle(70, 175, 100, 25));
+               jTextField3.setBounds(new Rectangle(180, 140, 115, 25));
+               jTextField3.setEditable(false);
+
+               jTextField3.setText(Float.toString(booking.getPrice()) + " \80");
+               jTextField4.setBounds(new Rectangle(180, 175, 115, 25));
+               jTextField4.setEditable(false);
+               jTextField4.setText(Float.toString(booking.getPrice()*(float)0.2) + " \80");
+               this.getContentPane().add(jTextField4, null);
+               this.getContentPane().add(jTextField3, null);
+               this.getContentPane().add(jLabel5, null);
+               this.getContentPane().add(jLabel4, null);
+               this.getContentPane().add(jButton1, null);
+               this.getContentPane().add(jLabel3, null);
+               this.getContentPane().add(jTextField2, null);
+               this.getContentPane().add(jLabel2, null);
+               this.getContentPane().add(jTextField1, null);
+               this.getContentPane().add(jLabel1, null);
+       }
+
+       private void jButton1_actionPerformed(ActionEvent e) {
+               this.setVisible(false);
+       }
+       
+}
\ No newline at end of file
diff --git a/ruralHouses/src/gui/BookRuralHouseGUI.java b/ruralHouses/src/gui/BookRuralHouseGUI.java
new file mode 100644 (file)
index 0000000..fead030
--- /dev/null
@@ -0,0 +1,221 @@
+package gui;
+
+import businessLogic.ApplicationFacadeInterface;
+
+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;
+
+       private JLabel jLabel1 = new JLabel();
+       private JComboBox jComboBox1;
+       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 myCalendar = null;
+       private JLabel jLabel5 = new JLabel();
+
+       public BookRuralHouseGUI() {
+               try {
+                       jbInit();
+               }
+               catch(Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       public BookRuralHouseGUI(int houseNumber, Date firstDay, Date lastDay) {
+               try {
+                       jbInit();
+
+                       /*jTextField1.setText(Integer.toString(houseNumber));
+                       long nights=(lastDay.getTime()-firstDay.getTime())/(1000*60*60*24);
+                       jTextField3.setText(Long.toString(nights));
+                       DateFormat dateformat1 = DateFormat.getDateInstance(1);
+
+                       Date first= new Date((long)(firstDay.getTime()));
+                       jTextField2.setText(dateformat1.format(first));
+                       GregorianCalendar cal=new GregorianCalendar();
+                       cal.setTime(first);
+                       int year=cal.get(Calendar.YEAR);
+                       int month=cal.get(Calendar.MONTH);
+                       int day=cal.get(Calendar.DAY_OF_MONTH);
+
+                       JYearChooser yc=jCalendar1.getYearChooser();
+               JMonthChooser mc=   jCalendar1.getMonthChooser();
+               JDayChooser dc= jCalendar1.getDayChooser();
+
+                       yc.setYear(year);
+               mc.setMonth(month);
+               dc.setDay(day); */
+
+               }
+               catch(Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void jbInit() throws Exception {
+               this.getContentPane().setLayout(null);
+               this.setSize(new Dimension(430, 440));
+               this.setTitle("Book Rural House");
+               jLabel1.setText("Rural house:");
+               ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+               Vector<RuralHouse> ruralHouses=facade.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));
+                               // Contact telephone
+                               String telephone=jTextField4.getText();
+                               try {
+                                       //Obtain the business logic from a StartWindow class (local or remote)
+                                       ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+
+                                       Booking book=facade.createBooking(house, firstDay, lastDay, telephone);
+                                       System.out.println(book.getPrice());
+                                       if (book!=null) {
+                                               BookRuralHouseConfirmationWindow confirmWindow=new BookRuralHouseConfirmationWindow(book);
+                                               confirmWindow.setVisible(true);
+                                       }
+                               }
+                               catch (OfferCanNotBeBooked e1) {
+                                       jLabel5.setText("Error: Booking is not possible");
+                                       JFrame a = new SearchOffersGUI();
+                                       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(myCalendar.getTime()));
+                               }
+                               else if (propertychangeevent.getPropertyName().equals("calendar")) {
+                                       myCalendar = (Calendar) propertychangeevent.getNewValue();
+                                       DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
+                                       jTextField2.setText(dateformat1.format(myCalendar.getTime()));
+                                       jCalendar1.setCalendar(myCalendar);
+                               }
+                       } 
+               });
+       }
+
+       private void jButton3_actionPerformed(ActionEvent e) {
+               this.setVisible(false);
+       }
+
+       private void jTextField3_focusLost() {
+               try {
+                       new Integer (jTextField3.getText());
+                       jLabel5.setText("");
+               }
+               catch (NumberFormatException ex) {
+                       jLabel5.setText("Error: Please introduce a number");
+               }
+       }
+
+       private void jTextField4_focusLost() {
+               try {
+                       new Integer (jTextField4.getText());
+                       jLabel5.setText("");
+               }
+               catch (NumberFormatException ex) {
+                       jLabel5.setText("Error: Please introduce a number");
+               }
+       }
+
+}
\ No newline at end of file
diff --git a/ruralHouses/src/gui/IntroduceOffer2GUI.java b/ruralHouses/src/gui/IntroduceOffer2GUI.java
new file mode 100644 (file)
index 0000000..276dcfa
--- /dev/null
@@ -0,0 +1,180 @@
+package gui;
+
+import java.beans.*;
+
+import java.sql.Date;
+import java.text.DateFormat;
+import java.util.*;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+import businessLogic.ApplicationFacadeInterface;
+
+import com.toedter.calendar.JCalendar;
+
+import domain.RuralHouse;
+
+public class IntroduceOffer2GUI extends JFrame  {
+       
+       private static final long serialVersionUID = 1L;
+
+       private JComboBox jComboBox1;
+       private JLabel jLabel1 = new JLabel();
+       private JLabel jLabel2 = new JLabel();
+       private JTextField jTextField1 = new JTextField();
+       private JLabel jLabel3 = new JLabel();
+       private JTextField jTextField2 = new JTextField();
+       private JLabel jLabel4 = new JLabel();
+       private JTextField jTextField3 = new JTextField();
+       private JButton jButton1 = new JButton();
+       // Code for JCalendar
+       private JCalendar jCalendar1 = new JCalendar();
+       private JCalendar jCalendar2 = new JCalendar();
+       private Calendar calendarInicio = null;
+       private Calendar calendarFin = null;
+       private JButton jButton2 = new JButton();
+       private JLabel jLabel5 = new JLabel();
+
+       public IntroduceOffer2GUI(Vector<RuralHouse> v) {
+               try     {
+                       jbInit(v);
+               }
+               catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void jbInit(Vector<RuralHouse> v) throws Exception {
+               this.getContentPane().setLayout(null);
+               this.setSize(new Dimension(513, 433));
+               this.setTitle("Set availability");
+
+               jComboBox1 = new JComboBox(v);
+               jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
+               jLabel1.setText("List of houses:");
+               jLabel1.setBounds(new Rectangle(25, 30, 95, 20));
+               jLabel2.setText("First day :");
+               jLabel2.setBounds(new Rectangle(25, 75, 85, 25));
+               jTextField1.setBounds(new Rectangle(25, 265, 220, 25));
+               jTextField1.setEditable(false);
+               jLabel3.setText("Last day :");
+               jLabel3.setBounds(new Rectangle(260, 75, 75, 25));
+               jTextField2.setBounds(new Rectangle(260, 265, 220, 25));
+               jTextField2.setEditable(false);
+               jLabel4.setText("Price:");
+               jLabel4.setBounds(new Rectangle(260, 30, 75, 20));
+               jTextField3.setBounds(new Rectangle(350, 30, 115, 20));
+               jTextField3.setText("0");
+               jButton1.setText("Accept");
+               jButton1.setBounds(new Rectangle(100, 360, 130, 30));
+               jTextField3.addFocusListener(new FocusListener() {
+                       public void focusGained(FocusEvent e) {}
+                       public void focusLost(FocusEvent e) {
+                               jTextField3_focusLost();
+                       }
+               });
+               jButton1.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton1_actionPerformed(e);
+                       }
+               });
+               jButton2.setText("Cancel");
+               jButton2.setBounds(new Rectangle(270, 360, 130, 30));
+               jButton2.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton2_actionPerformed(e);
+                       }
+               });
+               jLabel5.setBounds(new Rectangle(100, 320, 300, 20));
+               jLabel5.setForeground(Color.red);
+               jLabel5.setSize(new Dimension(305, 20));
+               jCalendar1.setBounds(new Rectangle(25, 100, 220, 165));
+               jCalendar2.setBounds(new Rectangle(260, 100, 220, 165));
+
+               // 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());
+                                       jTextField1.setText(dateformat.format(calendarInicio.getTime()));
+                               }
+                               else if (propertychangeevent.getPropertyName().equals("calendar")) {
+                                       calendarInicio = (Calendar) propertychangeevent.getNewValue();
+                                       DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
+                                       jTextField1.setText(dateformat1.format(calendarInicio.getTime()));
+                                       jCalendar1.setCalendar(calendarInicio);
+                               }
+                       } 
+               });
+
+               this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() {
+                       public void propertyChange(PropertyChangeEvent propertychangeevent) {
+                               if (propertychangeevent.getPropertyName().equals("locale")) {
+                                       jCalendar2.setLocale((Locale) propertychangeevent.getNewValue());
+                                       DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar2.getLocale());
+                                       jTextField2.setText(dateformat.format(calendarFin.getTime()));
+                               }
+                               else if (propertychangeevent.getPropertyName().equals("calendar")) {
+                                       calendarFin = (Calendar) propertychangeevent.getNewValue();
+                                       DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar2.getLocale());
+                                       jTextField2.setText(dateformat1.format(calendarFin.getTime()));
+                                       jCalendar2.setCalendar(calendarFin);
+                               }
+                       } 
+               });
+
+               this.getContentPane().add(jCalendar2, null);
+               this.getContentPane().add(jCalendar1, null);
+               this.getContentPane().add(jLabel5, null);
+               this.getContentPane().add(jButton2, null);
+               this.getContentPane().add(jButton1, null);
+               this.getContentPane().add(jTextField3, null);
+               this.getContentPane().add(jLabel4, null);
+               this.getContentPane().add(jTextField2, null);
+               this.getContentPane().add(jLabel3, null);
+               this.getContentPane().add(jTextField1, null);
+               this.getContentPane().add(jLabel2, null);
+               this.getContentPane().add(jLabel1, null);
+               this.getContentPane().add(jComboBox1, null);
+       }
+
+       private void jButton1_actionPerformed(ActionEvent e) {
+               RuralHouse ruralHouse=((RuralHouse)jComboBox1.getSelectedItem());
+               Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime());
+               //Remove the hour:minute:second:ms from the date 
+               firstDay=Date.valueOf(firstDay.toString());
+               Date lastDay=new Date(jCalendar2.getCalendar().getTime().getTime());
+               //Remove the hour:minute:second:ms from the date 
+               lastDay=Date.valueOf(lastDay.toString());
+               //It could be to trigger an exception if the introduced string is not a number
+               float price= Float.parseFloat(jTextField3.getText());
+               try {
+                       //Obtain the business logic from a StartWindow class (local or remote)
+                       ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+
+                       facade.createOffer(ruralHouse, firstDay, lastDay, price); 
+
+                       this.setVisible(false);
+               }
+               catch (Exception e1) {
+                       e1.printStackTrace();
+               }
+       }
+       
+       private void jButton2_actionPerformed(ActionEvent e) {
+               this.setVisible(false);
+       }
+
+       private void jTextField3_focusLost() {
+               try {
+                       new Integer (jTextField3.getText());
+                       jLabel5.setText("");
+               }
+               catch (NumberFormatException ex) {
+                       jLabel5.setText("Error: Please introduce a number");
+               }
+       }
+}
\ No newline at end of file
diff --git a/ruralHouses/src/gui/IntroduceOfferGUI.java b/ruralHouses/src/gui/IntroduceOfferGUI.java
new file mode 100644 (file)
index 0000000..5d768e8
--- /dev/null
@@ -0,0 +1,90 @@
+package gui;
+
+import javax.swing.*;
+import java.awt.Rectangle;
+
+import java.util.Vector;
+
+import businessLogic.ApplicationFacadeInterface;
+import domain.Owner;
+import domain.RuralHouse;
+
+
+public class IntroduceOfferGUI extends JFrame {
+
+       private static final long serialVersionUID = 1L;
+       private JPanel jContentPane = null;
+       private JComboBox jComboBox = null;
+       private JButton jButton = null;
+
+       public IntroduceOfferGUI() {
+               super();
+               initialize();
+       }
+
+       private void initialize() {
+               this.setSize(449, 293);
+               this.setContentPane(getJContentPane());
+               this.setTitle("Choose owner");
+
+       }
+
+       private JPanel getJContentPane() {
+               if (jContentPane == null) {
+                       jContentPane = new JPanel();
+                       jContentPane.setLayout(null);
+                       jContentPane.add(getJComboBox(), null);
+                       jContentPane.add(getJButton(), null);
+               }
+               return jContentPane;
+       }
+
+       private JComboBox getJComboBox() {
+               if (jComboBox == null) {
+                       try {
+                               ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+                               Vector<Owner> owners=facade.getOwners();
+                               jComboBox = new JComboBox(owners);
+                               jComboBox.setBounds(new Rectangle(63, 38, 175, 44));
+                       }
+                       catch (Exception e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+               }
+               return jComboBox;
+       }
+
+       private JButton getJButton() {
+               if (jButton == null) {
+                       jButton = new JButton();
+                       jButton.setBounds(new Rectangle(113, 146, 95, 59));
+                       jButton.setText("Show houses");
+                       jButton.addActionListener(new java.awt.event.ActionListener() {
+                               public void actionPerformed(java.awt.event.ActionEvent e) {
+                                       Owner owner=(Owner)jComboBox.getSelectedItem();
+                                       System.out.println(owner.getUsername());
+                                       Vector<RuralHouse> houseList=null;
+                                       try {
+                                               //Obtain the business logic from a StartWindow class (local or remote)
+                                               ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+                                               houseList=facade.getRuralHouses(owner);
+
+                                       }
+                                       catch (Exception e1) {
+                                               e1.printStackTrace();
+                                       }
+                                       if (houseList.isEmpty()!=true) {
+                                               JFrame a = new IntroduceOffer2GUI(houseList);
+                                               a.setVisible(true);
+                                       }
+                                       else if (houseList.isEmpty()==true) {
+                                               System.out.print("Owner does not exist or has no registered houses ");
+                                       }               
+                               }
+                       });
+               }
+               return jButton;
+       }
+
+}  //  @jve:decl-index=0:visual-constraint="222,33"
diff --git a/ruralHouses/src/gui/SearchOffersGUI.java b/ruralHouses/src/gui/SearchOffersGUI.java
new file mode 100644 (file)
index 0000000..02472f3
--- /dev/null
@@ -0,0 +1,178 @@
+package gui;
+
+import businessLogic.ApplicationFacadeInterface;
+
+import com.toedter.calendar.JCalendar;
+
+import domain.Offer;
+import domain.RuralHouse;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+import java.beans.*;
+
+import java.sql.Date;
+import java.text.DateFormat;
+import java.util.*;
+
+public class SearchOffersGUI extends JFrame {
+
+       private static final long serialVersionUID = 1L;
+
+       private JLabel jLabel1 = new JLabel();
+       private JComboBox jComboBox1;
+       private JLabel jLabel2 = new JLabel();
+       private JTextField jTextField2 = new JTextField();
+       private JLabel jLabel3 = new JLabel();
+       private JTextField jTextField3 = new JTextField();
+       private JButton jButton1 = new JButton();
+       private JButton jButton2 = new JButton();
+       // Code for JCalendar
+       private JCalendar jCalendar1 = new JCalendar();
+       private Calendar myCalendar = null;
+       private JLabel jLabel4 = new JLabel();
+       private JTextArea jTextArea1 = new JTextArea();
+       private JScrollPane scrollPane = new JScrollPane();
+
+       public SearchOffersGUI() {
+               try {
+                       jbInit();
+               }
+               catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void jbInit() throws Exception {
+               ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+
+               Vector<RuralHouse> rhs=facade.getAllRuralHouses();
+               jComboBox1 = new JComboBox(rhs);
+
+               this.getContentPane().setLayout(null);
+               this.setSize(new Dimension(440, 548));
+               this.setTitle("Search available rural houses");
+               jLabel1.setText("Rural house:");
+               jComboBox1.setBounds(new Rectangle(10, 10, 115, 25));
+               jLabel1.setBounds(new Rectangle(40, 20, 105, 25));
+               jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
+               jLabel2.setText("First day:");
+               jLabel2.setBounds(new Rectangle(40, 55, 75, 25));
+               jTextField2.setBounds(new Rectangle(190, 210, 155, 25));
+               jTextField2.setEditable(false);
+               jLabel3.setText("Number of nights:");
+               jLabel3.setBounds(new Rectangle(40, 250, 115, 25));
+               jTextField3.setBounds(new Rectangle(190, 250, 155, 25));
+               jTextField3.setText("0");
+               jButton1.setText("Accept");
+               jButton1.setBounds(new Rectangle(55, 455, 130, 30));
+               jButton1.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton1_actionPerformed(e);
+                       }
+               });
+               jButton2.setText("Close");
+               jButton2.setBounds(new Rectangle(230, 455, 130, 30));
+
+               jTextField3.addFocusListener(new FocusListener() {
+                       public void focusGained(FocusEvent e) { }
+                       public void focusLost(FocusEvent e) {
+                               jTextField3_focusLost();
+                       }
+               });
+               jButton2.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton2_actionPerformed(e);
+                       }
+               });
+               jLabel4.setBounds(new Rectangle(55, 300, 305, 30));
+               jLabel4.setForeground(Color.red);
+               jTextArea1.setEditable(false);
+               jCalendar1.setBounds(new Rectangle(190, 60, 225, 150));
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 135));
+               jTextArea1.setText("");
+               scrollPane.getViewport().add(jTextArea1, null);
+
+               this.getContentPane().add(scrollPane, null);
+               this.getContentPane().add(jCalendar1, null);
+               this.getContentPane().add(jLabel4, null);
+               this.getContentPane().add(jButton2, null);
+               this.getContentPane().add(jButton1, null);
+               this.getContentPane().add(jTextField3, null);
+               this.getContentPane().add(jLabel3, null);
+               this.getContentPane().add(jTextField2, 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(myCalendar.getTime()));
+                               }
+                               else if (propertychangeevent.getPropertyName().equals("calendar")) {
+                                       myCalendar = (Calendar) propertychangeevent.getNewValue();
+                                       DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
+                                       jTextField2.setText(dateformat1.format(myCalendar.getTime()));
+                                       jCalendar1.setCalendar(myCalendar);
+                               }
+                       } 
+               });
+
+       }
+
+       private void jButton2_actionPerformed(ActionEvent e) {
+               this.setVisible(false);
+       }
+
+       private void jTextField3_focusLost() {
+               try {
+                       new Integer (jTextField3.getText());
+                       jLabel4.setText("");
+               }
+               catch (NumberFormatException ex) {
+                       jLabel4.setText("Error: Please introduce a number");
+               }
+       }
+
+       private void jButton1_actionPerformed(ActionEvent e) {          
+               // House object
+               RuralHouse rh=(RuralHouse)jComboBox1.getSelectedItem();
+               // First day
+               Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime());
+               //Remove the hour:minute:second:ms from the date 
+               firstDay=Date.valueOf(firstDay.toString());
+               final long diams=1000*60*60*24;
+               long nights= diams * Integer.parseInt(jTextField3.getText());
+               // Last day
+               Date lastDay= new Date((long)(firstDay.getTime()+nights));
+               jTextArea1.setText("");
+               try {
+                       ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+                       Vector<Offer> v=facade.getOffers(rh, firstDay, lastDay);
+
+                       Enumeration<Offer> en=v.elements();
+                       Offer of;
+                       while (en.hasMoreElements()) {
+                               of=en.nextElement();
+                               firstDay= new Date(of.getFirstDay().getTime());
+                               firstDay=Date.valueOf(firstDay.toString());
+                               lastDay= new Date(of.getLastDay().getTime());
+                               lastDay=Date.valueOf(lastDay.toString());
+                               jTextArea1.append("Offer "+Integer.toString(of.getOfferNumber())+":from:"+firstDay+" to:"+lastDay+"\n");                        
+                       }
+
+                       //} catch (RemoteException e1) {
+                       //                      e1.printStackTrace();
+
+               }
+               catch (Exception e1) {
+                       e1.printStackTrace();
+               }
+       }
+}
\ No newline at end of file
diff --git a/ruralHouses/src/gui/StartWindow.java b/ruralHouses/src/gui/StartWindow.java
new file mode 100644 (file)
index 0000000..b6afbf1
--- /dev/null
@@ -0,0 +1,163 @@
+package gui;
+
+import javax.swing.*;
+import java.awt.*;
+
+import businessLogic.FacadeImplementation;
+import businessLogic.ApplicationFacadeInterface;
+
+import java.rmi.*;
+import configuration.Config;
+
+public class StartWindow extends JFrame {
+       
+       public static boolean clientServer = false;
+
+       private static final long serialVersionUID = 1L;
+
+       private JPanel jContentPane = null;
+       private JButton bookHouseButton = null;
+       private JButton createOfferButton = null;
+       private JButton searchAvailabilityButton = null;
+       private JButton exitButton = null;
+
+       public static ApplicationFacadeInterface facadeInterface;
+       
+       public StartWindow() {
+               super();
+               initialize();
+               this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+       }
+       
+       public static ApplicationFacadeInterface getBusinessLogic(){
+               return facadeInterface;
+       }
+       
+       private void initialize() {
+               // this.setSize(271, 295);
+               this.setSize(350, 400);
+               this.setContentPane(getJContentPane());
+               this.setTitle("Use Cases");
+       }
+
+       private JPanel getJContentPane() {
+               if (jContentPane == null) {
+                       jContentPane = new JPanel();
+//                     jContentPane.setLayout(null);
+                       jContentPane.setLayout(new BoxLayout(jContentPane,
+                                       BoxLayout.Y_AXIS));
+                       jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
+                       jContentPane.add(getBookHouseButton());
+                       jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
+                       jContentPane.add(getSearchAvailabilityButton());
+                       jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
+                       jContentPane.add(getCreateOfferButton());
+                       jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
+                       jContentPane.add(getExitButton());
+                       jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
+               }
+               return jContentPane;
+       }
+
+       private JButton getBookHouseButton() {
+               if (bookHouseButton == null) {
+                       bookHouseButton = new JButton();
+                       bookHouseButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
+                       bookHouseButton.setText("Book rural house");
+                       bookHouseButton.setAlignmentX(Component.CENTER_ALIGNMENT);
+                       bookHouseButton.addActionListener(new java.awt.event.ActionListener() {
+                               public void actionPerformed(java.awt.event.ActionEvent e) {
+                                       JFrame a = new BookRuralHouseGUI();
+                                       a.setVisible(true);
+                               }
+                       });
+               }
+               return bookHouseButton;
+       }
+
+       private JButton getCreateOfferButton() {
+               if (createOfferButton == null) {
+                       createOfferButton = new JButton();
+                       createOfferButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
+                       createOfferButton.setText("Introduce new offer");
+                       createOfferButton.setAlignmentX(Component.CENTER_ALIGNMENT);
+                       createOfferButton.addActionListener(new java.awt.event.ActionListener() {
+                               public void actionPerformed(java.awt.event.ActionEvent e) {
+                                       JFrame a = new IntroduceOfferGUI();
+                                       a.setVisible(true);
+                               }
+                       });
+               }
+               return createOfferButton;
+       }
+       
+       private JButton getSearchAvailabilityButton() {
+               if (searchAvailabilityButton == null) {
+                       searchAvailabilityButton = new JButton();
+                       searchAvailabilityButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
+                       searchAvailabilityButton.setText("Search availability");
+                       searchAvailabilityButton.setAlignmentX(Component.CENTER_ALIGNMENT);
+                       searchAvailabilityButton.addActionListener(new java.awt.event.ActionListener() {
+                               public void actionPerformed(java.awt.event.ActionEvent e) {
+                                       JFrame a = new SearchOffersGUI();
+                                       a.setVisible(true);
+                               }
+                       });
+               }
+               return searchAvailabilityButton;
+       }
+
+       private JButton getExitButton() {
+               if (exitButton == null) {
+                       exitButton = new JButton();
+                       exitButton.setText("Exit");
+                       exitButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
+                       exitButton.setAlignmentX(Component.CENTER_ALIGNMENT);
+                       exitButton.addActionListener(new java.awt.event.ActionListener() {
+                               public void actionPerformed(java.awt.event.ActionEvent e) {
+                                       //JFrame a = new QueryAvailabilityWindow();
+                                       ApplicationFacadeInterface facade=StartWindow.facadeInterface;
+                                       try {
+                                               facade.close();
+                                               setVisible(false);
+                                       }
+                                       catch (RemoteException e1) {
+                                               // TODO Auto-generated catch block
+                                               e1.printStackTrace();
+                                       }                                       
+                               }
+                       });
+               }
+               return exitButton;
+       }
+       
+       public static void main(String[] args) {                
+               try {
+                       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+
+                       Config c=Config.getInstance();
+                       if (!clientServer)
+                               facadeInterface=new FacadeImplementation();
+                       else {
+                               final String serverRMI = c.getServerRMI();
+                               // Remote service name
+                               String serviceName = "/"+c.getServiceRMI();
+                               //System.setSecurityManager(new RMISecurityManager());
+                               // RMI server port number
+                               int portNumber = Integer.parseInt(c.getPortRMI());
+                               // RMI server host IP IP 
+                               facadeInterface = (ApplicationFacadeInterface) Naming.lookup("rmi://"
+                                       + serverRMI + ":" + portNumber + serviceName);
+                       } 
+
+               }
+               catch (Exception e) {
+                       //System.out.println(e.toString());
+                       e.printStackTrace();
+               }
+               int x=0;
+               JFrame a = new StartWindow();
+               a.setVisible(true);
+       }
+
+} //@jve:decl-index=0:visual-constraint="0,0"