Package net.mzalewski.goblin.gui

Source Code of net.mzalewski.goblin.gui.MainWindow

package net.mzalewski.goblin.gui;

import net.mzalewski.goblin.gui.tabs.TransfersTab;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class MainWindow {

  final private String appName;
  final private String appVersion;
 
  final private Display display = new Display();
  final private Shell shell = new Shell(display);
  final private CTabFolder tabFolder = new CTabFolder(shell, SWT.BORDER);
  final private Composite statusBar = new Composite(shell, SWT.BORDER);
 
  final private Label versionLabel;
  final private Label downloadLabel;
  final private Label uploadLabel;
 
  final private Label downloadImageLabel;
  final private Label uploadImageLabel;
 
  public MainWindow(String appName, String appVersion) {
    this.appName = appName;
    this.appVersion = appVersion;
   
    versionLabel = new Label(statusBar, SWT.NONE);
    downloadImageLabel = new Label(statusBar, SWT.NONE);
    downloadLabel = new Label(statusBar, SWT.NONE);
    uploadImageLabel = new Label(statusBar, SWT.NONE);
    uploadLabel = new Label(statusBar, SWT.NONE);
  }
 
  public void create() {
    shell.setText(appName);
    shell.setImage(new Image(display, "goblin.ico"));
    shell.setLayout(new FillLayout());
   
    // main menu
    final Menu mainMenu = new Menu(shell, SWT.BAR);
    shell.setMenuBar(mainMenu);
   
    // file menu
    final MenuItem fileItem = new MenuItem(mainMenu, SWT.CASCADE);
    fileItem.setText("&Plik");
    final Menu fileSubMenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(fileSubMenu);
   
    MenuItem endItem = new MenuItem(fileSubMenu, SWT.PUSH);
    endItem.setText("Za&ko�cz");
    endItem.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        Thread.currentThread().stop();
      }
    } );
   
    // view menu
    final MenuItem viewItem = new MenuItem(mainMenu, SWT.CASCADE);
    viewItem.setText("&Widok");
    final Menu viewSubMenu = new Menu(shell, SWT.DROP_DOWN);
    viewItem.setMenu(viewSubMenu);
   
    MenuItem transfersItem = new MenuItem(viewSubMenu, SWT.PUSH);
    transfersItem.setText("&Transfery");
    transfersItem.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        TransfersTab.getInstance(tabFolder).show();
      }
    });

    // toolbar
    Image image = new Image(display, 24, 24);
    Color color = display.getSystemColor(SWT.COLOR_RED);
    GC gc = new GC(image);
    gc.setBackground(color);
    gc.fillRectangle(image.getBounds());
    gc.dispose();
    ToolBar toolBar = new ToolBar(shell, SWT.HORIZONTAL);
    for (int i=0; i<12; i++) {
      ToolItem item = new ToolItem(toolBar, SWT.PUSH);
      item.setImage(image);
    }
   
    final FormLayout form = new FormLayout();
    shell.setLayout (form);
   
    FormData ToolBarData = new FormData();
    ToolBarData.left = new FormAttachment(0, 0);
    ToolBarData.right = new FormAttachment(100, 0);
    ToolBarData.top = new FormAttachment(0, 0);
    ToolBarData.bottom = new FormAttachment(0, 30);
    toolBar.setLayoutData(ToolBarData);

    // tab folder
    final FormData tabFolderData = new FormData();
    tabFolderData.left = new FormAttachment(0, 0);
    tabFolderData.right = new FormAttachment(100, 0);
    tabFolderData.top = new FormAttachment(toolBar, 0);
    tabFolderData.bottom = new FormAttachment(100, -24);
    tabFolder.setLayoutData(tabFolderData);

    // create and show transfers tab
    TransfersTab.getInstance(tabFolder).show();
   
    // status bar
    statusBar.setLayout(new GridLayout(5, false));
    final FormData statusBarData = new FormData();
    statusBarData.left = new FormAttachment(0, 0);
    statusBarData.right = new FormAttachment(100, 0);
    statusBarData.top = new FormAttachment(tabFolder, 0);
    statusBarData.bottom = new FormAttachment(100, 0);
    statusBar.setLayoutData(statusBarData);
   
    // versionLabel
    versionLabel.setText(appName + " (Wersja: " + appVersion + ")");
    versionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));

    // download label
    Image downloadImage = new Image(display, "downloadArray.png");
    downloadImage.setBackground(downloadLabel.getBackground());
    downloadImageLabel.setImage(downloadImage);
    downloadImageLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, true, 1, 1));

    downloadLabel.setText("DOWNLOAD");
   
    // upload label
    Image uploadImage = new Image(display, "uploadArray.png");
    uploadImage.setBackground(uploadLabel.getBackground());
    uploadImageLabel.setImage(uploadImage);
   
    uploadLabel.setText("UPLOAD");
   
    shell.setMaximized(true);
    shell.pack();
    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
}
TOP

Related Classes of net.mzalewski.goblin.gui.MainWindow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.