1 package net.sourceforge.tracelog.utils; 2 3 import java.io.BufferedReader ; 4 import java.io.InputStream ; 5 import java.io.InputStreamReader ; 6 7 import org.apache.log4j.Logger; 8 import org.eclipse.swt.SWT; 9 import org.eclipse.swt.graphics.Color; 10 import org.eclipse.swt.graphics.Rectangle; 11 import org.eclipse.swt.widgets.Display; 12 import org.eclipse.swt.widgets.Shell; 13 14 public class Util { 15 private static Logger log = Logger.getLogger(Util.class); 16 public static final String FILE_PROJECT_PROPERTIES = "/net/sourceforge/tracelog/resources/resource.properties"; 17 18 private static final Display DISPLAY = new Display(); 19 public static final Color COLOR_WHITE = DISPLAY.getSystemColor(SWT.COLOR_WHITE); 20 public static final Color COLOR_GRAY = DISPLAY.getSystemColor(SWT.COLOR_GRAY); 21 22 private static String appVersion; 23 24 private static long currentTimeMillis = System.currentTimeMillis(); 25 26 31 public synchronized static String getUniqueId() { 32 return "" + currentTimeMillis++; 33 } 34 35 public static boolean isEmpty(String value) { 36 return value == null || value.trim().equals(""); 37 } 38 39 44 public static String getLatestVersion() { 45 if (appVersion == null) { 46 String line = ""; 47 String version = ""; 48 boolean loop = true; 49 50 ProjectProperties projectProperties = ProjectProperties.getInstance(); 51 52 try { 53 BufferedReader rd = new BufferedReader (new InputStreamReader (getOwnResource(projectProperties.getVersionFilePath()))); 54 55 while (loop && (line = rd.readLine()) != null) { 56 if (!line.trim().equals("")) { 57 version = line.substring(line.indexOf("-") + 1, line.indexOf("\t")).trim(); 58 loop = false; 59 } 60 } 61 62 rd.close(); 63 } 64 catch (Exception e) { 65 log.error(e.getMessage()); 66 } 67 68 appVersion = "v" + version; 69 } 70 71 return appVersion; 72 } 73 74 79 public static Display getDisplay() { 80 return DISPLAY; 81 } 82 83 90 public static InputStream getOwnResource(String fileName) { 91 return Util.class.getResourceAsStream(fileName); 92 } 93 94 102 public static void centerAlignedShell(Shell parentShell, Shell shell) { 103 Rectangle shellRect = shell.getBounds(); 104 Rectangle parentShellRect = parentShell.getBounds(); 105 106 int x = (parentShellRect.width - shellRect.width) / 2; 107 int y = (parentShellRect.height - shellRect.height) / 2; 108 109 shell.setLocation(parentShellRect.x + x, parentShellRect.y + y); 110 } 111 } 112 | Popular Tags |