From: camjan Date: Tue, 10 Mar 2015 17:02:41 +0000 (+0100) Subject: Query GUI finished last commit wrong X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/926c897bb5922fac8dd0463d2e822e96113a1dce Query GUI finished last commit wrong --- diff --git a/ruralHouses/src/gui/QueryAvailabilityGUI2.java b/ruralHouses/src/gui/QueryAvailabilityGUI2.java new file mode 100644 index 0000000..b176ef2 --- /dev/null +++ b/ruralHouses/src/gui/QueryAvailabilityGUI2.java @@ -0,0 +1,266 @@ +package gui; + +import java.beans.*; +import java.sql.Date; +import java.text.DateFormat; +import java.util.*; + +import javax.swing.*; + +import java.awt.*; +import java.awt.event.*; + +import businessLogic.OfferManager; + +import com.toedter.calendar.JCalendar; + +import domain.Offer; +import domain.RuralHouse; +import exceptions.OverlappingOfferExists; +import exceptions.BadDates; + +public class QueryAvailabilityGUI2 extends JFrame { + private static final long serialVersionUID = 1L; + + private JComboBox jComboBox1; + private JLabel jLabel2 = new JLabel(); + private JTextField jTextField1 = new JTextField(); + private JLabel jLabel3 = new JLabel(); + private JTextField jTextField2 = new JTextField(); + private JLabel jLabel4 = new JLabel(); + private JTextField jTextField3 = new JTextField(); + private JButton jButton1 = new JButton(); + + // Code for JCalendar + private JCalendar jCalendar1 = new JCalendar(); + private JCalendar jCalendar2 = new JCalendar(); + private Calendar calendarInicio = null; + private Calendar calendarFin = null; + private JButton jButton2 = new JButton(); + private JLabel jLabel5 = new JLabel(); + private final JLabel lblNewLabel = new JLabel(""); + private final JRadioButton ruralHouseName = new JRadioButton( + "Use RuralHouse name"); + private final ButtonGroup buttonGroup = new ButtonGroup(); + private final JMenuBar menuBar = new JMenuBar(); + private final JMenu mnMoreOptions = new JMenu("Search Options"); + private final JMenuItem PopUpM = new JMenuItem("More Filters"); + private final JPopupMenu popupMenu = new JPopupMenu(); + private final JLabel lblNewLabel_1 = new JLabel("Number of bedrooms:"); + private JTextField nBedrooms; + private JTextField nKitchens; + private final JLabel lblExtraFeatures = new JLabel("EXTRA FEATURES"); + private final JLabel lblNumberOfBaths = new JLabel("Number of baths:"); + private final JTextField nBaths = new JTextField(); + private final JLabel lblParkings = new JLabel("Parking slots:"); + private final JTextField nParkings = new JTextField(); + + public QueryAvailabilityGUI2(Vector v) { + nParkings.setText(""); + nParkings.setColumns(10); + nBaths.setColumns(10); + try { + jbInit(v); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void jbInit(Vector v) throws Exception { + this.getContentPane().setLayout(null); + this.setSize(new Dimension(550, 500)); + this.setTitle("Set availability"); + + jComboBox1 = new JComboBox(v); + jComboBox1.setBounds(new Rectangle(115, 30, 115, 20)); + jLabel2.setText("First day :"); + jLabel2.setBounds(new Rectangle(20, 134, 85, 25)); + jTextField1.setBounds(new Rectangle(20, 350, 220, 25)); + jTextField1.setEditable(false); + jLabel3.setText("Last day :"); + jLabel3.setBounds(new Rectangle(281, 134, 75, 25)); + jTextField2.setBounds(new Rectangle(281, 350, 220, 20)); + jTextField2.setEditable(false); + jLabel4.setText("Rural House name:"); + jLabel4.setBounds(new Rectangle(275, 30, 128, 20)); + jTextField3.setEnabled(false); + jTextField3.setBounds(new Rectangle(413, 30, 115, 20)); + jButton1.setText("Accept"); + jButton1.setBounds(new Rectangle(60, 377, 165, 30)); + jButton1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + jButton1_actionPerformed(e); + } + }); + jButton2.setText("Cancel"); + jButton2.setBounds(new Rectangle(305, 377, 162, 30)); + jButton2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + jButton2_actionPerformed(e); + } + }); + jLabel5.setBounds(new Rectangle(207, 600, 305, 20)); + jLabel5.setForeground(Color.red); + jLabel5.setSize(new Dimension(305, 20)); + jCalendar1.setBounds(new Rectangle(20, 184, 220, 165)); + jCalendar2.setBounds(new Rectangle(281, 184, 220, 165)); + + // Code for JCalendar + this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent propertychangeevent) { + if (propertychangeevent.getPropertyName().equals("locale")) { + jCalendar1.setLocale((Locale) propertychangeevent + .getNewValue()); + DateFormat dateformat = DateFormat.getDateInstance(1, + jCalendar1.getLocale()); + jTextField1.setText(dateformat.format(calendarInicio + .getTime())); + } else if (propertychangeevent.getPropertyName().equals( + "calendar")) { + calendarInicio = (Calendar) propertychangeevent + .getNewValue(); + DateFormat dateformat1 = DateFormat.getDateInstance(1, + jCalendar1.getLocale()); + jTextField1.setText(dateformat1.format(calendarInicio + .getTime())); + jCalendar1.setCalendar(calendarInicio); + } + } + }); + + this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent propertychangeevent) { + if (propertychangeevent.getPropertyName().equals("locale")) { + jCalendar2.setLocale((Locale) propertychangeevent + .getNewValue()); + DateFormat dateformat = DateFormat.getDateInstance(1, + jCalendar2.getLocale()); + jTextField2.setText(dateformat.format(calendarFin.getTime())); + } else if (propertychangeevent.getPropertyName().equals( + "calendar")) { + calendarFin = (Calendar) propertychangeevent.getNewValue(); + DateFormat dateformat1 = DateFormat.getDateInstance(1, + jCalendar2.getLocale()); + jTextField2.setText(dateformat1.format(calendarFin + .getTime())); + jCalendar2.setCalendar(calendarFin); + } + } + }); + popupMenu.setBounds(75, 125, 58, 16); + + addPopup(getContentPane(), popupMenu); + lblExtraFeatures.setHorizontalAlignment(SwingConstants.CENTER); + + popupMenu.add(lblExtraFeatures); + + popupMenu.add(lblNewLabel_1); + + nBedrooms = new JTextField(); + popupMenu.add(nBedrooms); + nBedrooms.setColumns(10); + + JLabel lblNumberOfKitchens = new JLabel("Number of kitchens:"); + popupMenu.add(lblNumberOfKitchens); + + nKitchens = new JTextField(); + popupMenu.add(nKitchens); + nKitchens.setColumns(10); + + popupMenu.add(lblNumberOfBaths); + + popupMenu.add(nBaths); + + popupMenu.add(lblParkings); + + popupMenu.add(nParkings); + + this.getContentPane().add(jCalendar2, null); + this.getContentPane().add(jCalendar1, null); + this.getContentPane().add(jLabel5, null); + this.getContentPane().add(jButton2, null); + this.getContentPane().add(jButton1, null); + this.getContentPane().add(jTextField3, null); + this.getContentPane().add(jLabel4, null); + this.getContentPane().add(jTextField2, null); + this.getContentPane().add(jLabel3, null); + this.getContentPane().add(jTextField1, null); + this.getContentPane().add(jLabel2, null); + this.getContentPane().add(jComboBox1, null); + lblNewLabel.setBounds(115, 301, 298, 38); + + getContentPane().add(lblNewLabel); + + JRadioButton district = new JRadioButton("Use district name"); + district.setSelected(true); + buttonGroup.add(district); + district.setBounds(20, 69, 128, 20); + getContentPane().add(district); + buttonGroup.add(ruralHouseName); + ruralHouseName.setBounds(276, 60, 177, 38); + district.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + int state = e.getStateChange(); + if (state == ItemEvent.SELECTED) { + jComboBox1.setEnabled(true); + } else if (state == ItemEvent.DESELECTED) { + jComboBox1.setEnabled(false); + } + } + }); + + ruralHouseName.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + int state = e.getStateChange(); + if (state == ItemEvent.SELECTED) { + jTextField3.setEnabled(true); + } else if (state == ItemEvent.DESELECTED) { + jTextField3.setEnabled(false); + } + } + }); + getContentPane().add(ruralHouseName); + + JLabel lblNewLabel_2 = new JLabel("District name:"); + lblNewLabel_2.setBounds(20, 30, 85, 17); + getContentPane().add(lblNewLabel_2); + + setJMenuBar(menuBar); + + menuBar.add(mnMoreOptions); + PopUpM.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + popupMenu.show(QueryAvailabilityGUI2.this,popupMenu.getX(), popupMenu.getY()); + } + }); + + mnMoreOptions.add(PopUpM); + } + + private void jButton1_actionPerformed(ActionEvent e) { + + } + + private void jButton2_actionPerformed(ActionEvent e) { + this.setVisible(false); + } + private static void addPopup(Component component, final JPopupMenu popup) { + component.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + if (e.isPopupTrigger()) { + showMenu(e); + } + } + public void mouseReleased(MouseEvent e) { + if (e.isPopupTrigger()) { + showMenu(e); + } + } + private void showMenu(MouseEvent e) { + popup.show(e.getComponent(), e.getX(), e.getY()); + } + }); + } +} \ No newline at end of file