blob: d390423887d8c76be1da9b672c4d014157ecaa54 (
plain) (
blame)
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
75
76
77
78
79
80
81
82
83
84
|
package gui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
public abstract class GuiManager {
static Shell mainShell;
static Composite contentComposite;
static Display display;
/**
* Add a new composite with content to the main Shell
* @param The composite to add, should be a GUI
*/
public static void addContent( Composite contentComposite ){
removeContent();
GuiManager.contentComposite = contentComposite;
mainShell.layout();
}
/**
* Remove the current content of the main shell
*/
private static void removeContent() {
if(contentComposite != null) {
GuiManager.contentComposite.dispose();
}
System.out.println(mainShell.toString());
}
public static Display getDisplay(){
return display;
}
public static void initGui() {
display = new Display();
mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER);
Menu menuBar = new Menu(mainShell, SWT.BAR);
MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE);
cascadeFileMenu.setText("&File");
Menu fileMenu = new Menu(mainShell, SWT.DROP_DOWN);
cascadeFileMenu.setMenu(fileMenu);
MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
exitItem.setText("&Exit");
exitItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
mainShell.getDisplay().dispose();
System.exit(0);
}
});
mainShell.setText("Dozmod");
mainShell.setMenuBar(menuBar);
mainShell.setLayout(new FillLayout());
addContent(new gui.core.LoginComposite(mainShell));
mainShell.pack();
mainShell.open();
while (!mainShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
|