⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spin.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    g.drawString("bg: "      + bgTime, 10, size.height - 20);    g.drawString("sprites: " + spriteTime, 10, size.height - 35);    g.drawString("fg: "      + fgTime, 10, size.height - 50);  }  public void paintBg(Graphics g) {    g.setColor(bgColor);    g.fillRect(0, 0, size.width, size.height);  }  void makeOff(boolean bForce) {    Dimension d = getSize();    if(d != null) {      if(bForce || 	 (size == null || d.width != size.width || d.height != size.height)) 	{	  size = d;	  center.setPos(size.width / 2, size.height / 2);	  bxNeedRecalc = true;	  sxNeedRecalc = true;	  memImage = createImage(d.width, d.height);	  memG  = memImage.getGraphics();	  	}    }  }	  public void start() {    if(runner != null) {      return;    }    runner = new Thread(this, "fwspin");    bRun = true;    runner.start();  }  public void stop() {    Activator.getTargetBC().removeBundleListener(this);    Activator.getTargetBC().removeServiceListener(this);    if(runner != null) {      bRun = false;      try {	runner.join(5 * 1000);      } catch (Exception  e) {	//      }    }    runner = null;  }  int hotX;  int hotY;  SpinItem center;  void toScreen(SpinItem item) {    double sx = item.getX();    double sy = item.getY();    double dx = sx - hotX;    double dy = sy - hotY;    double d2 = dx * dx + dy * dy;        double d  = Math.sqrt(d2);    double maxDist = 100;    if(bStepSize) {      maxDist = 10;    }        d = Math.min(d, maxDist);    double k = d / maxDist;    k = 1.0  - Math.sqrt(k);    /*    double m = 100;    d = Math.max(0.0, Math.min(m, d));    double k = m / (d + 1) / 10;    */    sx += k * dx;    sy += k * dy;    item.setSPos((int)sx, (int)sy, k);  }  BX getBX(Long id) {    return (BX)bundles.get(id);  }  BX getBX(long id) {    return getBX(new Long(id));  }  SX getSX(long id) {    for(Iterator it = services.keySet().iterator(); it.hasNext(); ) {      ServiceReference   sr = (ServiceReference)it.next();      SX                 sx = (SX)services.get(sr);      Long sid = (Long)sr.getProperty("service.id");      if(sid.longValue() == id) {	return sx;      }    }    return null;  }  public void paintSearch(Graphics g, double x, double y) {    paintBox(searchString, g, Color.white, Color.black, (int)x, (int)y, 	     .8, 300, 30);  }}class SX extends SpinItem {  ServiceReference sr;  String className;  String name;  Long   bid;    static String ignorePrefix = "com.gatespace.";  Spin spin;  public SX(Spin spin, ServiceReference sr) {    this.sr = sr;    this.spin = spin;    bid = new Long(sr.getBundle().getBundleId());    Object obj = Activator.getTargetBC().getService(sr);    if(obj == null) {      className = "null";    } else {      className = obj.getClass().getName();      if(className.equals("java.lang.Object")) {	className = ((String[])sr.getProperty("objectclass"))[0];      }    }     if(className.startsWith(ignorePrefix)) {      className = className.substring(ignorePrefix.length());    }    name = className + "/" + sr.getProperty("service.id");    if(obj != null) {      Activator.getTargetBC().ungetService(sr);    }  }  public void paint(Graphics g) {    g.setFont(spin.getFont(fac + (isActive() ? 1.0 : .2)));    g.setColor(isActive() ? Color.white : Color.gray);    g.drawString(name, sx, sy);    if(isActive()) {      paintDependencies(g);    }  }  public void paintInfo(Graphics g, double x, double y) {    StringBuffer sb = new StringBuffer();    sb.append("" + sr + "\n");    String[] keys = sr.getPropertyKeys();    for(int i = 0; keys != null && i < keys.length; i++) {      String key = keys[i];      Object val = sr.getProperty(key);      if(val.getClass().isArray()) {	Object[] vals = (Object[])val;	if(vals.length > 0) {	  sb.append(keys[i] + " = " + vals[0] + "\n");	  for(int j = 1; j < vals.length; j++) {	    sb.append("   " + vals[j] + "\n");	  }	}      } else {	sb.append(keys[i] + " = " + val + "\n");      }    }        spin.paintBox(sb.toString(), g, Color.white, Color.black, (int)x, (int)y, 		  .8, 300, 300);  }  Vector getNext(int dir) {    TreeMap map = new TreeMap();    if((dir & SpinItem.DIR_FROM) != 0) {      Bundle[] bl = sr.getUsingBundles();      for(int i = 0; bl != null && i < bl.length; i++) {	BX bx = spin.getBX(bl[i].getBundleId());	if(bx != null) {	  map.put(new Long(bx.b.getBundleId()), bx);	}      }    }    Vector v = new Vector();    for(Iterator it = map.keySet().iterator(); it.hasNext(); ) {      Long key      = (Long)it.next();      BX   bx       = (BX)map.get(key);      v.addElement(bx);    }    return v;  }  public void paintDependencies(Graphics g) {    BX bx = spin.getBX(sr.getBundle().getBundleId());    if(bx != null) {      g.setColor(Color.gray);      g.drawLine(sx, sy, bx.sx, bx.sy);    }    Bundle[] bl = sr.getUsingBundles();    for(int i = 0; bl != null && i < bl.length; i++) {      paintUsing(g, bl[i]);    }  }  public boolean isActive() {    return spin.isActive(this);  }  public void paintUsing(Graphics g, Bundle b) {    BX bx = spin.getBX(b.getBundleId());    if(bx == null) {      return;    }    double cx = spin.center.getSX();    double cy = spin.center.getSY();    g.setColor(BX.exportsToColor);    if(spin.use2D) {      CubicCurve2D.Double curve = 	new CubicCurve2D.Double (sx, sy,				 cx, cy, 				 cx, cy,				 bx.sx, bx.sy);                  ((Graphics2D)g).draw(curve);    } else {      drawSpline(g, 		 sx, sy,		 cx, cy, 		 cx, cy,		 bx.sx, bx.sy, 5);    }  }  public String toString() {    return name;  }}class BX extends SpinItem {  Bundle b;  String name;  Spin   spin;  public BX(Spin spin, Bundle b) {    this.b    = b;    this.spin = spin;    name = shortName(b);  }  public static Color importsFromColor = Color.blue;  public static Color exportsToColor   = Color.gray;  public boolean isActive() {    return spin.isActive(this);  }  Vector getNext(int dir) {    Map map = new TreeMap();    if(spin.pkgAdmin != null) {      ExportedPackage[] exp = spin.pkgAdmin.getExportedPackages(b);      if((dir & SpinItem.DIR_TO) != 0) {	for(int i = 0; exp != null && i < exp.length; i++) {	  Bundle[] bl =  exp[i].getImportingBundles();	  for(int j = 0; bl != null && j < bl.length; j++) {	    BX bx = spin.getBX(bl[j].getBundleId());	    if(bx != null) {	      map.put(new Long(bx.b.getBundleId()), bx);	    }	  }	}      }      if((dir & SpinItem.DIR_FROM) != 0) {	for(Iterator it = spin.bundles.keySet().iterator(); it.hasNext(); ) {	  Long key      = (Long)it.next();	  BX   bx       = (BX)spin.bundles.get(key);	  	  exp = spin.pkgAdmin.getExportedPackages(bx.b);	  boolean done = false;	  for(int i = 0; !done && exp != null && i < exp.length; i++) {	    Bundle[] bl =  exp[i].getImportingBundles();	    for(int j = 0; !done && bl != null && j < bl.length; j++) {	      if(bl[j].getBundleId() == b.getBundleId()) {		map.put(new Long(bx.b.getBundleId()), bx);		done = true;	      }	    }	  }	}      }    }    map.remove(new Long(b.getBundleId()));    Vector v = new Vector();    for(Iterator it = map.keySet().iterator(); it.hasNext(); ) {      Long key      = (Long)it.next();      BX   bx       = (BX)map.get(key);      v.addElement(bx);    }    return v;  }  public void paintDependencies(Graphics g) {    if(spin.pkgAdmin == null) return;    ExportedPackage[] exp = spin.pkgAdmin.getExportedPackages(b);    g.setColor(exportsToColor);    for(int i = 0; exp != null && i < exp.length; i++) {      Bundle[] bl =  exp[i].getImportingBundles();      for(int j = 0; bl != null && j < bl.length; j++) {	BX bx = spin.getBX(bl[j].getBundleId());	if(bx != null) {	  paintUsing(g, bx);	}      }    }    g.setColor(importsFromColor);    for(Iterator it = spin.bundles.keySet().iterator(); it.hasNext(); ) {      Long key      = (Long)it.next();      BX   bx       = (BX)spin.bundles.get(key);      exp = spin.pkgAdmin.getExportedPackages(bx.b);      boolean done = false;      for(int i = 0; !done && exp != null && i < exp.length; i++) {	Bundle[] bl =  exp[i].getImportingBundles();	for(int j = 0; !done && bl != null && j < bl.length; j++) {	  if(bl[j].getBundleId() == b.getBundleId()) {	    paintUsing(g, bx);	    done = true;	  }	}      }    }  }  public void paintInfo(Graphics g, double x, double y) {    StringBuffer sb = new StringBuffer();    sb.append(b.getLocation() + ", id=" + b.getBundleId() + "\n");    Dictionary headers = b.getHeaders();    for(Enumeration e = headers.keys(); e.hasMoreElements(); ) {      String key = (String)e.nextElement();      String val = (String)headers.get(key);      sb.append(key + ": " + val + "\n");    }    spin.paintBox(sb.toString(), g, Color.white, Color.black, (int)x, (int)y, 		  .8, 300, 300);  }  public void paintUsing(Graphics g, BX bx) {    double cx = spin.center.getSX();    double cy = spin.center.getSY();    if(spin.use2D) {      CubicCurve2D.Double curve = 	new CubicCurve2D.Double (sx, sy,				 cx, cy, 				 cx, cy,				 bx.sx, bx.sy);            ((Graphics2D)g).draw(curve);    } else {      drawSpline(g, sx, sy,		 cx, cy, 		 cx, cy,		 bx.sx, bx.sy, 5);    }      }  static Color installedColor   = Color.gray;  static Color uninstalledColor = Color.gray.darker();  static Color resolvedColor    = new Color(90, 90, 255);  static Color activeColor      = Color.yellow;  static Color stoppingColor    = Color.red;  static Color startingColor    = new Color(255, 0, 255);  public static Color getColor(int state) {    switch(state) {    case Bundle.INSTALLED:      return installedColor;    case Bundle.ACTIVE:      return activeColor;    case Bundle.RESOLVED:      return resolvedColor;    case Bundle.UNINSTALLED:      return uninstalledColor;    case Bundle.STARTING:      return startingColor;    case Bundle.STOPPING:       return stoppingColor;    }         return Color.black;  }  public void paint(Graphics g) {    g.setFont(spin.getFont(fac + (isActive() ? 1.0 : .8)));    if(isActive()) {      g.setColor(Color.white);    } else {      g.setColor(getColor(b.getState()));    }    g.drawString(name, sx, sy);    if(isActive()) {      paintDependencies(g);    }  }  public static String shortName(Bundle b) {    String s = b.getLocation();    int ix = s.lastIndexOf("/");    if(ix == -1) ix = s.lastIndexOf("\\");    if(ix != -1) {      s = s.substring(ix + 1);    }    if(s.endsWith(".jar")) s = s.substring(0, s.length() - 4);    return s;  }  public String toString() {    return name;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -