Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.Shell;
- import org.eclipse.swt.widgets.Text;
- import org.eclipse.swt.widgets.ProgressBar;
- import org.eclipse.swt.widgets.Label;
- import org.eclipse.swt.graphics.Rectangle;
- import org.eclipse.swt.widgets.Monitor;
- import org.eclipse.swt.widgets.Button;
- import org.eclipse.swt.widgets.Listener;
- import org.eclipse.swt.widgets.Control;
- import org.eclipse.swt.widgets.Event;
- import org.eclipse.swt.layout.GridData;
- import org.eclipse.swt.layout.GridLayout;
- import org.eclipse.swt.graphics.Image;
- public class SWTHelloWorld {
- private Shell shell;
- private Text txtConsole;
- public SWTHelloWorld (Display display) {
- shell = new Shell(display, SWT.TITLE | SWT.CLOSE | SWT.RESIZE);
- initShell();
- addIcon();
- addLabelInfo();
- addProgressBar();
- addLabelStatus();
- addTextboxConsole();
- addSeparator();
- addCheckBox();
- addButtonClear();
- shell.pack();
- shell.open ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void initShell() {
- shell.setText("Operation In Progress");
- //shell.setSize(515, 600);
- Image small = new Image(shell.getDisplay(), "Vuze.ico");
- GridLayout formGrid = new GridLayout(4, false);
- formGrid.horizontalSpacing = 4;
- formGrid.verticalSpacing = 4;
- formGrid.marginBottom = 5;
- formGrid.marginTop = 20;
- shell.setLayout(formGrid);
- shell.setImage(small);
- Rectangle bounds = shell.getDisplay().getPrimaryMonitor().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);
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void addIcon() {
- Button button3 = new Button(shell, SWT.PUSH);
- GridData gridData = new GridData();
- gridData.widthHint = 32;
- gridData.heightHint = 32;
- gridData.verticalSpan = 4;
- gridData.horizontalIndent = 25;
- gridData.verticalAlignment = SWT.TOP;
- button3.setLayoutData(gridData);
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void addProgressBar() {
- ProgressBar barProgress = new ProgressBar (shell, SWT.INDETERMINATE);
- GridData gridData = new GridData();
- gridData.horizontalSpan = 3;
- gridData.horizontalAlignment = GridData.FILL;
- gridData.widthHint = 385;
- gridData.grabExcessHorizontalSpace = true;
- barProgress.setLayoutData(gridData);
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void addLabelInfo() {
- Label lblInfo = new Label(shell, SWT.LEFT);
- GridData gridData = new GridData();
- gridData.horizontalSpan = 3;
- gridData.horizontalAlignment = GridData.FILL;
- lblInfo.setText("Greetings from SWT");
- lblInfo.setLayoutData(gridData);
- lblInfo.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void addLabelStatus() {
- Label lblStatus = new Label(shell, SWT.LEFT);
- GridData gridData = new GridData();
- gridData.horizontalSpan = 3;
- gridData.horizontalAlignment = GridData.FILL;
- lblStatus.setText("Something");
- lblStatus.setLayoutData(gridData);
- lblStatus.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void addTextboxConsole() {
- txtConsole = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
- GridData gridData = new GridData();
- gridData.horizontalSpan = 3;
- gridData.horizontalAlignment = SWT.FILL;
- gridData.verticalAlignment = SWT.FILL;
- gridData.heightHint = 480;
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.exclude = true;
- txtConsole.setLayoutData(gridData);
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void addSeparator() {
- Label rulSeparator = new Label(shell, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.HORIZONTAL);
- GridData gridData = new GridData();
- gridData.horizontalSpan = 4;
- gridData.horizontalAlignment = SWT.FILL;
- gridData.verticalAlignment = SWT.END;
- gridData.verticalIndent = 5;
- gridData.grabExcessVerticalSpace = true;
- rulSeparator.setLayoutData(gridData);
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void addCheckBox() {
- final Button chkDetails = new Button(shell, SWT.CHECK);
- chkDetails.setText("Show Console");
- GridData gridData = new GridData();
- gridData.horizontalSpan = 2;
- gridData.horizontalAlignment = SWT.LEFT;
- gridData.verticalAlignment = SWT.END;
- chkDetails.setLayoutData(gridData);
- chkDetails.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- if (chkDetails.getSelection()) {
- GridData data = (GridData) txtConsole.getLayoutData();
- data.exclude = false;
- txtConsole.setVisible(!data.exclude);
- shell.layout(false);
- //shell.setSize(515, 800);
- }
- else {
- GridData data = (GridData) txtConsole.getLayoutData();
- data.exclude = true;
- txtConsole.setVisible(!data.exclude);
- shell.layout(false);
- //shell.setSize(515, 200);
- }
- }
- });
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- private void addButtonClear() {
- Button btnClear = new Button(shell, SWT.PUSH);
- GridData gridData = new GridData();
- gridData.horizontalSpan = 2;
- gridData.widthHint = 130;
- gridData.horizontalAlignment = SWT.RIGHT;
- gridData.verticalAlignment = SWT.END;
- btnClear.setText("Cancel");
- btnClear.setLayoutData(gridData);
- }
- /**
- * Validates a chess move.
- *
- * @return
- */
- public static void main(String[] args) {
- Display display = new Display();
- SWTHelloWorld x = new SWTHelloWorld(display);
- display.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement