private static DB4oManager theDB4oManager = null;
private static DB4oManagerAux theDB4oManagerAux;
-
+
static ConfigXML c;
private DB4oManager() throws Exception {
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",
db.close();
}
}
-
-
+
@SuppressWarnings("finally")
public Offer createOffer(RuralHouse ruralHouse, Date firstDay,
Date lastDay, float price) throws RemoteException, Exception {
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,
try {
-
db.store(offer);
db.commit();
}
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
db.close();
}
}
-
/**
* This method creates a book with a corresponding parameters
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();
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
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()) {
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();
}
}
-
- 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
}
}
- 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;
}
-
-
-
+
}
}
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
*
return null;
}
+
public Offer overlapsWith( Date firstDay, Date lastDay) {
Iterator<Offer> e=offers.iterator();
--- /dev/null
+package gui;
+
+import java.awt.Color;
+import java.awt.Component;
+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 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 DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();
+
+
+ /**
+ * Create the frame.
+ */
+
+ public HouseFeaturesGUI(RuralHouse rh, Date FirstDay, Date LastDay) {
+
+ 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();
+ tableModel = new DefaultTableModel(null,new String[] {"Offer #", "FirstDay", "LastDay", "Price"});
+ table.setModel(tableModel);
+ scrollPane.setViewportView(table);
+
+ JButton btnBookSelected = new JButton("Book SelectedOffer");
+ btnBookSelected.setBounds(127, 511, 178, 23);
+ contentPane.add(btnBookSelected);
+
+ 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);
+ 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.before(firstDay)&&LastDay.after(lastDay)) {
+ setBackground(Color.GREEN);
+ setForeground(Color.BLACK);
+ } else {
+ setBackground(Color.RED);
+ setForeground(Color.BLACK);
+ }
+ return this;
+ }
+ });
+ }
+}
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:");
+++ /dev/null
-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
import javax.swing.*;
-
import java.awt.*;
import java.awt.event.*;
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");
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");
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));
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) {
popupMenu.add(lblNumberOfLivings);
popupMenu.add(nLivings);
-
+
this.getContentPane().add(jCalendar2, null);
this.getContentPane().add(jCalendar1, null);
this.getContentPane().add(jLabel5, null);
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
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);
+
}
}
});
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);
}
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);
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() {
--- /dev/null
+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);
+ }
+}
public class listOfHousesGUI extends JFrame {
private JPanel contentPane;
- private JTextField textField;
private JTable table;
private DefaultTableModel tableModel;
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);
"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;
row.add(rh.getFeatures().getnBaths());
row.add(rh.getFeatures().getnParkings());
row.add(rh.getFeatures().getnLivings());
- System.out.println(rh.getFeatures().getnLivings());
tableModel.addRow(row);
}