Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code
authorcamjan <jcampos004@ikasle.ehu.es>
Wed, 20 May 2015 16:46:45 +0000 (18:46 +0200)
committercamjan <jcampos004@ikasle.ehu.es>
Wed, 20 May 2015 16:46:45 +0000 (18:46 +0200)
55 files changed:
ruralHouses client/src/common/BookingInterface.java
ruralHouses client/src/domain/Account.java
ruralHouses client/src/domain/Administrator.java
ruralHouses client/src/domain/Booking.java
ruralHouses client/src/domain/Districs.java
ruralHouses client/src/domain/HouseFeatures.java
ruralHouses client/src/domain/Owner.java
ruralHouses client/src/domain/RuralHouse.java
ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java
ruralHouses client/src/gui/DeleteOwnerGUI.java
ruralHouses client/src/gui/HouseFeaturesGUI.java
ruralHouses client/src/gui/ModifyOfferGUI.java
ruralHouses client/src/gui/listOfOffers.java
ruralHouses/src/businessLogic/AdminManager.java
ruralHouses/src/businessLogic/BookingManager.java
ruralHouses/src/businessLogic/HouseManager.java
ruralHouses/src/businessLogic/OwnerManager.java [deleted file]
ruralHouses/src/common/BookingInterface.java
ruralHouses/src/common/HouseInterface.java
ruralHouses/src/common/OwnerInterface.java [deleted file]
ruralHouses/src/configuration/___IntNames.java [new file with mode: 0644]
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/dataAccess/DB4oManagerServer.java [deleted file]
ruralHouses/src/domain/Account.java
ruralHouses/src/domain/Administrator.java
ruralHouses/src/domain/Booking.java
ruralHouses/src/domain/Client.java
ruralHouses/src/domain/HouseFeatures.java
ruralHouses/src/domain/Owner.java
ruralHouses/src/domain/RuralHouse.java
ruralHouses/src/gui/.DS_Store [new file with mode: 0644]
ruralHouses/src/gui/AddOffersGUI.java [new file with mode: 0644]
ruralHouses/src/gui/AdminMenuGUI.java [new file with mode: 0644]
ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java [new file with mode: 0644]
ruralHouses/src/gui/DeleteOfferGUI.java [new file with mode: 0644]
ruralHouses/src/gui/DeleteOwnerGUI.java [new file with mode: 0644]
ruralHouses/src/gui/HouseFeaturesGUI.java [new file with mode: 0644]
ruralHouses/src/gui/HousesRelatedOwnerGUI.java [new file with mode: 0644]
ruralHouses/src/gui/LoginGUI.java [new file with mode: 0644]
ruralHouses/src/gui/ModifyHouseGUI.java [new file with mode: 0644]
ruralHouses/src/gui/ModifyOfferGUI.java [new file with mode: 0644]
ruralHouses/src/gui/OffersRelatedOwnerGUI.java [new file with mode: 0644]
ruralHouses/src/gui/OwnerMenuGUI.java [new file with mode: 0644]
ruralHouses/src/gui/OwnerRegistrationGUI.java [new file with mode: 0644]
ruralHouses/src/gui/QueryAvailabilityGUI2.java [new file with mode: 0644]
ruralHouses/src/gui/RequestDeleteHouseGUI.java [new file with mode: 0644]
ruralHouses/src/gui/RequestNewHouseGUI.java [new file with mode: 0644]
ruralHouses/src/gui/StartWindow.java [new file with mode: 0644]
ruralHouses/src/gui/listOfAdditionRequestsGUI.java [new file with mode: 0644]
ruralHouses/src/gui/listOfBookingRequestsGUI.java [new file with mode: 0644]
ruralHouses/src/gui/listOfHousesGUI.java [new file with mode: 0644]
ruralHouses/src/gui/listOfOffers.java [new file with mode: 0644]
ruralHouses/src/gui/listOfOwnerAddittionRequests.java [new file with mode: 0644]
ruralHouses/src/gui/listOfRemovalRequestsGUI.java [new file with mode: 0644]
ruralHouses/src/launcher/RMILauncher.java

index 8780f2f..598a537 100644 (file)
@@ -13,7 +13,6 @@ import exceptions.OfferCanNotBeBooked;
 public interface BookingInterface extends Remote {
 
 
-       public int getNumber() throws RemoteException;
 
 
        public void denyBooking(Booking b) throws RemoteException;
index 19fc1f5..03b334e 100644 (file)
@@ -4,7 +4,6 @@ import java.io.Serializable;
 import java.util.Arrays;
 
 
-
 public class Account implements Serializable {
 
        /**
@@ -22,8 +21,9 @@ public class Account implements Serializable {
        private boolean admin = false;
 
        
-       
 
+
+       
        public byte[] getUsername() {
                return username;
        }
@@ -40,6 +40,7 @@ public class Account implements Serializable {
                return admin;
        }
 
+       
        public void setAdmin(boolean admin) {
                this.admin = admin;
        }
@@ -62,8 +63,6 @@ public class Account implements Serializable {
                if (getClass() != obj.getClass())
                        return false;
                Account other = (Account) obj;
-               if (!Arrays.equals(password, other.password))
-                       return false;
                if (!Arrays.equals(username, other.username))
                        return false;
                return true;
index 845d089..d1ea781 100644 (file)
@@ -12,6 +12,7 @@ public class Administrator implements Serializable {
         */
        private static final long serialVersionUID = 1L;
 
+       private static Administrator admin = null;
        private static LinkedList<RuralHouse> addRequest;
        private static LinkedList<RuralHouse> removeRequest;
        private static LinkedList<Account> newOwnerRequest;
@@ -23,16 +24,7 @@ public class Administrator implements Serializable {
                newOwnerRequest = new LinkedList<Account>();
        }
 
-       public static Administrator getInstance() {
-               return null;
-
-
-       }
-
-       public static void saveInstance() {
-
-       }
-
+       
        public LinkedList<RuralHouse> getAddRequest() {
                return addRequest;
        }
index 13bc007..68575c6 100644 (file)
@@ -15,9 +15,7 @@ public class Booking implements Serializable  {
        private Offer offer;
        
        
-       public Booking() {
-       }
-
+       
        public Booking(int bN , Offer offer,Client client) {
                
                this.bookingNumber = bN;
@@ -27,12 +25,6 @@ public class Booking implements Serializable  {
                this.bookingDate= new java.util.Date(System.currentTimeMillis());
        }
        
-       public void imprimete(){
-               System.out.println(bookingNumber);
-               System.out.println(bookingDate);
-               System.out.println(client.toString());
-               System.out.println(offer);      
-       }
 
        public int getBookNumber() {
                return this.bookingNumber;
@@ -46,10 +38,7 @@ public class Booking implements Serializable  {
                return this.offer;
        }
 
-       public float getPrice() {
-               return this.offer.getPrice();
-       }
-       
+
        public void setBookDate(Date bookDate) {
                this.bookingDate = bookDate;
        }
@@ -57,7 +46,7 @@ public class Booking implements Serializable  {
        public Date getBookDate() {
                return this.bookingDate;
        }
-
+       
        public Client getClient() {
                return client;
        }
index db62454..2866692 100644 (file)
@@ -7,12 +7,12 @@ public enum Districs implements Serializable {
        /**
         * 
         */
-       BEA("Beatriz"), GUA("Guazate"), VEG("Vegas"), FAR("Farallón"), CED("Cedro"), MOT(
-                       "Monte LLano"), RIN("Rincón"), PUE("Pueblo"), QUA("Quebrada Arriba"), QEB(
-                       "Quebrada Abajo"), TOI("Toita"), MAB("Matón Abajo"), MAA(
-                       "Matón Arriba"), PIE("Piedras"), PAV("Pasto Viejo"), PEA(
+       BEA("Beatriz"), GUA("Guazate"), VEG("Vegas"), FAR("Farallón"), CED("Cedro"), MOT(
+                       "Monte LLano"), RIN("Rincón"), PUE("Pueblo"), QUA("Quebrada Arriba"), QEB(
+                       "Quebrada Abajo"), TOI("Toita"), MAB("Matón Abajo"), MAA(
+                       "Matón Arriba"), PIE("Piedras"), PAV("Pasto Viejo"), PEA(
                        "PedroAvila"), SUM("Sumido"), LAP("Lapa"), CER("Cercadillo"), JAJ(
-                       "JájomeAlto"), CUL("CulebrasAbajo");
+                       "JójomeAlto"), CUL("CulebrasAbajo");
                        
        private static final long serialVersionUID = 1L; 
 
index e79a446..52502cb 100644 (file)
@@ -17,51 +17,40 @@ public class HouseFeatures implements Serializable {
        public HouseFeatures(int nRooms, int nKitchens, int nBaths, int nLivings,
                        int nParkings) {
                super();
-               this.setnRooms(nRooms);
-               this.setnKitchens(nKitchens);
-               this.setnBaths(nBaths);
-               this.setnLivings(nLivings);
-               this.setnParkings(nParkings);
+               this.nRooms = nRooms;
+               this.nKitchens = nKitchens;
+               this.nBaths = nBaths;
+               this.nLivings = nLivings;
+               this.nParkings = nParkings;
        }
 
        public int getnRooms() {
                return nRooms;
        }
 
-       public void setnRooms(int nRooms) {
-               this.nRooms = nRooms;
-       }
+
 
        public int getnKitchens() {
                return nKitchens;
        }
 
-       public void setnKitchens(int nKitchens) {
-               this.nKitchens = nKitchens;
-       }
+
 
        public int getnBaths() {
                return nBaths;
        }
 
-       public void setnBaths(int nBaths) {
-               this.nBaths = nBaths;
-       }
+
 
        public int getnLivings() {
                return nLivings;
        }
 
-       public void setnLivings(int nLivings) {
-               this.nLivings = nLivings;
-       }
+
 
        public int getnParkings() {
                return nParkings;
        }
 
-       public void setnParkings(int nParkings) {
-               this.nParkings = nParkings;
-       }
 
 }
index 0c4fa4b..6bf0f97 100644 (file)
@@ -70,14 +70,6 @@ public class Owner implements Serializable {
                this.mailAccount = mailAccount;
        }
        
-       public Vector<Offer> getAllOffers (){
-               Vector<Offer> offers = new Vector<Offer>();
-               for(RuralHouse rh: this.ruralHouses){
-                       for(Offer of : rh.getAllOffers()){
-                       offers.add(of);
-                       }
-               }
-               return offers;
-       }
+       
 
 }
\ No newline at end of file
index d988b39..0c7fbb7 100644 (file)
@@ -14,8 +14,8 @@ public class RuralHouse implements Serializable {
        private Owner owner;
        private String district;
        private HouseFeatures features;
-       private Vector<Offer> offers;
-       private boolean isAccepted;
+       public Vector<Offer> offers;
+
 
        public RuralHouse() {
                super();
@@ -99,59 +99,7 @@ public class RuralHouse implements Serializable {
                return true;
        }
 
-       /**
-        * This method obtains available offers for a concrete house in a certain
-        * period
-        * 
-        * @param houseName
-        *            , 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.isBooked()))
-                               availableOffers.add(offer);
-               }
-               return availableOffers;
-       }
-
-       public Vector<Offer> getAllOffers() {
 
-               return this.offers;
-       }
-
-       /**
-        * 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.isBooked()))
-                               return offer;
-               }
-               return null;
-       }
 
        public Offer overlapsWith(Date firstDay, Date lastDay) {
 
@@ -166,13 +114,12 @@ public class RuralHouse implements Serializable {
                return null;
 
        }
+       
 
-       public boolean isAccepted() {
-               return isAccepted;
-       }
+       public Vector<Offer> getAllOffers() {
 
-       public void setAccepted(boolean isAccepted) {
-               this.isAccepted = isAccepted;
+               return this.offers;
        }
 
+
 }
index a313f3f..21f9ab6 100644 (file)
@@ -79,10 +79,11 @@ public class BookRuralHouseConfirmationWindow extends JFrame {
     jTextField3.setBounds(new Rectangle(180, 140, 115, 25));
     jTextField3.setEditable(false);
 
-    jTextField3.setText(Float.toString(book.getPrice()) + "\80");
+    jTextField3.setText(Float.toString(book.getOffer().getPrice()) + " \80");
     jTextField4.setBounds(new Rectangle(180, 175, 115, 25));
     jTextField4.setEditable(false);
-    jTextField4.setText(Float.toString(book.getPrice()*(float)0.2) + "\80");
+    jTextField4.setText(Float.toString(book.getOffer().getPrice()*(float)0.2) + " \80");
+
     this.getContentPane().add(jTextField4, null);
     this.getContentPane().add(jTextField3, null);
     this.getContentPane().add(jLabel5, null);
index 19d5513..982e022 100644 (file)
@@ -77,7 +77,7 @@ public class DeleteOwnerGUI extends JFrame {
                scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
                scrollPane.setBounds(23, 113, 536, 271);
                contentPane.add(scrollPane);
-               JLabel feedback = new JLabel("");
+               final JLabel feedback = new JLabel("");
                feedback.setBounds(134, 447, 307, 14);
                contentPane.add(feedback);
                JButton btnNewButton = new JButton("Delete from the system");
index de173a5..39d0bc9 100644 (file)
@@ -235,6 +235,7 @@ public class HouseFeaturesGUI extends JFrame {
                                row = table.getSelectedRow();
                        }
                });
+               
                Enumeration<Offer> rhs = rh.getAllOffers().elements();
                while (rhs.hasMoreElements()) {
                        Offer of = rhs.nextElement();
index 14dd98d..3e7a6c6 100644 (file)
@@ -89,7 +89,9 @@ public class ModifyOfferGUI extends JFrame {
                        Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
                } catch (RemoteException e1) {
                        e1.printStackTrace();
-               }               
+               }
+
+
                jComboBox1 = new JComboBox<RuralHouse>(Hlist);
 
                comboBox_o = new JComboBox<Offer>(
index 4651ff8..7d61def 100644 (file)
@@ -20,6 +20,7 @@ import javax.swing.table.DefaultTableModel;
 
 import domain.Offer;
 import domain.Owner;
+import domain.RuralHouse;
 
 public class listOfOffers extends JFrame {
 
@@ -54,8 +55,10 @@ public class listOfOffers extends JFrame {
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
                contentPane.setLayout(null);
-
-               this.offers = this.owner.getAllOffers();
+               this.offers = new Vector<Offer>();
+               for (RuralHouse rh: this.owner.getRuralHouses()){
+                       this.offers.addAll(rh.getAllOffers());
+               }
                JLabel lblNewLabel = new JLabel();
                lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
                lblNewLabel.setBounds(23, 41, 536, 33);
index 11d26b0..a7e3a2a 100644 (file)
@@ -76,8 +76,6 @@ public class AdminManager extends UnicastRemoteObject implements AdminInterface
 
        }
        
-
-       
        public boolean addAccountRequest(String usr,
                        String pss, Owner ow) throws RemoteException {
                
index 519dc54..356d3ba 100644 (file)
@@ -25,10 +25,8 @@ public final class BookingManager extends UnicastRemoteObject implements Booking
         * 
         */
        private static final long serialVersionUID = 1L;
-       private int bookingNumber = 0;
        dataAccess.DB4oManager dbMngr;
 
-       private static BookingManager theBookingManager;
 
        public BookingManager() throws RemoteException {
                super();
@@ -39,39 +37,7 @@ public final class BookingManager extends UnicastRemoteObject implements Booking
                }
        }
 
-       /**
-        * This method returns the next Booking number
-        * 
-        * @return the book number
-        */
-
-    public int getNumber() throws RemoteException{
-               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
-        * @throws RemoteException 
-        */
-
-       public BookingManager getInstance() throws RemoteException  {
-               ObjectContainer db=DB4oManager.getContainer();
-           BookingManager b = new BookingManager();
-           ObjectSet<BookingManager> result = db.queryByExample(b);
-           if (!result.hasNext()){
-               theBookingManager = new BookingManager();
-               db.store(theBookingManager);
-               db.commit();
-           } else theBookingManager=(BookingManager)result.next();
-               return theBookingManager;
-       }
 
        public void denyBooking(Booking b) throws RemoteException{
                                this.dbMngr.removeBooking(b);
index fb3e664..0233811 100644 (file)
@@ -60,24 +60,5 @@ public class HouseManager extends UnicastRemoteObject implements HouseInterface
                return this.dbMngr.getRuralHouses( ow, name ,town, nBed, nKit, nBath, nPark, nLiv);
        }
 
-       @Override
-       public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
-                       Exception {
-               return dbMngr.getAllRuralHouses();
-       }
-
-
-
-       // For future implementation
-       // @Override
-       // public void modifyHouse(int houseName, Owner owner, String description,
-       // String town, int nRooms, int nKitchens, int nBaths, int nLivings,
-       // int nParkings) {
-       // // TODO Auto-generated method stub
-       //
-       // }
-
-       // Maybe returning the offer is not necessary. Depends on GUI
-       // implementation.
 
 }
diff --git a/ruralHouses/src/businessLogic/OwnerManager.java b/ruralHouses/src/businessLogic/OwnerManager.java
deleted file mode 100644 (file)
index 9042bd2..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package businessLogic;
-
-import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.Vector;
-
-import common.OwnerInterface;
-
-import dataAccess.DB4oManager;
-import domain.Owner;
-
-public class OwnerManager extends UnicastRemoteObject implements OwnerInterface {
-       /**
-        * 
-        */
-       private static final long serialVersionUID = 1L;
-       DB4oManager dbMngr;
-
-       public OwnerManager() throws RemoteException {
-               super();
-               try {
-                       dbMngr = DB4oManager.getInstance();
-               } catch (Exception e) {
-
-                       e.printStackTrace();
-               }
-       }
-
-       /**
-        * This method existing  owners 
-        * 
-        */
-       public Vector<Owner> getOwners() throws RemoteException,
-                       Exception {
-               
-               
-               return dbMngr.getOwners();
-       }
-
-       
-}
index 8780f2f..598a537 100644 (file)
@@ -13,7 +13,6 @@ import exceptions.OfferCanNotBeBooked;
 public interface BookingInterface extends Remote {
 
 
-       public int getNumber() throws RemoteException;
 
 
        public void denyBooking(Booking b) throws RemoteException;
index e256ff7..9699e05 100644 (file)
@@ -23,8 +23,7 @@ public interface HouseInterface extends Remote {
         * 
         * @return a Set of rural houses
         */
-       public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
-       Exception, RemoteException;
+
 
        public boolean registerNewHouse(RuralHouse rh)throws RemoteException;
        
diff --git a/ruralHouses/src/common/OwnerInterface.java b/ruralHouses/src/common/OwnerInterface.java
deleted file mode 100644 (file)
index c96e013..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-package common;
-
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-import java.util.Vector;
-
-import domain.Owner;
-
-public interface OwnerInterface extends Remote {
-
-
-       public Vector<Owner> getOwners() throws RemoteException,
-       Exception;
-       
-}
diff --git a/ruralHouses/src/configuration/___IntNames.java b/ruralHouses/src/configuration/___IntNames.java
new file mode 100644 (file)
index 0000000..462ff65
--- /dev/null
@@ -0,0 +1,13 @@
+package configuration;
+
+public class ___IntNames {
+       private static String serverPath = "rmi://localhost:9999//";
+       public static String AdminManager = serverPath+"AdM";
+       public static String BookingManager = serverPath+"BoM";
+       public static String HouseManager = serverPath+"HoM";
+       public static String LoginManager = serverPath+"LoM";
+       public static String OfferManager = serverPath+"OfM";
+       public static String OwnerManager = serverPath+"OwM";
+       public static String AccountManager = serverPath+"AcM";
+       
+}
index a52ba8c..d17876f 100644 (file)
@@ -328,12 +328,12 @@ public class DB4oManager {
                                openSDB();
 
                        RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(), null,
-                                       ruralHouse.getDescription(), ruralHouse.getDistrict(), null);
+                                       null, null, null);
                        ObjectSet<RuralHouse> result = db.queryByExample(proto);
                        RuralHouse rh = (RuralHouse) result.next();
 
                        Offer offer;
-                       offer = rh.findOffer(firstDate, lastDate);
+                       offer = (Offer)db.queryByExample(new Offer(0, rh, firstDate, lastDate, 0)).get(0);
 
                        if (offer != null) {
                                offer.createBooking(theDB4oManagerAux.bookingNumber++, cl);
@@ -380,22 +380,7 @@ public class DB4oManager {
                }
        }
 
-       public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
-                       Exception {
 
-               if (c.isDatabaseLocal() == false)
-                       openSDB();
-               else
-                       openDB();
-
-               try {
-                       RuralHouse proto = new RuralHouse(null, null, null, null, null);
-                       ObjectSet<RuralHouse> result = db.queryByExample(proto);
-                       return new Vector<RuralHouse>(result);
-               } finally {
-                       db.close();
-               }
-       }
 
        public boolean existsOverlappingOffer(RuralHouse rh, Date firstDay,
                        Date lastDay) throws RemoteException, OverlappingOfferExists {
@@ -419,10 +404,6 @@ public class DB4oManager {
                }
        }
 
-       public static ObjectContainer getContainer() {
-               return db;
-       }
-
        public void close() {
                db.close();
                System.out.println("DataBase closed");
@@ -567,7 +548,7 @@ public class DB4oManager {
                        openDB();
 
                try {
-                       ObjectSet<Account> result = db.queryByExample(new Account(own));
+                       ObjectSet<Account> result = db.queryByExample(new Account(null,null,own));
                        if (!result.isEmpty()) {
                                db.delete(result.get(0));
                                db.commit();
diff --git a/ruralHouses/src/dataAccess/DB4oManagerServer.java b/ruralHouses/src/dataAccess/DB4oManagerServer.java
deleted file mode 100644 (file)
index 106cfff..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-package dataAccess;
-
-import java.awt.BorderLayout;
-import java.awt.FlowLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.File;
-
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JPanel;
-import javax.swing.JTextArea;
-import javax.swing.border.EmptyBorder;
-
-import com.db4o.ObjectServer;
-import com.db4o.cs.Db4oClientServer;
-import com.db4o.cs.config.ServerConfiguration;
-
-import configuration.ConfigXML;
-import domain.Owner;
-
-public class DB4oManagerServer extends JDialog {
-
-       /**
-        * 
-        */
-       private static final long serialVersionUID = 1L;
-       private final JPanel contentPanel = new JPanel();
-       JTextArea textArea;
-       ObjectServer server;
-       private ServerConfiguration configurationCS;
-
-       /**
-        * Launch the application.
-        */
-       public static void main(String[] args) {
-               try {
-                       DB4oManagerServer dialog = new DB4oManagerServer();
-                       dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-                       dialog.setVisible(true);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
-       /**
-        * Create the dialog.
-        */
-       public DB4oManagerServer() {
-               setTitle("DB4oManagerServer: running the database server");
-               setBounds(100, 100, 486, 180);
-               getContentPane().setLayout(new BorderLayout());
-               contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
-               getContentPane().add(contentPanel, BorderLayout.CENTER);
-               contentPanel.setLayout(new BorderLayout(0, 0));
-               {
-                       textArea = new JTextArea();
-                       contentPanel.add(textArea);
-               }
-               {
-                       JPanel buttonPane = new JPanel();
-                       buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
-                       getContentPane().add(buttonPane, BorderLayout.SOUTH);
-                       {
-                               JButton okButton = new JButton("OK");
-                               okButton.addActionListener(new ActionListener() {
-                                       public void actionPerformed(ActionEvent e) {
-                                               textArea.append("\n\n\nClosing the database... ");
-                                           try {
-                                                       server.close();
-                                               } catch (Exception e1) {
-                                               }
-                                               System.exit(1);
-                                       }
-                               });
-                               okButton.setActionCommand("OK");
-                               buttonPane.add(okButton);
-                               getRootPane().setDefaultButton(okButton);
-                       }
-                       {
-                               JButton cancelButton = new JButton("Cancel");
-                               cancelButton.setActionCommand("Cancel");
-                               buttonPane.add(cancelButton);
-                       }
-               }
-               
-               ConfigXML c=ConfigXML.getInstance();
-               
-               
-               try{
-
-                       if (c.getDataBaseOpenMode().equals("initialize")) new File(c.getDb4oFilename()).delete();
-                       
-                       configurationCS = Db4oClientServer.newServerConfiguration();
-                       configurationCS.common().activationDepth(c.getActivationDepth());
-                       configurationCS.common().updateDepth(c.getUpdateDepth());
-                       configurationCS.common().objectClass(Owner.class).cascadeOnDelete(true);
-
-                       server = Db4oClientServer.openServer(configurationCS,
-                                                                                                c.getDb4oFilename(),c.getDatabasePort());
-                       
-                       textArea.append("\nConnection to the database '"+c.getDb4oFilename()+"' opened in port "+c.getDatabasePort());
-       
-                   server.grantAccess(c.getUser(),c.getPassword());
-
-                   textArea.append("\nAccess granted to: "+c.getUser());
-
-
-
-                       textArea.append("\nPress button to exit this database server... ");
-                       
-               } catch (Exception e) {
-                       textArea.append("Something has happened in DB4oManagerServer: "+e.toString());
-
-               }
-       }
-}
-       
index 08e841c..7fb472c 100644 (file)
@@ -2,9 +2,9 @@ package domain;
 
 import java.io.Serializable;
 import java.util.Arrays;
-
 import businessLogic.SecurityManager;
 
+
 public class Account implements Serializable {
 
        /**
@@ -21,20 +21,12 @@ public class Account implements Serializable {
        private Owner owner;
        private boolean admin = false;
 
-       
        public Account(byte[] usr){
                this.username = usr;
                this.salt =null;
                this.password = null;
                this.owner = null;
                
-       }
-       public Account(Owner own){
-               this.username = null;
-               this.salt =null;
-               this.password = null;
-               this.owner = own;
-               
        }
        public Account(String usr, String pass, boolean isAdmin) {
                this.username = SecurityManager.getInstance().calculateHash(usr);
@@ -55,7 +47,9 @@ public class Account implements Serializable {
 
        }
 
+
        
+
        public byte[] getUsername() {
                return username;
        }
index 8244f09..eb42f26 100644 (file)
@@ -55,6 +55,7 @@ public class Administrator implements Serializable {
                }
        }
 
+       
        public LinkedList<RuralHouse> getAddRequest() {
                return addRequest;
        }
index 60cfd2f..4b68a70 100644 (file)
@@ -3,7 +3,7 @@ package domain;
 import java.io.Serializable;
 import java.util.Date;
 
-public class Booking implements Serializable {
+public class Booking implements Serializable  {
 
        /**
         * 
@@ -13,30 +13,25 @@ public class Booking implements Serializable {
        private Date bookingDate;
        private Client client;
        private Offer offer;
-
-       public Booking(int bN, Offer offer, Client client, Date date) {
+       
+       
+       
+       public Booking(int bN , Offer offer,Client client) {
+               
                this.bookingNumber = bN;
                this.offer = offer;
-               this.client = client;
-               // Booking date is assigned to actual date
-               this.bookingDate = date;
+               this.client=client;
+               //Booking date is assigned to actual date
+               this.bookingDate= new java.util.Date(System.currentTimeMillis());
        }
+       
 
-       public Booking(int bN, Offer offer, Client client) {
-
+       public Booking(int bN , Offer offer,Client client, Date bookDate) {
                this.bookingNumber = bN;
                this.offer = offer;
-               this.client = client;
-               // Booking date is assigned to actual date
-               this.bookingDate = new java.util.Date(System.currentTimeMillis());
-       }
+               this.client=client;
+               this.bookingDate= bookDate;     }
 
-       public void imprimete() {
-               System.out.println(bookingNumber);
-               System.out.println(bookingDate);
-               System.out.println(client.toString());
-               System.out.println(offer);
-       }
 
        public int getBookNumber() {
                return this.bookingNumber;
@@ -50,9 +45,6 @@ public class Booking implements Serializable {
                return this.offer;
        }
 
-       public float getPrice() {
-               return this.offer.getPrice();
-       }
 
        public void setBookDate(Date bookDate) {
                this.bookingDate = bookDate;
@@ -61,7 +53,7 @@ public class Booking implements Serializable {
        public Date getBookDate() {
                return this.bookingDate;
        }
-
+       
        public Client getClient() {
                return client;
        }
@@ -69,5 +61,5 @@ public class Booking implements Serializable {
        public void setClient(Client client) {
                this.client = client;
        }
-
+       
 }
\ No newline at end of file
index 28730df..a4c0baf 100644 (file)
@@ -2,7 +2,7 @@ package domain;
 
 import java.io.Serializable;
 
-public class Client implements Serializable{
+public class Client  implements Serializable{
 
        /**
         * 
index e79a446..52502cb 100644 (file)
@@ -17,51 +17,40 @@ public class HouseFeatures implements Serializable {
        public HouseFeatures(int nRooms, int nKitchens, int nBaths, int nLivings,
                        int nParkings) {
                super();
-               this.setnRooms(nRooms);
-               this.setnKitchens(nKitchens);
-               this.setnBaths(nBaths);
-               this.setnLivings(nLivings);
-               this.setnParkings(nParkings);
+               this.nRooms = nRooms;
+               this.nKitchens = nKitchens;
+               this.nBaths = nBaths;
+               this.nLivings = nLivings;
+               this.nParkings = nParkings;
        }
 
        public int getnRooms() {
                return nRooms;
        }
 
-       public void setnRooms(int nRooms) {
-               this.nRooms = nRooms;
-       }
+
 
        public int getnKitchens() {
                return nKitchens;
        }
 
-       public void setnKitchens(int nKitchens) {
-               this.nKitchens = nKitchens;
-       }
+
 
        public int getnBaths() {
                return nBaths;
        }
 
-       public void setnBaths(int nBaths) {
-               this.nBaths = nBaths;
-       }
+
 
        public int getnLivings() {
                return nLivings;
        }
 
-       public void setnLivings(int nLivings) {
-               this.nLivings = nLivings;
-       }
+
 
        public int getnParkings() {
                return nParkings;
        }
 
-       public void setnParkings(int nParkings) {
-               this.nParkings = nParkings;
-       }
 
 }
index eb436f9..6bf0f97 100644 (file)
@@ -14,10 +14,6 @@ public class Owner implements Serializable {
        private String mailAccount = "";
        private Vector<RuralHouse> ruralHouses;
 
-//     public Owner(String name) {
-//             this.name = name;
-//             ruralHouses = new hVector<RuralHouse>();
-//     }
 
        public Owner(String name, String bankAccount,String mail) {
                this.bankAccount = bankAccount;
index 529f691..0c7fbb7 100644 (file)
@@ -14,8 +14,7 @@ public class RuralHouse implements Serializable {
        private Owner owner;
        private String district;
        private HouseFeatures features;
-       private Vector<Offer> offers;
-       private boolean isAccepted;
+       public Vector<Offer> offers;
 
 
        public RuralHouse() {
@@ -100,59 +99,7 @@ public class RuralHouse implements Serializable {
                return true;
        }
 
-       /**
-        * This method obtains available offers for a concrete house in a certain
-        * period
-        * 
-        * @param houseName
-        *            , 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.isBooked()))
-                               availableOffers.add(offer);
-               }
-               return availableOffers;
-       }
 
-       public Vector<Offer> getAllOffers() {
-
-               return this.offers;
-       }
-
-       /**
-        * 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.isBooked()))
-                               return offer;
-               }
-               return null;
-       }
 
        public Offer overlapsWith(Date firstDay, Date lastDay) {
 
@@ -167,13 +114,12 @@ public class RuralHouse implements Serializable {
                return null;
 
        }
+       
 
-       public boolean isAccepted() {
-               return isAccepted;
-       }
+       public Vector<Offer> getAllOffers() {
 
-       public void setAccepted(boolean isAccepted) {
-               this.isAccepted = isAccepted;
+               return this.offers;
        }
 
+
 }
diff --git a/ruralHouses/src/gui/.DS_Store b/ruralHouses/src/gui/.DS_Store
new file mode 100644 (file)
index 0000000..5008ddf
Binary files /dev/null and b/ruralHouses/src/gui/.DS_Store differ
diff --git a/ruralHouses/src/gui/AddOffersGUI.java b/ruralHouses/src/gui/AddOffersGUI.java
new file mode 100644 (file)
index 0000000..e8b3df6
--- /dev/null
@@ -0,0 +1,255 @@
+package gui;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.rmi.Naming;
+import java.sql.Date;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+
+import com.toedter.calendar.JCalendar;
+import common.OfferInterface;
+
+import configuration.___IntNames;
+import domain.RuralHouse;
+import exceptions.BadDates;
+import exceptions.OverlappingOfferExists;
+
+
+
+public class AddOffersGUI extends JFrame  {
+private static final long serialVersionUID = 1L;
+
+       
+  private JComboBox<RuralHouse> 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();
+  private final JLabel lblNewLabel = new JLabel("");
+  
+
+  public AddOffersGUI(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<RuralHouse>(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);
+    lblNewLabel.setBounds(115, 301, 298, 38);
+    
+    getContentPane().add(lblNewLabel);
+  }
+
+  private void jButton1_actionPerformed(ActionEvent e)
+  {
+               RuralHouse ruralHouse=((RuralHouse)jComboBox1.getSelectedItem());
+
+               // The next instruction creates a java.sql.Date object from the date selected in the JCalendar object
+               Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime());
+               // The next instruction removes the hour, minute, second and ms from the date
+               // This has to be made because the date will be stored in db4o as a java.util.Date object 
+               // that would store those data, and that would give problems when comparing dates later
+               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());
+               
+               
+               try {
+
+                       //It could be to trigger an exception if the introduced string is not a number
+                       float price= Float.parseFloat(jTextField3.getText());
+
+                       //Obtain the business logic from a StartWindow class (local or remote)
+                       OfferInterface offerM = null;
+                       try {
+                               offerM = (OfferInterface) Naming
+                                               .lookup(___IntNames.OfferManager);
+                       } catch (Exception e1) {
+                               System.out.println("Error accessing remote authentication: "
+                                               + e1.toString());
+                       }
+                       
+                       offerM.createOffer(ruralHouse, firstDay, lastDay, price); 
+
+                       jLabel5.setText("Offer created");
+
+               } catch (java.lang.NumberFormatException e1) {
+                       jLabel5.setText(jTextField3.getText()+ " is not a valid price");
+               } catch (OverlappingOfferExists e1) {
+                       jLabel5.setText("There exists an overlapping offer");
+               }
+               catch (BadDates e1) {
+                       jLabel5.setText("Last day is before first day in the offer");
+               } catch (NullPointerException e1){
+                       jLabel5.setText("Bad dates or there exists an overlapping offer");
+               } 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: Introduce a number");
+  }
+ }
+}
\ No newline at end of file
diff --git a/ruralHouses/src/gui/AdminMenuGUI.java b/ruralHouses/src/gui/AdminMenuGUI.java
new file mode 100644 (file)
index 0000000..24dcb27
--- /dev/null
@@ -0,0 +1,76 @@
+package gui;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+
+public class AdminMenuGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+
+
+       
+       /**
+        * Create the frame.
+        */
+       public AdminMenuGUI() {
+               
+               
+               this.setTitle("Administrator Menu");
+               this.getContentPane().setLayout(null);
+               setBounds(100, 100, 450, 500);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               //TODO BOTH BUTTONS ARE TO MODIFY
+               JButton btnAdd = new JButton("Add requests");
+               btnAdd.setBounds(120, 67, 164, 81);
+               btnAdd.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new listOfAdditionRequestsGUI();
+                               a.setVisible(true);
+                       }
+               });
+               
+               JButton btnDel = new JButton("Delete Requests");
+               btnDel.setBounds(120, 159, 164, 73);
+               btnDel.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new listOfRemovalRequestsGUI();
+                               a.setVisible(true);
+                       }
+               });
+               
+               JButton btnOwneraddition = new JButton("OwnerAddition");
+               btnOwneraddition.setBounds(120, 243, 164, 73);
+               btnOwneraddition.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new listOfOwnerAddittionRequests();
+                               a.setVisible(true);
+                       }
+               });
+               contentPane.setLayout(null);
+               contentPane.add(btnOwneraddition);
+               contentPane.add(btnDel);
+               contentPane.add(btnAdd);
+       
+               JButton btnOwnerDeletion = new JButton("Owner Deletion");
+               btnOwnerDeletion.setBounds(120, 331, 164, 73);
+               btnOwnerDeletion.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new DeleteOwnerGUI();
+                               a.setVisible(true);
+                       }
+               });
+               contentPane.add(btnOwnerDeletion);
+       }
+}
diff --git a/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java b/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java
new file mode 100644 (file)
index 0000000..21f9ab6
--- /dev/null
@@ -0,0 +1,103 @@
+package gui;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+
+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 book)
+  {
+    try
+    {
+      jbInit(book);
+    }
+    catch(Exception e)
+    {
+      e.printStackTrace();
+    }
+
+  }
+
+  private void jbInit(Booking book) throws Exception
+  {
+         
+
+    this.getContentPane().setLayout(null);
+    this.setSize(new Dimension(416, 316));
+    this.setTitle("See Booking Details");
+    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(book.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(book.getBookNumber()));
+    
+    jLabel3.setText("You must deposit 20% of the total ammount of a book in the next three days.");
+    jLabel3.setBounds(new Rectangle(20, 105, 370, 25));
+    jButton1.setText("Close");
+    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 ammount:");
+    jLabel5.setBounds(new Rectangle(70, 175, 100, 25));
+    jTextField3.setBounds(new Rectangle(180, 140, 115, 25));
+    jTextField3.setEditable(false);
+
+    jTextField3.setText(Float.toString(book.getOffer().getPrice()) + " \80");
+    jTextField4.setBounds(new Rectangle(180, 175, 115, 25));
+    jTextField4.setEditable(false);
+    jTextField4.setText(Float.toString(book.getOffer().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/DeleteOfferGUI.java b/ruralHouses/src/gui/DeleteOfferGUI.java
new file mode 100644 (file)
index 0000000..d9f5ab8
--- /dev/null
@@ -0,0 +1,159 @@
+package gui;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.border.EmptyBorder;
+
+import common.HouseInterface;
+import common.OfferInterface;
+
+import configuration.___IntNames;
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class DeleteOfferGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JLabel feedback;
+       private JComboBox<RuralHouse> comboBox;
+       private JComboBox<Offer> comboBox_1;
+       private JButton btnDelete;
+       private Vector<RuralHouse> Hlist = null;
+       private HouseInterface hm = null;
+
+       /**
+        * Create the frame.
+        */
+       public DeleteOfferGUI(Owner o) {
+               try {
+                       hm = (HouseInterface) Naming
+                                       .lookup(___IntNames.HouseManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               try {
+                       Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
+               } catch (RemoteException e1) {
+                       e1.printStackTrace();
+               }       
+               setBounds(100, 100, 450, 300);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+
+               comboBox = new JComboBox<RuralHouse>(this.Hlist);
+               comboBox.setBounds(101, 38, 314, 20);
+
+               comboBox_1 = new JComboBox<Offer>();
+               comboBox_1.setBounds(101, 76, 314, 20);
+               Vector<Offer> vo = ((RuralHouse) comboBox.getSelectedItem()).getAllOffers();
+               comboBox_1.removeAllItems();
+               for (Offer of : vo) {
+                       comboBox_1.addItem(of);
+                       ;
+               }
+
+               JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
+               rdbtnIAmSure.setBounds(101, 134, 108, 23);
+
+               btnDelete = new JButton("DELETE");
+               btnDelete.setBounds(92, 226, 117, 23);
+               btnDelete.setEnabled(false);
+
+               comboBox.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               Vector<Offer> vo = ((RuralHouse) comboBox.getSelectedItem()).getAllOffers();
+                               comboBox_1.removeAllItems();
+                               for (Offer of : vo) {
+                                       comboBox_1.addItem(of);
+                                       ;
+                               }
+
+                       }
+
+               });
+
+               rdbtnIAmSure.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent e) {
+                               int state = e.getStateChange();
+                               if (state == ItemEvent.SELECTED) {
+                                       if (comboBox_1.getSelectedItem() != null)
+                                               btnDelete.setEnabled(true);
+                               } else if (state == ItemEvent.DESELECTED) {
+                                       btnDelete.setEnabled(false);
+                               }
+                       }
+               });
+
+               JLabel lblHouse = new JLabel("House:");
+               lblHouse.setBounds(25, 41, 68, 14);
+
+               JLabel lblOffer = new JLabel("Offer:");
+               lblOffer.setBounds(25, 79, 68, 14);
+               contentPane.setLayout(null);
+               contentPane.add(btnDelete);
+               contentPane.add(rdbtnIAmSure);
+               contentPane.add(lblHouse);
+               contentPane.add(lblOffer);
+               contentPane.add(comboBox);
+               contentPane.add(comboBox_1);
+               
+               feedback = new JLabel("");
+               feedback.setBounds(140, 178, 202, 23);
+               contentPane.add(feedback);
+
+               btnDelete.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               actionListenerButton(arg0);
+
+                       }
+
+               });
+       }
+
+       private void actionListenerButton(ActionEvent e) {
+
+               Offer toDel = (Offer) comboBox_1.getSelectedItem();
+               OfferInterface oM = null;
+               try {
+                       oM = (OfferInterface) Naming
+                                       .lookup(___IntNames.OfferManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               
+               try {
+                       oM.deleteOffer((RuralHouse) comboBox.getSelectedItem(), toDel);
+                       comboBox_1.removeItem(toDel);
+                       btnDelete.setEnabled(false);
+                       feedback.setText("Offer correctly deleted");
+               } catch (Exception e1) {
+                       feedback.setText("Imposible to delete the offer");
+                       e1.printStackTrace();
+               }
+               
+       }
+}
diff --git a/ruralHouses/src/gui/DeleteOwnerGUI.java b/ruralHouses/src/gui/DeleteOwnerGUI.java
new file mode 100644 (file)
index 0000000..982e022
--- /dev/null
@@ -0,0 +1,139 @@
+package gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableModel;
+
+import common.AccountInterface;
+import common.AdminInterface;
+
+import configuration.___IntNames;
+import domain.Owner;
+
+public class DeleteOwnerGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+
+       private DefaultTableModel tableModel;
+       private AdminInterface AdM = null;
+       private Vector<Owner> owners = new Vector<Owner>();
+
+       /**
+        * Create the frame.
+        */
+       public DeleteOwnerGUI() {
+               setTitle("Current owners:");
+               try {
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               setBounds(100, 100, 600, 500);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+               try {
+                       AdM = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out
+                                       .println("Error accessing remote authentication: "
+                                                       + e1.toString());
+               }
+               this.owners = AdM.getAllOwners();
+               JLabel lblNewLabel = new JLabel();
+               lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+               lblNewLabel.setBounds(23, 41, 536, 33);
+               contentPane.add(lblNewLabel);
+               if (this.owners.isEmpty())
+                       lblNewLabel
+                                       .setText("There are not owners in the system");
+               else
+                       lblNewLabel.setText("List of owners:");
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+               scrollPane.setBounds(23, 113, 536, 271);
+               contentPane.add(scrollPane);
+               final JLabel feedback = new JLabel("");
+               feedback.setBounds(134, 447, 307, 14);
+               contentPane.add(feedback);
+               JButton btnNewButton = new JButton("Delete from the system");
+               btnNewButton.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
+                                       AccountInterface acm = null;
+                                       
+                                       try {
+                                               acm = (AccountInterface) Naming
+                                                               .lookup(___IntNames.AccountManager);
+                                       } catch (Exception e1) {
+                                               System.out.println("Error accessing remote authentication: "
+                                                               + e1.toString());
+                                       }
+
+                                       try {
+                                               if(acm.removeAccount(table.getSelectedRow()))
+                                                       {
+                                                       feedback.setText("Deleted from the system");
+                                                       }
+                                       } catch (RemoteException e1) {
+                                               e1.printStackTrace();
+                                       }
+                                       
+                                       ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
+                               }
+                       }
+               });
+               btnNewButton.setBounds(88, 396, 428, 40);
+               contentPane.add(btnNewButton);
+               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[] {
+                               "Name", "E-mail", "Bank Account" });
+
+               table.setModel(tableModel);
+               
+               
+               Enumeration<Owner> rhs = this.owners.elements();
+               while (rhs.hasMoreElements()) {
+                       Owner own = rhs.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(own.getName());
+                       row.add(own.getMailAccount());
+                       row.add(own.getBankAccount());
+                       tableModel.addRow(row);
+               }
+               
+               
+       }
+}
diff --git a/ruralHouses/src/gui/HouseFeaturesGUI.java b/ruralHouses/src/gui/HouseFeaturesGUI.java
new file mode 100644 (file)
index 0000000..39d0bc9
--- /dev/null
@@ -0,0 +1,322 @@
+package gui;
+
+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.rmi.Naming;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.DefaultTableModel;
+
+import common.BookingInterface;
+
+import configuration.___IntNames;
+import domain.Booking;
+import domain.Client;
+import domain.Offer;
+import domain.RuralHouse;
+
+public class HouseFeaturesGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JLabel lblDistrict;
+       private JTextField District_f;
+       private JLabel lblDescription;
+       private JTextField description_f;
+       private JLabel lblKitchen;
+       private JTextField kitchens_f;
+       private JLabel lblRooms;
+       private JTextField rooms_f;
+       private JLabel lblLivings;
+       private JTextField lRooms_f;
+       private JLabel lblParkings;
+       private JTextField parkings_f;
+       private JLabel lblBaths;
+       private JTextField baths_f;
+       private JTable table;
+       private DefaultTableModel tableModel;
+       private RuralHouse rh;
+       private Vector<Offer> offers= new Vector<Offer>();
+       private JTextField telIn;
+       private int row;
+       private JLabel labelPhone;
+       private JLabel lblName;
+       private JTextField nameField;
+       private JLabel lblEmail;
+       private JTextField mailField;
+
+       /**
+        * Create the frame.
+        */
+
+       public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay,
+                       final Date LastDay) {
+               this.rh = RH;
+               this.getContentPane().setLayout(null);
+               setBounds(100, 100, 500, 700);
+               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);
+               baths_f.setColumns(10);
+               contentPane.setLayout(null);
+               contentPane.add(lblParkings);
+               contentPane.add(parkings_f);
+               contentPane.add(lblRooms);
+               contentPane.add(rooms_f);
+               contentPane.add(lblBaths);
+               contentPane.add(baths_f);
+               contentPane.add(lblDistrict);
+               contentPane.add(District_f);
+               contentPane.add(lblLivings);
+               contentPane.add(lRooms_f);
+               contentPane.add(lblKitchen);
+               contentPane.add(kitchens_f);
+               contentPane.add(description_f);
+               contentPane.add(lblDescription);
+               parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings()));
+               rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
+               baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
+               District_f.setText(rh.getDistrict());
+               kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens()));
+               description_f.setText(rh.getDescription());
+               lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings()));
+               JLabel lblAvailbleOffers = new JLabel("Availble Offers:");
+               lblAvailbleOffers.setBounds(30, 286, 86, 14);
+               contentPane.add(lblAvailbleOffers);
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(40, 311, 376, 183);
+               contentPane.add(scrollPane);
+
+               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(238, 614, 178, 23);
+               contentPane.add(btnBookSelected);
+
+               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(170, 282, 261, 23);
+               contentPane.add(lblNewLabel);
+
+               JLabel lblNewLabel_1 = new JLabel("Telephone num:");
+               lblNewLabel_1.setBounds(10, 618, 83, 14);
+               contentPane.add(lblNewLabel_1);
+
+               telIn = new JTextField();
+               telIn.setBounds(103, 615, 129, 20);
+               contentPane.add(telIn);
+               telIn.setColumns(10);
+
+               labelPhone = new JLabel("");
+               labelPhone.setBounds(238, 252, 178, 14);
+               contentPane.add(labelPhone);
+
+               lblName = new JLabel("Name:");
+               lblName.setBounds(10, 516, 46, 14);
+               contentPane.add(lblName);
+
+               nameField = new JTextField();
+               nameField.setBounds(103, 513, 178, 20);
+               contentPane.add(nameField);
+               nameField.setColumns(10);
+
+               lblEmail = new JLabel("E-mail:");
+               lblEmail.setBounds(10, 565, 46, 14);
+               contentPane.add(lblEmail);
+
+               mailField = new JTextField();
+               mailField.setBounds(103, 562, 178, 20);
+               contentPane.add(mailField);
+               mailField.setColumns(10);
+
+               table.addMouseListener(new MouseAdapter() {
+                       @Override
+                       public void mouseClicked(MouseEvent arg0) {
+                               row = table.getSelectedRow();
+                       }
+               });
+               
+               Enumeration<Offer> rhs = rh.getAllOffers().elements();
+               while (rhs.hasMoreElements()) {
+                       Offer of = rhs.nextElement();
+                       if (of.getBookings() == null
+                                       || !of.isBooked()) {
+                               offers.add(of);
+                               Vector<Object> row = new Vector<Object>();
+                               row.add(of.getOfferNumber());
+                               row.add(of.getFirstDay());
+                               row.add(of.getLastDay());
+                               row.add(of.getPrice());
+                               tableModel.addRow(row);
+                       }
+               }
+               table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+                       /**
+                        * 
+                        */
+                       private static final long serialVersionUID = 1L;
+
+                       @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 (LastDay.before(lastDay) || FirstDay.after(firstDay)) {
+                                               setBackground(Color.RED);
+                                               setForeground(Color.BLACK);
+                                       } else {
+                                               setBackground(Color.GREEN);
+                                               setForeground(Color.BLACK);
+                                       }
+                               }
+                               return this;
+                       }
+               });
+       }
+
+       private void jButton_ActionPerformed(ActionEvent arg0) {
+
+               BookingInterface bookingM = null;
+               try {
+                       bookingM = (BookingInterface) Naming
+                                       .lookup(___IntNames.BookingManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               
+               if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")
+                               && mailField
+                               .getText()
+                               .matches(
+                                               "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
+               && !nameField.getText().isEmpty()) {
+                       labelPhone.setText("");
+                       Vector<Booking> book = null;
+                       try {
+                               if (table.getRowCount() != 0) {
+                                       Client cl = new Client(nameField.getText(),
+                                                       mailField.getText(), telIn.getText());
+                                       book = bookingM.createBooking(rh, offers.get(row)
+                                                       .getFirstDay(), offers.get(row).getLastDay(),cl);
+                               }
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                       }
+                       if (book != null) {
+                               BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
+                                               book.lastElement());
+                               confirmWindow.setVisible(true);
+                       }
+               } else {
+                       labelPhone.setText("Bad formatted data.");
+
+               }
+       }
+}
diff --git a/ruralHouses/src/gui/HousesRelatedOwnerGUI.java b/ruralHouses/src/gui/HousesRelatedOwnerGUI.java
new file mode 100644 (file)
index 0000000..16884c3
--- /dev/null
@@ -0,0 +1,84 @@
+package gui;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.GroupLayout;
+import javax.swing.GroupLayout.Alignment;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+
+import domain.Owner;
+
+public class HousesRelatedOwnerGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private Owner owner;
+       /**
+        * Create the frame.
+        */
+       public HousesRelatedOwnerGUI(Owner o) {
+               this.getContentPane().setLayout(null);
+               owner = o;
+               setBounds(100, 100, 450, 562);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               
+               JButton btnCreateHouses = new JButton("Create Request");
+               btnCreateHouses.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               Frame a = new RequestNewHouseGUI(owner);
+                               a.setVisible(true);
+                       }
+               });
+               
+               JButton btnModifyHouses = new JButton("Modify Houses");
+               btnModifyHouses.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               
+                               Frame a = new ModifyHouseGUI(owner);
+                               a.setVisible(true);
+                               
+                       }
+               });
+               
+               JButton btnDeleteHouses = new JButton("Delete Request");
+               btnDeleteHouses.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new RequestDeleteHouseGUI(owner);
+                               a.setVisible(true);
+                       }
+               });
+               GroupLayout gl_contentPane = new GroupLayout(contentPane);
+               gl_contentPane.setHorizontalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGap(110)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                               .addComponent(btnDeleteHouses, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1125, Short.MAX_VALUE)
+                                               .addComponent(btnModifyHouses, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1125, Short.MAX_VALUE)
+                                               .addComponent(btnCreateHouses, GroupLayout.DEFAULT_SIZE, 1125, Short.MAX_VALUE))
+                                       .addGap(121))
+               );
+               gl_contentPane.setVerticalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGap(88)
+                                       .addComponent(btnCreateHouses, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
+                                       .addGap(40)
+                                       .addComponent(btnModifyHouses, GroupLayout.PREFERRED_SIZE, 57, GroupLayout.PREFERRED_SIZE)
+                                       .addGap(39)
+                                       .addComponent(btnDeleteHouses, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
+                                       .addContainerGap(394, Short.MAX_VALUE))
+               );
+               contentPane.setLayout(gl_contentPane);
+       }
+}
diff --git a/ruralHouses/src/gui/LoginGUI.java b/ruralHouses/src/gui/LoginGUI.java
new file mode 100644 (file)
index 0000000..cf075b2
--- /dev/null
@@ -0,0 +1,168 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.Frame;
+import java.awt.KeyEventDispatcher;
+import java.awt.KeyboardFocusManager;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+
+import common.LoginInterface;
+
+import configuration.___IntNames;
+import domain.Account;
+
+public class LoginGUI extends JFrame {
+
+       private static final long serialVersionUID= 1L;
+       private JPanel jContentPane = null;
+       private JTextField usernameField;
+       private JPasswordField passwordField;
+       private LoginInterface loginManager = null;
+       private JLabel loginFeedback;
+       private JButton btnRegister;
+       protected boolean isFocused = false;
+       public LoginGUI() {
+               super();
+               initialize();
+       }
+
+       private void initialize() {
+               try {
+                       loginManager = (LoginInterface) Naming
+                                       .lookup(___IntNames.LoginManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               this.setSize(449, 293);
+               this.setContentPane(getJContentPane());
+               this.setTitle("Login");
+               addWindowListener(new WindowAdapter() {
+
+
+                       @Override
+                       public void windowGainedFocus(WindowEvent e) {
+                               isFocused = true;
+                       }
+
+                       @Override
+                       public void windowLostFocus(WindowEvent e) {
+                               isFocused = false;
+                       }
+               });
+
+        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
+
+                       @Override
+                       public boolean dispatchKeyEvent(KeyEvent e) {
+                               if (isFocused && e.getKeyCode() == KeyEvent.VK_ENTER )
+                                       jButton_ActionPerformed();
+                               
+                               return false;
+                       }});
+       }
+
+       
+       private JPanel getJContentPane() {
+               if (jContentPane == null) {
+                       jContentPane = new JPanel();
+                       jContentPane.setLayout(null);
+                       
+                       JLabel usernameTag = new JLabel("Username:");
+                       usernameTag.setBounds(56, 67, 104, 20);
+                       jContentPane.add(usernameTag);
+                       
+                       JLabel passwordTag = new JLabel("Password:");
+                       passwordTag.setBounds(56, 132, 104, 15);
+                       jContentPane.add(passwordTag);
+                       
+                       usernameField = new JTextField();
+                       usernameField.setBounds(202, 65, 133, 25);
+                       jContentPane.add(usernameField);
+                       usernameField.setColumns(10);
+                       
+                       passwordField = new JPasswordField();
+                       passwordField.setBounds(202, 122, 133, 25);
+                       jContentPane.add(passwordField);
+                       
+                       JButton loginButton = new JButton("Login");
+                       loginButton.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent arg0) {
+
+                               jButton_ActionPerformed();      
+                               }                                       
+                       });
+                       loginButton.setBounds(95, 179, 117, 25);
+                       jContentPane.add(loginButton);
+                       
+                       loginFeedback = new JLabel("");
+                       loginFeedback.setForeground(Color.RED);
+                       loginFeedback.setHorizontalAlignment(SwingConstants.CENTER);
+                       loginFeedback.setBounds(83, 216, 269, 25);
+                       jContentPane.add(loginFeedback);
+                       
+                       btnRegister = new JButton("Register");
+                       btnRegister.setBounds(222, 180, 113, 23);
+                       btnRegister.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent arg0) {
+
+                               jButton_ActionPerformed2(arg0); 
+                               }                                       
+                       });
+                       jContentPane.add(btnRegister);
+               }
+               return jContentPane;
+       }
+       private void jButton_ActionPerformed2(ActionEvent e){
+               
+               
+                       this.setVisible(false);
+                       Frame a = new OwnerRegistrationGUI();
+                       a.setVisible(true);
+               
+               
+       }
+
+
+       
+       private void jButton_ActionPerformed(){
+                       
+               Account acc = null;
+               try {
+                       acc = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
+               } catch (RemoteException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               if (acc == null) loginFeedback.setText("Incorrect username or password");
+               else if( acc.getAdmin()) {
+                       this.setVisible(false);
+                       Frame a = new AdminMenuGUI();
+                       a.setVisible(true);
+               } else {
+                       if(acc.getOwner()==null){
+                               loginFeedback.setText("Incorrect username or password");
+                       }else{
+                               this.setVisible(false);
+                               Frame a = new OwnerMenuGUI(acc.getOwner());
+                               a.setVisible(true);             
+                       }
+               }
+               
+       }
+}  // @jve:decl-index=0:visual-constraint="222,33"
+
diff --git a/ruralHouses/src/gui/ModifyHouseGUI.java b/ruralHouses/src/gui/ModifyHouseGUI.java
new file mode 100644 (file)
index 0000000..d5db84c
--- /dev/null
@@ -0,0 +1,237 @@
+package gui;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+import javax.swing.border.EmptyBorder;
+
+import common.HouseInterface;
+
+import configuration.___IntNames;
+import domain.Districs;
+import domain.HouseFeatures;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class ModifyHouseGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private Owner owner;
+       private JLabel lblDistrict;
+       private JLabel feedback;
+       private JLabel lblDescription;
+       private JTextField description_f;
+       private JLabel lblKitchen;
+       private JTextField kitchens_f;
+       private JLabel lblRooms;
+       private JTextField rooms_f;
+       private JLabel lblLivings;
+       private JTextField lRooms_f;
+       private JLabel lblParkings;
+       private JTextField parkings_f;
+       private JLabel lblBaths;
+       private String[] distric;
+       private JTextField baths_f;
+       private JButton btnConfirm;
+       private JComboBox<RuralHouse> houseBox;
+       private  JComboBox<String> comboBox;
+       private RuralHouse rh;
+
+       /**
+        * Create the frame.
+        */
+       public ModifyHouseGUI(final Owner o) {
+               this.distric=Districs.longNames();
+                comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
+
+                               this.distric));
+               this.getContentPane().setLayout(null);
+               owner = o;
+               setBounds(100, 100, 500, 583);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+
+               JLabel lblCode = new JLabel("House Name:");
+               lblCode.setBounds(15, 88, 64, 14);
+               lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               lblDistrict = new JLabel("District:");
+               lblDistrict.setBounds(39, 119, 70, 14);
+               lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               lblDescription = new JLabel("Description:");
+               lblDescription.setBounds(231, 88, 90, 14);
+               lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               description_f = new JTextField();
+               description_f.setBounds(241, 113, 178, 129);
+               description_f.setColumns(10);
+
+               lblKitchen = new JLabel("Kitchens:");
+               lblKitchen.setBounds(230, 316, 70, 14);
+               lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               kitchens_f = new JTextField();
+               kitchens_f.setBounds(318, 313, 86, 20);
+               kitchens_f.setColumns(10);
+
+               lblRooms = new JLabel("Rooms:");
+               lblRooms.setBounds(39, 316, 70, 14);
+               lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               rooms_f = new JTextField();
+               rooms_f.setBounds(127, 313, 86, 20);
+               rooms_f.setColumns(10);
+
+               lblLivings = new JLabel("Living rooms:");
+               lblLivings.setBounds(237, 354, 63, 14);
+               lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               lRooms_f = new JTextField();
+               lRooms_f.setBounds(318, 351, 86, 20);
+               lRooms_f.setColumns(10);
+
+               lblParkings = new JLabel("Parkings:");
+               lblParkings.setBounds(39, 404, 70, 14);
+               lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               parkings_f = new JTextField();
+               parkings_f.setBounds(127, 401, 86, 20);
+               parkings_f.setColumns(10);
+
+               lblBaths = new JLabel("Baths:");
+               lblBaths.setBounds(39, 354, 70, 14);
+               lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               baths_f = new JTextField();
+               baths_f.setBounds(127, 351, 86, 20);
+               baths_f.setColumns(10);
+
+               btnConfirm = new JButton("Confirm");
+               btnConfirm.setBounds(145, 462, 69, 23);
+               btnConfirm.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+
+                               RuralHouse newRh = new RuralHouse(rh.getHouseName(), owner,
+                                               description_f.getText(), (String)comboBox.getSelectedItem(),
+                                               new HouseFeatures(new Integer(rooms_f.getText()),
+                                                               new Integer(kitchens_f.getText()), new Integer(
+                                                                               baths_f.getText()), new Integer(
+                                                                               lRooms_f.getText()), new Integer(
+                                                                               parkings_f.getText())));
+                               HouseInterface hm= null;
+                               try {
+                                       hm = (HouseInterface) Naming
+                                                       .lookup(___IntNames.HouseManager);
+                               } catch (Exception e1) {
+                                       System.out.println("Error accessing remote authentication: "
+                                                       + e1.toString());
+                               }
+               
+                               try {
+                                       if (hm.registerNewHouse(newRh)) {
+                                               owner.getRuralHouses().add(newRh);
+                                               houseBox.removeItem(rh);
+                                               feedback.setText("House properly modified");
+                                       } else
+                                               feedback.setText("Imposible to modify the house");
+                               } catch (RemoteException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+
+                       }
+               });
+               HouseInterface hm= null;
+               try {
+                       hm = (HouseInterface) Naming
+                                       .lookup(___IntNames.HouseManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               Vector<RuralHouse> list = null;
+               try {
+                       list = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
+               } catch (RemoteException e1) {
+                       e1.printStackTrace();
+               }
+               
+               houseBox = new JComboBox<RuralHouse>(list);
+               if (!o.getRuralHouses().isEmpty()) {
+                       rh = (RuralHouse) houseBox.getSelectedItem();                   
+                       comboBox.setSelectedItem(rh.getDistrict());             
+                       description_f.setText(rh.getDescription());
+                       kitchens_f.setText(Integer
+                                       .toString(rh.getFeatures().getnKitchens()));
+                       rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
+                       lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings()));
+                       parkings_f.setText(Integer
+                                       .toString(rh.getFeatures().getnParkings()));
+                       baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
+                       houseBox.setBounds(89, 85, 124, 20);
+               }else{
+                       feedback.setText("Not available houses");
+                       btnConfirm.setEnabled(false);
+               }
+               houseBox.addItemListener(new ItemListener() {
+                       @Override
+                       public void itemStateChanged(ItemEvent e) {
+                               rh = (RuralHouse) houseBox.getSelectedItem();
+                               comboBox.setSelectedItem(rh.getDistrict());
+                               description_f.setText(rh.getDescription());
+                               kitchens_f.setText(Integer.toString(rh.getFeatures()
+                                               .getnKitchens()));
+                               rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
+                               lRooms_f.setText(Integer.toString(rh.getFeatures()
+                                               .getnLivings()));
+                               parkings_f.setText(Integer.toString(rh.getFeatures()
+                                               .getnParkings()));
+                               baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
+
+                       }
+               });
+               contentPane.setLayout(null);
+               contentPane.add(lblParkings);
+               contentPane.add(parkings_f);
+               contentPane.add(lblRooms);
+               contentPane.add(rooms_f);
+               contentPane.add(lblCode);
+               contentPane.add(houseBox);
+               contentPane.add(lblBaths);
+               contentPane.add(baths_f);
+               contentPane.add(lblDistrict);
+               contentPane.add(lblLivings);
+               contentPane.add(lRooms_f);
+               contentPane.add(lblKitchen);
+               contentPane.add(kitchens_f);
+               contentPane.add(description_f);
+               contentPane.add(lblDescription);
+               contentPane.add(btnConfirm);
+
+               feedback = new JLabel("");
+               feedback.setBounds(189, 510, 195, 23);
+               contentPane.add(feedback);
+               
+               comboBox.setBounds(127, 116, 86, 20);
+               contentPane.add(comboBox);
+       }
+}
diff --git a/ruralHouses/src/gui/ModifyOfferGUI.java b/ruralHouses/src/gui/ModifyOfferGUI.java
new file mode 100644 (file)
index 0000000..3e7a6c6
--- /dev/null
@@ -0,0 +1,334 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.sql.Date;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+
+import com.toedter.calendar.JCalendar;
+import common.HouseInterface;
+import common.OfferInterface;
+
+import configuration.___IntNames;
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+import exceptions.BadDates;
+
+public class ModifyOfferGUI extends JFrame {
+
+       private static final long serialVersionUID = 1L;
+
+       private JComboBox<RuralHouse> 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();
+       private final JLabel jLabel1_o = new JLabel();
+       private JComboBox<Offer> comboBox_o;
+       private Vector<RuralHouse> Hlist = null;
+       private OfferInterface  om = null;
+       private HouseInterface hm = null;
+
+
+       public ModifyOfferGUI(Owner o) {
+               try {
+                       jbInit(o);
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void jbInit(Owner o) throws Exception {
+               this.getContentPane().setLayout(null);
+               this.setSize(new Dimension(513, 433));
+               this.setTitle("Set availability");
+
+
+               try {
+                       om = (OfferInterface) Naming
+                                       .lookup(___IntNames.OfferManager);
+                       hm = (HouseInterface) Naming
+                                       .lookup(___IntNames.HouseManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               try {
+                       Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
+               } catch (RemoteException e1) {
+                       e1.printStackTrace();
+               }
+
+
+               jComboBox1 = new JComboBox<RuralHouse>(Hlist);
+
+               comboBox_o = new JComboBox<Offer>(
+                               ((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers());
+               DateFormat dateformat1 = DateFormat.getDateInstance(1,
+                               jCalendar1.getLocale());
+               if (!((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers()
+                               .isEmpty()) {
+                       jTextField1.setText(dateformat1.format(((Offer) comboBox_o
+                                       .getSelectedItem()).getFirstDay()));
+                       jTextField2.setText(dateformat1.format(((Offer) comboBox_o
+                                       .getSelectedItem()).getLastDay()));             
+                       jLabel4.setText(Float.toString(((Offer) comboBox_o
+                                       .getSelectedItem()).getPrice()));
+                       jTextField3.setText(Float.toString(((Offer) comboBox_o
+                                       .getSelectedItem()).getPrice()));
+               } else {
+                       jLabel5.setText("There are no offers for the selected rural house");
+                       jCalendar1.setEnabled(false);
+                       jCalendar2.setEnabled(false);
+                       jButton1.setEnabled(false);
+                       comboBox_o.setEnabled(false);
+                       jTextField3.setEnabled(false);
+               }
+               jComboBox1.setBounds(new Rectangle(115, 12, 115, 20));
+               jLabel1.setText("List of houses:");
+               jLabel1.setBounds(new Rectangle(25, 12, 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();
+                       }
+               });
+
+               jComboBox1.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+
+                               Vector<Offer> vo= null;
+                               try {
+                                       vo = om.getRuralHouseOffers((RuralHouse) jComboBox1.getSelectedItem());
+                               } catch (RemoteException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                               comboBox_o.removeAllItems();
+                               if (!vo.isEmpty()) {
+                                       jCalendar1.setEnabled(true);
+                                       jCalendar2.setEnabled(true);
+                                       jButton1.setEnabled(true);
+                                       comboBox_o.setEnabled(true);
+                                       jTextField3.setEnabled(true);
+                                       jLabel5.setText("");
+                                       for (Offer of : vo) {
+                                               comboBox_o.addItem(of);
+                                       }
+                               } else {
+                                       jLabel5.setText("There are no offers for the selected rural house");
+                                       jCalendar1.setEnabled(false);
+                                       jCalendar2.setEnabled(false);
+                                       jButton1.setEnabled(false);
+                                       comboBox_o.setEnabled(false);
+                                       jTextField3.setEnabled(false);
+                                       
+                               }
+                       }
+
+               });
+
+               comboBox_o.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               if (arg0.getStateChange() == ItemEvent.SELECTED) {
+                                       Offer of = (Offer) comboBox_o.getSelectedItem();
+                                       DateFormat dateformat1 = DateFormat.getDateInstance(1,
+                                                       jCalendar1.getLocale());
+                                       jTextField1.setText(dateformat1.format(of.getFirstDay()));
+                                       jTextField2.setText(dateformat1.format(of.getLastDay()));
+                               }
+                       }
+
+               });
+
+               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);
+               jLabel1_o.setText("List of offers:");
+               jLabel1_o.setBounds(new Rectangle(25, 30, 95, 20));
+               jLabel1_o.setBounds(25, 44, 95, 20);
+
+               getContentPane().add(jLabel1_o);
+               comboBox_o.setBounds(new Rectangle(115, 30, 115, 20));
+               comboBox_o.setBounds(115, 44, 115, 20);
+
+               getContentPane().add(comboBox_o);
+       }
+
+       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());
+               
+
+               try {
+
+                       // It could be to trigger an exception if the introduced string is
+                       // not a number
+                       float price = Float.parseFloat(jTextField3.getText());
+
+                       // Obtain the business logic from a StartWindow class (local or
+                       // remote)
+                       OfferInterface offerM = null;
+                       try {
+                               offerM = (OfferInterface) Naming
+                                               .lookup(___IntNames.OfferManager);
+                       } catch (Exception e1) {
+                               System.out.println("Error accessing remote authentication: "
+                                               + e1.toString());
+                       }
+                       
+                       offerM.deleteOffer(ruralHouse, (Offer) comboBox_o.getSelectedItem());
+                       offerM.createOffer(ruralHouse, firstDay, lastDay, price);
+
+                       jLabel5.setText("Offer modified");
+
+               } catch (java.lang.NumberFormatException e1) {
+                       jLabel5.setText(jTextField3.getText() + " is not a valid price");
+               } catch (BadDates e1) {
+                       jLabel5.setText("Last day is before first day in the offer");
+               } 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/OffersRelatedOwnerGUI.java b/ruralHouses/src/gui/OffersRelatedOwnerGUI.java
new file mode 100644 (file)
index 0000000..fe2d073
--- /dev/null
@@ -0,0 +1,84 @@
+package gui;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.GroupLayout;
+import javax.swing.GroupLayout.Alignment;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+
+import domain.Owner;
+
+public class OffersRelatedOwnerGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private Owner owner;
+       /**
+        * Create the frame.
+        */
+       public OffersRelatedOwnerGUI(Owner o) {
+               this.getContentPane().setLayout(null);
+               owner = o;
+               setBounds(100, 100, 450, 562);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               
+               JButton btnCreateOffers = new JButton("Create Offers");
+               btnCreateOffers.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               Frame a = new AddOffersGUI(owner.getRuralHouses());
+                               a.setVisible(true);
+                       }
+               });
+               
+               JButton btnModifyOffers = new JButton("Modify Offers");
+               btnModifyOffers.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               
+                               Frame a = new ModifyOfferGUI(owner);
+                               a.setVisible(true);
+                               
+                       }
+               });
+               
+               JButton btnDeleteOffers = new JButton("Delete Offers");
+               btnDeleteOffers.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new DeleteOfferGUI(owner);
+                               a.setVisible(true);
+                       }
+               });
+               GroupLayout gl_contentPane = new GroupLayout(contentPane);
+               gl_contentPane.setHorizontalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGap(110)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                               .addComponent(btnDeleteOffers, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1125, Short.MAX_VALUE)
+                                               .addComponent(btnModifyOffers, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1125, Short.MAX_VALUE)
+                                               .addComponent(btnCreateOffers, GroupLayout.DEFAULT_SIZE, 1125, Short.MAX_VALUE))
+                                       .addGap(121))
+               );
+               gl_contentPane.setVerticalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGap(88)
+                                       .addComponent(btnCreateOffers, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
+                                       .addGap(40)
+                                       .addComponent(btnModifyOffers, GroupLayout.PREFERRED_SIZE, 57, GroupLayout.PREFERRED_SIZE)
+                                       .addGap(39)
+                                       .addComponent(btnDeleteOffers, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
+                                       .addContainerGap(394, Short.MAX_VALUE))
+               );
+               contentPane.setLayout(gl_contentPane);
+       }
+}
diff --git a/ruralHouses/src/gui/OwnerMenuGUI.java b/ruralHouses/src/gui/OwnerMenuGUI.java
new file mode 100644 (file)
index 0000000..244b242
--- /dev/null
@@ -0,0 +1,87 @@
+package gui;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.GroupLayout;
+import javax.swing.GroupLayout.Alignment;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.LayoutStyle.ComponentPlacement;
+import javax.swing.border.EmptyBorder;
+
+import domain.Owner;
+
+public class OwnerMenuGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private Owner owner;
+
+
+       /**
+        * Create the frame.
+        */
+       public OwnerMenuGUI(Owner o) {
+               this.setTitle("Owner Menu");
+               this.getContentPane().setLayout(null);
+               owner = o;
+               setBounds(100, 100, 450, 473);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               
+               JButton btnHouses = new JButton("Houses");
+               btnHouses.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new HousesRelatedOwnerGUI(owner);
+                               a.setVisible(true);
+                       }
+               });
+
+               JButton btnOffers = new JButton("Offers");
+               btnOffers.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new OffersRelatedOwnerGUI(owner);
+                               a.setVisible(true);
+                       }
+               });
+               
+               JButton btnBookings = new JButton("Bookings");
+               btnBookings.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new listOfOffers(owner);
+                               a.setVisible(true);
+                       }
+               });
+               GroupLayout gl_contentPane = new GroupLayout(contentPane);
+               gl_contentPane.setHorizontalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGap(115)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
+                                               .addComponent(btnBookings, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                                               .addComponent(btnOffers, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
+                                               .addComponent(btnHouses, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
+                                       .addContainerGap(145, Short.MAX_VALUE))
+               );
+               gl_contentPane.setVerticalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGap(62)
+                                       .addComponent(btnHouses, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
+                                       .addGap(58)
+                                       .addComponent(btnOffers, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
+                                       .addPreferredGap(ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
+                                       .addComponent(btnBookings, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
+                                       .addContainerGap())
+               );
+               contentPane.setLayout(gl_contentPane);
+       }
+
+}
diff --git a/ruralHouses/src/gui/OwnerRegistrationGUI.java b/ruralHouses/src/gui/OwnerRegistrationGUI.java
new file mode 100644 (file)
index 0000000..62395d5
--- /dev/null
@@ -0,0 +1,170 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.EmptyBorder;
+
+import common.AdminInterface;
+
+import configuration.___IntNames;
+import domain.Owner;
+
+public class OwnerRegistrationGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel panel;
+       private JTextField nameField;
+       private JTextField userNameField;
+       private AdminInterface am = null;
+       private JTextField passField;
+       private JTextField bank1Field;
+       private JTextField bank2Field;
+       private JTextField bank3Field;
+       private JTextField bank4Field;
+       private JTextField emailField;
+       private JLabel lblWhenAcceptedYou;
+       private JLabel feedback;
+
+       /**
+        * Create the frame.
+        */
+       public OwnerRegistrationGUI() {
+
+               try {
+                       am = (AdminInterface) Naming.lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               setTitle("Owner registration");
+               setBounds(100, 100, 500, 400);
+               panel = new JPanel();
+               panel.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(panel);
+               panel.setLayout(null);
+
+               JLabel nameLb = new JLabel("Name:");
+               nameLb.setBounds(37, 45, 46, 14);
+               panel.add(nameLb);
+
+               nameField = new JTextField();
+               nameField.setBounds(147, 42, 86, 20);
+               panel.add(nameField);
+               nameField.setColumns(10);
+
+               JLabel lblUsername = new JLabel("Username:");
+               lblUsername.setBounds(37, 212, 69, 14);
+               panel.add(lblUsername);
+
+               userNameField = new JTextField();
+               userNameField.setBounds(147, 209, 86, 20);
+               panel.add(userNameField);
+               userNameField.setColumns(10);
+
+               JLabel lblPassword = new JLabel("Password:");
+               lblPassword.setBounds(37, 258, 69, 14);
+               panel.add(lblPassword);
+
+               passField = new JTextField();
+               passField.setBounds(147, 255, 86, 20);
+               panel.add(passField);
+               passField.setColumns(10);
+
+               JLabel lblBankAccount = new JLabel("Bank account:");
+               lblBankAccount.setBounds(37, 94, 69, 14);
+               panel.add(lblBankAccount);
+
+               bank1Field = new JTextField();
+               bank1Field.setBounds(147, 91, 61, 20);
+               panel.add(bank1Field);
+
+               bank2Field = new JTextField();
+               bank2Field.setBounds(218, 91, 61, 20);
+               panel.add(bank2Field);
+
+               bank3Field = new JTextField();
+               bank3Field.setBounds(289, 91, 32, 20);
+               panel.add(bank3Field);
+
+               bank4Field = new JTextField();
+               bank4Field.setBounds(331, 91, 117, 20);
+               panel.add(bank4Field);
+
+               JButton btnSendRegistrationRequest = new JButton(
+                               "Send registration request");
+               btnSendRegistrationRequest.setBounds(127, 316, 194, 23);
+               btnSendRegistrationRequest.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+
+                               jButton_ActionPerformed(arg0);
+                       }
+               });
+
+               panel.add(btnSendRegistrationRequest);
+
+               JLabel lblEmail = new JLabel("E-mail:");
+               lblEmail.setBounds(37, 155, 46, 14);
+               panel.add(lblEmail);
+
+               emailField = new JTextField();
+               emailField.setBounds(147, 152, 148, 20);
+               panel.add(emailField);
+               emailField.setColumns(10);
+
+               lblWhenAcceptedYou = new JLabel(
+                               "When accepted you will receive an e-mail");
+               lblWhenAcceptedYou.setForeground(Color.GREEN);
+               lblWhenAcceptedYou.setBounds(127, 291, 214, 14);
+               panel.add(lblWhenAcceptedYou);
+
+               feedback = new JLabel("");
+               feedback.setForeground(Color.RED);
+               feedback.setEnabled(false);
+               feedback.setBounds(127, 344, 214, 20);
+               panel.add(feedback);
+       }
+
+       private void jButton_ActionPerformed(ActionEvent e) {
+
+               if (!emailField
+                               .getText()
+                               .matches(
+                                               "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
+                               || !this.nameField.getText().isEmpty()||this.bank1Field.getText().length()!=4 || this.bank2Field.getText().length()!=4
+                               ||this.bank3Field.getText().length()!=2 || this.bank4Field.getText().length()!=10) {
+                       Owner own = new Owner(this.nameField.getText(),
+                                       this.bank1Field.getText() + " " + this.bank2Field.getText()
+                                                       + " " + this.bank3Field.getText() + " "
+                                                       + this.bank4Field.getText(),
+                                       this.emailField.getText());
+
+                       try {
+                               if (this.am.addAccountRequest(this.userNameField.getText(),
+                                               this.passField.getText(), own)) {
+                                       this.am.saveInstance();
+                                       this.feedback.setText("Request sended");
+                               } else {
+                                       this.feedback.setText("Can't send the request");
+                               }
+                       } catch (RemoteException e1) {
+                               // TODO Auto-generated catch block
+                               e1.printStackTrace();
+                       }
+               } else {
+                       this.feedback.setText("Bad formatted data");
+               }
+
+       }
+}
diff --git a/ruralHouses/src/gui/QueryAvailabilityGUI2.java b/ruralHouses/src/gui/QueryAvailabilityGUI2.java
new file mode 100644 (file)
index 0000000..6f4358e
--- /dev/null
@@ -0,0 +1,369 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.sql.Date;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.Vector;
+
+import javax.swing.ButtonGroup;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+
+import com.toedter.calendar.JCalendar;
+import common.HouseInterface;
+
+import configuration.___IntNames;
+import domain.Districs;
+import domain.RuralHouse;
+
+public class QueryAvailabilityGUI2 extends JFrame {
+       private static final long serialVersionUID = 1L;
+
+       private JComboBox<String> jComboBox1;
+       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();
+       private final JLabel lblNewLabel = new JLabel("");
+       private final JRadioButton ruralHouseName = new JRadioButton(
+                       "Use RuralHouse name");
+       private final JRadioButton district = new JRadioButton("Use District Name");
+       private final ButtonGroup buttonGroup = new ButtonGroup();
+       private final JMenuBar menuBar = new JMenuBar();
+       private final JMenu mnMoreOptions = new JMenu("Search Options");
+       private final JMenuItem PopUpM = new JMenuItem("More Filters");
+       private final JPopupMenu popupMenu = new JPopupMenu();
+       private final JLabel lblNewLabel_1 = new JLabel("Number of bedrooms:");
+       private JTextField nBedrooms;
+       private JTextField nKitchens;
+       private final JLabel lblExtraFeatures = new JLabel("EXTRA FEATURES");
+       private final JLabel lblNumberOfBaths = new JLabel("Number of baths:");
+       private final JTextField nBaths = new JTextField();
+       private final JLabel lblParkings = new JLabel("Parking slots:");
+       private final JTextField nParkings = new JTextField();
+       private HouseInterface houseMan = null;
+       private final JLabel lblNumberOfLivings = new JLabel("Number of Livings:");
+       private final JTextField nLivings = new JTextField();
+       private final JLabel feedback = new JLabel("");
+
+       public QueryAvailabilityGUI2() {
+               
+               try {
+                       houseMan =  (HouseInterface) Naming
+                                       .lookup(___IntNames.HouseManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               nLivings.setText("0");
+               nLivings.setColumns(10);
+               nParkings.setText("0");
+               nParkings.setColumns(10);
+               nBaths.setText("0");
+               nBaths.setColumns(10);
+               try {
+                       jbInit();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void jbInit() throws Exception {
+               this.getContentPane().setLayout(null);
+               this.setSize(new Dimension(550, 500));
+               this.setTitle("Query Availability");
+
+               jComboBox1 = new JComboBox<String>(new DefaultComboBoxModel<String>(
+                               Districs.longNames()));
+               jComboBox1.setEnabled(false);
+               jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
+               jLabel2.setText("First day :");
+               jLabel2.setBounds(new Rectangle(20, 134, 85, 25));
+               jTextField1.setBounds(new Rectangle(20, 350, 220, 25));
+               jTextField1.setEditable(false);
+               jLabel3.setText("Last day :");
+               jLabel3.setBounds(new Rectangle(281, 134, 75, 25));
+               jTextField2.setBounds(new Rectangle(281, 350, 220, 20));
+               jTextField2.setEditable(false);
+               jLabel4.setText("Rural House name:");
+               jLabel4.setBounds(new Rectangle(275, 30, 128, 20));
+               jTextField3.setBounds(new Rectangle(413, 30, 115, 20));
+               jButton1.setText("Search");
+               jButton1.setBounds(new Rectangle(60, 377, 165, 30));
+               jButton1.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton1_actionPerformed(e);
+                       }
+               });
+               jButton2.setText("Cancel");
+               jButton2.setBounds(new Rectangle(305, 377, 162, 30));
+               jButton2.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton2_actionPerformed(e);
+                       }
+               });
+               jLabel5.setBounds(new Rectangle(207, 600, 305, 20));
+               jLabel5.setForeground(Color.red);
+               jLabel5.setSize(new Dimension(305, 20));
+               jCalendar1.setBounds(new Rectangle(20, 184, 220, 165));
+               jCalendar2.setBounds(new Rectangle(281, 184, 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);
+                               }
+                       }
+               });
+               popupMenu.setBounds(75, 125, 58, 16);
+
+               addPopup(getContentPane(), popupMenu);
+               lblExtraFeatures.setHorizontalAlignment(SwingConstants.CENTER);
+
+               popupMenu.add(lblExtraFeatures);
+
+               popupMenu.add(lblNewLabel_1);
+
+               nBedrooms = new JTextField();
+               nBedrooms.setText("0");
+               popupMenu.add(nBedrooms);
+               nBedrooms.setColumns(10);
+
+               JLabel lblNumberOfKitchens = new JLabel("Number of kitchens:");
+               popupMenu.add(lblNumberOfKitchens);
+
+               nKitchens = new JTextField();
+               nKitchens.setText("0");
+               popupMenu.add(nKitchens);
+               nKitchens.setColumns(10);
+
+               popupMenu.add(lblNumberOfBaths);
+
+               popupMenu.add(nBaths);
+
+               popupMenu.add(lblParkings);
+
+               popupMenu.add(nParkings);
+
+               popupMenu.add(lblNumberOfLivings);
+
+               popupMenu.add(nLivings);
+
+               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(jComboBox1, null);
+               lblNewLabel.setBounds(115, 301, 298, 38);
+
+               getContentPane().add(lblNewLabel);
+               ;
+               district.setBounds(20, 69, 128, 20);
+               getContentPane().add(district);
+               buttonGroup.add(ruralHouseName);
+               buttonGroup.add(district);
+               ruralHouseName.setSelected(true);
+               ruralHouseName.setBounds(276, 60, 177, 38);
+               district.addItemListener(new ItemListener() {
+                       @Override
+                       public void itemStateChanged(ItemEvent e) {
+                               int state = e.getStateChange();
+                               if (state == ItemEvent.SELECTED) {
+                                       jComboBox1.setEnabled(true);
+                                       jCalendar1.setEnabled(false);
+                                       jCalendar2.setEnabled(false);
+                               } else if (state == ItemEvent.DESELECTED) {
+                                       jComboBox1.setEnabled(false);
+
+                               }
+                       }
+               });
+
+               ruralHouseName.addItemListener(new ItemListener() {
+                       @Override
+                       public void itemStateChanged(ItemEvent e) {
+                               int state = e.getStateChange();
+                               if (state == ItemEvent.SELECTED) {
+                                       jTextField3.setEnabled(true);
+                                       jCalendar1.setEnabled(true);
+                                       jCalendar2.setEnabled(true);
+                               } else if (state == ItemEvent.DESELECTED) {
+                                       jTextField3.setEnabled(false);
+                               }
+                       }
+               });
+               getContentPane().add(ruralHouseName);
+
+               JLabel lblNewLabel_2 = new JLabel("District name:");
+               lblNewLabel_2.setBounds(20, 30, 85, 17);
+               getContentPane().add(lblNewLabel_2);
+               feedback.setHorizontalAlignment(SwingConstants.CENTER);
+               feedback.setForeground(Color.RED);
+               feedback.setBounds(134, 413, 269, 17);
+
+               getContentPane().add(feedback);
+
+               setJMenuBar(menuBar);
+
+               menuBar.add(mnMoreOptions);
+               PopUpM.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               popupMenu.show(QueryAvailabilityGUI2.this, popupMenu.getX(),
+                                               popupMenu.getY());
+                       }
+               });
+
+               mnMoreOptions.add(PopUpM);
+       }
+
+       private void jButton1_actionPerformed(ActionEvent e) {
+               if (this.district.isSelected()) {
+                       Vector<RuralHouse> houses = null;
+                       try {
+                               houses = houseMan.getHouses(null, null, jComboBox1
+                                               .getSelectedItem().toString(), Integer.parseInt(nBedrooms
+                                               .getText()), Integer.parseInt(nKitchens.getText()), Integer
+                                               .parseInt(nBaths.getText()), Integer.parseInt(nParkings
+                                               .getText()), Integer.parseInt(nLivings.getText()));
+                       } catch (NumberFormatException | RemoteException e1) {
+                               // TODO Auto-generated catch block
+                               e1.printStackTrace();
+                       }
+                       listOfHousesGUI list = new listOfHousesGUI(houses);
+                       list.setVisible(true);
+               } else if (this.ruralHouseName.isSelected()) {
+                       try {
+                               RuralHouse rh = houseMan.getHouses(null, jTextField3.getText(), null,
+                                               0, 0, 0, 0, 0).get(0);
+                               // The next instruction creates a java.sql.Date object from the
+                               // date selected in the JCalendar object
+                               Date firstDay = new Date(jCalendar1.getCalendar().getTime()
+                                               .getTime());
+                               // The next instruction removes the hour, minute, second and ms
+                               // from the date
+                               // This has to be made because the date will be stored in db4o
+                               // as a java.util.Date object
+                               // that would store those data, and that would give problems
+                               // when comparing dates later
+                               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());
+                               if(firstDay!=null&&lastDay!=null&&firstDay.before(lastDay)){
+                               HouseFeaturesGUI hou = new HouseFeaturesGUI(rh, firstDay,
+                                               lastDay);
+                               hou.setVisible(true);
+                               }else{
+                                       feedback.setText("Wrong Dates");
+                               }
+                               
+                       } catch (Exception e1) {
+                               feedback.setText("Not matching houses");
+                       }
+               }
+       }
+
+       private void jButton2_actionPerformed(ActionEvent e) {
+               this.setVisible(false);
+       }
+
+       private static void addPopup(Component component, final JPopupMenu popup) {
+               component.addMouseListener(new MouseAdapter() {
+                       public void mousePressed(MouseEvent e) {
+                               if (e.isPopupTrigger()) {
+                                       showMenu(e);
+                               }
+                       }
+
+                       public void mouseReleased(MouseEvent e) {
+                               if (e.isPopupTrigger()) {
+                                       showMenu(e);
+                               }
+                       }
+
+                       private void showMenu(MouseEvent e) {
+                               popup.show(e.getComponent(), e.getX(), e.getY());
+                       }
+               });
+       }
+}
\ No newline at end of file
diff --git a/ruralHouses/src/gui/RequestDeleteHouseGUI.java b/ruralHouses/src/gui/RequestDeleteHouseGUI.java
new file mode 100644 (file)
index 0000000..4bd854c
--- /dev/null
@@ -0,0 +1,111 @@
+package gui;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.border.EmptyBorder;
+
+import common.AdminInterface;
+
+import configuration.___IntNames;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class RequestDeleteHouseGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private Owner owner;
+       private JComboBox<RuralHouse> comboBox;
+       private JButton btnDelete;
+       private AdminInterface am = null;
+       JLabel feedback = new JLabel("");
+
+       /**
+        * Create the frame.
+        */
+       public RequestDeleteHouseGUI(Owner o) {
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               this.owner = o;
+               setBounds(100, 100, 450, 300);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+       
+               comboBox = new JComboBox<RuralHouse>(this.owner.getRuralHouses());
+               comboBox.setBounds(75, 55, 332, 20);
+               
+
+               JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
+               rdbtnIAmSure.setBounds(90, 154, 90, 23);
+               
+               btnDelete = new JButton("REQUEST");
+               btnDelete.setBounds(90, 213, 90, 23);
+               btnDelete.setEnabled(false);
+               
+               rdbtnIAmSure.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent e) {
+                               int state = e.getStateChange();
+                               if (state == ItemEvent.SELECTED){
+                                       btnDelete.setEnabled(true);
+                               }
+                               else if (state == ItemEvent.DESELECTED){
+                                       btnDelete.setEnabled(false);
+                               }
+                       }
+               });
+               contentPane.setLayout(null);
+               contentPane.add(comboBox);
+               contentPane.add(rdbtnIAmSure);
+               contentPane.add(btnDelete);
+               feedback.setBounds(90, 184, 274, 18);
+               contentPane.add(feedback);
+               
+               btnDelete.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               actionListenerButton(arg0);
+                               
+                       }
+
+                       
+               });
+       }
+       
+       private void actionListenerButton(ActionEvent e){
+               RuralHouse toDel = (RuralHouse)comboBox.getSelectedItem();
+               
+               try {
+                       if(am.addDeletionRequest(toDel)){
+                               am.saveInstance();
+                               feedback.setText("Delete request sended");
+                               
+                       }else{
+                               feedback.setText("Request cannot be sended(Already sended)");
+                       }
+               } catch (RemoteException e1) {
+                       // TODO Auto-generated catch block
+                       e1.printStackTrace();
+               }
+       }
+}
diff --git a/ruralHouses/src/gui/RequestNewHouseGUI.java b/ruralHouses/src/gui/RequestNewHouseGUI.java
new file mode 100644 (file)
index 0000000..e22a4f2
--- /dev/null
@@ -0,0 +1,269 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.GroupLayout;
+import javax.swing.GroupLayout.Alignment;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.LayoutStyle.ComponentPlacement;
+import javax.swing.SwingConstants;
+import javax.swing.border.EmptyBorder;
+
+import common.AdminInterface;
+
+import configuration.___IntNames;
+import domain.Districs;
+import domain.HouseFeatures;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class RequestNewHouseGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private Owner owner;
+       private JLabel lblCode ;
+       private JLabel feedback = new JLabel("");
+       private JTextField Code_f;
+       private JLabel lblTown;
+       private JLabel lblDescription;
+       private JTextField description_f;
+       private JLabel lblKitchen;
+       private JTextField kitchens_f;
+       private JLabel lblRooms;
+       private JTextField rooms_f;
+       private JLabel lblLivings;
+       private JTextField lRooms_f;
+       private JLabel lblParkings;
+       private JTextField parkings_f;
+       private JLabel lblBaths;
+       private JTextField baths_f;
+       private JButton btnRegister;
+       private AdminInterface am = null;
+       private JComboBox<String> comboBox;
+
+
+       /**
+        * Create the frame.
+        */
+       public RequestNewHouseGUI(Owner o) {
+               comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
+                               Districs.longNames()));
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               this.setTitle("New House");
+               setBackground(Color.WHITE);
+               this.getContentPane().setLayout(null);
+               owner = o;
+               setBounds(100, 100, 500, 583);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               
+               lblCode = new JLabel("House Name:");
+               lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               Code_f = new JTextField();
+               Code_f.setColumns(10);
+               
+               lblTown = new JLabel("District:");
+               lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               lblDescription = new JLabel("Description(optional):");
+               lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               description_f = new JTextField();
+               description_f.setToolTipText("");
+               description_f.setHorizontalAlignment(SwingConstants.LEFT);
+               description_f.setColumns(10);
+               
+               lblKitchen = new JLabel("Kitchens:");
+               lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               kitchens_f = new JTextField();
+               kitchens_f.setColumns(10);
+               
+               lblRooms = new JLabel("Rooms:");
+               lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               rooms_f = new JTextField();
+               rooms_f.setColumns(10);
+               
+               lblLivings = new JLabel("Living rooms:");
+               lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               lRooms_f = new JTextField();
+               lRooms_f.setColumns(10);
+               
+               lblParkings = new JLabel("Parkings:");
+               lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               parkings_f = new JTextField();
+               parkings_f.setColumns(10);
+               
+               lblBaths = new JLabel("Baths:");
+               lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               baths_f = new JTextField();
+               baths_f.setColumns(10);
+               
+               btnRegister = new JButton("Request registration");
+               btnRegister.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               RuralHouse rh = null;
+                               try {
+                                       //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
+                                       rh = new RuralHouse(Code_f.getText(),
+                                                               owner, description_f.getText(),
+                                                               (String) comboBox.getSelectedItem(), new HouseFeatures(Integer.parseInt(rooms_f.getText()),
+                                                                               Integer.parseInt(kitchens_f.getText()),
+                                                                               Integer.parseInt(baths_f.getText()),
+                                                                               Integer.parseInt(lRooms_f.getText()),
+                                                                               Integer.parseInt(parkings_f.getText())) );
+                               
+                               }
+                               catch(NumberFormatException e){
+                                       e.printStackTrace();
+                               }
+                               
+                               try {
+                                       if(am.addAdditionRequest(rh)){
+                                               am.saveInstance();
+                                               feedback.setText("Request sended");
+                                       }else{
+                                               feedback.setText("Request cannot be sended(Already added)");
+                                       }
+                               } catch (RemoteException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       }
+               });
+               
+               
+               
+               
+               GroupLayout gl_contentPane = new GroupLayout(contentPane);
+               gl_contentPane.setHorizontalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addContainerGap()
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                                                               .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                                                                       .addGroup(gl_contentPane.createSequentialGroup()
+                                                                                               .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                                                               .addGap(18)
+                                                                                               .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
+                                                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
+                                                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                                                       .addComponent(lblLivings)
+                                                                                                       .addGap(18)
+                                                                                                       .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                                                       .addComponent(lblCode)
+                                                                                                       .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                                                                                                       .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
+                                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                                       .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                                                       .addGap(18)
+                                                                                       .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
+                                                                       .addGap(29)
+                                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                                                               .addComponent(lblDescription)
+                                                                               .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
+                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                       .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                                       .addGap(18)
+                                                                       .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                       .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                                       .addGap(18)
+                                                                       .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(18)
+                                                       .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                       .addPreferredGap(ComponentPlacement.UNRELATED)
+                                                       .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(140)
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                                               .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
+                                                               .addComponent(btnRegister))))
+                                       .addContainerGap(97, Short.MAX_VALUE))
+               );
+               gl_contentPane.setVerticalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGap(20)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(63)
+                                                       .addComponent(lblDescription)
+                                                       .addPreferredGap(ComponentPlacement.RELATED)
+                                                       .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(60)
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
+                                                               .addComponent(lblCode)
+                                                               .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                       .addPreferredGap(ComponentPlacement.UNRELATED)
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
+                                                               .addComponent(lblTown)
+                                                               .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                       .addGap(18)
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                                               .addComponent(lblLivings)
+                                                               .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
+                                       .addGap(63)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(3)
+                                                       .addComponent(lblRooms))
+                                               .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                       .addPreferredGap(ComponentPlacement.RELATED)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(3)
+                                                       .addComponent(lblKitchen)))
+                                       .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(3)
+                                                       .addComponent(lblBaths))
+                                               .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                       .addGap(45)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
+                                               .addComponent(lblParkings)
+                                               .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                       .addGap(41)
+                                       .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
+                                       .addPreferredGap(ComponentPlacement.UNRELATED)
+                                       .addComponent(btnRegister)
+                                       .addGap(54))
+               );
+               contentPane.setLayout(gl_contentPane);
+       }
+}
diff --git a/ruralHouses/src/gui/StartWindow.java b/ruralHouses/src/gui/StartWindow.java
new file mode 100644 (file)
index 0000000..e938084
--- /dev/null
@@ -0,0 +1,186 @@
+package gui;
+
+/**
+ * @author willCodeForFood
+ */
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.KeyEventDispatcher;
+import java.awt.KeyboardFocusManager;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.rmi.RMISecurityManager;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+import javax.swing.UIManager;
+
+import configuration.ConfigXML;
+
+@SuppressWarnings("deprecation")
+public class StartWindow extends JFrame {
+
+       private static final long serialVersionUID = 1L;
+
+       private JPanel jContentPane = null;
+       private JButton boton2 = null;
+       private JButton boton3 = null;
+       private static configuration.ConfigXML c;
+       private JLabel lblNewLabel;
+
+       public static void main(String[] args) {
+
+               StartWindow a = new StartWindow();
+               
+               System.setProperty("java.security.policy", "java.policy");
+               
+               a.setVisible(true);
+
+               try {
+
+                       c = ConfigXML.getInstance();
+
+                       System.setProperty("java.security.policy", c.getJavaPolicyPath());
+
+                       System.setSecurityManager(new RMISecurityManager());
+
+                       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+
+                       c = configuration.ConfigXML.getInstance();
+
+               } catch (com.db4o.ext.DatabaseFileLockedException e) {
+                       a.lblNewLabel
+                                       .setText("Database locked: Do not run BusinessLogicServer or BusinessLogicServer!!");
+                       a.lblNewLabel.setForeground(Color.RED);
+                       System.out.println("Error in StartWindow: " + e.toString());
+               } catch (Exception e) {
+                       a.lblNewLabel.setText("Error: " + e.toString());
+                       a.lblNewLabel.setForeground(Color.RED);
+                       System.out.println("Error in StartWindow: " + e.toString());
+               }
+
+       }
+
+       /**
+        * This is the default constructor
+        */
+
+       public StartWindow() {
+               super();
+
+               addWindowListener(new WindowAdapter() {
+                       @Override
+                       public void windowClosing(WindowEvent e) {
+
+                               System.exit(1);
+                       }
+
+               });
+
+               KeyboardFocusManager.getCurrentKeyboardFocusManager()
+                               .addKeyEventDispatcher(new KeyEventDispatcher() {
+
+                                       @Override
+                                       public boolean dispatchKeyEvent(KeyEvent e) {
+                                               switch (e.getKeyCode()) {
+
+                                               case KeyEvent.VK_ESCAPE:
+                                                       System.exit(1);
+                                               
+                                               }
+                                               return false;
+                                       }
+                               });
+               initialize();
+               // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+       }
+
+       /**
+        * This method initializes this
+        * 
+        * @return void
+        */
+       private void initialize() {
+               // this.setSize(271, 295);
+               this.setSize(495, 290);
+               this.setContentPane(getJContentPane());
+               this.setTitle("Rural Houses");
+       }
+
+       /**
+        * This method initializes jContentPane
+        * 
+        * @return javax.swing.JPanel
+        */
+       private JPanel getJContentPane() {
+               if (jContentPane == null) {
+                       jContentPane = new JPanel();
+                       jContentPane.setLayout(null);
+                       jContentPane.add(getLblNewLabel());
+                       jContentPane.add(getBoton2());
+                       jContentPane.add(getBoton3());
+               }
+               return jContentPane;
+       }
+
+       /**
+        * This method initializes boton2
+        * 
+        * @return javax.swing.JButton
+        */
+       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) {
+                                       // C?digo cedido por la universidad
+                                       JFrame a = new LoginGUI();
+                                       a.setVisible(true);
+                               }
+                       });
+               }
+               return boton2;
+       }
+
+       /**
+        * This method initializes boton3
+        * 
+        * @return javax.swing.JButton
+        */
+       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) {
+                                       // C?digo cedido por la universidad
+                                       // JFrame a = new QueryAvailabilityWindow();
+                                       JFrame a = new QueryAvailabilityGUI2();
+
+                                       a.setVisible(true);
+                               }
+                       });
+               }
+               return boton3;
+       }
+
+       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);
+               }
+               return lblNewLabel;
+       }
+
+} // @jve:decl-index=0:visual-constraint="0,0"
+
diff --git a/ruralHouses/src/gui/listOfAdditionRequestsGUI.java b/ruralHouses/src/gui/listOfAdditionRequestsGUI.java
new file mode 100644 (file)
index 0000000..30e5e66
--- /dev/null
@@ -0,0 +1,162 @@
+package gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableModel;
+
+import common.AdminInterface;
+import common.HouseInterface;
+
+import configuration.___IntNames;
+import domain.RuralHouse;
+
+public class listOfAdditionRequestsGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+       private DefaultTableModel tableModel;
+       private AdminInterface am = null;
+       private Vector<RuralHouse> houses;
+       /**
+        * Create the frame.
+        */
+       public listOfAdditionRequestsGUI() {
+               
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               
+               setTitle("Adding requests");
+               try {
+                       this.houses= am.getAdditionRequests();
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               setBounds(100, 100, 600, 450);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+
+               JLabel lblNewLabel = new JLabel();
+               lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+               lblNewLabel.setBounds(23, 41, 536, 33);
+               contentPane.add(lblNewLabel);
+               if (houses.isEmpty())
+                       lblNewLabel.setText("There are not houses to be added");
+               else
+                       lblNewLabel.setText("List of houses to be added:");
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+               scrollPane.setBounds(23, 113, 536, 271);
+               contentPane.add(scrollPane);
+
+               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);
+               
+               JButton btnNewButton = new JButton("Confirm Addition");
+               btnNewButton.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
+                                       HouseInterface hm= null;
+                                       try {
+                                               hm = (HouseInterface) Naming
+                                                               .lookup(___IntNames.HouseManager);
+                                       } catch (Exception e1) {
+                                               System.out.println("Error accessing remote authentication: "
+                                                               + e1.toString());
+                                       }
+                                       
+                                       RuralHouse rh = houses.get(table.getSelectedRow());
+                                       //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
+                                       try {
+                                               hm.registerNewHouse(rh);
+                                               am.removeHouseAdditionRequests(rh);
+                                               am.saveInstance();
+                                       } catch (RemoteException e1) {
+                                               // TODO Auto-generated catch block
+                                               e1.printStackTrace();
+                                       }
+                                       
+                                       ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
+                               }
+                       }
+               });
+               btnNewButton.setBounds(88, 396, 169, 25);
+               contentPane.add(btnNewButton);
+               
+               JButton btnDenyAddition = new JButton("Deny Addition");
+               btnDenyAddition.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
+                                       RuralHouse rh = houses.get(table.getSelectedRow());
+                                       try {
+                                               am.removeHouseAdditionRequests(rh);
+                                               am.saveInstance();
+                                       } catch (RemoteException e) {
+                                               // TODO Auto-generated catch block
+                                               e.printStackTrace();
+                                       }
+                                       ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
+                                       houses.remove(rh);
+                               }
+                       }
+               });
+               btnDenyAddition.setBounds(300, 396, 169, 25);
+               contentPane.add(btnDenyAddition);
+               Enumeration<RuralHouse> en = houses.elements();
+               RuralHouse rh;
+               
+               while (en.hasMoreElements()) {
+                       rh = en.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(rh.getHouseName());
+                       row.add(rh.getFeatures().getnRooms());
+                       row.add(rh.getFeatures().getnKitchens());
+                       row.add(rh.getFeatures().getnBaths());
+                       row.add(rh.getFeatures().getnParkings());
+                       row.add(rh.getFeatures().getnLivings());
+                       tableModel.addRow(row);
+               }
+
+       }
+}
diff --git a/ruralHouses/src/gui/listOfBookingRequestsGUI.java b/ruralHouses/src/gui/listOfBookingRequestsGUI.java
new file mode 100644 (file)
index 0000000..423ea4d
--- /dev/null
@@ -0,0 +1,197 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.DefaultTableModel;
+
+import common.BookingInterface;
+
+import configuration.___IntNames;
+import domain.Booking;
+import domain.Offer;
+
+public class listOfBookingRequestsGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+       private Offer off;
+       private BookingInterface bookM = null;
+       private DefaultTableModel tableModel;
+       private Vector<Booking> bookings = new Vector<Booking>();
+
+       /**
+        * Create the frame.
+        */
+       public listOfBookingRequestsGUI(Offer of) {
+               setTitle("Adding requests");
+               this.off = of;
+
+               try {
+
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               setBounds(100, 100, 600, 500);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+
+               this.bookings = this.off.getBookings();
+               JLabel lblNewLabel = new JLabel();
+               lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+               lblNewLabel.setBounds(23, 41, 536, 33);
+               contentPane.add(lblNewLabel);
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+               scrollPane.setBounds(23, 113, 536, 271);
+               contentPane.add(scrollPane);
+
+               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[] { "Booking Number", "Booking Date", "Name",
+                                               "E-mail", "Telephone" });
+
+               table.setModel(tableModel);
+
+               JButton btnNewButton = new JButton("Confirm Booking");
+               btnNewButton.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               try {
+                                       bookM = (BookingInterface) Naming
+                                                       .lookup(___IntNames.BookingManager);
+                               } catch (Exception e1) {
+                                       System.out
+                                                       .println("Error accessing remote authentication: "
+                                                                       + e1.toString());
+                               }
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       if (table.getRowCount() != 0
+                                                       && table.getSelectedRow() != -1) {
+                                               Booking book = bookings.get(table.getSelectedRow());
+                                               try {
+                                                       bookM.acceptBooking(book);
+                                               } catch (RemoteException e1) {
+                                                       e1.printStackTrace();
+                                               }
+                                               contentPane.setVisible(false);
+
+                                       }
+
+                               }
+                       }
+               });
+               btnNewButton.setBounds(33, 396, 169, 25);
+               contentPane.add(btnNewButton);
+
+               JButton btnDenyAddition = new JButton("Deny Booking");
+               btnDenyAddition.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               try {
+                                       bookM = (BookingInterface) Naming
+                                                       .lookup(___IntNames.BookingManager);
+                               } catch (Exception e1) {
+                                       System.out
+                                                       .println("Error accessing remote authentication: "
+                                                                       + e1.toString());
+                               }
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       Booking book = bookings.get(table.getSelectedRow());
+                                       try {
+                                               bookM.denyBooking(book);
+                                       } catch (RemoteException e) {
+                                               e.printStackTrace();
+                                       }
+                                       ((DefaultTableModel) table.getModel()).removeRow(table
+                                                       .getSelectedRow());
+                                       bookings.remove(book);
+
+                               }
+                       }
+               });
+               if (bookings.isEmpty())
+                       lblNewLabel
+                                       .setText("There are not bookings to be confirmed or denied");
+               else {
+                       lblNewLabel.setText("List of bookings:");
+                       if (this.bookings.get(0).getOffer().isBooked()) {
+                               btnDenyAddition.setEnabled(false);
+                               btnNewButton.setEnabled(false);
+                       }
+               }
+               
+               btnDenyAddition.setBounds(390, 395, 169, 25);
+               contentPane.add(btnDenyAddition);
+
+               Enumeration<Booking> en = this.bookings.elements();
+               Booking book;
+               while (en.hasMoreElements()) {
+                       book = en.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(book.getBookNumber());
+                       row.add(book.getBookDate());
+                       row.add(book.getClient().getName());
+                       row.add(book.getClient().getMailAccount());
+                       row.add(book.getClient().getTelephone());
+                       tableModel.addRow(row);
+               }
+               table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+                       /**
+                        * 
+                        */
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       public Component getTableCellRendererComponent(JTable table,
+                                       Object value, boolean isSelected, boolean hasFocus,
+                                       int row, int col) {
+
+                               super.getTableCellRendererComponent(table, value, isSelected,
+                                               hasFocus, row, col);
+
+                               if (!bookings.get(row).getOffer().isBooked()) {
+                                       setBackground(Color.RED);
+                                       setForeground(Color.BLACK);
+                               } else {
+                                       setBackground(Color.GREEN);
+                                       setForeground(Color.BLACK);
+                               }
+
+                               return this;
+                       }
+               });
+       }
+
+}
diff --git a/ruralHouses/src/gui/listOfHousesGUI.java b/ruralHouses/src/gui/listOfHousesGUI.java
new file mode 100644 (file)
index 0000000..c144ccc
--- /dev/null
@@ -0,0 +1,100 @@
+package gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableModel;
+
+import domain.RuralHouse;
+
+public class listOfHousesGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+       private DefaultTableModel tableModel;
+       private Vector<RuralHouse> houses;
+       /**
+        * Create the frame.
+        */
+       public listOfHousesGUI(Vector<RuralHouse> rhs) {
+               try {
+                       this.houses=rhs;
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               setBounds(100, 100, 600, 450);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+
+               JLabel lblNewLabel = new JLabel();
+               lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+               lblNewLabel.setBounds(23, 41, 536, 33);
+               contentPane.add(lblNewLabel);
+               if (houses.isEmpty())
+                       lblNewLabel.setText("There are not houses matching your search");
+               else
+                       lblNewLabel.setText("List of houses that match your search:");
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+               scrollPane.setBounds(23, 113, 536, 271);
+               contentPane.add(scrollPane);
+
+               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>();
+                       row.add(rh.getHouseName());
+                       row.add(rh.getFeatures().getnRooms());
+                       row.add(rh.getFeatures().getnKitchens());
+                       row.add(rh.getFeatures().getnBaths());
+                       row.add(rh.getFeatures().getnParkings());
+                       row.add(rh.getFeatures().getnLivings());
+                       tableModel.addRow(row);
+               }
+
+       }
+}
diff --git a/ruralHouses/src/gui/listOfOffers.java b/ruralHouses/src/gui/listOfOffers.java
new file mode 100644 (file)
index 0000000..7d61def
--- /dev/null
@@ -0,0 +1,138 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.DefaultTableModel;
+
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class listOfOffers extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+       private Owner owner;
+
+       private DefaultTableModel tableModel;
+       private Vector<Offer> offers = new Vector<Offer>();
+
+       /**
+        * Create the frame.
+        */
+       public listOfOffers(Owner own) {
+               setTitle("Adding requests");
+               this.owner = own;
+               try {
+
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               setBounds(100, 100, 600, 450);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+               this.offers = new Vector<Offer>();
+               for (RuralHouse rh: this.owner.getRuralHouses()){
+                       this.offers.addAll(rh.getAllOffers());
+               }
+               JLabel lblNewLabel = new JLabel();
+               lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+               lblNewLabel.setBounds(23, 41, 536, 33);
+               contentPane.add(lblNewLabel);
+               if (this.offers.isEmpty())
+                       lblNewLabel
+                                       .setText("There are not bookings to be confirmed or denied");
+               else
+                       lblNewLabel.setText("List of offers:");
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+               scrollPane.setBounds(23, 113, 536, 271);
+               contentPane.add(scrollPane);
+               
+               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[] { "Offer #",
+                               "FirstDay", "LastDay", "Price" ,"RuralHouse"});
+
+               // Maybe there is a better way to avoid interaction.
+               // table.setEnabled(false);
+               table.setModel(tableModel);
+               table.addMouseListener( new MouseAdapter(){                     
+                       @Override
+                       public void mouseClicked(MouseEvent arg0) {
+                               int row = table.getSelectedRow();
+                               listOfBookingRequestsGUI feat = new listOfBookingRequestsGUI(offers.get(row));
+                               feat.setVisible(true);
+                       }
+               });
+               Enumeration<Offer> rhs = this.offers.elements();
+               while (rhs.hasMoreElements()) {
+                       Offer of = rhs.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(of.getOfferNumber());
+                       row.add(of.getFirstDay());
+                       row.add(of.getLastDay());
+                       row.add(of.getPrice());
+                       row.add(of.getRuralHouse().getHouseName());
+                       tableModel.addRow(row);
+               }
+               
+               table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+                       /**
+                        * 
+                        */
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       public Component getTableCellRendererComponent(JTable table,
+                                       Object value, boolean isSelected, boolean hasFocus,
+                                       int row, int col) {
+
+                               super.getTableCellRendererComponent(table, value, isSelected,
+                                               hasFocus, row, col);
+
+                               if (!offers.get(row).isBooked()) {
+                                       setBackground(Color.ORANGE);
+                                       setForeground(Color.BLACK);
+                               } else {
+                                       setBackground(Color.GREEN);
+                                       setForeground(Color.BLACK);
+                               }
+
+                               return this;
+                       }
+               });
+
+       }
+}
diff --git a/ruralHouses/src/gui/listOfOwnerAddittionRequests.java b/ruralHouses/src/gui/listOfOwnerAddittionRequests.java
new file mode 100644 (file)
index 0000000..b3297b4
--- /dev/null
@@ -0,0 +1,159 @@
+package gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableModel;
+
+import common.AccountInterface;
+import common.AdminInterface;
+
+import configuration.___IntNames;
+import domain.Account;
+
+public class listOfOwnerAddittionRequests extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+       private DefaultTableModel tableModel;
+       private AdminInterface am = null;
+       private Vector<Account> accounts;
+       /**
+        * Create the frame.
+        */
+       public  listOfOwnerAddittionRequests()  {
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }               
+               setTitle("Adding requests");
+               try {
+                       this.accounts= am.getOwnerAdditionRequests();
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               setBounds(100, 100, 600, 450);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+
+               JLabel lblNewLabel = new JLabel();
+               lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+               lblNewLabel.setBounds(23, 41, 536, 33);
+               contentPane.add(lblNewLabel);
+               if (accounts.isEmpty())
+                       lblNewLabel.setText("There are not owners to be added");
+               else
+                       lblNewLabel.setText("List of owners to be added:");
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+               scrollPane.setBounds(23, 113, 536, 271);
+               contentPane.add(scrollPane);
+
+               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[] {
+                               "Name", "E-mail", "Bank Account" });
+               
+               table.setModel(tableModel);
+               
+               JButton btnNewButton = new JButton("Confirm Addition");
+               btnNewButton.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
+                                       AccountInterface acm = null;
+                                       
+                                       try {
+                                               acm = (AccountInterface) Naming
+                                                               .lookup(___IntNames.AccountManager);
+                                       } catch (Exception e1) {
+                                               System.out.println("Error accessing remote authentication: "
+                                                               + e1.toString());
+                                       }
+
+                                       try {
+                                               acm.addAccount(table.getSelectedRow());
+                                               am.removeOwnerAdditionRequests(table.getSelectedRow());
+                                               am.saveInstance();
+                                       } catch (RemoteException e1) {
+                                               e1.printStackTrace();
+                                       }
+                                       
+                                       ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
+                                       
+                               }
+                       }
+               });
+               btnNewButton.setBounds(88, 396, 169, 25);
+               contentPane.add(btnNewButton);
+               
+               JButton btnDenyAddition = new JButton("Deny Addition");
+               btnDenyAddition.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
+                                       try {
+                                               am.removeOwnerAdditionRequests(table.getSelectedRow());
+                                               am.saveInstance();
+                                       } catch (RemoteException e) {
+                                               e.printStackTrace();
+                                       }
+                                       
+                                       ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
+                               }
+                       }
+               });
+               btnDenyAddition.setBounds(300, 396, 169, 25);
+               contentPane.add(btnDenyAddition);
+               Enumeration<Account> en = accounts.elements();
+               Account acc;
+               
+               while (en.hasMoreElements()) {
+                       acc = en.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(acc.getOwner().getName());
+                       row.add(acc.getOwner().getMailAccount());
+                       row.add(acc.getOwner().getBankAccount());                       
+                       tableModel.addRow(row);
+               }
+
+       }
+}
diff --git a/ruralHouses/src/gui/listOfRemovalRequestsGUI.java b/ruralHouses/src/gui/listOfRemovalRequestsGUI.java
new file mode 100644 (file)
index 0000000..a85c246
--- /dev/null
@@ -0,0 +1,158 @@
+package gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableModel;
+
+import common.AdminInterface;
+import common.HouseInterface;
+
+import configuration.___IntNames;
+import domain.RuralHouse;
+
+public class listOfRemovalRequestsGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+       private DefaultTableModel tableModel;
+       private AdminInterface am = null;
+       private Vector<RuralHouse> houses;
+
+       /**
+        * Create the frame.
+        */
+       public listOfRemovalRequestsGUI() {
+               try {
+                       am = (AdminInterface) Naming.lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               setTitle("Deleting requests");
+               try {
+                       this.houses = am.getDeletionRequests();
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               setBounds(100, 100, 600, 450);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+
+               JLabel lblNewLabel = new JLabel();
+               lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+               lblNewLabel.setBounds(23, 41, 536, 33);
+               contentPane.add(lblNewLabel);
+               if (houses.isEmpty())
+                       lblNewLabel.setText("There are not houses to be deleted");
+               else
+                       lblNewLabel.setText("List of houses to be deleted:");
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+               scrollPane.setBounds(23, 113, 536, 271);
+               contentPane.add(scrollPane);
+
+               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" });
+
+               table.setModel(tableModel);
+               Enumeration<RuralHouse> en = houses.elements();
+               RuralHouse rh;
+               JButton btnNewButton = new JButton("Confirm Deletion");
+               btnNewButton.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       HouseInterface hm = null;
+                                       try {
+                                               hm = (HouseInterface) Naming
+                                                               .lookup(___IntNames.HouseManager);
+                                       } catch (Exception e1) {
+                                               System.out
+                                                               .println("Error accessing remote authentication: "
+                                                                               + e1.toString());
+                                       }
+                                       RuralHouse rh = houses.get(table.getSelectedRow());
+
+                                       try {
+                                               hm.removeHouse(rh, rh.getOwner());
+                                               am.removeHouseDeletionRequests(rh);
+                                               am.saveInstance();
+                                       } catch (RemoteException e1) {
+                                               e1.printStackTrace();
+                                       }
+                                       ((DefaultTableModel) table.getModel()).removeRow(houses
+                                                       .indexOf(rh));
+                                       houses.remove(rh);
+
+                               }
+                       }
+               });
+               btnNewButton.setBounds(90, 396, 169, 25);
+               contentPane.add(btnNewButton);
+
+               JButton btnNewButton_1 = new JButton("Deny Deletion");
+               btnNewButton_1.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       RuralHouse rh = houses.get(table.getSelectedRow());
+                                       ((DefaultTableModel) table.getModel()).removeRow(houses
+                                                       .indexOf(rh));
+                                       houses.remove(rh);
+                                       try {
+                                               am.removeHouseDeletionRequests(rh);
+                                               am.saveInstance();
+                                       } catch (RemoteException e1) {
+                                               // TODO Auto-generated catch block
+                                               e1.printStackTrace();
+                                       }
+
+                               }
+                       }
+               });
+               btnNewButton_1.setBounds(291, 396, 169, 25);
+               contentPane.add(btnNewButton_1);
+               while (en.hasMoreElements()) {
+                       rh = en.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(rh.getHouseName());
+                       row.add(rh.getFeatures().getnRooms());
+                       row.add(rh.getFeatures().getnKitchens());
+                       row.add(rh.getFeatures().getnBaths());
+                       row.add(rh.getFeatures().getnParkings());
+                       row.add(rh.getFeatures().getnLivings());
+                       tableModel.addRow(row);
+               }
+
+       }
+}
index 008e371..c76316a 100644 (file)
@@ -10,7 +10,6 @@ import businessLogic.BookingManager;
 import businessLogic.HouseManager;
 import businessLogic.LoginManager;
 import businessLogic.OfferManager;
-import businessLogic.OwnerManager;
 
 @SuppressWarnings("deprecation")
 public class RMILauncher {
@@ -37,7 +36,6 @@ public class RMILauncher {
                boolean bok = runBooking();
                boolean hou = runHouse();
                boolean off = runOffer();
-               boolean own = runOwner();
                boolean log = runLogin();
                boolean acc = runAccount();
 
@@ -46,7 +44,6 @@ public class RMILauncher {
                                                        "\t House:  "+hou+
                                                        "\t Login:  "+log+
                                                        "\t Offer:  "+off+
-                                                       "\t Owner:  "+own+
                                                        "\t Account: "+acc);
        }
        
@@ -126,17 +123,7 @@ public class RMILauncher {
        }
 
        
-       private static boolean runOwner() {
-               try {
-                       Remote remoteOwner = new OwnerManager();
-                       String authService = "rmi://localhost:9999//OwM";
-                       Naming.rebind(authService, remoteOwner);
-                       return true;
-               } catch (Exception e) {
-                       System.out.println(e.toString());
-                       return false;
-               }
-       }
+
        
        
 }