b6afbf1115fefc3f6ef2c3d1bece8be75f2b93a1
[RRRRHHHH_Code] / ruralHouses / src / gui / StartWindow.java
1 package gui;
2
3 import javax.swing.*;
4 import java.awt.*;
5
6 import businessLogic.FacadeImplementation;
7 import businessLogic.ApplicationFacadeInterface;
8
9 import java.rmi.*;
10 import configuration.Config;
11
12 public class StartWindow extends JFrame {
13         
14         public static boolean clientServer = false;
15
16         private static final long serialVersionUID = 1L;
17
18         private JPanel jContentPane = null;
19         private JButton bookHouseButton = null;
20         private JButton createOfferButton = null;
21         private JButton searchAvailabilityButton = null;
22         private JButton exitButton = null;
23
24         public static ApplicationFacadeInterface facadeInterface;
25         
26         public StartWindow() {
27                 super();
28                 initialize();
29                 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
30         }
31         
32         public static ApplicationFacadeInterface getBusinessLogic(){
33                 return facadeInterface;
34         }
35         
36         private void initialize() {
37                 // this.setSize(271, 295);
38                 this.setSize(350, 400);
39                 this.setContentPane(getJContentPane());
40                 this.setTitle("Use Cases");
41         }
42
43         private JPanel getJContentPane() {
44                 if (jContentPane == null) {
45                         jContentPane = new JPanel();
46 //                      jContentPane.setLayout(null);
47                         jContentPane.setLayout(new BoxLayout(jContentPane,
48                                         BoxLayout.Y_AXIS));
49                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
50                         jContentPane.add(getBookHouseButton());
51                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
52                         jContentPane.add(getSearchAvailabilityButton());
53                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
54                         jContentPane.add(getCreateOfferButton());
55                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
56                         jContentPane.add(getExitButton());
57                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
58                 }
59                 return jContentPane;
60         }
61
62         private JButton getBookHouseButton() {
63                 if (bookHouseButton == null) {
64                         bookHouseButton = new JButton();
65                         bookHouseButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
66                         bookHouseButton.setText("Book rural house");
67                         bookHouseButton.setAlignmentX(Component.CENTER_ALIGNMENT);
68                         bookHouseButton.addActionListener(new java.awt.event.ActionListener() {
69                                 public void actionPerformed(java.awt.event.ActionEvent e) {
70                                         JFrame a = new BookRuralHouseGUI();
71                                         a.setVisible(true);
72                                 }
73                         });
74                 }
75                 return bookHouseButton;
76         }
77
78         private JButton getCreateOfferButton() {
79                 if (createOfferButton == null) {
80                         createOfferButton = new JButton();
81                         createOfferButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
82                         createOfferButton.setText("Introduce new offer");
83                         createOfferButton.setAlignmentX(Component.CENTER_ALIGNMENT);
84                         createOfferButton.addActionListener(new java.awt.event.ActionListener() {
85                                 public void actionPerformed(java.awt.event.ActionEvent e) {
86                                         JFrame a = new IntroduceOfferGUI();
87                                         a.setVisible(true);
88                                 }
89                         });
90                 }
91                 return createOfferButton;
92         }
93         
94         private JButton getSearchAvailabilityButton() {
95                 if (searchAvailabilityButton == null) {
96                         searchAvailabilityButton = new JButton();
97                         searchAvailabilityButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
98                         searchAvailabilityButton.setText("Search availability");
99                         searchAvailabilityButton.setAlignmentX(Component.CENTER_ALIGNMENT);
100                         searchAvailabilityButton.addActionListener(new java.awt.event.ActionListener() {
101                                 public void actionPerformed(java.awt.event.ActionEvent e) {
102                                         JFrame a = new SearchOffersGUI();
103                                         a.setVisible(true);
104                                 }
105                         });
106                 }
107                 return searchAvailabilityButton;
108         }
109
110         private JButton getExitButton() {
111                 if (exitButton == null) {
112                         exitButton = new JButton();
113                         exitButton.setText("Exit");
114                         exitButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
115                         exitButton.setAlignmentX(Component.CENTER_ALIGNMENT);
116                         exitButton.addActionListener(new java.awt.event.ActionListener() {
117                                 public void actionPerformed(java.awt.event.ActionEvent e) {
118                                         //JFrame a = new QueryAvailabilityWindow();
119                                         ApplicationFacadeInterface facade=StartWindow.facadeInterface;
120                                         try {
121                                                 facade.close();
122                                                 setVisible(false);
123                                         }
124                                         catch (RemoteException e1) {
125                                                 // TODO Auto-generated catch block
126                                                 e1.printStackTrace();
127                                         }                                       
128                                 }
129                         });
130                 }
131                 return exitButton;
132         }
133         
134         public static void main(String[] args) {                
135                 try {
136                         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
137
138                         Config c=Config.getInstance();
139                         if (!clientServer)
140                                 facadeInterface=new FacadeImplementation();
141                         else {
142                                 final String serverRMI = c.getServerRMI();
143                                 // Remote service name
144                                 String serviceName = "/"+c.getServiceRMI();
145                                 //System.setSecurityManager(new RMISecurityManager());
146                                 // RMI server port number
147                                 int portNumber = Integer.parseInt(c.getPortRMI());
148                                 // RMI server host IP IP 
149                                 facadeInterface = (ApplicationFacadeInterface) Naming.lookup("rmi://"
150                                         + serverRMI + ":" + portNumber + serviceName);
151                         } 
152
153                 }
154                 catch (Exception e) {
155                         //System.out.println(e.toString());
156                         e.printStackTrace();
157                 }
158                 int x=0;
159                 JFrame a = new StartWindow();
160                 a.setVisible(true);
161         }
162
163 } //@jve:decl-index=0:visual-constraint="0,0"