summaryrefslogtreecommitdiff
path: root/src/client/MainWindow.java
blob: f3fbf6357eec2d2579de5aa9b3ff03f0545963ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package org.manzerbredes.open_klm.client;


import javax.swing.*;
import org.manzerbredes.open_klm.drivers.*;


/**
 * Main Window
 * 
 * @author Manzerbredes
 *
 */
public class MainWindow extends JFrame {
	

	/**
	 * Define serial Version UID
	 */
	private static final long serialVersionUID = 8058826286308946977L;
	
	
	/**
	 * Contain all JPanel corresponding to each driver type
	 */
	private Class<?>[] driverJPanels={
			JPanelTypeA.class
	};
	
	
	/**
	 * Build a main window
	 * @param aDriver
	 */
	public MainWindow(Driver aDriver){
		// Configure main window
		this.initUI();
	
        // Add driver panel
        for(int i=0;i<this.driverJPanels.length;i++){
        	try {
        		// Build a panel
				DriverJPanel driverJPanel=(DriverJPanel) driverJPanels[i].newInstance();
				// If the panel have the same type of the driver try to init it
				if(driverJPanel.getType().equals(aDriver.getType())){
					// If init success add it to the main window
					if(driverJPanel.initUI(aDriver)){
						this.add((JPanel) driverJPanel);
					}
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
        }
        
        // Display the main window
		this.setVisible(true);
	}
	
	
	/**
	 * Configure main window
	 */
	private void initUI(){
		// Configure MainWindow
		this.setTitle("Open KLM");
		this.setSize(700, 500);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	
}