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

📄 obrdisplayer.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	    getOBR().setRepositoryURLs(urls);	    refreshList(true);	  } catch (Exception e) {	    obrErr = "" + e;	  }	}      } catch (Exception e) {	e.printStackTrace();      }    }            /**     * Set the selected bundle by settingt the HTML detail string.     */    void setSelected(TreeNode node) {      if(node != null && (node instanceof OBRNode)) {	brSelected = (OBRNode)node;	Bundle b = getBundle(brSelected.getBundleRecord());	if(b != null) {	  gotoBid(b.getBundleId());	} else {	  getBundleSelectionModel().clearSelection();	}      } else {	brSelected = null;      }      installButton.setEnabled(brSelected != null && !bBusy);      startButton.setEnabled(brSelected != null && !bBusy);      StringBuffer sb = new StringBuffer();            sb.append("<html>\n");      sb.append("<table border=\"0\" width=\"100%\">\n");      sb.append("<tr>");            if(node != null  && (node instanceof HTMLable)) {	HTMLable htmlNode = (HTMLable)node;	sb.append("<td valign=\"top\" bgcolor=\"#eeeeee\">");	Util.startFont(sb, "-1");		sb.append(htmlNode.getTitle());	sb.append("</font>\n");	sb.append("</td>\n");	String   iconURL  = htmlNode.getIconURL();	if(iconURL != null && !"".equals(iconURL.trim())) {	  sb.append("<td valign=\"top\" bgcolor=\"#eeeeee\">");	  sb.append("<img align=\"left\" src=\"" + iconURL + "\">");	  sb.append("</td>");	}             } else {	sb.append("");      }      sb.append("</tr>\n");      sb.append("</table>\n");      if(node != null  && (node instanceof HTMLable)) {	HTMLable htmlNode = (HTMLable)node;	sb.append(htmlNode.toHTML());      }            sb.append("</html>");      setHTML(sb.toString());      recordTree.invalidate();      recordTree.repaint();    }        public void setBundle(Bundle b) {    }        public void stop() {      if(recordTree != null) {	ToolTipManager.sharedInstance().registerComponent(recordTree);      }    }          void setHTML(String s) {      html.setText(s);            SwingUtilities.invokeLater(new Runnable() {	  public void run() {	    try {	      JViewport vp = htmlScroll.getViewport();	      if(vp != null) {	      vp.setViewPosition(new Point(0,0));	      htmlScroll.setViewport(vp);	      }  	    } catch (Exception e) {	      e.printStackTrace();	    }	  }	});    }  }    void gotoBid(long bid) {    getBundleSelectionModel().clearSelection();    getBundleSelectionModel().setSelected(bid, true);  }    /**   * If possible, get the bundle matchin a bundle record.   *   * @param br record to search for   * @return an installed bundle, if the bbudle record seem to be installed   */  Bundle getBundle(BundleRecord br) {        Bundle[] bl = bc.getBundles();        for(int i = 0; bl != null && i < bl.length; i++) {      if(Util.bundleEqual(bl[i], br)) {	return bl[i];      }    }    return null;  }    /**   * Check if a bundle record seem to be installed.   */  boolean isInstalled(BundleRecord br) {    return getBundle(br) != null;  }    void appendHelp(StringBuffer sb) {    String urlPrefix = "bundle://" + bc.getBundle().getBundleId();    sb.append("<p>" +	      "Select a bundle from the bundle repository list, then " + 	      "select the install or start icons." + 	      "</p>");    /*    sb.append("<p>" + 	      "<img src=\"" + urlPrefix + "/player_play.png\">" + 	      "Install and start a bundle and its dependencies." + 	      "</p>" + 	      "<img src=\"" + urlPrefix + "/player_install.png\">" + 	      "Install a bundle and its dependencies." + 	      "</p>" +	      "<p>" +	      "<img src=\"" + urlPrefix + "/update.png\">" + 	      "Reload the bundle repository list." + 	      "</p>" + 	      "<p>" + 	      "<img src=\"" + urlPrefix + "/sort_select.png\"> " + 	      "Change category sorting." + 	      "</p>"	      );    */  }    /**   * Simple interface for things that can produce HTML   */  interface HTMLable {    public String getTitle();    public String toHTML();    public String getIconURL();  }  /**   * Comparator class for comparing two BundleRecords   *   * <p>   * Sort first by case-insensite name, tehn by version   * </p>   */  class BRComparator implements Comparator {    public int compare(Object o1, Object o2) {      BundleRecord br1 = (BundleRecord)o1;      BundleRecord br2 = (BundleRecord)o2;      String s1 = Util.getBRName(br1).toLowerCase();      String s2 = Util.getBRName(br2).toLowerCase();      int n = 0;            try {	n = s1.compareTo(s2);	if(n == 0) {	  s1 = (String)br1.getAttribute(BundleRecord.BUNDLE_VERSION);	  s2 = (String)br2.getAttribute(BundleRecord.BUNDLE_VERSION);	}		n = s1.compareTo(s2);      } catch (Exception e) {      }      return n;    }  }  /**   * TreeNode to top of OBR tree.   */  class TopNode extends DefaultMutableTreeNode implements HTMLable {        String name;        public TopNode(String name) {      this.name = name;    }    public String getIconURL() {      return null;    }        public String toString() {      return name;    }        public String getTitle() {      return toString();    }        public String toHTML() {      StringBuffer sb = new StringBuffer();            if(!"".equals(obrErr)) {	Util.startFont(sb);	sb.append("<pre>");	sb.append(obrErr);	sb.append("</pre>");	sb.append("</font>");      } else {	Util.startFont(sb);		BundleRepositoryService obr = getOBR();		if(obr != null) {	  sb.append("<p>");	  sb.append("<b>Repository URLs</b><br>");	  String[] urls = obr.getRepositoryURLs();	  for(int i = 0; i < urls.length; i++) {	    sb.append(urls[i]);	    if(i < urls.length - 1) {	      sb.append("<br>");	    }	  }	  sb.append("</p>");	  sb.append("<p>");	  sb.append("Total number of bundles: " + obr.getBundleRecordCount());	  sb.append("</p>");	}		appendHelp(sb);		sb.append("</font>");      }      return sb.toString();    }  }    /**   * Tree node for grouping BundleRecords into categories in OBR tree   */  class CategoryNode extends DefaultMutableTreeNode implements HTMLable {    String category;    public CategoryNode(String category) {      this.category = category;    }    public String getIconURL() {      return null;    }    public String toString() {      return category + " (" + getChildCount() + ")";    }    public String getTitle() {      return toString();    }    public String toHTML() {      StringBuffer sb = new StringBuffer();      Util.startFont(sb);      BundleRepositoryService obr = getOBR();      if(obr != null) {	sb.append("<p>");	sb.append("Bundles in this category: " + getChildCount());	sb.append("</p>");      }            appendHelp(sb);      sb.append("</font>");      return sb.toString();    }  }  /**   * Tree Node for wrapping a BundleRecord in the OBR tree.   */  class OBRNode extends DefaultMutableTreeNode implements HTMLable {    String       name;    StringBuffer log = new StringBuffer();    BundleRecord br;    boolean bInstalled = false;    boolean     bBusy;    public OBRNode(BundleRecord br) {      super(null);      this.br = br;      name = Util.getBRName(br);      //      setIcon(bundleIcon);    }    public BundleRecord getBundleRecord() {      return br;    }    public void appendLog(String s) {      log.append(s);    }    public String getLog() {      return log.toString();    }    void setInstalled(boolean bInstalled) {      this.bInstalled = bInstalled;    }    public String toString() {      StringBuffer sb = new StringBuffer();            sb.append(name);      if(bInstalled) {	sb.append(" (installed)");      }      return sb.toString();    }    public String getIconURL() {      String iconURL = (String)br.getAttribute("Application-Icon");            if(iconURL != null && !"".equals(iconURL)) {	StringBuffer sb = new StringBuffer();		if(iconURL.startsWith("!")) {	  if(!iconURL.startsWith("!/")) {	    iconURL = "!/" + iconURL.substring(1);	  }	  iconURL = "jar:" + 	    br.getAttribute(BundleRecord.BUNDLE_UPDATELOCATION) +  iconURL;	} else if(-1 == iconURL.indexOf(":")) {	  iconURL = "jar:" + 	    br.getAttribute(BundleRecord.BUNDLE_UPDATELOCATION) + "!/" + iconURL;	}	return iconURL;      }            return null;    }    public String toHTML() {      StringBuffer sb = new StringBuffer();      String[]     attrs = br.getAttributes();            Map map = new TreeMap();      for(int i = 0; i < attrs.length; i++) {	Object obj = br.getAttribute(attrs[i]);	map.put(attrs[i], Util.toHTML(obj));      }      String desc = (String)br.getAttribute(BundleRecord.BUNDLE_DESCRIPTION);      if(desc != null) {	Util.startFont(sb);	sb.append("<p>");	sb.append(desc);	sb.append("</p>");	sb.append("</font>");	map.remove(BundleRecord.BUNDLE_DESCRIPTION);	map.remove(BundleRecord.BUNDLE_DESCRIPTION.toLowerCase());      }      sb.append("<table border=0>");      String log = getLog().trim();      if(log != null && !"".equals(log)) {	sb.append("<tr>");	sb.append("<td bgcolor=\"#eeeeee\" colspan=\"2\" valign=\"top\">");	sb.append("<pre>");	Util.startFont(sb, "-2");	sb.append(log);	sb.append("</font>");	sb.append("<pre>");	sb.append("</td>");	sb.append("</tr>");	      }      for(Iterator it = map.keySet().iterator(); it.hasNext();) {	String key = (String)it.next();	String val = (String)map.get(key);		sb.append("<tr>");	sb.append("<td valign=\"top\"><b>");	Util.startFont(sb);	sb.append(key);	sb.append("</b></font>");	sb.append("</td>");		sb.append("<td valign=\"top\">");	Util.startFont(sb);	sb.append(val);	sb.append("</font>");	sb.append("</td>");		sb.append("</tr>");      }            sb.append("</table>\n");      return sb.toString();    }    public String getTitle() {      return toString();    }  }}

⌨️ 快捷键说明

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