Guest User

Untitled

a guest
Nov 28th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. import java.io.File;
  2.  
  3. public class SomeShell extends Shell {
  4.     private Text text;
  5.  
  6.     /**
  7.      * Launch the application.
  8.      * @param args
  9.      */
  10.     public static void main(String args[]) {
  11.         try {
  12.             Display display = Display.getDefault();
  13.             SomeShell shell = new SomeShell(display);
  14.             shell.open();
  15.             shell.layout();
  16.             while (!shell.isDisposed()) {
  17.                 if (!display.readAndDispatch()) {
  18.                     display.sleep();
  19.                 }
  20.             }
  21.         } catch (Exception e) {
  22.             e.printStackTrace();
  23.         }
  24.     }
  25.  
  26.     /**
  27.      * Create the shell.
  28.      * @param display
  29.      */
  30.     public SomeShell(Display display) {
  31.         super(display, SWT.SHELL_TRIM);
  32.        
  33.         text = new Text(this, SWT.BORDER);
  34.         text.setBounds(83, 37, 75, 27);
  35.        
  36.         Label lblNewLabel = new Label(this, SWT.NONE);
  37.         lblNewLabel.setBounds(10, 37, 68, 17);
  38.         lblNewLabel.setText("New Label");
  39.         createContents();
  40.        
  41.         try {
  42.             setDiplayIcons(this);
  43.         } catch (FileNotFoundException e) {
  44.             // TODO Auto-generated catch block
  45.             e.printStackTrace();
  46.         }
  47.     }
  48.  
  49.     /**
  50.      * Create contents of the shell.
  51.      */
  52.     protected void createContents() {
  53.         setText("SWT Application");
  54.         setSize(450, 300);
  55.  
  56.     }
  57.  
  58.     @Override
  59.     protected void checkSubclass() {
  60.         // Disable the check that prevents subclassing of SWT components
  61.     }
  62.    
  63.     protected void setDiplayIcons(Shell shell) throws FileNotFoundException{
  64.         Display display = shell.getDisplay();
  65.         InputStream inputImgTray = new FileInputStream(new File("icon.png"));
  66.         Image image = new Image(display, inputImgTray);
  67.         shell.setImage(image);
  68.  
  69.         Tray tray = display.getSystemTray();
  70.  
  71.         final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
  72.         tip.setMessage("Balloon Message Goes Here!");
  73.         if(tray != null) {
  74.             TrayItem trayItem = new TrayItem(tray, SWT.NONE);
  75.             trayItem.setImage(image);
  76.             tip.setText("Balloon Title goes here.");
  77.             trayItem.setToolTip(tip);
  78.             final Menu menu = new Menu(shell, SWT.POP_UP);
  79.             MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
  80.             menuItem.setText("Button A");
  81.             menuItem = new MenuItem(menu, SWT.PUSH);
  82.             menuItem.setText("Button B");
  83.             menuItem = new MenuItem(menu, SWT.PUSH);
  84.             menuItem.setText("Show Tooltip");
  85.             menuItem.addListener (SWT.Selection, new Listener () {          
  86.                 public void handleEvent (Event e) {
  87.                     tip.setVisible(true);
  88.                 }
  89.             });        
  90.             trayItem.addListener (SWT.MenuDetect, new Listener () {
  91.                 public void handleEvent (Event event) {
  92.                     menu.setVisible (true);
  93.                 }
  94.             });        
  95.         }
  96.  
  97.     }      
  98. }
Advertisement
Add Comment
Please, Sign In to add comment