Debbugin continues...
[RRRRHHHH_Code] / ruralHouses / src / gui / RequestNewHouseGUI.java
index d0cf337..76f182e 100644 (file)
@@ -6,6 +6,7 @@ import java.awt.event.ActionListener;
 
 import javax.swing.GroupLayout;
 import javax.swing.GroupLayout.Alignment;
+import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
@@ -16,10 +17,13 @@ import javax.swing.SwingConstants;
 import javax.swing.border.EmptyBorder;
 
 import businessLogic.AdminManager;
+import domain.Districs;
 import domain.HouseFeatures;
 import domain.Owner;
 import domain.RuralHouse;
 
+import javax.swing.JComboBox;
+
 public class RequestNewHouseGUI extends JFrame {
 
        /**
@@ -29,9 +33,9 @@ public class RequestNewHouseGUI extends JFrame {
        private JPanel contentPane;
        private Owner owner;
        private JLabel lblCode ;
+       private JLabel feedback = new JLabel("");
        private JTextField Code_f;
        private JLabel lblTown;
-       private JTextField Town_f;
        private JLabel lblDescription;
        private JTextField description_f;
        private JLabel lblKitchen;
@@ -46,13 +50,15 @@ public class RequestNewHouseGUI extends JFrame {
        private JTextField baths_f;
        private JButton btnRegister;
        private AdminManager am;
+       private JComboBox comboBox;
 
 
        /**
         * Create the frame.
         */
        public RequestNewHouseGUI(Owner o) {
-               
+               JComboBox<String> comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
+                               Districs.longNames()));
                am  = new AdminManager();
                this.setTitle("New House");
                setBackground(Color.WHITE);
@@ -63,18 +69,15 @@ public class RequestNewHouseGUI extends JFrame {
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
                
-               lblCode = new JLabel("House Code:");
+               lblCode = new JLabel("House Name:");
                lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
                
                Code_f = new JTextField();
                Code_f.setColumns(10);
                
-               lblTown = new JLabel("Town:");
+               lblTown = new JLabel("District:");
                lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
                
-               Town_f = new JTextField();
-               Town_f.setColumns(10);
-               
                lblDescription = new JLabel("Description(optional):");
                lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
                
@@ -121,7 +124,7 @@ public class RequestNewHouseGUI extends JFrame {
                                        //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(),
-                                                               Town_f.getText() ,new HouseFeatures(Integer.parseInt(rooms_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()),
@@ -132,17 +135,22 @@ public class RequestNewHouseGUI extends JFrame {
                                        e.printStackTrace();
                                }
                                
-                               am.addAdditionRequest(rh);
+                               if(am.addAdditionRequest(rh)){
+                                       feedback.setText("Request sended");
+                               }else{
+                                       feedback.setText("Request cannot be sended(Already added)");
+                               }
                        }
                });
+               
+               
+               
+               
                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()
-                                                       .addGap(140)
-                                                       .addComponent(btnRegister))
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                        .addContainerGap()
                                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
@@ -152,7 +160,7 @@ public class RequestNewHouseGUI extends JFrame {
                                                                                        .addGroup(gl_contentPane.createSequentialGroup()
                                                                                                .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
                                                                                                .addGap(18)
-                                                                                               .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                                                               .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
                                                                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
                                                                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                                                                        .addComponent(lblLivings)
@@ -182,7 +190,12 @@ public class RequestNewHouseGUI extends JFrame {
                                                        .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)))
+                                                       .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(
@@ -202,8 +215,8 @@ public class RequestNewHouseGUI extends JFrame {
                                                                .addComponent(Code_f, 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(lblTown)
+                                                               .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                                        .addGap(18)
                                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
                                                                .addComponent(lblLivings)
@@ -220,7 +233,7 @@ public class RequestNewHouseGUI extends JFrame {
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                        .addGap(3)
                                                        .addComponent(lblKitchen)))
-                                       .addPreferredGap(ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
+                                       .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                .addGroup(gl_contentPane.createSequentialGroup()
                                                        .addGap(3)
@@ -230,7 +243,9 @@ public class RequestNewHouseGUI extends JFrame {
                                        .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                                .addComponent(lblParkings)
                                                .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
-                                       .addGap(88)
+                                       .addGap(41)
+                                       .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
+                                       .addPreferredGap(ComponentPlacement.UNRELATED)
                                        .addComponent(btnRegister)
                                        .addGap(54))
                );