Minor error correction and some bugs, alongside with modify offers quality of life...
authorEneko Pinzolas Murua <kelossus@localhost.localdomain>
Fri, 10 Apr 2015 10:37:22 +0000 (12:37 +0200)
committerEneko Pinzolas Murua <kelossus@localhost.localdomain>
Fri, 10 Apr 2015 10:37:22 +0000 (12:37 +0200)
12 files changed:
ruralHouses/src/businessLogic/BookingManager.java
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/domain/RuralHouse.java
ruralHouses/src/gui/BookRuralHouseGUI.java [deleted file]
ruralHouses/src/gui/HouseFeaturesGUI.java [new file with mode: 0644]
ruralHouses/src/gui/ModifyHouseGUI.java
ruralHouses/src/gui/ModifyOfferGUI.java
ruralHouses/src/gui/QueryAvailabilityGUI.java [deleted file]
ruralHouses/src/gui/QueryAvailabilityGUI2.java
ruralHouses/src/gui/StartWindow.java
ruralHouses/src/gui/TableRowRenderingTip.java [new file with mode: 0644]
ruralHouses/src/gui/listOfHousesGUI.java

index d4069fc..24dd41c 100644 (file)
@@ -1,6 +1,6 @@
 package businessLogic;
 
-import java.sql.Date;
+import java.util.Date;
 
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
index 8ec88c7..8078e78 100644 (file)
@@ -5,7 +5,7 @@ import java.io.File;
 //import java.util.Vector;
 
 import java.rmi.RemoteException;
-import java.sql.Date;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.ListIterator;
 import java.util.Vector;
@@ -37,7 +37,7 @@ public class DB4oManager {
        private static DB4oManager theDB4oManager = null;
 
        private static DB4oManagerAux theDB4oManagerAux;
-       
+
        static ConfigXML c;
 
        private DB4oManager() throws Exception {
@@ -112,12 +112,14 @@ public class DB4oManager {
                try {
                        Owner jon = new Owner("Jon");
                        Owner alfredo = new Owner("Alfredo");
-                       jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Ezkio", 3, 3, 3, 3, 3);
-                       jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Jaca", 4, 4, 4, 4, 4);
+                       jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Beatriz", 3, 3, 3, 3,
+                                       3);
+                       jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Guazate", 4, 4, 4,
+                                       4, 4);
                        jon.setBankAccount("1349 5677 21 2133567777");
-                       alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Pitillas", 5, 5, 5, 5,
-                                       5);
-                       alfredo.addRuralHouse("Murgoitz", "", "Murgia", 6, 6, 6, 6, 6);
+                       alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Vegas", 5,
+                                       5, 5, 5, 5);
+                       alfredo.addRuralHouse("Murgoitz", "", "Cedro", 6, 6, 6, 6, 6);
                        alfredo.setBankAccount("4144 0087 23 9700002133");
                        Account jonAcc = new Account("userJon", "passJon", jon);
                        Account alfredoAcc = new Account("userAlfredo", "passAlfredo",
@@ -155,6 +157,7 @@ public class DB4oManager {
        }
        
        
+
        public Offer createOffer(RuralHouse ruralHouse, Date firstDay,
                        Date lastDay, float price) throws RemoteException, Exception {
                Offer o = null;
@@ -166,8 +169,8 @@ public class DB4oManager {
 
                try {
 
-                       RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(),
-                                       null, null, null, null);
+                       RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(), null,
+                                       null, null, null);
                        ObjectSet result = db.queryByExample(proto);
                        RuralHouse rh = (RuralHouse) result.next();
                        o = rh.createOffer(theDB4oManagerAux.offerNumber++, firstDay,
@@ -195,7 +198,6 @@ public class DB4oManager {
 
                try {
 
-                       
                        db.store(offer);
                        db.commit();
 
@@ -207,9 +209,10 @@ public class DB4oManager {
                }
                return offer;
        }
-       
+
        @SuppressWarnings("finally")
-       public void deleteOffer(RuralHouse rh, Offer offer) throws RemoteException, Exception {
+       public void deleteOffer(RuralHouse rh, Offer offer) throws RemoteException,
+                       Exception {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
@@ -228,7 +231,6 @@ public class DB4oManager {
                        db.close();
                }
        }
-       
 
        /**
         * This method creates a book with a corresponding parameters
@@ -253,9 +255,8 @@ public class DB4oManager {
                        if (c.isDatabaseLocal() == false)
                                openSDB();
 
-                       RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(),
-                                       null, ruralHouse.getDescription(), ruralHouse.getDistrict(),
-                                       null);
+                       RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(), null,
+                                       ruralHouse.getDescription(), ruralHouse.getDistrict(), null);
                        ObjectSet result = db.queryByExample(proto);
                        RuralHouse rh = (RuralHouse) result.next();
 
@@ -336,10 +337,9 @@ public class DB4oManager {
 
                try {
 
-                       RuralHouse rhn = (RuralHouse) db
-                                       .queryByExample(
-                                                       new RuralHouse(rh.getHouseName(), null, null,
-                                                                       null, null)).next();
+                       RuralHouse rhn = (RuralHouse) db.queryByExample(
+                                       new RuralHouse(rh.getHouseName(), null, null, null, null))
+                                       .next();
                        if (rhn.overlapsWith(firstDay, lastDay) != null)
                                throw new OverlappingOfferExists();
                        else
@@ -400,8 +400,8 @@ public class DB4oManager {
                        openDB();
 
                boolean stored = false;
-               RuralHouse house = new RuralHouse(rh.getHouseName(), null, null,
-                               null, null);
+               RuralHouse house = new RuralHouse(rh.getHouseName(), null, null, null,
+                               null);
                try {
                        ObjectSet<Owner> result = db.queryByExample(house);
                        if (result.isEmpty()) {
@@ -415,18 +415,17 @@ public class DB4oManager {
                return stored;
        }
 
-
        public void removeHouse(RuralHouse rh, Owner owner) {
 
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
-                       openDB();               
+                       openDB();
                try {
                        ObjectSet<RuralHouse> result = db.queryByExample(rh);
                        if (!result.isEmpty()) {
                                RuralHouse found = (RuralHouse) result.get(0);
-//                             db.delete(found.getOwner());
+                               // db.delete(found.getOwner());
                                db.store(owner);
                                db.delete(found);
                                db.commit();
@@ -438,10 +437,10 @@ public class DB4oManager {
                }
 
        }
-       
-       public Vector<RuralHouse> getRuralHousesByTown(String town){
-               RuralHouse rh = new RuralHouse(null,null,null,town,null);
-               
+
+       public Vector<RuralHouse> getRuralHousesByTown(String town) {
+               RuralHouse rh = new RuralHouse(null, null, null, town, null);
+
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
@@ -458,49 +457,50 @@ public class DB4oManager {
                }
 
        }
-       public RuralHouse getRuralHouseByName(String name){
-               RuralHouse rh = new RuralHouse(name,null,null,null,null);
-               
+
+       public RuralHouse getRuralHouseByName(String name) {
+               RuralHouse rh = new RuralHouse(name, null, null, null, null);
+
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
                        openDB();
-               
-               try{
+
+               try {
                        ObjectSet<RuralHouse> result = db.queryByExample(rh);
                        Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
-                       while(result.hasNext())
+                       while (result.hasNext())
                                ruralHouses.add(result.next());
                        db.close();
-                       return ruralHouses.get(0);
-               } catch (NullPointerException e){
+                       if (!ruralHouses.isEmpty())
+                               return ruralHouses.get(0);
+                       else
+                               return null;
+               } catch (NullPointerException e) {
                        return null;
                }
-               
-               
-               
+
        }
-       
-       public Vector<RuralHouse> getRuralHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv){
-               HouseFeatures fea = new HouseFeatures(nBed,nKit,nBath,nLiv,nPark);
-               RuralHouse rh = new RuralHouse(null,null,null,town,fea);
+
+       public Vector<RuralHouse> getRuralHouses(String town, int nBed, int nKit,
+                       int nBath, int nPark, int nLiv) {
+               HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark);
+               RuralHouse rh = new RuralHouse(null, null, null, town, fea);
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
                        openDB();
-               
-               try{
+
+               try {
                        ObjectSet<RuralHouse> result = db.queryByExample(rh);
                        Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
-                       while(result.hasNext())
+                       while (result.hasNext())
                                ruralHouses.add(result.next());
                        db.close();
                        return ruralHouses;
-               } catch (NullPointerException e){
+               } catch (NullPointerException e) {
                        return null;
                }
-               
-               
-               
+
        }
 }
index 2e61137..423d5e7 100644 (file)
@@ -130,7 +130,17 @@ public class RuralHouse implements Serializable {
                return availableOffers;
        }
        
-       
+       public Vector<Offer> getAllOffers() {
+               Vector<Offer> availableOffers=new Vector<Offer>();
+               Iterator<Offer> e=offers.iterator();
+               Offer offer;
+               while (e.hasNext()){
+                       offer=e.next();
+                       if ( (offer.getBooking()==null) )
+                               availableOffers.add(offer);
+               }
+               return availableOffers;
+       }
        /**
         * This method obtains the offer that match exactly with a given dates that has not been booked
         * 
@@ -149,6 +159,7 @@ public class RuralHouse implements Serializable {
                return null;            
        }
        
+       
 public Offer overlapsWith( Date firstDay,  Date lastDay) {
                
                Iterator<Offer> e=offers.iterator();
diff --git a/ruralHouses/src/gui/BookRuralHouseGUI.java b/ruralHouses/src/gui/BookRuralHouseGUI.java
deleted file mode 100644 (file)
index 7a262fc..0000000
+++ /dev/null
@@ -1,267 +0,0 @@
-package gui;
-
-import businessLogic.BookingManager;
-import businessLogic.HouseManager;
-
-import com.toedter.calendar.*;
-
-import domain.Booking;
-import domain.RuralHouse;
-import exceptions.OfferCanNotBeBooked;
-
-import java.beans.*;
-import java.sql.Date;
-import java.text.*;
-import java.util.*;
-
-import javax.swing.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-
-
-public class BookRuralHouseGUI extends JFrame {
-private static final long serialVersionUID = 1L;
-public static final long MILLSECS_PER_DAY= 24 * 60 * 60 * 1000;
-
-  private JLabel jLabel1 = new JLabel();
-  private JComboBox jComboBox1;
-  Vector<RuralHouse> ruralHouses;
-  private JLabel jLabel2 = new JLabel();
-  private JLabel jLabel3 = new JLabel();
-  private JLabel jLabel4 = new JLabel();
-  private JTextField jTextField2 = new JTextField();
-  private JTextField jTextField3 = new JTextField();
-  private JTextField jTextField4 = new JTextField();
-  private JButton jButton2 = new JButton();
-  private JButton jButton3 = new JButton();
-  
-  // Code for JCalendar
-  private JCalendar jCalendar1 = new JCalendar();
-  private Calendar calendarMio = null;
-  private JLabel jLabel5 = new JLabel();
-  
-  
-
-public BookRuralHouseGUI()
- {
-    try
-    {
-      jbInit();
-      
-     
-    }
-    catch(Exception e)
-    {
-      e.printStackTrace();
-    }
-  }
-  public BookRuralHouseGUI(String houseName,Date firstDay,Date lastDay)
-  {
-    try
-    {
-      jbInit();
-      
-      
-      // Put the "houseNumber", "firstDay" and "lastDay" in the graphical components of the user interface
-      for (int i=0; i<ruralHouses.size();i++){
-         if (((RuralHouse)ruralHouses.get(i)).getHouseName()==houseName) {
-                 jComboBox1.setSelectedIndex(i);
-                 break;
-         }
-      }
-      
-      Calendar c=new GregorianCalendar();
-      c.setTime(firstDay);
-      //jCalendar1.setCalendar(new GregorianCalendar(firstDay.getYear()+1900,firstDay.getMonth(),firstDay.getDate()));
-      jCalendar1.setCalendar(c);
-      
-      long numberOfDays = (long) (lastDay.getTime()-firstDay.getTime()) / MILLSECS_PER_DAY;
-      jTextField3.setText(Long.toString(numberOfDays));
-      
-
-      
-    }
-    catch(Exception e)
-    {
-      e.printStackTrace();
-    }
-  }
-
-  private void jbInit() throws Exception
-  {
-    this.getContentPane().setLayout(null);
-    this.setSize(new Dimension(410, 413));
-    this.setTitle("Book Rural House");
-    jLabel1.setText("Rural house:");
-    HouseManager houseM = new HouseManager();
-       ruralHouses=houseM.getAllRuralHouses();
-
-       jComboBox1 = new JComboBox(ruralHouses);
-
-    jLabel1.setBounds(new Rectangle(15, 10, 115, 20));
-    jComboBox1.setBounds(new Rectangle(120, 10, 175, 20));
-
-    
-    jTextField3.addFocusListener(new FocusListener()
-      {
-          public void focusGained(FocusEvent e)
-          {
-          }
-  
-          public void focusLost(FocusEvent e)
-          {
-            jTextField3_focusLost();
-          }
-      });
-    jTextField4.addFocusListener(new FocusListener()
-      {
-          public void focusGained(FocusEvent e)
-          {
-          }
-  
-          public void focusLost(FocusEvent e)
-          {
-            jTextField4_focusLost();
-          }
-      });
-    jLabel2.setText("Arrival day:");
-    jLabel2.setBounds(new Rectangle(15, 40, 115, 20));
-    jLabel3.setText("Number of nights:");
-    jLabel3.setBounds(new Rectangle(15, 240, 115, 20));
-    jLabel4.setText("Telephone contact number:");
-    jLabel4.setBounds(new Rectangle(15, 270, 140, 20));
-    jTextField2.setBounds(new Rectangle(155, 205, 140, 20));
-    jTextField2.setEditable(false);
-    jTextField3.setBounds(new Rectangle(155, 240, 140, 20));
-    jTextField3.setText("0");
-    jTextField4.setBounds(new Rectangle(155, 270, 140, 20));
-    jTextField4.setText("0");
-    jButton2.setText("Accept");
-    jButton2.setBounds(new Rectangle(50, 345, 130, 30));
-    jButton2.setSize(new Dimension(130, 30));
-    jButton2.addActionListener(new ActionListener()
-      {
-        public void actionPerformed(ActionEvent e)
-        {
-               // House code
-               RuralHouse house=(RuralHouse)jComboBox1.getSelectedItem();
-               // Arrival date
-               Date firstDay= new Date(jCalendar1.getCalendar().getTime().getTime());
-
-               firstDay=Date.valueOf(firstDay.toString());
-               // Last day
-               // Number of days expressed in milliseconds
-               long nights=1000*60*60*24* Integer.parseInt(jTextField3.getText());
-               Date lastDay= new Date((long)(firstDay.getTime()+nights));
-               // Telephone contact
-               String telephone=jTextField4.getText();
-               try {
-                               
-                       //Obtain the business logic from a StartWindow class (local or remote)
-                       BookingManager bookingM = new BookingManager();
-                                               
-                       Booking book=bookingM.createBooking(house, firstDay, lastDay, telephone);
-                               if (book!=null) {
-                               BookRuralHouseConfirmationWindow confirmWindow=new BookRuralHouseConfirmationWindow(book);
-                               confirmWindow.setVisible(true);
-                               jLabel5.setText("Booking made");
-
-                               }
-                               else jLabel5.setText("There is not available offer for these dates");
-                       } catch (OfferCanNotBeBooked e1) {
-                               jLabel5.setText("Error: It is not possible to book");
-                               JFrame a = new QueryAvailabilityGUI();
-                           a.setVisible(true);
-                       
-        } catch (Exception e1) {
-                       
-                       e1.printStackTrace();
-        }}
-      });
-    jButton3.setText("Cancel");
-    jButton3.setBounds(new Rectangle(220, 345, 130, 30));
-    jButton3.setSize(new Dimension(130, 30));
-    jButton3.addActionListener(new ActionListener()
-      {
-        public void actionPerformed(ActionEvent e)
-        {
-          jButton3_actionPerformed(e);
-        }
-      });
-    jLabel5.setBounds(new Rectangle(50, 310, 300, 20));
-    jLabel5.setForeground(Color.red);
-    jCalendar1.setBounds(new Rectangle(155, 50, 235, 145));
-    this.getContentPane().add(jCalendar1, null);
-    this.getContentPane().add(jLabel5, null);
-    this.getContentPane().add(jButton3, null);
-    this.getContentPane().add(jButton2, null);
-    this.getContentPane().add(jTextField4, null);
-    this.getContentPane().add(jTextField3, null);
-    this.getContentPane().add(jTextField2, null);
-    this.getContentPane().add(jLabel4, null);
-    this.getContentPane().add(jLabel3, null);
-    this.getContentPane().add(jLabel2, null);
-    this.getContentPane().add(jComboBox1, null);
-    this.getContentPane().add(jLabel1, null);
-    
-    // Code for JCalendar
-    this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener()
-    {
-      public void propertyChange(PropertyChangeEvent propertychangeevent)
-      {
-        if (propertychangeevent.getPropertyName().equals("locale"))
-        {
-          jCalendar1.setLocale((Locale) propertychangeevent.getNewValue());
-          DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale());
-          jTextField2.setText(dateformat.format(calendarMio.getTime()));
-          
-        }
-        else if (propertychangeevent.getPropertyName().equals("calendar"))
-        {
-          calendarMio = (Calendar) propertychangeevent.getNewValue();
-          DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
-          jTextField2.setText(dateformat1.format(calendarMio.getTime()));
-          jCalendar1.setCalendar(calendarMio);
-        }
-      } 
-    });
-  }
-
-  private void jButton3_actionPerformed(ActionEvent e)
-  {
-    this.setVisible(false);
-  }
-
-  public void setConfirmBooking(boolean b){
-         if (b) jLabel5.setText("Booking made");
-  }
- private void jTextField3_focusLost()
- {
-   try
-  {
-    new Integer (jTextField3.getText());
-    jLabel5.setText("");
-  }
-  catch (NumberFormatException ex)
-  {
-    jLabel5.setText("Error: Introduce a number");
-  }
- }
- private void jTextField4_focusLost()
- {
-   try
-  {
-    new Integer (jTextField4.getText());
-    jLabel5.setText("");
-  }
-  catch (NumberFormatException ex)
-  {
-    jLabel5.setText("Error: Introduce a number");
-  }
- }
-}
\ No newline at end of file
diff --git a/ruralHouses/src/gui/HouseFeaturesGUI.java b/ruralHouses/src/gui/HouseFeaturesGUI.java
new file mode 100644 (file)
index 0000000..ecc44ab
--- /dev/null
@@ -0,0 +1,258 @@
+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.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 businessLogic.BookingManager;
+import domain.Booking;
+import domain.Offer;
+import domain.RuralHouse;
+import exceptions.OfferCanNotBeBooked;
+
+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 DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();
+       private RuralHouse rh;
+       private JTextField telIn;
+       private int row;
+
+       /**
+        * Create the frame.
+        */
+
+       public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay, final Date LastDay) {
+               this.rh = RH;
+               this.getContentPane().setLayout(null);
+               setBounds(100, 100, 500, 583);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+
+               lblDistrict = new JLabel("District:");
+               lblDistrict.setBounds(23, 67, 70, 14);
+               lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               District_f = new JTextField();
+               District_f.setEditable(false);
+               District_f.setBounds(103, 64, 86, 20);
+               District_f.setColumns(10);
+
+               lblDescription = new JLabel("Description:");
+               lblDescription.setBounds(215, 67, 90, 14);
+               lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               description_f = new JTextField();
+               description_f.setEditable(false);
+               description_f.setBounds(238, 99, 178, 129);
+               description_f.setColumns(10);
+
+               lblKitchen = new JLabel("Kitchens:");
+               lblKitchen.setBounds(23, 211, 70, 14);
+               lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               kitchens_f = new JTextField();
+               kitchens_f.setEditable(false);
+               kitchens_f.setBounds(103, 202, 86, 20);
+               kitchens_f.setColumns(10);
+
+               lblRooms = new JLabel("Rooms:");
+               lblRooms.setBounds(23, 102, 70, 14);
+               lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               rooms_f = new JTextField();
+               rooms_f.setEditable(false);
+               rooms_f.setBounds(103, 99, 86, 20);
+               rooms_f.setColumns(10);
+
+               lblLivings = new JLabel("Living rooms:");
+               lblLivings.setBounds(30, 236, 63, 14);
+               lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               lRooms_f = new JTextField();
+               lRooms_f.setEditable(false);
+               lRooms_f.setBounds(103, 233, 86, 20);
+               lRooms_f.setColumns(10);
+
+               lblParkings = new JLabel("Parkings:");
+               lblParkings.setBounds(23, 174, 70, 14);
+               lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               parkings_f = new JTextField();
+               parkings_f.setEditable(false);
+               parkings_f.setBounds(103, 171, 86, 20);
+               parkings_f.setColumns(10);
+
+               lblBaths = new JLabel("Baths:");
+               lblBaths.setBounds(23, 143, 70, 14);
+               lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               baths_f = new JTextField();
+               baths_f.setEditable(false);
+               baths_f.setBounds(103, 140, 86, 20);
+               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, 505, 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(152, 277, 261, 23);
+               contentPane.add(lblNewLabel);
+               
+               JLabel lblNewLabel_1 = new JLabel("Telephone num:");
+               lblNewLabel_1.setBounds(10, 509, 83, 14);
+               contentPane.add(lblNewLabel_1);
+               
+               telIn = new JTextField();
+               telIn.setBounds(99, 505, 129, 20);
+               contentPane.add(telIn);
+               telIn.setColumns(10);
+               table.addMouseListener( new MouseAdapter(){                     
+                       @Override
+                       public void mouseClicked(MouseEvent arg0) {
+                               row = table.getSelectedRow();
+                       }
+               });
+               Enumeration<Offer> rhs = rh.getAllOffers().elements();
+               while (rhs.hasMoreElements()) {
+                       Offer of = rhs.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(of.getOfferNumber());
+                       row.add(of.getFirstDay());
+                       row.add(of.getLastDay());
+                       row.add(of.getPrice());
+                       tableModel.addRow(row);
+
+               }
+               table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+                       @Override
+                       public Component getTableCellRendererComponent(JTable table,
+                                       Object value, boolean isSelected, boolean hasFocus,
+                                       int row, int col) {
+
+                               super.getTableCellRendererComponent(table, value, isSelected,
+                                               hasFocus, row, col);
+
+                               Date firstDay = (Date) table.getModel().getValueAt(row, 1);
+                               Date lastDay = (Date) table.getModel().getValueAt(row, 2);
+                               if (FirstDay != 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) {
+               BookingManager bookingM = new BookingManager();
+               //RegExp to see if telephone number is correct??TODO
+               Booking book = null;
+               try {
+                       book = bookingM.createBooking(rh, rh.offers.get(row).getFirstDay(), rh.offers.get(row).getLastDay(), telIn.getText());
+               } catch (OfferCanNotBeBooked e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               if (book != null) {
+                       BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
+                                       book);
+                       confirmWindow.setVisible(true);
+               }
+       }
+}
index 737267e..497829e 100644 (file)
@@ -65,7 +65,7 @@ public class ModifyHouseGUI extends JFrame {
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
                
-               JLabel lblCode = new JLabel("House Code:");
+               JLabel lblCode = new JLabel("House Name:");
                lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
                
                lblDistrict = new JLabel("District:");
index 651d85c..853ce07 100644 (file)
@@ -56,7 +56,10 @@ public class ModifyOfferGUI extends JFrame  {
 
                jComboBox1 = new JComboBox<RuralHouse>(v);
                
-               comboBox_o = new JComboBox<Offer>();
+               comboBox_o = new JComboBox<Offer>(((RuralHouse)jComboBox1.getSelectedItem()).getAllOffers());
+               DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
+               jTextField1.setText(dateformat1.format(((Offer) comboBox_o.getSelectedItem()).getFirstDay()));
+               jTextField2.setText(dateformat1.format(((Offer) comboBox_o.getSelectedItem()).getLastDay()));
                
                jComboBox1.setBounds(new Rectangle(115, 12, 115, 20));
                jLabel1.setText("List of houses:");
diff --git a/ruralHouses/src/gui/QueryAvailabilityGUI.java b/ruralHouses/src/gui/QueryAvailabilityGUI.java
deleted file mode 100644 (file)
index 557cca4..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-package gui;
-
-import businessLogic.HouseManager;
-
-import com.toedter.calendar.JCalendar;
-
-import domain.Offer;
-import domain.RuralHouse;
-
-import javax.swing.*;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.beans.*;
-import java.sql.Date;
-import java.text.DateFormat;
-import java.util.*;
-
-import javax.swing.table.DefaultTableModel;
-
-
-
-
-
-public class QueryAvailabilityGUI extends JFrame {
-private static final long serialVersionUID = 1L;
-
-  private JLabel jLabel1 = new JLabel();
-  private JLabel jLabel2 = new JLabel();
-  private JTextField jTextField2 = new JTextField();
-  private JLabel jLabel3 = new JLabel();
-  private JTextField jTextField3 = new JTextField();
-  private JButton jButton1 = new JButton();
-  private JButton jButton2 = new JButton();
-  
-  // Code for JCalendar
-  private JCalendar jCalendar1 = new JCalendar();
-  private Calendar calendarMio = null;
-  private JLabel jLabel4 = new JLabel();
-  private JScrollPane scrollPane = new JScrollPane();
-  private JComboBox comboBox ;
-  private JTable table;
-  private DefaultTableModel tableModel;
-  private final JLabel labelNoOffers = new JLabel("");
-  private String[] columnNames = new String[] {
-               "Offer#", "Rural House", "First Day", "Last Day", "Price"
-       };
-
-
-                                                                                                                                                                       
-  public QueryAvailabilityGUI()
-  {
-       
-    try
-    {
-      jbInit();
-    }
-    catch(Exception e)
-    {
-      e.printStackTrace();
-    }
-
-  }
-
-  private void jbInit() throws Exception
-  {
-       HouseManager houseM = new HouseManager();
-               
-       
-       
-       Vector<RuralHouse> rhs=houseM.getAllRuralHouses();
-       
-       comboBox = new JComboBox(rhs);
-       //comboBox.setModel(new DefaultComboBoxModel(rhs));
-
-       
-    this.getContentPane().setLayout(null);
-    this.setSize(new Dimension(433, 548));
-    this.setTitle("Query availability");
-    jLabel1.setText("Rural house code:");
-    jLabel1.setBounds(new Rectangle(27, 20, 128, 25));
-    jLabel2.setText("First day:");
-    jLabel2.setBounds(new Rectangle(40, 55, 75, 25));
-    jTextField2.setBounds(new Rectangle(190, 210, 155, 25));
-    jTextField2.setEditable(false);
-    jLabel3.setText("Number of nights:");
-    jLabel3.setBounds(new Rectangle(40, 250, 115, 25));
-    jTextField3.setBounds(new Rectangle(190, 250, 155, 25));
-    jTextField3.setText("0");
-    jButton1.setText("Accept");
-    jButton1.setBounds(new Rectangle(55, 455, 130, 30));
-    jButton1.addActionListener(new ActionListener()
-             {
-               public void actionPerformed(ActionEvent e)
-               {
-                 jButton1_actionPerformed(e);
-               }
-             });
-    jButton2.setText("Close");
-    jButton2.setBounds(new Rectangle(230, 455, 130, 30));
-    
-   
-    jTextField3.addFocusListener(new FocusListener()
-      {
-          public void focusGained(FocusEvent e)
-          {
-          }
-  
-          public void focusLost(FocusEvent e)
-          {
-            jTextField3_focusLost();
-          }
-      });
-    jButton2.addActionListener(new ActionListener()
-      {
-        public void actionPerformed(ActionEvent e)
-        {
-          jButton2_actionPerformed(e);
-        }
-      });
-    jLabel4.setBounds(new Rectangle(55, 300, 305, 30));
-    jLabel4.setForeground(Color.red);
-    jCalendar1.setBounds(new Rectangle(190, 60, 225, 150));
-    scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
-    
-    this.getContentPane().add(scrollPane, null);
-    
-    table = new JTable();
-    table.addMouseListener(new MouseAdapter() {
-       @Override
-       public void mouseClicked(MouseEvent e) {
-               int i=table.getSelectedRow();
-               String houseName =  (String) tableModel.getValueAt(i,1);
-                       Date firstDate=new Date(((java.util.Date)tableModel.getValueAt(i,2)).getTime());
-                       Date lastDate=new Date(((java.util.Date)tableModel.getValueAt(i,3)).getTime());
-       
-                       BookRuralHouseGUI b=new BookRuralHouseGUI(houseName,firstDate,lastDate);
-                       b.setVisible(true);}
-    });
-
-    scrollPane.setViewportView(table);
-    tableModel = new DefaultTableModel(
-                       null,
-               columnNames);
-               
-    table.setModel(tableModel);
-    this.getContentPane().add(jCalendar1, null);
-    this.getContentPane().add(jLabel4, null);
-    this.getContentPane().add(jButton2, null);
-    this.getContentPane().add(jButton1, null);
-    this.getContentPane().add(jTextField3, null);
-    this.getContentPane().add(jLabel3, null);
-    this.getContentPane().add(jTextField2, null);
-    this.getContentPane().add(jLabel2, null);
-    this.getContentPane().add(jLabel1, null);
-    comboBox.setBounds(new Rectangle(245, 22, 115, 20));
-    comboBox.setBounds(189, 22, 115, 20);
-    
-    getContentPane().add(comboBox);
-    labelNoOffers.setBounds(73, 432, 265, 14);
-    
-    getContentPane().add(labelNoOffers);
-    
-    // Codigo para el JCalendar
-    this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener()
-    {
-      public void propertyChange(PropertyChangeEvent propertychangeevent)
-      {
-        if (propertychangeevent.getPropertyName().equals("locale"))
-        {
-          jCalendar1.setLocale((Locale) propertychangeevent.getNewValue());
-          DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale());
-          jTextField2.setText(dateformat.format(calendarMio.getTime()));
-        }
-        else if (propertychangeevent.getPropertyName().equals("calendar"))
-        {
-          calendarMio = (Calendar) propertychangeevent.getNewValue();
-          DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
-          jTextField2.setText(dateformat1.format(calendarMio.getTime()));
-          jCalendar1.setCalendar(calendarMio);
-        }
-      } 
-    });
-    
-
-  }
-
-  private void jButton2_actionPerformed(ActionEvent e)
-  {
-    this.setVisible(false);
-  }
-  
-  
- private void jTextField3_focusLost()
- {
-   try
-  {
-    new Integer (jTextField3.getText());
-    jLabel4.setText("");
-  }
-  catch (NumberFormatException ex)
-  {
-    jLabel4.setText("Error: Introduce a number");
-  }
- }
-
- private void jButton1_actionPerformed(ActionEvent e)
- {             
-               // House object
-               RuralHouse rh=(RuralHouse)comboBox.getSelectedItem();
-               // First day
-               Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime());
-           //Remove the hour:minute:second:ms from the date 
-               firstDay=Date.valueOf(firstDay.toString());
-               final long diams=1000*60*60*24;
-               long nights= diams * Integer.parseInt(jTextField3.getText());
-               // Last day
-       Date lastDay= new Date((long)(firstDay.getTime()+nights));
-       
-       try {
-               
-
-               Vector<Offer> v=rh.getOffers(firstDay, lastDay);
-  
-                       Enumeration<Offer> en=v.elements();
-                       Offer of;
-                       tableModel.setDataVector(null, columnNames);
-                       if (!en.hasMoreElements())
-                               labelNoOffers.setText("There are no offers at these dates");
-                       else {
-                               labelNoOffers.setText("Select an offer if you want to book");
-
-                               while (en.hasMoreElements()) {
-                                       of=en.nextElement();
-                                       System.out.println("Offer retrieved: "+of.toString());
-                                       Vector<Object> row = new Vector<Object>();
-                                       row.add(of.getOfferNumber());
-                                       row.add(of.getRuralHouse().getHouseName());
-
-                                       // Dates are stored in db4o as java.util.Date objects instead of java.sql.Date objects
-                                       // They have to be converted into java.sql.Date objects before
-                                       Date firstDaySqlDate = new Date(of.getFirstDay().getTime());
-                                       Date lastDaySqlDate = new Date(of.getLastDay().getTime());
-                                       row.add(firstDaySqlDate);
-                                       row.add(lastDaySqlDate);
-                                       row.add(of.getPrice());
-
-                                       
-                                       tableModel.addRow(row);                                         
-                               }
-                       }
-
-               
-       } catch (Exception e1) {
-
-          labelNoOffers.setText(e1.getMessage());
-       }}      
-       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
index a12ad16..cdb3282 100644 (file)
@@ -7,7 +7,6 @@ import java.util.*;
 
 import javax.swing.*;
 
-
 import java.awt.*;
 import java.awt.event.*;
 
@@ -44,7 +43,7 @@ public class QueryAvailabilityGUI2 extends JFrame {
        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 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");
@@ -61,6 +60,7 @@ public class QueryAvailabilityGUI2 extends JFrame {
        private HouseManager houseMan = new HouseManager();
        private final JLabel lblNumberOfLivings = new JLabel("Number of Livings:");
        private final JTextField nLivings = new JTextField();
+       private final JLabel feedback = new JLabel("");
 
        public QueryAvailabilityGUI2() {
                nLivings.setText("0");
@@ -83,6 +83,7 @@ public class QueryAvailabilityGUI2 extends JFrame {
 
                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));
@@ -94,9 +95,8 @@ public class QueryAvailabilityGUI2 extends JFrame {
                jTextField2.setEditable(false);
                jLabel4.setText("Rural House name:");
                jLabel4.setBounds(new Rectangle(275, 30, 128, 20));
-               jTextField3.setEnabled(false);
                jTextField3.setBounds(new Rectangle(413, 30, 115, 20));
-               jButton1.setText("Accept");
+               jButton1.setText("Search");
                jButton1.setBounds(new Rectangle(60, 377, 165, 30));
                jButton1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
@@ -191,7 +191,7 @@ public class QueryAvailabilityGUI2 extends JFrame {
                popupMenu.add(lblNumberOfLivings);
 
                popupMenu.add(nLivings);
-
+               
                this.getContentPane().add(jCalendar2, null);
                this.getContentPane().add(jCalendar1, null);
                this.getContentPane().add(jLabel5, null);
@@ -207,13 +207,12 @@ public class QueryAvailabilityGUI2 extends JFrame {
                lblNewLabel.setBounds(115, 301, 298, 38);
 
                getContentPane().add(lblNewLabel);
-
-               district.setSelected(true);
                ;
                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
@@ -221,8 +220,11 @@ public class QueryAvailabilityGUI2 extends JFrame {
                                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);
+
                                }
                        }
                });
@@ -233,6 +235,8 @@ public class QueryAvailabilityGUI2 extends JFrame {
                                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);
                                }
@@ -243,6 +247,11 @@ public class QueryAvailabilityGUI2 extends JFrame {
                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);
 
@@ -267,14 +276,31 @@ public class QueryAvailabilityGUI2 extends JFrame {
                        listOfHousesGUI list = new listOfHousesGUI(houses);
                        list.setVisible(true);
                } else if (this.ruralHouseName.isSelected()) {
-                       // show features of specific house
-                       // TODO
+                       RuralHouse rh = houseMan.getHouseByName(jTextField3.getText());
+                       // 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 (rh != null) {
+                               HouseFeaturesGUI hou = new HouseFeaturesGUI(rh,firstDay,lastDay);
+                               hou.setVisible(true);
+                       } else {
+                               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() {
index 8d2b019..e115587 100644 (file)
@@ -4,7 +4,6 @@ package gui;
  * @author willCodeForFood
  */
 import exceptions.DB4oManagerCreationException;
-import gui.BookRuralHouseGUI;
 
 import javax.swing.*;
 
@@ -28,7 +27,6 @@ public class StartWindow extends JFrame {
        private static final long serialVersionUID = 1L;
 
        private JPanel jContentPane = null;
-       private JButton boton1 = null;
        private JButton boton2 = null;
        private JButton boton3 = null;
        private static configuration.ConfigXML c;
@@ -127,39 +125,15 @@ public class StartWindow extends JFrame {
         */
        private JPanel getJContentPane() {
                if (jContentPane == null) {
-                       GridLayout gridLayout = new GridLayout();
-                       gridLayout.setRows(4);
-                       gridLayout.setColumns(1);
                        jContentPane = new JPanel();
-                       jContentPane.setLayout(gridLayout);
+                       jContentPane.setLayout(null);
                        jContentPane.add(getLblNewLabel());
-                       jContentPane.add(getBoton2(), null);
-                       jContentPane.add(getBoton3(), null);
-                       jContentPane.add(getBoton1(), null);
+                       jContentPane.add(getBoton2());
+                       jContentPane.add(getBoton3());
                }
                return jContentPane;
        }
 
-       /**
-        * This method initializes boton1
-        * 
-        * @return javax.swing.JButton
-        */
-       private JButton getBoton1() {
-               if (boton1 == null) {
-                       boton1 = new JButton();
-                       boton1.setText("Book rural house");
-                       boton1.addActionListener(new java.awt.event.ActionListener() {
-                               public void actionPerformed(java.awt.event.ActionEvent e) {
-                                       // C?digo cedido por la univerdad
-                                       JFrame a = new BookRuralHouseGUI();
-                                       a.setVisible(true);
-                               }
-                       });
-               }
-               return boton1;
-       }
-
        /**
         * This method initializes boton2
         * 
@@ -168,6 +142,7 @@ public class StartWindow extends JFrame {
        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) {
@@ -188,6 +163,7 @@ public class StartWindow extends JFrame {
        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) {
@@ -206,6 +182,7 @@ public class StartWindow extends JFrame {
        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);
diff --git a/ruralHouses/src/gui/TableRowRenderingTip.java b/ruralHouses/src/gui/TableRowRenderingTip.java
new file mode 100644 (file)
index 0000000..860db19
--- /dev/null
@@ -0,0 +1,135 @@
+package gui;
+
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.table.*;
+import javax.swing.border.*;
+
+public class TableRowRenderingTip extends JPanel
+{
+       public TableRowRenderingTip()
+       {
+               Object[] columnNames = {"Type", "Company", "Shares", "Price", "Boolean"};
+               Object[][] data =
+               {
+                       {"Buy", "IBM", new Integer(1000), new Double(80.5), Boolean.TRUE},
+                       {"Sell", "Dell", new Integer(2000), new Double(6.25), Boolean.FALSE},
+                       {"Short Sell", "Apple", new Integer(3000), new Double(7.35), Boolean.TRUE},
+                       {"Buy", "MicroSoft", new Integer(4000), new Double(27.50), Boolean.FALSE},
+                       {"Short Sell", "Cisco", new Integer(5000), new Double(20), Boolean.TRUE}
+               };
+
+               DefaultTableModel model = new DefaultTableModel(data, columnNames)
+               {
+                       public Class getColumnClass(int column)
+                       {
+                               return getValueAt(0, column).getClass();
+                       }
+               };
+
+               JTabbedPane tabbedPane = new JTabbedPane();
+               tabbedPane.addTab("Alternating", createAlternating(model));
+               tabbedPane.addTab("Border", createBorder(model));
+               tabbedPane.addTab("Data", createData(model));
+               add( tabbedPane );
+       }
+
+       private JComponent createAlternating(DefaultTableModel model)
+       {
+               JTable table = new JTable( model )
+               {
+                       public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
+                       {
+                               Component c = super.prepareRenderer(renderer, row, column);
+
+                               //  Alternate row color
+
+                               if (!isRowSelected(row))
+                                       c.setBackground(row % 2 == 0 ? getBackground() : Color.LIGHT_GRAY);
+
+                               return c;
+                       }
+               };
+
+               table.setPreferredScrollableViewportSize(table.getPreferredSize());
+               table.changeSelection(0, 0, false, false);
+               return new JScrollPane( table );
+       }
+
+       private JComponent createBorder(DefaultTableModel model)
+       {
+
+               JTable table = new JTable( model )
+               {
+                       private Border outside = new MatteBorder(1, 0, 1, 0, Color.RED);
+                       private Border inside = new EmptyBorder(0, 1, 0, 1);
+                       private Border highlight = new CompoundBorder(outside, inside);
+
+                       public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
+                       {
+                               Component c = super.prepareRenderer(renderer, row, column);
+                               JComponent jc = (JComponent)c;
+
+                               // Add a border to the selected row
+
+                               if (isRowSelected(row))
+                                       jc.setBorder( highlight );
+
+                               return c;
+                       }
+               };
+
+               table.setPreferredScrollableViewportSize(table.getPreferredSize());
+               table.changeSelection(0, 0, false, false);
+               return new JScrollPane( table );
+       }
+
+       private JComponent createData(DefaultTableModel model)
+       {
+               JTable table = new JTable( model )
+               {
+                       public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
+                       {
+                               Component c = super.prepareRenderer(renderer, row, column);
+
+                               //  Color row based on a cell value
+
+                               if (!isRowSelected(row))
+                               {
+                                       c.setBackground(getBackground());
+                                       int modelRow = convertRowIndexToModel(row);
+                                       String type = (String)getModel().getValueAt(modelRow, 0);
+                                       if ("Buy".equals(type)) c.setBackground(Color.GREEN);
+                                       if ("Sell".equals(type)) c.setBackground(Color.YELLOW);
+                               }
+
+                               return c;
+                       }
+               };
+
+               table.setPreferredScrollableViewportSize(table.getPreferredSize());
+               table.changeSelection(0, 0, false, false);
+        table.setAutoCreateRowSorter(true);
+               return new JScrollPane( table );
+       }
+
+       public static void main(String[] args)
+       {
+               SwingUtilities.invokeLater(new Runnable() {
+                       public void run() {
+                               createAndShowGUI();
+                       }
+               });
+       }
+
+       public static void createAndShowGUI()
+       {
+               JFrame.setDefaultLookAndFeelDecorated(true);
+               JFrame frame = new JFrame("Table Row Rendering");
+               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+               frame.add( new TableRowRenderingTip() );
+               frame.pack();
+               frame.setLocationRelativeTo(null);
+               frame.setVisible(true);
+       }
+}
index 0478466..b8db0df 100644 (file)
@@ -21,6 +21,8 @@ import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;
 
 import java.awt.Component;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import java.sql.Date;
 import java.util.Enumeration;
 import java.util.LinkedList;
@@ -31,60 +33,66 @@ import javax.swing.Box;
 public class listOfHousesGUI extends JFrame {
 
        private JPanel contentPane;
-       private JTextField textField;
        private JTable table;
        private DefaultTableModel tableModel;
-
-       /**
+       private Vector<RuralHouse> houses;
+       /**
         * Create the frame.
         */
-       public listOfHousesGUI(Vector<RuralHouse> houses) {
+       public listOfHousesGUI(Vector<RuralHouse> rhs) {
                try {
-                       init(houses);
+                       this.houses=rhs;
+                       init();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
 
-       private void init(Vector<RuralHouse> houses) throws Exception {
+       private void init() throws Exception {
                setBounds(100, 100, 600, 450);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
                contentPane.setLayout(null);
 
-               JLabel lblNewLabel = new JLabel("List of available houses in:");
+               JLabel lblNewLabel = new JLabel();
                lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
-               lblNewLabel.setBounds(23, 41, 325, 33);
+               lblNewLabel.setBounds(23, 41, 536, 33);
                contentPane.add(lblNewLabel);
-
-               textField = new JTextField();
-               textField.setEnabled(false);
-               textField.setEditable(false);
-               textField.setFont(new Font("Tahoma", Font.PLAIN, 27));
-               textField.setBounds(373, 41, 152, 33);
-               contentPane.add(textField);
-               textField.setColumns(10);
                if (houses.isEmpty())
-                       textField.setText("No houses Matching");
+                       lblNewLabel.setText("There are not houses matching your search");
                else
-                       textField.setText(houses.get(0).getDistrict());
+                       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();
+               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.setEnabled(false);
                table.setModel(tableModel);
                Enumeration<RuralHouse> en = houses.elements();
                RuralHouse rh;
-
+               table.addMouseListener( new MouseAdapter(){                     
+                       @Override
+                       public void mouseClicked(MouseEvent arg0) {
+                               int row = table.getSelectedRow();
+                               HouseFeaturesGUI feat = new HouseFeaturesGUI(houses.get(row),null,null);
+                               feat.setVisible(true);
+                       }
+               });
                while (en.hasMoreElements()) {
                        rh = en.nextElement();
                        Vector<Object> row = new Vector<Object>();
@@ -94,7 +102,6 @@ public class listOfHousesGUI extends JFrame {
                        row.add(rh.getFeatures().getnBaths());
                        row.add(rh.getFeatures().getnParkings());
                        row.add(rh.getFeatures().getnLivings());
-                       System.out.println(rh.getFeatures().getnLivings());
                        tableModel.addRow(row);
                }