Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses / src / gui / RequestNewHouseGUI.java
diff --git a/ruralHouses/src/gui/RequestNewHouseGUI.java b/ruralHouses/src/gui/RequestNewHouseGUI.java
new file mode 100644 (file)
index 0000000..e22a4f2
--- /dev/null
@@ -0,0 +1,269 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.GroupLayout;
+import javax.swing.GroupLayout.Alignment;
+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.border.EmptyBorder;
+
+import common.AdminInterface;
+
+import configuration.___IntNames;
+import domain.Districs;
+import domain.HouseFeatures;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class RequestNewHouseGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private Owner owner;
+       private JLabel lblCode ;
+       private JLabel feedback = new JLabel("");
+       private JTextField Code_f;
+       private JLabel lblTown;
+       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 JButton btnRegister;
+       private AdminInterface am = null;
+       private JComboBox<String> comboBox;
+
+
+       /**
+        * Create the frame.
+        */
+       public RequestNewHouseGUI(Owner o) {
+               comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
+                               Districs.longNames()));
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               this.setTitle("New House");
+               setBackground(Color.WHITE);
+               this.getContentPane().setLayout(null);
+               owner = o;
+               setBounds(100, 100, 500, 583);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               
+               lblCode = new JLabel("House Name:");
+               lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               Code_f = new JTextField();
+               Code_f.setColumns(10);
+               
+               lblTown = new JLabel("District:");
+               lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               lblDescription = new JLabel("Description(optional):");
+               lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               description_f = new JTextField();
+               description_f.setToolTipText("");
+               description_f.setHorizontalAlignment(SwingConstants.LEFT);
+               description_f.setColumns(10);
+               
+               lblKitchen = new JLabel("Kitchens:");
+               lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               kitchens_f = new JTextField();
+               kitchens_f.setColumns(10);
+               
+               lblRooms = new JLabel("Rooms:");
+               lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               rooms_f = new JTextField();
+               rooms_f.setColumns(10);
+               
+               lblLivings = new JLabel("Living rooms:");
+               lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               lRooms_f = new JTextField();
+               lRooms_f.setColumns(10);
+               
+               lblParkings = new JLabel("Parkings:");
+               lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               parkings_f = new JTextField();
+               parkings_f.setColumns(10);
+               
+               lblBaths = new JLabel("Baths:");
+               lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
+               
+               baths_f = new JTextField();
+               baths_f.setColumns(10);
+               
+               btnRegister = new JButton("Request registration");
+               btnRegister.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               RuralHouse rh = null;
+                               try {
+                                       //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
+                                       rh = new RuralHouse(Code_f.getText(),
+                                                               owner, description_f.getText(),
+                                                               (String) comboBox.getSelectedItem(), new HouseFeatures(Integer.parseInt(rooms_f.getText()),
+                                                                               Integer.parseInt(kitchens_f.getText()),
+                                                                               Integer.parseInt(baths_f.getText()),
+                                                                               Integer.parseInt(lRooms_f.getText()),
+                                                                               Integer.parseInt(parkings_f.getText())) );
+                               
+                               }
+                               catch(NumberFormatException e){
+                                       e.printStackTrace();
+                               }
+                               
+                               try {
+                                       if(am.addAdditionRequest(rh)){
+                                               am.saveInstance();
+                                               feedback.setText("Request sended");
+                                       }else{
+                                               feedback.setText("Request cannot be sended(Already added)");
+                                       }
+                               } catch (RemoteException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       }
+               });
+               
+               
+               
+               
+               GroupLayout gl_contentPane = new GroupLayout(contentPane);
+               gl_contentPane.setHorizontalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addContainerGap()
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                                                               .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                                                                       .addGroup(gl_contentPane.createSequentialGroup()
+                                                                                               .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                                                               .addGap(18)
+                                                                                               .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
+                                                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
+                                                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                                                       .addComponent(lblLivings)
+                                                                                                       .addGap(18)
+                                                                                                       .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                                                       .addComponent(lblCode)
+                                                                                                       .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                                                                                                       .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, 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)))
+                                                                       .addGap(29)
+                                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                                                               .addComponent(lblDescription)
+                                                                               .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
+                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                       .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                                       .addGap(18)
+                                                                       .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                                       .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                                       .addGap(18)
+                                                                       .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(18)
+                                                       .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
+                                                       .addPreferredGap(ComponentPlacement.UNRELATED)
+                                                       .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(140)
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                                               .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
+                                                               .addComponent(btnRegister))))
+                                       .addContainerGap(97, Short.MAX_VALUE))
+               );
+               gl_contentPane.setVerticalGroup(
+                       gl_contentPane.createParallelGroup(Alignment.LEADING)
+                               .addGroup(gl_contentPane.createSequentialGroup()
+                                       .addGap(20)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(63)
+                                                       .addComponent(lblDescription)
+                                                       .addPreferredGap(ComponentPlacement.RELATED)
+                                                       .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(60)
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
+                                                               .addComponent(lblCode)
+                                                               .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                       .addPreferredGap(ComponentPlacement.UNRELATED)
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
+                                                               .addComponent(lblTown)
+                                                               .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                       .addGap(18)
+                                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
+                                                               .addComponent(lblLivings)
+                                                               .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
+                                       .addGap(63)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(3)
+                                                       .addComponent(lblRooms))
+                                               .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                       .addPreferredGap(ComponentPlacement.RELATED)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(3)
+                                                       .addComponent(lblKitchen)))
+                                       .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
+                                               .addGroup(gl_contentPane.createSequentialGroup()
+                                                       .addGap(3)
+                                                       .addComponent(lblBaths))
+                                               .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                       .addGap(45)
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
+                                               .addComponent(lblParkings)
+                                               .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                       .addGap(41)
+                                       .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
+                                       .addPreferredGap(ComponentPlacement.UNRELATED)
+                                       .addComponent(btnRegister)
+                                       .addGap(54))
+               );
+               contentPane.setLayout(gl_contentPane);
+       }
+}