Revision: 3307 http://vexi.svn.sourceforge.net/vexi/?rev=3307&view=rev Author: clrg Date: 2008-12-17 12:34:00 +0000 (Wed, 17 Dec 2008)
Log Message: ----------- - Add update() as possible fix for launcher flickering - Convert tabs to spaces Modified Paths: -------------- trunk/launch/org.vexi.launch/src/org/vexi/launcher/Launcher.java Modified: trunk/launch/org.vexi.launch/src/org/vexi/launcher/Launcher.java =================================================================== --- trunk/launch/org.vexi.launch/src/org/vexi/launcher/Launcher.java 2008-12-17 02:06:32 UTC (rev 3306) +++ trunk/launch/org.vexi.launch/src/org/vexi/launcher/Launcher.java 2008-12-17 12:34:00 UTC (rev 3307) @@ -9,67 +9,67 @@ import java.util.List; public class Launcher extends Applet { - - String[] permittedDomains; - - static public void main(String[] args) throws Exception{ - log(new Launcher().findJvmBinary()); - } - + + String[] permittedDomains; + + static public void main(String[] args) throws Exception{ + log(new Launcher().findJvmBinary()); + } + // REMARK - shoudl be the same (or at least non-conflicting) - // as the cacheName in the vexi core + // as the cacheName in the vexi core static String cacheName(String url) { return url.replace('/', '_').replace('\\', '_').replace(':', '_'); } - - static private void log(String s){ - System.err.println(s); - } - - - static private String getEnv(String name) { - try{ - return System.getenv(name); - }catch(Throwable t){ - // REMARK - they deprecated this in 1.4, only to bring it back in 1.5. - // By deprecated we mean it throws an error. So here we fall back to - // getting it from the commandline. - try { - String os = System.getProperty("os.name").toLowerCase(); - Process p; - String cmd; - if (os.indexOf("windows 9") != -1 || os.indexOf("windows me") != -1) { - cmd = "command.com /c set"; - } else if (os.indexOf("windows") > -1) { - cmd = "cmd.exe /c set"; - } else { - cmd = "env"; - } - p = Runtime.getRuntime().exec(cmd); - BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); - String s; - while ((s = br.readLine()) != null) - if (s.startsWith(name + "=")) - return s.substring(name.length() + 1); - } catch (Exception e) { - } - return null; - } - } - - - private String findInJavaHome(String os_name, String javaHome){ + + static private void log(String s){ + System.err.println(s); + } + + + static private String getEnv(String name) { + try{ + return System.getenv(name); + }catch(Throwable t){ + // REMARK - they deprecated this in 1.4, only to bring it back in 1.5. + // By deprecated we mean it throws an error. So here we fall back to + // getting it from the commandline. + try { + String os = System.getProperty("os.name").toLowerCase(); + Process p; + String cmd; + if (os.indexOf("windows 9") != -1 || os.indexOf("windows me") != -1) { + cmd = "command.com /c set"; + } else if (os.indexOf("windows") > -1) { + cmd = "cmd.exe /c set"; + } else { + cmd = "env"; + } + p = Runtime.getRuntime().exec(cmd); + BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + String s; + while ((s = br.readLine()) != null) + if (s.startsWith(name + "=")) + return s.substring(name.length() + 1); + } catch (Exception e) { + } + return null; + } + } + + + private String findInJavaHome(String os_name, String javaHome){ if (javaHome != null && !javaHome.equals("")) { String r = javaHome + File.separatorChar + "bin" + File.separatorChar + "java"; if (os_name.indexOf("windows") != -1) {r += ".exe";} if (new File(r).exists()) return r; } return null; - } - + } + /** searches for the JVM binary in the usual places * @throws Problem */ - private String findJvmBinary() throws Exception { + private String findJvmBinary() throws Exception { String jvmBinary = null; String os_name = System.getProperty("os.name", "").toLowerCase(); @@ -93,85 +93,85 @@ String path = getEnv("PATH"); if (path == null) {path = getEnv("Path");} if (path!=null) { - StringTokenizer st = new StringTokenizer(path, File.pathSeparatorChar + ""); - while(st.hasMoreTokens()) { - String s = st.nextToken(); - if (new File(s + File.separatorChar + "java").exists() || new File(s + File.separatorChar + "java.exe").exists() ) { - jvmBinary = s + File.separatorChar + "java"; - if (os_name.indexOf("windows") != -1) {jvmBinary += ".exe";} - return jvmBinary; - } - } + StringTokenizer st = new StringTokenizer(path, File.pathSeparatorChar + ""); + while(st.hasMoreTokens()) { + String s = st.nextToken(); + if (new File(s + File.separatorChar + "java").exists() || new File(s + File.separatorChar + "java.exe").exists() ) { + jvmBinary = s + File.separatorChar + "java"; + if (os_name.indexOf("windows") != -1) {jvmBinary += ".exe";} + return jvmBinary; + } + } } throw new Problem("Couldn't find a suitable JVM binary! See console log for details"); } - - public final void init() { - try { - BufferedReader br = new BufferedReader( - new InputStreamReader( - getClass().getResourceAsStream ("urllist"))); - List l = new LinkedList(); - String line; - while((line=br.readLine())!=null){ - line = line.trim(); - if(line.length()>0) l.add(line); - } - - permittedDomains = new String[l.size()]; - for(int i=0; i<l.size(); i++){ - permittedDomains[i]=(String)l.get(i); - } - - } catch (Throwable e) { - update(-1,"Error: applet unable to find permitted domains"); - throw new Error(e); - } + + public final void init() { + try { + BufferedReader br = new BufferedReader( + new InputStreamReader( + getClass().getResourceAsStream ("urllist"))); + List l = new LinkedList(); + String line; + while ((line=br.readLine())!=null) { + line = line.trim(); + if(line.length()>0) l.add(line); + } + + permittedDomains = new String[l.size()]; + for(int i=0; i<l.size(); i++){ + permittedDomains[i]=(String)l.get(i); + } + + } catch (Throwable e) { + update(-1,"Error: applet unable to find permitted domains"); + throw new Error(e); + } - - - new Thread(){ - public void run() { - java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { - public Object run() { - go(); - return null; - } - }); - } - }.start(); + + + new Thread() { + public void run() { + java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { + public Object run() { + go(); + return null; + } + }); + } + }.start(); - } - + } + /** loads a file from a url, verifying that it was properly signed */ private void loadFromURL(URL u, File target) throws IOException { - File tempfile = new File(target.getParent(),target.getName()+".temp"); - final String filename = (u+"").substring((u+"").lastIndexOf("/")+1); - final URLConnection uc = u.openConnection(); - uc.setUseCaches(false); // don't use the possibly short Java cache - uc.connect(); + File tempfile = new File(target.getParent(),target.getName()+".temp"); + final String filename = (u+"").substring((u+"").lastIndexOf("/")+1); + final URLConnection uc = u.openConnection(); + uc.setUseCaches(false); // don't use the possibly short Java cache + uc.connect(); InputStream is = uc.getInputStream(); final double contentLength = (double)uc.getContentLength(); long remoteDate = uc.getLastModified(); long localDate = target.lastModified(); if(target.exists() && remoteDate<=localDate){ - log("... using cached copy of file " + target.getAbsolutePath()); - return; + log("... using cached copy of file " + target.getAbsolutePath()); + return; } // display the progress indicator as we go is = new FilterInputStream(new BufferedInputStream(is)) { int total = 0; int percent = 0; private void display(){ - double loaded = ((double)total) / contentLength; + double loaded = ((double)total) / contentLength; int newpercent = ((int)Math.ceil(loaded * 100)); if(newpercent!=percent){ - percent = newpercent; - //log(percent + "%"); - update((double)percent, "Downloading "+ filename + " " + percent + "%"); + percent = newpercent; + //log(percent + "%"); + update((double)percent, "Downloading "+ filename + " " + percent + "%"); } } @@ -202,83 +202,83 @@ out.close(); if(target.exists()){ - if(!target.delete()) throw new Error("Could not update: " + target); + if(!target.delete()) throw new Error("Could not update: " + target); } if(!tempfile.renameTo(target)){ - throw new Error("Could not rename downloaded file!!"); + throw new Error("Could not rename downloaded file!!"); } //update(100.0, "Finished download"); - log("... finished downloading file to " + target.getAbsolutePath()); + log("... finished downloading file to " + target.getAbsolutePath()); } /** fetches a file from the distribution site, writing it to the appropriate place */ File fetch(String url) throws IOException { - String filename = cacheName(url); - log("Downloading " + url); + String filename = cacheName(url); + log("Downloading " + url); - URL u = new URL(url); - File target = new File(vexidir + File.separatorChar + filename); + URL u = new URL(url); + File target = new File(vexidir + File.separatorChar + filename); loadFromURL(u, target); return target; } - + private String vexidir = null; - boolean checkUrl(String url){ - if(url.startsWith("file")) return true; - if(url.startsWith("http")){ - // remove the protocol - url = url.substring(url.indexOf("//")+2); - while(true){ - for(int i=0; i<permittedDomains.length; i++){ - if(url.startsWith(permittedDomains[i])) return true; - } - // if we are a subdomain remove leading part and recheck - if( url.indexOf('.')==-1) break; - url = url.substring(url.indexOf('.')+1); - } + boolean checkUrl(String url) { + if (url.startsWith("file")) return true; + if (url.startsWith("http")) { + // remove the protocol + url = url.substring(url.indexOf("//")+2); + while (true) { + for (int i=0; i<permittedDomains.length; i++) { + if (url.startsWith(permittedDomains[i])) return true; + } + // if we are a subdomain remove leading part and recheck + if (url.indexOf('.')==-1) break; + url = url.substring(url.indexOf('.')+1); + } - } - return false; + } + return false; } private String join(String[] ss){ - String r = ""; - for(int i=0; i<ss.length; i++){ - if(i>0)r+=","; - r+=ss[i]; - } - return r; + String r = ""; + for(int i=0; i<ss.length; i++){ + if(i>0)r+=","; + r+=ss[i]; + } + return r; } void prepareVexiDir(){ - // Prepare .vexi directory - vexidir = System.getProperty("user.home") + File.separatorChar + ".vexi"; + // Prepare .vexi directory + vexidir = System.getProperty("user.home") + File.separatorChar + ".vexi"; new File(vexidir).mkdirs(); } - private void go() { - try{ - // Check codebase is permitted - String url = getCodeBase()+""; - update(0.0, ""+url); - //log("Codebase is "+url); + private void go() { + try{ + // Check codebase is permitted + String url = getCodeBase()+""; + update(0.0, ""+url); + //log("Codebase is "+url); - if(!checkUrl(url)) throw new Problem("Applet can not be run from unknown domain " + url + "\nPermitted domains: " + join(permittedDomains)); - - - prepareVexiDir(); - - - String core = getParameter("core"); - if(core==null) throw new Problem("Core property not set"); - - String coreurl = url+core; - String corefile = fetch(coreurl).getName(); - - Vector command = new Vector(); - command.add(findJvmBinary()); + if(!checkUrl(url)) throw new Problem("Applet can not be run from unknown domain " + url + "\nPermitted domains: " + join(permittedDomains)); + + + prepareVexiDir(); + + + String core = getParameter("core"); + if(core==null) throw new Problem("Core property not set"); + + String coreurl = url+core; + String corefile = fetch(coreurl).getName(); + + Vector command = new Vector(); + command.add(findJvmBinary()); if (getParameter("mem") != null) { command.add("-Xmx" + getParameter("mem")); } @@ -291,35 +291,35 @@ } for (int i = 0; i<100;i++) { - String fetch = getParameter("vexi" + i); + String fetch = getParameter("vexi" + i); if (fetch == null) break; fetch(fetch); command.add(fetch); } - // REMARK - discovering os/architecture not relevant until - // native builds are working again - /* - String os_name = System.getProperty("os.name", "").toLowerCase(); - log("os.name == " + os_name); - Vector command = new Vector(); - String arch = null; - if (os_name.indexOf("linux") != -1) { - arch = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("/bin/uname -m").getInputStream())).readLine(); - log("arch is " + arch); - }*/ + // REMARK - discovering os/architecture not relevant until + // native builds are working again + /* + String os_name = System.getProperty("os.name", "").toLowerCase(); + log("os.name == " + os_name); + Vector command = new Vector(); + String arch = null; + if (os_name.indexOf("linux") != -1) { + arch = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("/bin/uname -m").getInputStream())).readLine(); + log("arch is " + arch); + }*/ spawn(command); - - } catch (Problem e){ - update(-1.0, e.getMessage()); - log(e.getMessage()); - } catch (Throwable e) { - update(-1.0, "Error; please check the Java console"); - e.printStackTrace(); - } - } - + + } catch (Problem e){ + update(-1.0, e.getMessage()); + log(e.getMessage()); + } catch (Throwable e) { + update(-1.0, "Error; please check the Java console"); + e.printStackTrace(); + } + } + private void spawn(Vector command) throws IOException { String[] command_vec = new String[command.size()]; command.copyInto(command_vec); @@ -332,8 +332,8 @@ String s = stderr.readLine(); update(1.0, "Vexi Loaded"); while (s != null) { - log(s); - s = stderr.readLine(); + log(s); + s = stderr.readLine(); } try { p.waitFor(); @@ -348,60 +348,63 @@ log("exiting... " + p.exitValue()); } - - static class Display{ - double percent = 0.0; - String text = ""; + + static class Display { + double percent = 0.0; + String text = ""; } - static public class Problem extends Exception{ public Problem(String message){super(message);}} + static public class Problem extends Exception { + public Problem(String message) { super(message); } + } private Image backbuffer = null; Display display = new Display(); - - public final void paint(Graphics g2) { + + public final void paint(Graphics g) { update(g); } + public final void update(Graphics g2) { if (backbuffer == null || backbuffer.getWidth(null) != getSize().width || backbuffer.getHeight(null) != getSize().height) backbuffer = createImage(getSize().width, getSize().height); if (backbuffer == null) return; Graphics g = backbuffer.getGraphics(); - double percent; - String text; - synchronized(display){ - percent = display.percent; - text = display.text; - } - g.setColor(percent < 0 ? Color.red : Color.blue); - percent = Math.abs(percent); + double percent; + String text; + synchronized(display){ + percent = display.percent; + text = display.text; + } + g.setColor(percent < 0 ? Color.red : Color.blue); + percent = Math.abs(percent); - int w = (int)((double)getSize().width * percent); - g.fillRect(0, 0, w, getSize().height); - g.setColor(Color.darkGray); - g.fillRect(w, 0, getSize().width - w, getSize().height); + int w = (int)((double)getSize().width * percent); + g.fillRect(0, 0, w, getSize().height); + g.setColor(Color.darkGray); + g.fillRect(w, 0, getSize().width - w, getSize().height); - Font f = new Font("Sans-serif", Font.BOLD, 12); - FontRenderContext frc = new FontRenderContext(null, true, true); - LineMetrics lm = f.getLineMetrics(text, frc); - g.setFont(f); + Font f = new Font("Sans-serif", Font.BOLD, 12); + FontRenderContext frc = new FontRenderContext(null, true, true); + LineMetrics lm = f.getLineMetrics(text, frc); + g.setFont(f); - int x = (int)((getSize().width - f.getStringBounds(text, frc).getWidth()) / 2); - int y = (int)(((getSize().height - lm.getAscent() - lm.getDescent()) / 2) + lm.getAscent()); - g.setColor(Color.white); - g.drawString(text, x, y); - - + int x = (int)((getSize().width - f.getStringBounds(text, frc).getWidth()) / 2); + int y = (int)(((getSize().height - lm.getAscent() - lm.getDescent()) / 2) + lm.getAscent()); + g.setColor(Color.white); + g.drawString(text, x, y); + + g2.setClip(0, 0, getSize().width, getSize().height); g2.drawImage(backbuffer, 0, 0, null); } - + protected void update(double percent, String text) { - synchronized(display){ - display.percent = percent; - display.text = text; + synchronized (display) { + display.percent = percent; + display.text = text; } repaint(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn