From: camjan Date: Wed, 8 Apr 2015 13:18:53 +0000 (+0200) Subject: New GUI for booking and querying availability X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/3e4f7e3ac3a466acc64546b44749c887605677eb New GUI for booking and querying availability --- diff --git a/ruralHouses/src/businessLogic/BookingManager.java b/ruralHouses/src/businessLogic/BookingManager.java index d4069fc..24dd41c 100644 --- a/ruralHouses/src/businessLogic/BookingManager.java +++ b/ruralHouses/src/businessLogic/BookingManager.java @@ -1,6 +1,6 @@ package businessLogic; -import java.sql.Date; +import java.util.Date; import com.db4o.ObjectContainer; import com.db4o.ObjectSet; diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 12ff701..7275ba2 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -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; diff --git a/ruralHouses/src/gui/BookRuralHouseGUI.java b/ruralHouses/src/gui/BookRuralHouseGUI.java deleted file mode 100644 index 7a262fc..0000000 --- a/ruralHouses/src/gui/BookRuralHouseGUI.java +++ /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 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 rhs = rh.getAllOffers().elements(); - while(rhs.hasMoreElements()){ + while (rhs.hasMoreElements()) { Offer of = rhs.nextElement(); Vector row = new Vector(); row.add(of.getOfferNumber()); @@ -174,27 +212,49 @@ public class HouseFeaturesGUI extends JFrame { 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; - } + 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 (FirstDay.before(firstDay) || FirstDay.equals(firstDay) + && LastDay.after(lastDay) + || LastDay.equals(lastDay)) { + setBackground(Color.GREEN); + setForeground(Color.BLACK); + } else { + setBackground(Color.RED); + 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); + } + } } diff --git a/ruralHouses/src/gui/StartWindow.java b/ruralHouses/src/gui/StartWindow.java index 8d2b019..e115587 100644 --- a/ruralHouses/src/gui/StartWindow.java +++ b/ruralHouses/src/gui/StartWindow.java @@ -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/listOfHousesGUI.java b/ruralHouses/src/gui/listOfHousesGUI.java index 0b6429b..e75b125 100644 --- a/ruralHouses/src/gui/listOfHousesGUI.java +++ b/ruralHouses/src/gui/listOfHousesGUI.java @@ -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; @@ -33,19 +35,20 @@ public class listOfHousesGUI extends JFrame { private JPanel contentPane; private JTable table; private DefaultTableModel tableModel; - - /** + private Vector houses; + /** * Create the frame. */ - public listOfHousesGUI(Vector houses) { + public listOfHousesGUI(Vector rhs) { try { - init(houses); + this.houses=rhs; + init(); } catch (Exception e) { e.printStackTrace(); } } - private void init(Vector houses) throws Exception { + private void init() throws Exception { setBounds(100, 100, 600, 450); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); @@ -65,17 +68,31 @@ public class listOfHousesGUI extends JFrame { scrollPane.setBounds(23, 113, 536, 271); contentPane.add(scrollPane); - table = new JTable(); + 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.setModel(tableModel); Enumeration en = houses.elements(); RuralHouse rh; - + table.addMouseListener( new MouseAdapter(){ + @Override + public void mouseClicked(MouseEvent arg0) { + int row = table.getSelectedRow(); + HouseFeaturesGUI feat = new HouseFeaturesGUI(houses.get(row),null,null); + feat.setVisible(true); + } + }); while (en.hasMoreElements()) { rh = en.nextElement(); Vector row = new Vector();