admin completed
[RRRRHHHH_Code] / ruralHouses / src / gui / ModifyHouseGUI.java
index a273b6e..29bc627 100644 (file)
@@ -1,21 +1,25 @@
 package gui;
 
-import java.awt.BorderLayout;
-import java.awt.EventQueue;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
 
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.border.EmptyBorder;
 import javax.swing.GroupLayout;
 import javax.swing.GroupLayout.Alignment;
-
-import domain.Owner;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
 import javax.swing.JLabel;
+import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.LayoutStyle.ComponentPlacement;
 import javax.swing.SwingConstants;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
+import javax.swing.border.EmptyBorder;
+
+import businessLogic.HouseManager;
+import domain.Owner;
+import domain.RuralHouse;
 
 public class ModifyHouseGUI extends JFrame {
 
@@ -25,8 +29,8 @@ public class ModifyHouseGUI extends JFrame {
        private static final long serialVersionUID = 1L;
        private JPanel contentPane;
        private Owner owner;
-       private JLabel lblTown;
-       private JTextField Town_f;
+       private JLabel lblDistrict;
+       private JTextField District_f;
        private JLabel lblDescription;
        private JTextField description_f;
        private JLabel lblKitchen;
@@ -39,9 +43,9 @@ public class ModifyHouseGUI extends JFrame {
        private JTextField parkings_f;
        private JLabel lblBaths;
        private JTextField baths_f;
-       private JButton btnRegister;
-       private JComboBox comboBox;
-       
+       private JButton btnConfirm;
+       private JComboBox<RuralHouse> houseBox;
+       private RuralHouse rh;
 
 
        /**
@@ -55,14 +59,14 @@ 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);
                
-               lblTown = new JLabel("Town:");
-               lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
+               lblDistrict = new JLabel("District:");
+               lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
                
-               Town_f = new JTextField();
-               Town_f.setColumns(10);
+               District_f = new JTextField();
+               District_f.setColumns(10);
                
                lblDescription = new JLabel("Description:");
                lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
@@ -100,9 +104,44 @@ public class ModifyHouseGUI extends JFrame {
                baths_f = new JTextField();
                baths_f.setColumns(10);
                
-               btnRegister = new JButton("Register House");
+               btnConfirm = new JButton("Confirm");
+               btnConfirm.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               
+                               
+                               HouseManager hm = new HouseManager();
+                               hm.removeHouse(rh, owner);
+                               //TODO registernewhouse must check before if the house is created to delete it before creating it.
+                               hm.registerNewHouse(rh.getHouseName(),
+                                               owner,
+                                               description_f.getText(),
+                                               District_f.getText(),
+                                               new Integer(rooms_f.getText()),
+                                               new Integer(kitchens_f.getText()),
+                                               new Integer(baths_f.getText()),
+                                               new Integer(lRooms_f.getText()),
+                                               new Integer(parkings_f.getText())
+                               );
+                       }
+               });
+               
+               houseBox = new JComboBox<RuralHouse>(o.getRuralHouses());
+               
+               houseBox.addItemListener(new ItemListener() {
+            @Override
+            public void itemStateChanged(ItemEvent e) {
+                rh = (RuralHouse)houseBox.getSelectedItem();
+                District_f.setText(rh.getDistrict());
+                description_f.setText(rh.getDescription());
+                kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens()));
+                rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms()));
+                lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings()));
+                parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings()));
+                baths_f.setText(Integer.toString(rh.getFeatures().getnBaths()));
+                
+            }
+        });
                
-               comboBox = new JComboBox();
                GroupLayout gl_contentPane = new GroupLayout(contentPane);
                gl_contentPane.setHorizontalGroup(
                        gl_contentPane.createParallelGroup(Alignment.LEADING)
@@ -122,15 +161,15 @@ public class ModifyHouseGUI extends JFrame {
                                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                                        .addComponent(lblCode)
                                                                        .addPreferredGap(ComponentPlacement.UNRELATED)
-                                                                       .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE))
+                                                                       .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE))
                                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                                        .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(18)
                                                                        .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                                                .addGroup(gl_contentPane.createSequentialGroup()
-                                                                       .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                                       .addComponent(lblDistrict, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(18)
-                                                                       .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
+                                                                       .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                                        .addGap(17)
@@ -152,7 +191,7 @@ public class ModifyHouseGUI extends JFrame {
                                                                                .addComponent(lblDescription, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)))))
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                        .addGap(140)
-                                                       .addComponent(btnRegister)))
+                                                       .addComponent(btnConfirm)))
                                        .addContainerGap())
                );
                gl_contentPane.setVerticalGroup(
@@ -164,11 +203,11 @@ public class ModifyHouseGUI extends JFrame {
                                                        .addGap(60)
                                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                                                .addComponent(lblCode)
-                                                               .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                               .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                                        .addPreferredGap(ComponentPlacement.UNRELATED)
                                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
-                                                               .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-                                                               .addComponent(lblTown)))
+                                                               .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                                               .addComponent(lblDistrict)))
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                        .addGap(63)
                                                        .addComponent(lblDescription)
@@ -201,7 +240,7 @@ public class ModifyHouseGUI extends JFrame {
                                                        .addComponent(lblParkings))
                                                .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                        .addGap(41)
-                                       .addComponent(btnRegister)
+                                       .addComponent(btnConfirm)
                                        .addGap(54))
                );
                contentPane.setLayout(gl_contentPane);