From afdc662adbf492cfbe163a6689e2ccc0e035b328 Mon Sep 17 00:00:00 2001 From: camjan Date: Wed, 25 Mar 2015 17:43:35 +0100 Subject: [PATCH] Villatripas de arriba districs added and the option of searching houses with diferent parameters --- .../src/businessLogic/HouseManager.java | 5 ++ .../businessLogic/HouseManagerInterface.java | 1 + ruralHouses/src/dataAccess/DB4oManager.java | 25 ++++++ ruralHouses/src/domain/Districs.java | 25 ++++++ ruralHouses/src/domain/HouseFeatures.java | 40 ++++++++++ .../src/gui/QueryAvailabilityGUI2.java | 78 ++++++++++++------- ruralHouses/src/gui/listOfHousesGUI.java | 58 ++++++++++---- 7 files changed, 188 insertions(+), 44 deletions(-) create mode 100644 ruralHouses/src/domain/Districs.java diff --git a/ruralHouses/src/businessLogic/HouseManager.java b/ruralHouses/src/businessLogic/HouseManager.java index ba1aed7..70e8985 100644 --- a/ruralHouses/src/businessLogic/HouseManager.java +++ b/ruralHouses/src/businessLogic/HouseManager.java @@ -58,6 +58,11 @@ public class HouseManager implements HouseManagerInterface { return this.dbMngr.getRuralHousesByTown(town); } + + public Vector getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) { + + return this.dbMngr.getRuralHouses(town, nBed, nKit, nBath, nPark, nLiv); + } diff --git a/ruralHouses/src/businessLogic/HouseManagerInterface.java b/ruralHouses/src/businessLogic/HouseManagerInterface.java index 35670d9..321b82e 100644 --- a/ruralHouses/src/businessLogic/HouseManagerInterface.java +++ b/ruralHouses/src/businessLogic/HouseManagerInterface.java @@ -23,6 +23,7 @@ public interface HouseManagerInterface { public void removeHouse(RuralHouse rh, Owner owner); + public Vector getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) ; /** * @param district diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index eff779f..5dabd6f 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -18,6 +18,7 @@ import com.db4o.cs.config.ClientConfiguration; import configuration.ConfigXML; import domain.Account; import domain.Booking; +import domain.HouseFeatures; import domain.Offer; //import dataModel.Offer; import domain.Owner; @@ -36,6 +37,7 @@ public class DB4oManager { private static DB4oManager theDB4oManager = null; private static DB4oManagerAux theDB4oManagerAux; + static ConfigXML c; private DB4oManager() throws Exception { @@ -478,5 +480,28 @@ public class DB4oManager { + } + + public Vector 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{ + ObjectSet result = db.queryByExample(rh); + Vector ruralHouses = new Vector(); + while(result.hasNext()) + ruralHouses.add(result.next()); + db.close(); + return ruralHouses; + } catch (NullPointerException e){ + return null; + } + + + } } diff --git a/ruralHouses/src/domain/Districs.java b/ruralHouses/src/domain/Districs.java new file mode 100644 index 0000000..fa2fee5 --- /dev/null +++ b/ruralHouses/src/domain/Districs.java @@ -0,0 +1,25 @@ +package domain; + +public enum Districs { + 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"); + + private final String longName; + + Districs(String longName) { + this.longName = longName; + } + + public static String[] longNames() { + String[] result = new String[Districs.values().length]; + for (Districs d : Districs.values()) { + result[d.ordinal()] = d.longName; + } + return result; + + } +} diff --git a/ruralHouses/src/domain/HouseFeatures.java b/ruralHouses/src/domain/HouseFeatures.java index c26de8a..2327608 100644 --- a/ruralHouses/src/domain/HouseFeatures.java +++ b/ruralHouses/src/domain/HouseFeatures.java @@ -11,10 +11,50 @@ public class HouseFeatures { 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); + } + + 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/gui/QueryAvailabilityGUI2.java b/ruralHouses/src/gui/QueryAvailabilityGUI2.java index d95dcfe..a12ad16 100644 --- a/ruralHouses/src/gui/QueryAvailabilityGUI2.java +++ b/ruralHouses/src/gui/QueryAvailabilityGUI2.java @@ -7,6 +7,7 @@ import java.util.*; import javax.swing.*; + import java.awt.*; import java.awt.event.*; @@ -15,6 +16,7 @@ import businessLogic.OfferManager; import com.toedter.calendar.JCalendar; +import domain.Districs; import domain.Offer; import domain.RuralHouse; import exceptions.OverlappingOfferExists; @@ -42,7 +44,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"); @@ -57,10 +59,15 @@ public class QueryAvailabilityGUI2 extends JFrame { private final JLabel lblParkings = new JLabel("Parking slots:"); private final JTextField nParkings = new JTextField(); private HouseManager houseMan = new HouseManager(); + private final JLabel lblNumberOfLivings = new JLabel("Number of Livings:"); + private final JTextField nLivings = new JTextField(); public QueryAvailabilityGUI2() { - nParkings.setText(""); + nLivings.setText("0"); + nLivings.setColumns(10); + nParkings.setText("0"); nParkings.setColumns(10); + nBaths.setText("0"); nBaths.setColumns(10); try { jbInit(); @@ -72,10 +79,10 @@ public class QueryAvailabilityGUI2 extends JFrame { private void jbInit() throws Exception { this.getContentPane().setLayout(null); this.setSize(new Dimension(550, 500)); - this.setTitle("Set availability"); + this.setTitle("Query Availability"); - //TODO here we should add the districts of villatripas this is just for testing purposes - jComboBox1 = new JComboBox(this.houseMan.getAllRuralHouses()); + jComboBox1 = new JComboBox(new DefaultComboBoxModel( + Districs.longNames())); jComboBox1.setBounds(new Rectangle(115, 30, 115, 20)); jLabel2.setText("First day :"); jLabel2.setBounds(new Rectangle(20, 134, 85, 25)); @@ -152,33 +159,39 @@ public class QueryAvailabilityGUI2 extends JFrame { } }); 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); @@ -195,7 +208,8 @@ public class QueryAvailabilityGUI2 extends JFrame { getContentPane().add(lblNewLabel); - district.setSelected(true);; + district.setSelected(true); + ; district.setBounds(20, 69, 128, 20); getContentPane().add(district); buttonGroup.add(ruralHouseName); @@ -212,7 +226,7 @@ public class QueryAvailabilityGUI2 extends JFrame { } } }); - + ruralHouseName.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { @@ -225,35 +239,43 @@ public class QueryAvailabilityGUI2 extends JFrame { } }); getContentPane().add(ruralHouseName); - + JLabel lblNewLabel_2 = new JLabel("District name:"); lblNewLabel_2.setBounds(20, 30, 85, 17); getContentPane().add(lblNewLabel_2); - + setJMenuBar(menuBar); - + menuBar.add(mnMoreOptions); PopUpM.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - popupMenu.show(QueryAvailabilityGUI2.this,popupMenu.getX(), popupMenu.getY()); + popupMenu.show(QueryAvailabilityGUI2.this, popupMenu.getX(), + popupMenu.getY()); } }); - + mnMoreOptions.add(PopUpM); } private void jButton1_actionPerformed(ActionEvent e) { - if(this.district.isSelected()){ - //show list of houses GUI - } - else if(this.ruralHouseName.isSelected()){ - //show features of specific house + if (this.district.isSelected()) { + Vector houses = houseMan.getHouses(jComboBox1 + .getSelectedItem().toString(), Integer.parseInt(nBedrooms + .getText()), Integer.parseInt(nKitchens.getText()), Integer + .parseInt(nBaths.getText()), Integer.parseInt(nParkings + .getText()), Integer.parseInt(nLivings.getText())); + listOfHousesGUI list = new listOfHousesGUI(houses); + list.setVisible(true); + } else if (this.ruralHouseName.isSelected()) { + // show features of specific house + // TODO } } 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) { @@ -261,11 +283,13 @@ public class QueryAvailabilityGUI2 extends JFrame { 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()); } diff --git a/ruralHouses/src/gui/listOfHousesGUI.java b/ruralHouses/src/gui/listOfHousesGUI.java index 726f738..d610030 100644 --- a/ruralHouses/src/gui/listOfHousesGUI.java +++ b/ruralHouses/src/gui/listOfHousesGUI.java @@ -3,6 +3,8 @@ package gui; import java.awt.BorderLayout; import java.awt.EventQueue; +import domain.*; + import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; @@ -19,6 +21,10 @@ import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import java.awt.Component; +import java.sql.Date; +import java.util.Enumeration; +import java.util.LinkedList; +import java.util.Vector; import javax.swing.Box; @@ -27,31 +33,31 @@ public class listOfHousesGUI extends JFrame { private JPanel contentPane; private JTextField textField; private JTable table; + private DefaultTableModel tableModel; /** * Create the frame. */ - public listOfHousesGUI() { + public listOfHousesGUI(Vector houses) { try { - init(); + init(houses); } catch (Exception e) { e.printStackTrace(); } } - - private void init() throws Exception - { + + private void init(Vector houses) 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:"); lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); lblNewLabel.setBounds(23, 41, 325, 33); contentPane.add(lblNewLabel); - + textField = new JTextField(); textField.setEnabled(false); textField.setEditable(false); @@ -59,20 +65,38 @@ public class listOfHousesGUI extends JFrame { textField.setBounds(373, 41, 152, 33); contentPane.add(textField); textField.setColumns(10); - + if (houses.isEmpty()) + textField.setText("No houses Matching"); + else + textField.setText(houses.get(0).getTown()); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); scrollPane.setBounds(23, 113, 536, 271); contentPane.add(scrollPane); - + table = new JTable(); scrollPane.setViewportView(table); - table.setModel(new DefaultTableModel( - new Object[][] { - }, - new String[] { - "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" - } - )); - } + 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; + + 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()); + System.out.println(rh.getFeatures().getnLivings()); + tableModel.addRow(row); + } + + } } -- 2.20.1