Author: jm
Date: 2012-08-29 12:33:05 -0700 (Wed, 29 Aug 2012)
New Revision: 30289
Modified:
core3/support/trunk/splash-updater-impl/src/main/java/org/cytoscape/splash/internal/SplashActivator.java
core3/support/trunk/splash-updater-impl/src/main/java/org/cytoscape/splash/internal/SplashManipulator.java
Log:
Fixes #1124: We now have a proper progress bar on the splash screen
Modified:
core3/support/trunk/splash-updater-impl/src/main/java/org/cytoscape/splash/internal/SplashActivator.java
===================================================================
---
core3/support/trunk/splash-updater-impl/src/main/java/org/cytoscape/splash/internal/SplashActivator.java
2012-08-29 19:18:56 UTC (rev 30288)
+++
core3/support/trunk/splash-updater-impl/src/main/java/org/cytoscape/splash/internal/SplashActivator.java
2012-08-29 19:33:05 UTC (rev 30289)
@@ -2,10 +2,6 @@
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkListener;
-import org.osgi.framework.BundleListener;
-//import
org.springframework.osgi.context.event.OsgiBundleApplicationContextListener;
-import java.util.Properties;
/**
* Meant to be run at startLevel 1 so that the splash screen pops up before all
@@ -17,10 +13,9 @@
* Called whenever the OSGi framework starts our bundle
*/
public void start( BundleContext bc ) throws Exception {
- SplashManipulator splash = new SplashManipulator();
- bc.addFrameworkListener(splash);
+ SplashManipulator splash = new SplashManipulator(bc);
+ bc.addFrameworkListener(splash);
bc.addBundleListener(splash);
-//
bc.registerService(OsgiBundleApplicationContextListener.class.getName(),splash,new
Properties());
}
/**
Modified:
core3/support/trunk/splash-updater-impl/src/main/java/org/cytoscape/splash/internal/SplashManipulator.java
===================================================================
---
core3/support/trunk/splash-updater-impl/src/main/java/org/cytoscape/splash/internal/SplashManipulator.java
2012-08-29 19:18:56 UTC (rev 30288)
+++
core3/support/trunk/splash-updater-impl/src/main/java/org/cytoscape/splash/internal/SplashManipulator.java
2012-08-29 19:33:05 UTC (rev 30289)
@@ -1,28 +1,42 @@
package org.cytoscape.splash.internal;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
import java.awt.SplashScreen;
-import java.awt.Graphics2D;
-import java.awt.Color;
-import java.awt.AlphaComposite;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
import org.osgi.framework.FrameworkEvent;
-import org.osgi.framework.BundleListener;
import org.osgi.framework.FrameworkListener;
-//import
org.springframework.osgi.context.event.OsgiBundleContextRefreshedEvent;
-//import
org.springframework.osgi.context.event.OsgiBundleApplicationContextEvent;
-//import
org.springframework.osgi.context.event.OsgiBundleApplicationContextListener;
-import java.awt.Font;
-public class SplashManipulator implements
- //OsgiBundleApplicationContextListener,
+public class SplashManipulator implements
BundleListener,
FrameworkListener {
private final SplashScreen splash;
private final Graphics2D g;
private final Font font;
+ private Set<Long> resolved;
+ private Set<Long> started;
+ private BundleContext context;
- public SplashManipulator() {
+ public SplashManipulator(BundleContext context) {
+ this.context = context;
+ resolved = new HashSet<Long>();
+ started = new HashSet<Long>();
+
+ for (Bundle bundle : context.getBundles()) {
+ long id = bundle.getBundleId();
+ resolved.add(id);
+ if (bundle.getState() == Bundle.ACTIVE)
+ started.add(id);
+ }
+
splash = SplashScreen.getSplashScreen();
if (splash == null)
g = null;
@@ -33,31 +47,49 @@
}
public void bundleChanged(BundleEvent event) {
- if ( event.getType() == BundleEvent.STARTED )
+ if ( event.getType() == BundleEvent.RESOLVED )
+ resolved.add(event.getBundle().getBundleId());
+
+ if ( event.getType() == BundleEvent.STARTED ) {
+ started.add(event.getBundle().getBundleId());
renderSplashFrame(event.getBundle().getSymbolicName() +
" started");
+ }
}
public void frameworkEvent(FrameworkEvent event) {
- if ( event.getType() == FrameworkEvent.STARTED )
+ if ( event.getType() == FrameworkEvent.STARTED ) {
renderSplashFrame("OSGi finished.");
+ context.removeBundleListener(this);
+ context.removeFrameworkListener(this);
+ resolved.clear();
+ started.clear();
+ }
}
-// public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent
event) {
-// if ( event instanceof OsgiBundleContextRefreshedEvent )
-// renderSplashFrame( event.getBundle().getSymbolicName()
+ " refreshed");
-// }
-
private synchronized void renderSplashFrame(String message) {
if ( g == null || splash == null || !splash.isVisible() )
return;
- //g.setComposite(AlphaComposite.Clear);
g.setColor(Color.WHITE);
g.fillRect(20,300,800,40);
g.setPaintMode();
g.setColor(Color.BLACK);
g.setFont(font);
g.drawString(message, 20, 320);
+
+ int totalResolved = resolved.size();
+ int totalStarted = started.size();
+ double progress = totalResolved == 0 ? 0 : (double) totalStarted /
totalResolved;
+ g.setColor(new Color(computeColor(progress)));
+ int progressWidth = (int) (800.0 * progress);
+ g.fillRect(20, 304, progressWidth, 4);
if ( splash.isVisible() )
splash.update();
}
+
+ private int computeColor(double progress) {
+ int red = (int) (progress * 247);
+ int green = (int) (progress * 148);
+ int blue = (int) (progress * 30);
+ return (red << 16) | (green << 8) | blue;
+ }
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.