cleaning
[RRRRHHHH_Code] / ruralHouses / src / gui / ModifyHouseGUI.java
diff --git a/ruralHouses/src/gui/ModifyHouseGUI.java b/ruralHouses/src/gui/ModifyHouseGUI.java
new file mode 100644 (file)
index 0000000..691b0ca
--- /dev/null
@@ -0,0 +1,236 @@
+package gui;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import javax.swing.DefaultComboBoxModel;
+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.SwingConstants;
+import javax.swing.border.EmptyBorder;
+
+import common.HouseInterface;
+import configuration.___IntNames;
+import domain.Districs;
+import domain.HouseFeatures;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class ModifyHouseGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private Owner owner;
+       private JLabel lblDistrict;
+       private JLabel feedback;
+       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 String[] distric;
+       private JTextField baths_f;
+       private JButton btnConfirm;
+       private JComboBox<RuralHouse> houseBox;
+       private  JComboBox<String> comboBox;
+       private RuralHouse rh;
+
+       /**
+        * Create the frame.
+        */
+       public ModifyHouseGUI(final Owner o) {
+               this.distric=Districs.longNames();
+                comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
+
+                               this.distric));
+               this.getContentPane().setLayout(null);
+               owner = o;
+               setBounds(100, 100, 500, 583);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+
+               JLabel lblCode = new JLabel("House Name:");
+               lblCode.setBounds(15, 88, 64, 14);
+               lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               lblDistrict = new JLabel("District:");
+               lblDistrict.setBounds(39, 119, 70, 14);
+               lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               lblDescription = new JLabel("Description:");
+               lblDescription.setBounds(231, 88, 90, 14);
+               lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               description_f = new JTextField();
+               description_f.setBounds(241, 113, 178, 129);
+               description_f.setColumns(10);
+
+               lblKitchen = new JLabel("Kitchens:");
+               lblKitchen.setBounds(230, 316, 70, 14);
+               lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               kitchens_f = new JTextField();
+               kitchens_f.setBounds(318, 313, 86, 20);
+               kitchens_f.setColumns(10);
+
+               lblRooms = new JLabel("Rooms:");
+               lblRooms.setBounds(39, 316, 70, 14);
+               lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               rooms_f = new JTextField();
+               rooms_f.setBounds(127, 313, 86, 20);
+               rooms_f.setColumns(10);
+
+               lblLivings = new JLabel("Living rooms:");
+               lblLivings.setBounds(237, 354, 63, 14);
+               lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               lRooms_f = new JTextField();
+               lRooms_f.setBounds(318, 351, 86, 20);
+               lRooms_f.setColumns(10);
+
+               lblParkings = new JLabel("Parkings:");
+               lblParkings.setBounds(39, 404, 70, 14);
+               lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               parkings_f = new JTextField();
+               parkings_f.setBounds(127, 401, 86, 20);
+               parkings_f.setColumns(10);
+
+               lblBaths = new JLabel("Baths:");
+               lblBaths.setBounds(39, 354, 70, 14);
+               lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
+
+               baths_f = new JTextField();
+               baths_f.setBounds(127, 351, 86, 20);
+               baths_f.setColumns(10);
+
+               btnConfirm = new JButton("Confirm");
+               btnConfirm.setBounds(145, 462, 69, 23);
+               btnConfirm.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+
+                               RuralHouse newRh = new RuralHouse(rh.getHouseName(), owner,
+                                               description_f.getText(), (String)comboBox.getSelectedItem(),
+                                               new HouseFeatures(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())));
+                               HouseInterface hm= null;
+                               try {
+                                       hm = (HouseInterface) Naming
+                                                       .lookup(___IntNames.HouseManager);
+                               } catch (Exception e1) {
+                                       System.out.println("Error accessing remote authentication: "
+                                                       + e1.toString());
+                               }
+               
+                               try {
+                                       if (hm.registerNewHouse(newRh)) {
+                                               owner.getRuralHouses().add(newRh);
+                                               houseBox.removeItem(rh);
+                                               feedback.setText("House properly modified");
+                                       } else
+                                               feedback.setText("Imposible to modify the house");
+                               } catch (RemoteException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+
+                       }
+               });
+               HouseInterface hm= null;
+               try {
+                       hm = (HouseInterface) Naming
+                                       .lookup(___IntNames.HouseManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               Vector<RuralHouse> list = null;
+               try {
+                       list = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
+               } catch (RemoteException e1) {
+                       e1.printStackTrace();
+               }
+               
+               houseBox = new JComboBox<RuralHouse>(list);
+               if (!o.getRuralHouses().isEmpty()) {
+                       rh = (RuralHouse) houseBox.getSelectedItem();                   
+                       comboBox.setSelectedItem(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()));
+                       houseBox.setBounds(89, 85, 124, 20);
+               }else{
+                       feedback.setText("Not available houses");
+                       btnConfirm.setEnabled(false);
+               }
+               houseBox.addItemListener(new ItemListener() {
+                       @Override
+                       public void itemStateChanged(ItemEvent e) {
+                               rh = (RuralHouse) houseBox.getSelectedItem();
+                               comboBox.setSelectedItem(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()));
+
+                       }
+               });
+               contentPane.setLayout(null);
+               contentPane.add(lblParkings);
+               contentPane.add(parkings_f);
+               contentPane.add(lblRooms);
+               contentPane.add(rooms_f);
+               contentPane.add(lblCode);
+               contentPane.add(houseBox);
+               contentPane.add(lblBaths);
+               contentPane.add(baths_f);
+               contentPane.add(lblDistrict);
+               contentPane.add(lblLivings);
+               contentPane.add(lRooms_f);
+               contentPane.add(lblKitchen);
+               contentPane.add(kitchens_f);
+               contentPane.add(description_f);
+               contentPane.add(lblDescription);
+               contentPane.add(btnConfirm);
+
+               feedback = new JLabel("");
+               feedback.setBounds(189, 510, 195, 23);
+               contentPane.add(feedback);
+               
+               comboBox.setBounds(127, 116, 86, 20);
+               contentPane.add(comboBox);
+       }
+}