From d30bcc8a3c13bbf5144b03a644c1345865aed708 Mon Sep 17 00:00:00 2001 From: pinene Date: Wed, 20 May 2015 18:32:33 +0200 Subject: [PATCH] cleaning --- .../src/common/BookingInterface.java | 1 - ruralHouses client/src/domain/Account.java | 7 +- .../src/domain/Administrator.java | 10 +- ruralHouses client/src/domain/Booking.java | 17 +- ruralHouses client/src/domain/Districs.java | 10 +- .../src/domain/HouseFeatures.java | 29 +- ruralHouses client/src/domain/Owner.java | 12 +- ruralHouses client/src/domain/RuralHouse.java | 59 +-- .../gui/BookRuralHouseConfirmationWindow.java | 4 +- .../src/gui/HouseFeaturesGUI.java | 1 + .../src/gui/ModifyOfferGUI.java | 4 +- ruralHouses client/src/gui/listOfOffers.java | 7 +- .../src/businessLogic/AdminManager.java | 2 - .../src/businessLogic/BookingManager.java | 34 -- .../src/businessLogic/HouseManager.java | 19 - .../src/businessLogic/OwnerManager.java | 41 -- ruralHouses/src/common/BookingInterface.java | 1 - ruralHouses/src/common/HouseInterface.java | 3 +- ruralHouses/src/common/OwnerInterface.java | 15 - .../src/configuration/___IntNames.java | 13 + ruralHouses/src/dataAccess/DB4oManager.java | 26 +- .../src/dataAccess/DB4oManagerServer.java | 118 ------ ruralHouses/src/domain/Booking.java | 15 +- ruralHouses/src/domain/HouseFeatures.java | 29 +- ruralHouses/src/domain/RuralHouse.java | 58 +-- ruralHouses/src/gui/.DS_Store | Bin 0 -> 6148 bytes ruralHouses/src/gui/AddOffersGUI.java | 255 ++++++++++++ ruralHouses/src/gui/AdminMenuGUI.java | 84 ++++ .../gui/BookRuralHouseConfirmationWindow.java | 102 +++++ ruralHouses/src/gui/DeleteOfferGUI.java | 145 +++++++ ruralHouses/src/gui/HouseFeaturesGUI.java | 319 +++++++++++++++ .../src/gui/HousesRelatedOwnerGUI.java | 84 ++++ ruralHouses/src/gui/LoginGUI.java | 168 ++++++++ ruralHouses/src/gui/ModifyHouseGUI.java | 236 +++++++++++ ruralHouses/src/gui/ModifyOfferGUI.java | 333 ++++++++++++++++ .../src/gui/OffersRelatedOwnerGUI.java | 84 ++++ ruralHouses/src/gui/OwnerMenuGUI.java | 87 +++++ ruralHouses/src/gui/OwnerRegistrationGUI.java | 162 ++++++++ .../src/gui/QueryAvailabilityGUI2.java | 369 ++++++++++++++++++ .../src/gui/RequestDeleteHouseGUI.java | 111 ++++++ ruralHouses/src/gui/RequestNewHouseGUI.java | 269 +++++++++++++ ruralHouses/src/gui/StartWindow.java | 186 +++++++++ .../src/gui/listOfAdditionRequestsGUI.java | 163 ++++++++ .../src/gui/listOfBookingRequestsGUI.java | 140 +++++++ ruralHouses/src/gui/listOfHousesGUI.java | 100 +++++ ruralHouses/src/gui/listOfOffers.java | 110 ++++++ .../src/gui/listOfOwnerAddittionRequests.java | 158 ++++++++ .../src/gui/listOfRemovalRequestsGUI.java | 160 ++++++++ ruralHouses/src/launcher/RMILauncher.java | 15 +- 49 files changed, 3897 insertions(+), 478 deletions(-) delete mode 100644 ruralHouses/src/businessLogic/OwnerManager.java delete mode 100644 ruralHouses/src/common/OwnerInterface.java create mode 100644 ruralHouses/src/configuration/___IntNames.java delete mode 100644 ruralHouses/src/dataAccess/DB4oManagerServer.java create mode 100644 ruralHouses/src/gui/.DS_Store create mode 100644 ruralHouses/src/gui/AddOffersGUI.java create mode 100644 ruralHouses/src/gui/AdminMenuGUI.java create mode 100644 ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java create mode 100644 ruralHouses/src/gui/DeleteOfferGUI.java create mode 100644 ruralHouses/src/gui/HouseFeaturesGUI.java create mode 100644 ruralHouses/src/gui/HousesRelatedOwnerGUI.java create mode 100644 ruralHouses/src/gui/LoginGUI.java create mode 100644 ruralHouses/src/gui/ModifyHouseGUI.java create mode 100644 ruralHouses/src/gui/ModifyOfferGUI.java create mode 100644 ruralHouses/src/gui/OffersRelatedOwnerGUI.java create mode 100644 ruralHouses/src/gui/OwnerMenuGUI.java create mode 100644 ruralHouses/src/gui/OwnerRegistrationGUI.java create mode 100644 ruralHouses/src/gui/QueryAvailabilityGUI2.java create mode 100644 ruralHouses/src/gui/RequestDeleteHouseGUI.java create mode 100644 ruralHouses/src/gui/RequestNewHouseGUI.java create mode 100644 ruralHouses/src/gui/StartWindow.java create mode 100644 ruralHouses/src/gui/listOfAdditionRequestsGUI.java create mode 100644 ruralHouses/src/gui/listOfBookingRequestsGUI.java create mode 100644 ruralHouses/src/gui/listOfHousesGUI.java create mode 100644 ruralHouses/src/gui/listOfOffers.java create mode 100644 ruralHouses/src/gui/listOfOwnerAddittionRequests.java create mode 100644 ruralHouses/src/gui/listOfRemovalRequestsGUI.java diff --git a/ruralHouses client/src/common/BookingInterface.java b/ruralHouses client/src/common/BookingInterface.java index 8262f30..0d2db53 100644 --- a/ruralHouses client/src/common/BookingInterface.java +++ b/ruralHouses client/src/common/BookingInterface.java @@ -13,7 +13,6 @@ import exceptions.OfferCanNotBeBooked; public interface BookingInterface extends Remote { - public int getNumber() throws RemoteException; public void removeDenyBooking(Booking b) throws RemoteException; diff --git a/ruralHouses client/src/domain/Account.java b/ruralHouses client/src/domain/Account.java index 19fc1f5..03b334e 100644 --- a/ruralHouses client/src/domain/Account.java +++ b/ruralHouses client/src/domain/Account.java @@ -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; diff --git a/ruralHouses client/src/domain/Administrator.java b/ruralHouses client/src/domain/Administrator.java index 845d089..0d516c5 100644 --- a/ruralHouses client/src/domain/Administrator.java +++ b/ruralHouses client/src/domain/Administrator.java @@ -12,6 +12,7 @@ public class Administrator implements Serializable { */ private static final long serialVersionUID = 1L; + private static Administrator admin = null; private static LinkedList addRequest; private static LinkedList removeRequest; private static LinkedList newOwnerRequest; @@ -23,15 +24,6 @@ public class Administrator implements Serializable { newOwnerRequest = new LinkedList(); } - public static Administrator getInstance() { - return null; - - - } - - public static void saveInstance() { - - } public LinkedList getAddRequest() { return addRequest; diff --git a/ruralHouses client/src/domain/Booking.java b/ruralHouses client/src/domain/Booking.java index 13bc007..68575c6 100644 --- a/ruralHouses client/src/domain/Booking.java +++ b/ruralHouses client/src/domain/Booking.java @@ -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; } diff --git a/ruralHouses client/src/domain/Districs.java b/ruralHouses client/src/domain/Districs.java index db62454..2866692 100644 --- a/ruralHouses client/src/domain/Districs.java +++ b/ruralHouses client/src/domain/Districs.java @@ -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; diff --git a/ruralHouses client/src/domain/HouseFeatures.java b/ruralHouses client/src/domain/HouseFeatures.java index e79a446..52502cb 100644 --- a/ruralHouses client/src/domain/HouseFeatures.java +++ b/ruralHouses client/src/domain/HouseFeatures.java @@ -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; - } } diff --git a/ruralHouses client/src/domain/Owner.java b/ruralHouses client/src/domain/Owner.java index 550aceb..eb436f9 100644 --- a/ruralHouses client/src/domain/Owner.java +++ b/ruralHouses client/src/domain/Owner.java @@ -16,7 +16,7 @@ public class Owner implements Serializable { // public Owner(String name) { // this.name = name; -// ruralHouses = new Vector(); +// ruralHouses = new hVector(); // } public Owner(String name, String bankAccount,String mail) { @@ -74,14 +74,6 @@ public class Owner implements Serializable { this.mailAccount = mailAccount; } - public Vector getAllOffers (){ - Vector offers = new Vector(); - for(RuralHouse rh: this.ruralHouses){ - for(Offer of : rh.getAllOffers()){ - offers.add(of); - } - } - return offers; - } + } \ No newline at end of file diff --git a/ruralHouses client/src/domain/RuralHouse.java b/ruralHouses client/src/domain/RuralHouse.java index 4245458..27f8d7f 100644 --- a/ruralHouses client/src/domain/RuralHouse.java +++ b/ruralHouses client/src/domain/RuralHouse.java @@ -15,7 +15,6 @@ public class RuralHouse implements Serializable { private String district; private HouseFeatures features; public Vector offers; - public boolean isAccepted; public RuralHouse() { super(); @@ -99,59 +98,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 getOffers(Date firstDay, Date lastDay) { - Vector availableOffers = new Vector(); - Iterator 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 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 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,5 +113,11 @@ public class RuralHouse implements Serializable { return null; } + + + public Vector getAllOffers() { + + return this.offers; + } } diff --git a/ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java b/ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java index a268b46..c26d9df 100644 --- a/ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java +++ b/ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java @@ -79,10 +79,10 @@ public class BookRuralHouseConfirmationWindow extends JFrame { jTextField3.setBounds(new Rectangle(180, 140, 115, 25)); jTextField3.setEditable(false); - jTextField3.setText(Float.toString(book.getPrice()) + " �"); + jTextField3.setText(Float.toString(book.getOffer().getPrice()) + " �"); jTextField4.setBounds(new Rectangle(180, 175, 115, 25)); jTextField4.setEditable(false); - jTextField4.setText(Float.toString(book.getPrice()*(float)0.2) + " �"); + jTextField4.setText(Float.toString(book.getOffer().getPrice()*(float)0.2) + " �"); this.getContentPane().add(jTextField4, null); this.getContentPane().add(jTextField3, null); this.getContentPane().add(jLabel5, null); diff --git a/ruralHouses client/src/gui/HouseFeaturesGUI.java b/ruralHouses client/src/gui/HouseFeaturesGUI.java index 327ee05..62e81e9 100644 --- a/ruralHouses client/src/gui/HouseFeaturesGUI.java +++ b/ruralHouses client/src/gui/HouseFeaturesGUI.java @@ -234,6 +234,7 @@ public class HouseFeaturesGUI extends JFrame { row = table.getSelectedRow(); } }); + Enumeration rhs = rh.getAllOffers().elements(); while (rhs.hasMoreElements()) { Offer of = rhs.nextElement(); diff --git a/ruralHouses client/src/gui/ModifyOfferGUI.java b/ruralHouses client/src/gui/ModifyOfferGUI.java index 9259130..d5422bf 100644 --- a/ruralHouses client/src/gui/ModifyOfferGUI.java +++ b/ruralHouses client/src/gui/ModifyOfferGUI.java @@ -75,7 +75,6 @@ public class ModifyOfferGUI extends JFrame { this.setSize(new Dimension(513, 433)); this.setTitle("Set availability"); -<<<<<<< HEAD try { om = (OfferInterface) Naming @@ -91,8 +90,7 @@ public class ModifyOfferGUI extends JFrame { } catch (RemoteException e1) { e1.printStackTrace(); } -======= ->>>>>>> 25898b619dd708c9f15a44200b545cac11404b73 + jComboBox1 = new JComboBox(Hlist); diff --git a/ruralHouses client/src/gui/listOfOffers.java b/ruralHouses client/src/gui/listOfOffers.java index 76006af..1a49f1c 100644 --- a/ruralHouses client/src/gui/listOfOffers.java +++ b/ruralHouses client/src/gui/listOfOffers.java @@ -17,6 +17,7 @@ import javax.swing.table.DefaultTableModel; import domain.Offer; import domain.Owner; +import domain.RuralHouse; public class listOfOffers extends JFrame { @@ -51,8 +52,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(); + 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); diff --git a/ruralHouses/src/businessLogic/AdminManager.java b/ruralHouses/src/businessLogic/AdminManager.java index e7b38c9..688cc9c 100644 --- a/ruralHouses/src/businessLogic/AdminManager.java +++ b/ruralHouses/src/businessLogic/AdminManager.java @@ -67,8 +67,6 @@ public class AdminManager extends UnicastRemoteObject implements AdminInterface } - - public boolean addAccountRequest(String usr, String pss, Owner ow) throws RemoteException { diff --git a/ruralHouses/src/businessLogic/BookingManager.java b/ruralHouses/src/businessLogic/BookingManager.java index 601eb3a..985bf56 100644 --- a/ruralHouses/src/businessLogic/BookingManager.java +++ b/ruralHouses/src/businessLogic/BookingManager.java @@ -23,10 +23,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(); @@ -37,39 +35,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 result = db.queryByExample(b); - if (!result.hasNext()){ - theBookingManager = new BookingManager(); - db.store(theBookingManager); - db.commit(); - } else theBookingManager=(BookingManager)result.next(); - return theBookingManager; - } public void removeDenyBooking(Booking b) throws RemoteException{ b.getOffer().getBookings().remove(b); diff --git a/ruralHouses/src/businessLogic/HouseManager.java b/ruralHouses/src/businessLogic/HouseManager.java index fb3e664..0233811 100644 --- a/ruralHouses/src/businessLogic/HouseManager.java +++ b/ruralHouses/src/businessLogic/HouseManager.java @@ -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 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 index 9042bd2..0000000 --- a/ruralHouses/src/businessLogic/OwnerManager.java +++ /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 getOwners() throws RemoteException, - Exception { - - - return dbMngr.getOwners(); - } - - -} diff --git a/ruralHouses/src/common/BookingInterface.java b/ruralHouses/src/common/BookingInterface.java index 8262f30..0d2db53 100644 --- a/ruralHouses/src/common/BookingInterface.java +++ b/ruralHouses/src/common/BookingInterface.java @@ -13,7 +13,6 @@ import exceptions.OfferCanNotBeBooked; public interface BookingInterface extends Remote { - public int getNumber() throws RemoteException; public void removeDenyBooking(Booking b) throws RemoteException; diff --git a/ruralHouses/src/common/HouseInterface.java b/ruralHouses/src/common/HouseInterface.java index e256ff7..9699e05 100644 --- a/ruralHouses/src/common/HouseInterface.java +++ b/ruralHouses/src/common/HouseInterface.java @@ -23,8 +23,7 @@ public interface HouseInterface extends Remote { * * @return a Set of rural houses */ - public Vector 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 index c96e013..0000000 --- a/ruralHouses/src/common/OwnerInterface.java +++ /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 getOwners() throws RemoteException, - Exception; - -} diff --git a/ruralHouses/src/configuration/___IntNames.java b/ruralHouses/src/configuration/___IntNames.java new file mode 100644 index 0000000..462ff65 --- /dev/null +++ b/ruralHouses/src/configuration/___IntNames.java @@ -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"; + +} diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index d8a59f2..baab98a 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -319,12 +319,12 @@ public class DB4oManager { openSDB(); RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(), null, - ruralHouse.getDescription(), ruralHouse.getDistrict(), null); + null, null, null); ObjectSet 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); @@ -371,24 +371,6 @@ public class DB4oManager { } } - - public Vector getAllRuralHouses() throws RemoteException, - Exception { - - if (c.isDatabaseLocal() == false) - openSDB(); - else - openDB(); - - try { - RuralHouse proto = new RuralHouse(null, null, null, null, null); - ObjectSet result = db.queryByExample(proto); - return new Vector(result); - } finally { - db.close(); - } - } - public boolean existsOverlappingOffer(RuralHouse rh, Date firstDay, Date lastDay) throws RemoteException, OverlappingOfferExists { @@ -411,10 +393,6 @@ public class DB4oManager { } } - public static ObjectContainer getContainer() { - return db; - } - public void close() { db.close(); System.out.println("DataBase closed"); diff --git a/ruralHouses/src/dataAccess/DB4oManagerServer.java b/ruralHouses/src/dataAccess/DB4oManagerServer.java deleted file mode 100644 index 106cfff..0000000 --- a/ruralHouses/src/dataAccess/DB4oManagerServer.java +++ /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()); - - } - } -} - diff --git a/ruralHouses/src/domain/Booking.java b/ruralHouses/src/domain/Booking.java index cdde621..68575c6 100644 --- a/ruralHouses/src/domain/Booking.java +++ b/ruralHouses/src/domain/Booking.java @@ -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; } diff --git a/ruralHouses/src/domain/HouseFeatures.java b/ruralHouses/src/domain/HouseFeatures.java index e79a446..52502cb 100644 --- a/ruralHouses/src/domain/HouseFeatures.java +++ b/ruralHouses/src/domain/HouseFeatures.java @@ -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; - } } diff --git a/ruralHouses/src/domain/RuralHouse.java b/ruralHouses/src/domain/RuralHouse.java index 07259c8..27f8d7f 100644 --- a/ruralHouses/src/domain/RuralHouse.java +++ b/ruralHouses/src/domain/RuralHouse.java @@ -98,59 +98,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 getOffers(Date firstDay, Date lastDay) { - Vector availableOffers = new Vector(); - Iterator 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 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 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) { @@ -165,5 +113,11 @@ public class RuralHouse implements Serializable { return null; } + + + public Vector getAllOffers() { + + return this.offers; + } } diff --git a/ruralHouses/src/gui/.DS_Store b/ruralHouses/src/gui/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 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 v) + { + try + { + jbInit(v); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + private void jbInit(Vector v) throws Exception + { + this.getContentPane().setLayout(null); + this.setSize(new Dimension(513, 433)); + this.setTitle("Set availability"); + + + jComboBox1 = new JComboBox(v); + jComboBox1.setBounds(new Rectangle(115, 30, 115, 20)); + jLabel1.setText("List of houses:"); + jLabel1.setBounds(new Rectangle(25, 30, 95, 20)); + jLabel2.setText("First day :"); + jLabel2.setBounds(new Rectangle(25, 75, 85, 25)); + jTextField1.setBounds(new Rectangle(25, 265, 220, 25)); + jTextField1.setEditable(false); + jLabel3.setText("Last day :"); + jLabel3.setBounds(new Rectangle(260, 75, 75, 25)); + jTextField2.setBounds(new Rectangle(260, 265, 220, 25)); + jTextField2.setEditable(false); + jLabel4.setText("Price:"); + jLabel4.setBounds(new Rectangle(260, 30, 75, 20)); + jTextField3.setBounds(new Rectangle(350, 30, 115, 20)); + jTextField3.setText("0"); + jButton1.setText("Accept"); + jButton1.setBounds(new Rectangle(100, 360, 130, 30)); + jTextField3.addFocusListener(new FocusListener() + { + public void focusGained(FocusEvent e) + { + } + + public void focusLost(FocusEvent e) + { + jTextField3_focusLost(); + } + }); + jButton1.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + jButton1_actionPerformed(e); + } + }); + jButton2.setText("Cancel"); + jButton2.setBounds(new Rectangle(270, 360, 130, 30)); + jButton2.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + jButton2_actionPerformed(e); + } + }); + jLabel5.setBounds(new Rectangle(100, 320, 300, 20)); + jLabel5.setForeground(Color.red); + jLabel5.setSize(new Dimension(305, 20)); + jCalendar1.setBounds(new Rectangle(25, 100, 220, 165)); + jCalendar2.setBounds(new Rectangle(260, 100, 220, 165)); + + // Code for JCalendar + this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent propertychangeevent) + { + if (propertychangeevent.getPropertyName().equals("locale")) + { + jCalendar1.setLocale((Locale) propertychangeevent.getNewValue()); + DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale()); + jTextField1.setText(dateformat.format(calendarInicio.getTime())); + } + else if (propertychangeevent.getPropertyName().equals("calendar")) + { + calendarInicio = (Calendar) propertychangeevent.getNewValue(); + DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale()); + jTextField1.setText(dateformat1.format(calendarInicio.getTime())); + jCalendar1.setCalendar(calendarInicio); + } + } + }); + + this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent propertychangeevent) + { + if (propertychangeevent.getPropertyName().equals("locale")) + { + jCalendar2.setLocale((Locale) propertychangeevent.getNewValue()); + DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar2.getLocale()); + jTextField2.setText(dateformat.format(calendarFin.getTime())); + } + else if (propertychangeevent.getPropertyName().equals("calendar")) + { + calendarFin = (Calendar) propertychangeevent.getNewValue(); + DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar2.getLocale()); + jTextField2.setText(dateformat1.format(calendarFin.getTime())); + jCalendar2.setCalendar(calendarFin); + } + } + }); + + + this.getContentPane().add(jCalendar2, null); + this.getContentPane().add(jCalendar1, null); + this.getContentPane().add(jLabel5, null); + this.getContentPane().add(jButton2, null); + this.getContentPane().add(jButton1, null); + this.getContentPane().add(jTextField3, null); + this.getContentPane().add(jLabel4, null); + this.getContentPane().add(jTextField2, null); + this.getContentPane().add(jLabel3, null); + this.getContentPane().add(jTextField1, null); + this.getContentPane().add(jLabel2, null); + this.getContentPane().add(jLabel1, null); + this.getContentPane().add(jComboBox1, null); + 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 index 0000000..eef2ba4 --- /dev/null +++ b/ruralHouses/src/gui/AdminMenuGUI.java @@ -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; + +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, 473); + 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.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new listOfAdditionRequestsGUI(); + a.setVisible(true); + } + }); + + JButton btnDel = new JButton("Delete Requests"); + btnDel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new listOfRemovalRequestsGUI(); + a.setVisible(true); + } + }); + + JButton btnOwneraddition = new JButton("OwnerAddition"); + btnOwneraddition.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new listOfOwnerAddittionRequests(); + 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.TRAILING, false) + .addComponent(btnOwneraddition, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(btnDel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE) + .addComponent(btnAdd, Alignment.LEADING, 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(btnAdd, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) + .addGap(58) + .addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) + .addGap(52) + .addComponent(btnOwneraddition, GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE) + .addContainerGap()) + ); + contentPane.setLayout(gl_contentPane); + } +} diff --git a/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java b/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java new file mode 100644 index 0000000..c26d9df --- /dev/null +++ b/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java @@ -0,0 +1,102 @@ +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()) + " �"); + jTextField4.setBounds(new Rectangle(180, 175, 115, 25)); + jTextField4.setEditable(false); + jTextField4.setText(Float.toString(book.getOffer().getPrice()*(float)0.2) + " �"); + 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 index 0000000..d3a79e4 --- /dev/null +++ b/ruralHouses/src/gui/DeleteOfferGUI.java @@ -0,0 +1,145 @@ +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.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.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 Owner owner; + private JLabel feedback; + private JComboBox comboBox; + private JComboBox comboBox_1; + private JButton btnDelete; + + /** + * Create the frame. + */ + public DeleteOfferGUI(Owner o) { + this.owner = o; + setBounds(100, 100, 450, 300); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + + comboBox = new JComboBox(this.owner.getRuralHouses()); + comboBox.setBounds(101, 38, 314, 20); + + comboBox_1 = new JComboBox(); + comboBox_1.setBounds(101, 76, 314, 20); + Vector vo = ((RuralHouse) comboBox.getSelectedItem()).offers; + 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 vo = ((RuralHouse) comboBox.getSelectedItem()).offers; + 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/HouseFeaturesGUI.java b/ruralHouses/src/gui/HouseFeaturesGUI.java new file mode 100644 index 0000000..62e81e9 --- /dev/null +++ b/ruralHouses/src/gui/HouseFeaturesGUI.java @@ -0,0 +1,319 @@ +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 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 rhs = rh.getAllOffers().elements(); + while (rhs.hasMoreElements()) { + Offer of = rhs.nextElement(); + if (of.getBookings() != null) { + Vector row = new Vector(); + 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 book = null; + try { + if (table.getRowCount() != 0) { + Client cl = new Client(nameField.getText(), + mailField.getText(), telIn.getText()); + book = bookingM.createBooking(rh, rh.offers.get(row) + .getFirstDay(), rh.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 index 0000000..16884c3 --- /dev/null +++ b/ruralHouses/src/gui/HousesRelatedOwnerGUI.java @@ -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 index 0000000..cf075b2 --- /dev/null +++ b/ruralHouses/src/gui/LoginGUI.java @@ -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 index 0000000..691b0ca --- /dev/null +++ b/ruralHouses/src/gui/ModifyHouseGUI.java @@ -0,0 +1,236 @@ +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 houseBox; + private JComboBox comboBox; + private RuralHouse rh; + + /** + * Create the frame. + */ + public ModifyHouseGUI(final Owner o) { + this.distric=Districs.longNames(); + comboBox = new JComboBox(new DefaultComboBoxModel( + + 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 list = null; + try { + list = hm.getHouses(o, null, null, 0, 0, 0, 0, 0); + } catch (RemoteException e1) { + e1.printStackTrace(); + } + + houseBox = new JComboBox(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 index 0000000..d5422bf --- /dev/null +++ b/ruralHouses/src/gui/ModifyOfferGUI.java @@ -0,0 +1,333 @@ +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 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 comboBox_o; + private Vector 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(Hlist); + + comboBox_o = new JComboBox( + ((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 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 index 0000000..fe2d073 --- /dev/null +++ b/ruralHouses/src/gui/OffersRelatedOwnerGUI.java @@ -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 index 0000000..244b242 --- /dev/null +++ b/ruralHouses/src/gui/OwnerMenuGUI.java @@ -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 index 0000000..5a4ffe9 --- /dev/null +++ b/ruralHouses/src/gui/OwnerRegistrationGUI.java @@ -0,0 +1,162 @@ +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) { + + 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(); + } + + } +} diff --git a/ruralHouses/src/gui/QueryAvailabilityGUI2.java b/ruralHouses/src/gui/QueryAvailabilityGUI2.java new file mode 100644 index 0000000..6f4358e --- /dev/null +++ b/ruralHouses/src/gui/QueryAvailabilityGUI2.java @@ -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 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(new DefaultComboBoxModel( + 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 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 index 0000000..4bd854c --- /dev/null +++ b/ruralHouses/src/gui/RequestDeleteHouseGUI.java @@ -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 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(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 index 0000000..e22a4f2 --- /dev/null +++ b/ruralHouses/src/gui/RequestNewHouseGUI.java @@ -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 comboBox; + + + /** + * Create the frame. + */ + public RequestNewHouseGUI(Owner o) { + comboBox = new JComboBox(new DefaultComboBoxModel( + 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 index 0000000..e938084 --- /dev/null +++ b/ruralHouses/src/gui/StartWindow.java @@ -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 index 0000000..d112532 --- /dev/null +++ b/ruralHouses/src/gui/listOfAdditionRequestsGUI.java @@ -0,0 +1,163 @@ +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 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)); + houses.remove(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 en = houses.elements(); + RuralHouse rh; + + while (en.hasMoreElements()) { + rh = en.nextElement(); + Vector row = new Vector(); + 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 index 0000000..982d7f2 --- /dev/null +++ b/ruralHouses/src/gui/listOfBookingRequestsGUI.java @@ -0,0 +1,140 @@ +package gui; + +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +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.BookingInterface; + +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 bookings = new Vector(); + + /** + * 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); + if (bookings.isEmpty()) + lblNewLabel + .setText("There are not bookings to be confirmed or denied"); + else + lblNewLabel.setText("List of bookings:"); + 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" }); + + // Maybe there is a better way to avoid interaction. + // table.setEnabled(false); + table.setModel(tableModel); + + JButton btnNewButton = new JButton("Confirm Booking"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + 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(); + } + } + + } + } + }); + btnNewButton.setBounds(33, 396, 169, 25); + contentPane.add(btnNewButton); + + JButton btnDenyAddition = new JButton("Deny Booking"); + btnDenyAddition.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { + Booking book = bookings.get(table.getSelectedRow()); + try { + bookM.removeDenyBooking(book); + } catch (RemoteException e) { + e.printStackTrace(); + } + + } + } + }); + btnDenyAddition.setBounds(390, 395, 169, 25); + contentPane.add(btnDenyAddition); + + Enumeration en = this.bookings.elements(); + Booking book; + while (en.hasMoreElements()) { + book = en.nextElement(); + Vector row = new Vector(); + 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); + } + + } +} diff --git a/ruralHouses/src/gui/listOfHousesGUI.java b/ruralHouses/src/gui/listOfHousesGUI.java new file mode 100644 index 0000000..c144ccc --- /dev/null +++ b/ruralHouses/src/gui/listOfHousesGUI.java @@ -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 houses; + /** + * Create the frame. + */ + public listOfHousesGUI(Vector 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 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 row = new Vector(); + 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 index 0000000..1a49f1c --- /dev/null +++ b/ruralHouses/src/gui/listOfOffers.java @@ -0,0 +1,110 @@ +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.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 offers = new Vector(); + + /** + * 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(); + 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 rhs = this.offers.elements(); + while (rhs.hasMoreElements()) { + Offer of = rhs.nextElement(); + Vector row = new Vector(); + row.add(of.getOfferNumber()); + row.add(of.getFirstDay()); + row.add(of.getLastDay()); + row.add(of.getPrice()); + row.add(of.getRuralHouse().getHouseName()); + tableModel.addRow(row); + + } + + } +} diff --git a/ruralHouses/src/gui/listOfOwnerAddittionRequests.java b/ruralHouses/src/gui/listOfOwnerAddittionRequests.java new file mode 100644 index 0000000..01aaf8f --- /dev/null +++ b/ruralHouses/src/gui/listOfOwnerAddittionRequests.java @@ -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.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 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 en = accounts.elements(); + Account acc; + + while (en.hasMoreElements()) { + acc = en.nextElement(); + Vector row = new Vector(); + 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 index 0000000..62daded --- /dev/null +++ b/ruralHouses/src/gui/listOfRemovalRequestsGUI.java @@ -0,0 +1,160 @@ +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 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 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()); + ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); + try { + hm.removeHouse(rh, rh.getOwner()); + am.removeHouseDeletionRequests(rh); + am.saveInstance(); + } catch (RemoteException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + 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 row = new Vector(); + 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/launcher/RMILauncher.java b/ruralHouses/src/launcher/RMILauncher.java index 008e371..c76316a 100644 --- a/ruralHouses/src/launcher/RMILauncher.java +++ b/ruralHouses/src/launcher/RMILauncher.java @@ -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; - } - } + } -- 2.20.1