Borneq

IconEditApp.java

Jul 23rd, 2015
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. // Copyright (c) 2015 Andrzej Borucki, see LICENSE file
  2. package com.blogspot.borneq;
  3.  
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.eclipse.swt.widgets.Display;
  8.  
  9. /**
  10.  * Start application class with static {@code main} method
  11.  * which creates {@code Display} object and call main window constructor
  12.  * @author Andrzej Borucki
  13.  * @version 1.0
  14.  * @since   2015-07-13
  15.  */
  16. public class IconEditApp {
  17.     static private List<ShellMain> shellList;
  18.     private static Display display;
  19.     static public void registerShell(ShellMain shell) {
  20.         shellList.add(shell);
  21.     }
  22.  
  23.     static private int getWaitingShellCount()
  24.     {
  25.         int countWaiting = 0;
  26.         int startSize = shellList.size();
  27.         //this for loop it gives me more control than
  28.         //for (: shellList) where was error for empty list
  29.         for (int i=startSize-1; i>=0; i--)
  30.         {
  31.             ShellMain shell = shellList.get(i);
  32.             if (!shell.isDisposed())
  33.                 countWaiting++;
  34.             else
  35.                 shellList.remove(i); //enable GC dispose memory
  36.         }
  37.         return countWaiting;
  38.     }
  39.  
  40.     static private void startEventLoop() {
  41.         while (getWaitingShellCount()>0) {
  42.             if (!display.readAndDispatch())
  43.                 display.sleep();
  44.         }
  45.     }
  46.  
  47.     /**
  48.      * Entry point of application
  49.      * @param args list of arguments
  50.      */
  51.     public static void main(String[] args) {
  52.         shellList = new ArrayList<ShellMain>();
  53.         display = new Display();
  54.         registerShell(new ShellMain());
  55.         startEventLoop();
  56.         display.dispose();
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment