/**
*
*/
package com.waxayaz.TomcatMI.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import com.waxayaz.TomcatMI.ui.components.InstanceTabPane;
import com.waxayaz.TomcatMI.ui.components.InstancesTree;
/**
* @author Waxayaz
*
*/
public class MainWindow {
public static Display display = new Display();
private Shell shell = new Shell(display);
private SashForm sashForm;
private InstanceTabPane tabPane;
public MainWindow() {
buildUI();
}
private void buildUI() {
shell.setText("Tomcat Multi Instances - Waxayaz 2011");
shell.setLayout(new FillLayout());
sashForm = new SashForm(shell, SWT.HORIZONTAL);
InstancesTree tree = new InstancesTree(sashForm);
tabPane = new InstanceTabPane(sashForm);
tree.setTabPane(tabPane);
sashForm.setWeights(new int[]{20, 80});
buildMenuBar();
shell.setSize(900, 650);
// Center shell on Screen
Monitor primary = display.getPrimaryMonitor();
Rectangle bounds = primary.getBounds();
Rectangle rect = shell.getBounds();
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 2;
shell.setLocation(x, y);
shell.open();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
}
private void buildMenuBar() {
Menu menuBar = new Menu(shell, SWT.BAR);
////////////////////////////////////////////////////////////
// FILE
MenuItem fileMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
fileMenuHeader.setText("&File");
Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
fileMenuHeader.setMenu(fileMenu);
MenuItem fileExitItem = new MenuItem(fileMenu, SWT.PUSH);
fileExitItem.setText("E&xit");
fileExitItem.addSelectionListener(new fileExitItemListener());
////////////////////////////////////////////////////////////
// HELP
MenuItem helpMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
helpMenuHeader.setText("&Help");
Menu helpMenu = new Menu(shell, SWT.DROP_DOWN);
helpMenuHeader.setMenu(helpMenu);
MenuItem helpAboutItem = new MenuItem(helpMenu, SWT.PUSH);
helpAboutItem.setText("&About");
helpAboutItem.addSelectionListener(new helpAboutItemListener());
shell.setMenuBar(menuBar);
}
class fileExitItemListener implements SelectionListener {
public void widgetSelected(SelectionEvent event) {
widgetDefaultSelected(event);
}
public void widgetDefaultSelected(SelectionEvent event) {
shell.close();
display.dispose();
}
}
class helpAboutItemListener implements SelectionListener {
public void widgetSelected(SelectionEvent event) {
widgetDefaultSelected(event);
}
public void widgetDefaultSelected(SelectionEvent event) {
System.out.println("About !");
}
}
}