0b6429b45644b5286f8c317021e7fbf08e686a0c
[RRRRHHHH_Code] / ruralHouses / src / gui / listOfHousesGUI.java
1 package gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.EventQueue;
5
6 import domain.*;
7
8 import javax.swing.JFrame;
9 import javax.swing.JPanel;
10 import javax.swing.border.EmptyBorder;
11 import javax.swing.JLabel;
12
13 import java.awt.Font;
14
15 import javax.swing.JTextField;
16 import javax.swing.JScrollPane;
17
18 import java.awt.Rectangle;
19
20 import javax.swing.JTable;
21 import javax.swing.table.DefaultTableModel;
22
23 import java.awt.Component;
24 import java.sql.Date;
25 import java.util.Enumeration;
26 import java.util.LinkedList;
27 import java.util.Vector;
28
29 import javax.swing.Box;
30
31 public class listOfHousesGUI extends JFrame {
32
33         private JPanel contentPane;
34         private JTable table;
35         private DefaultTableModel tableModel;
36
37         /**
38          * Create the frame.
39          */
40         public listOfHousesGUI(Vector<RuralHouse> houses) {
41                 try {
42                         init(houses);
43                 } catch (Exception e) {
44                         e.printStackTrace();
45                 }
46         }
47
48         private void init(Vector<RuralHouse> houses) throws Exception {
49                 setBounds(100, 100, 600, 450);
50                 contentPane = new JPanel();
51                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
52                 setContentPane(contentPane);
53                 contentPane.setLayout(null);
54
55                 JLabel lblNewLabel = new JLabel();
56                 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
57                 lblNewLabel.setBounds(23, 41, 536, 33);
58                 contentPane.add(lblNewLabel);
59                 if (houses.isEmpty())
60                         lblNewLabel.setText("There are not houses matching your search");
61                 else
62                         lblNewLabel.setText("List of houses that match your search:");
63                 JScrollPane scrollPane = new JScrollPane();
64                 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
65                 scrollPane.setBounds(23, 113, 536, 271);
66                 contentPane.add(scrollPane);
67
68                 table = new JTable();
69                 scrollPane.setViewportView(table);
70                 tableModel = new DefaultTableModel(null, new String[] {
71                                 "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
72                                 "Livings" });
73                 //Maybe there is a better way to avoid interaction.
74                 //table.setEnabled(false);
75                 table.setModel(tableModel);
76                 Enumeration<RuralHouse> en = houses.elements();
77                 RuralHouse rh;
78
79                 while (en.hasMoreElements()) {
80                         rh = en.nextElement();
81                         Vector<Object> row = new Vector<Object>();
82                         row.add(rh.getHouseName());
83                         row.add(rh.getFeatures().getnRooms());
84                         row.add(rh.getFeatures().getnKitchens());
85                         row.add(rh.getFeatures().getnBaths());
86                         row.add(rh.getFeatures().getnParkings());
87                         row.add(rh.getFeatures().getnLivings());
88                         tableModel.addRow(row);
89                 }
90
91         }
92 }