4 * @author willCodeForFood
6 import exceptions.DB4oManagerCreationException;
7 import gui.BookRuralHouseGUI;
11 import configuration.ConfigXML;
12 //import businessLogic.FacadeImplementation;
13 import businessLogic.ApplicationFacadeInterface;
14 import businessLogic.FacadeImplementation;
17 import java.awt.Color;
19 import java.awt.Rectangle;
20 import java.awt.Dimension;
21 import java.awt.BorderLayout;
22 import java.awt.FlowLayout;
23 import java.awt.GridLayout;
24 import java.awt.GridBagLayout;
25 import java.awt.GridBagConstraints;
26 import java.awt.event.WindowAdapter;
27 import java.awt.event.WindowEvent;
30 public class StartWindow extends JFrame {
32 private static final long serialVersionUID = 1L;
34 private JPanel jContentPane = null;
35 private JButton boton1 = null;
36 private JButton boton2 = null;
37 private JButton boton3 = null;
38 private static configuration.ConfigXML c;
40 public static ApplicationFacadeInterface facadeInterface;
41 private JLabel lblNewLabel;
43 public static void main(String[] args) {
45 StartWindow a = new StartWindow();
50 c=ConfigXML.getInstance();
52 System.setProperty("java.security.policy", c.getJavaPolicyPath());
54 System.setSecurityManager(new RMISecurityManager());
56 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
58 c=configuration.ConfigXML.getInstance();
59 if (c.isBusinessLogicLocal())
60 facadeInterface=new FacadeImplementation();
63 final String businessLogicNode = c.getBusinessLogicNode();
64 // Remote service name
65 String serviceName = "/"+c.getServiceRMI();
66 // RMI server port number
67 int portNumber = Integer.parseInt(c.getPortRMI());
68 // RMI server host IP IP
69 facadeInterface = (ApplicationFacadeInterface) Naming.lookup("rmi://"
70 + businessLogicNode + ":" + portNumber + serviceName);
73 } catch (java.rmi.ConnectException e) {
74 a.lblNewLabel.setText("No business logic: Run BusinessLogicServer first!!");
75 a.lblNewLabel.setForeground(Color.RED);
76 System.out.println("Error in StartWindow: "+e.toString());
77 } catch (java.rmi.NotBoundException e) {
78 a.lblNewLabel.setText("No business logic: Maybe problems running BusinessLogicServer");
79 a.lblNewLabel.setForeground(Color.RED);
80 System.out.println("Error in StartWindow: "+e.toString());
81 } catch (com.db4o.ext.DatabaseFileLockedException e) {
82 a.lblNewLabel.setText("Database locked: Do not run BusinessLogicServer or BusinessLogicServer!!");
83 a.lblNewLabel.setForeground(Color.RED);
84 System.out.println("Error in StartWindow: "+e.toString());
85 } catch (Exception e) {
86 a.lblNewLabel.setText("Error: "+e.toString());
87 a.lblNewLabel.setForeground(Color.RED);
88 System.out.println("Error in StartWindow: "+e.toString());
96 * This is the default constructor
99 public StartWindow() {
102 addWindowListener(new WindowAdapter() {
104 public void windowClosing(WindowEvent e) {
105 ApplicationFacadeInterface facade=StartWindow.facadeInterface;
107 if (c.isBusinessLogicLocal()) facade.close();
108 } catch (Exception e1) {
109 // TODO Auto-generated catch block
110 System.out.println("Error: "+e1.toString()+" , probably problems with Business Logic or Database");
116 //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
118 public static ApplicationFacadeInterface getBusinessLogic(){
119 return facadeInterface;
124 * This method initializes this
128 private void initialize() {
129 // this.setSize(271, 295);
130 this.setSize(495, 290);
131 this.setContentPane(getJContentPane());
132 this.setTitle("Rural Houses");
136 * This method initializes jContentPane
138 * @return javax.swing.JPanel
140 private JPanel getJContentPane() {
141 if (jContentPane == null) {
142 GridLayout gridLayout = new GridLayout();
143 gridLayout.setRows(4);
144 gridLayout.setColumns(1);
145 jContentPane = new JPanel();
146 jContentPane.setLayout(gridLayout);
147 jContentPane.add(getLblNewLabel());
148 jContentPane.add(getBoton2(), null);
149 jContentPane.add(getBoton3(), null);
150 jContentPane.add(getBoton1(), null);
156 * This method initializes boton1
158 * @return javax.swing.JButton
160 private JButton getBoton1() {
161 if (boton1 == null) {
162 boton1 = new JButton();
163 boton1.setText("Book rural house");
164 boton1.addActionListener(new java.awt.event.ActionListener() {
165 public void actionPerformed(java.awt.event.ActionEvent e) {
166 // C?digo cedido por la univerdad
167 JFrame a = new BookRuralHouseGUI();
176 * This method initializes boton2
178 * @return javax.swing.JButton
180 private JButton getBoton2() {
181 if (boton2 == null) {
182 boton2 = new JButton();
183 boton2.setText("Login");
184 boton2.addActionListener(new java.awt.event.ActionListener() {
185 public void actionPerformed(java.awt.event.ActionEvent e) {
186 // C?digo cedido por la universidad
187 JFrame a = new LoginGUI();
196 * This method initializes boton3
198 * @return javax.swing.JButton
200 private JButton getBoton3() {
201 if (boton3 == null) {
202 boton3 = new JButton();
203 boton3.setText("Query availability");
204 boton3.addActionListener(new java.awt.event.ActionListener() {
205 public void actionPerformed(java.awt.event.ActionEvent e) {
206 // C?digo cedido por la universidad
207 //JFrame a = new QueryAvailabilityWindow();
208 JFrame a = new QueryAvailabilityGUI();
218 private JLabel getLblNewLabel() {
219 if (lblNewLabel == null) {
220 lblNewLabel = new JLabel("Select option:");
221 lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 13));
222 lblNewLabel.setForeground(Color.BLACK);
223 lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
228 } // @jve:decl-index=0:visual-constraint="0,0"