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

📄 desktop.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      Activator.log.error("Failed to write to " + file, e);    } finally {      try { out.close(); } catch (Exception ignored) { }    }    String txt =      "Saved deploy archive as\n\n" +      "  " + file.getAbsolutePath() + "\n\n" +      "To run, unpack the archive and run with\n\n" +      "  java -jar framwork.jar\n";    JOptionPane.showMessageDialog(frame,                                  txt,                                  "Saved deploy archive",                                  JOptionPane.INFORMATION_MESSAGE,                                  null);  }  public Bundle[] getSelectedBundles() {    int n = 0;    for(int i = 0; i < bundleCache.length; i++) {      if(bundleSelModel.isSelected(bundleCache[i].getBundleId())) {        n++;      }    }    Bundle[] bl = new Bundle[n];    n = 0;    for(int i = 0; i < bundleCache.length; i++) {      if(bundleSelModel.isSelected(bundleCache[i].getBundleId())) {        bl[n++] = bundleCache[i];      }    }    return bl;  }  void startBundle(Bundle b) {    try {      b.start();    } catch (Exception e) {      showErr("failed to start bundle " +              Util.getBundleName(b), e);    }  }  void stopBundles(Bundle[] bl) {    for(int i = 0; bl != null && i < bl.length; i++) {      Bundle b = bl[i];      stopBundle(b);    }  }  void startBundles(Bundle[] bl) {    for(int i = 0; bl != null && i < bl.length; i++) {      Bundle b = bl[i];      startBundle(b);    }  }  void updateBundles(Bundle[] bl) {    for(int i = 0; bl != null && i < bl.length; i++) {      Bundle b = bl[i];      updateBundle(b);    }  }  void uninstallBundles(Bundle[] bl) {    for(int i = 0; bl != null && i < bl.length; i++) {      Bundle b = bl[i];      uninstallBundle(b, true);    }  }  void stopBundle(Bundle b) {    int n = 0;    if(b.getBundleId() == Activator.getTargetBC().getBundle().getBundleId() ||       b.getBundleId() == 0) {      Object[] options = { Strings.get("yes"),                           Strings.get("no")};      n = JOptionPane        .showOptionDialog(frame,                          Strings.fmt("fmt_q_stopdesktop",                                      Util.getBundleName(b)),                          Strings.get("yes"),                          JOptionPane.YES_NO_OPTION,                          JOptionPane.QUESTION_MESSAGE,                          null,                          options,                          options[1]);    }    if(n == 0) {      try {        b.stop();      } catch (Exception e) {        showErr("failed to stop bundle " +                Util.getBundleName(b), e);      }    }  }  void refreshBundle(Bundle[] b) {    ServiceReference sr = Activator.getTargetBC().getServiceReference(PackageAdmin.class.getName());    if(sr != null) {      PackageAdmin packageAdmin = (PackageAdmin)Activator.getTargetBC().getService(sr);      if(packageAdmin != null) {        if(b != null && b.length == 0) {          b = null;        }        packageAdmin.refreshPackages(b);      }      Activator.getTargetBC().ungetService(sr);    }  }  void updateBundle(Bundle b) {    try {      boolean bUpdateIsUpdate = "true".equals(System.getProperty("org.knopflerfish.desktop.updateisupdate", "true"));      if(bUpdateIsUpdate || b == Activator.getBC().getBundle()) {        b.update();      } else {        String location = (String)b.getHeaders().get(Constants.BUNDLE_UPDATELOCATION);        if(location == null || "".equals(location)) {          location = b.getLocation();        }        if(uninstallBundle(b, true)) {          refreshBundle(new Bundle[] { b });          Bundle newBundle = Activator.getTargetBC().installBundle(location);          if(Util.canBeStarted(newBundle)) {            startBundle(newBundle);          }        }      }    } catch (Exception e) {      showErr("failed to update bundle " + Util.getBundleName(b), e);    }  }  boolean uninstallBundle(Bundle b, boolean bAsk) {    Object[] options = {Strings.get("yes"),                        Strings.get("no")};    int n = bAsk      ? JOptionPane      .showOptionDialog(frame,                        Strings.fmt("q_uninstallbundle",                                     Util.getBundleName(b)),                        Strings.get("msg_uniunstallbundle"),                        JOptionPane.YES_NO_OPTION,                        JOptionPane.QUESTION_MESSAGE,                        null,                        options,                        options[1])      : 0;    if(n == 0) {      try {        b.uninstall();        return true;      } catch (Exception e) {        showErr("failed to uninstall bundle " + Util.getBundleName(b), e);      }    }    return false;  }  void showErr(String msg, Exception e) {    if(msg != null && !"".equals(msg)) {      System.out.println(msg);    }    Throwable t = e;    while(t instanceof BundleException &&          ((BundleException) t).getNestedException() != null) {      t = ((BundleException) t).getNestedException();    }    t.printStackTrace();  }  // DropTargetListener  public void drop(DropTargetDropEvent e) {    // This code is f***ing unbelievable.    // How is anyone supposed to create it from scratch?    try {      DataFlavor[] dfl = e.getCurrentDataFlavors();      Transferable tr  = e.getTransferable();      if(e.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {        e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);        java.util.List files = (java.util.List)tr.getTransferData(DataFlavor.javaFileListFlavor);        for(Iterator it = files.iterator(); it.hasNext();) {          File file = (File)it.next();          addFile(file);        }        e.dropComplete(true);      } else if(e.isDataFlavorSupported(DataFlavor.stringFlavor)) {        e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);        String filename = (String)tr.getTransferData(DataFlavor.stringFlavor);        addFile(new File(filename));        e.dropComplete(true);      } else {        // Reject drop      }    }    catch(IOException ioe) {      showErr(null, ioe);    }    catch(UnsupportedFlavorException ufe) {      showErr("Unsupported data type", ufe);    }  }  // DropTargetListener  public void dragEnter(DropTargetDragEvent e) {    //    System.out.println("dragEnter " + e);  }  // DropTargetListener  public void dragExit(DropTargetEvent e) {    //    System.out.println("dragExit " + e);  }  // DropTargetListener  public void dragOver(DropTargetDragEvent e) {    //    System.out.println("dragOver " + e);  }  // DropTargetListener  public void dropActionChanged(DropTargetDragEvent e) {    //    System.out.println("dropActionChanged " + e);  }  void addFile(File file) {    try {      if(file.getName().toUpperCase().endsWith(".JAR")) {        try {          String location = "file:" + file.getAbsolutePath();          Bundle b = Activator.getTargetBC().installBundle(location);          Dictionary headers = b.getHeaders();          if(Util.canBeStarted(b)) {            startBundle(b);          }        } catch (Exception e) {          showErr(null, e);        }      }    } catch (Exception e) {      Activator.log.error("Failed to add file", e);    }  }  public void stop() {    if(tips != null) {      tips.setVisible(false);      tips = null;    }    frameLocation = frame.getLocationOnScreen();    frameSize     = frame.getSize();    alive = false;    slTracker.close();    dispTracker.close();    pkgTracker.close();    // Make sure floating windows are closed    for(int i = 0; i < detailPanel.getTabCount(); i++) {      Component comp = detailPanel.getComponentAt(i);      if(comp instanceof JFloatable) {        ((JFloatable)comp).setAutoClose(true);      }    }    Activator.getTargetBC().removeBundleListener(this);    if(consoleSwing != null) {      consoleSwing.stop();      consoleSwing = null;    }    if(frame != null) {      frame.setVisible(false);      frame = null;    }  }  public void valueChanged(long bid) {    if(!alive) {      return;    }    updateBundleViewSelections();  }  public void frameworkEvent(FrameworkEvent ev) {    if(!alive) {      return;    }    switch(ev.getType()) {    case FrameworkEvent.STARTLEVEL_CHANGED:      updateStartLevel();      break;    }  }  Bundle[] bundleCache;  public void bundleChanged(BundleEvent ev) {    if(!alive) {      return;    }    Bundle b = ev.getBundle();    bundleCache = Activator.getTargetBC().getBundles();    boolean bMyself = false;    if(Activator.getTargetBC() == Activator.getBC()) {      bMyself = b.getBundleId() == Activator.getBC().getBundle().getBundleId();    }    updateStatusBar();    toolBar.revalidate();    toolBar.repaint();  }  void updateStatusBar() {  }  JTips tips = null;  void showTips() {    if(tips == null) {      tips = new JTips("/tips.html");    }    tips.setVisible(true);  }  void showInfo() {    JTextPane html = new JTextPane();    html.setContentType("text/html");    html.setEditable(false);    html.setText(Util.getSystemInfo());    final JScrollPane scroll = new JScrollPane(html);    scroll.setPreferredSize(new Dimension(420, 300));    SwingUtilities.invokeLater(new Runnable() {        public void run() {          JViewport vp = scroll.getViewport();          if(vp != null) {            vp.setViewPosition(new Point(0,0));            scroll.setViewport(vp);          }        }      });    JOptionPane.showMessageDialog(frame,                                  scroll,                                  "Framework info",                                  JOptionPane.INFORMATION_MESSAGE,                                  null);  }  void showVersion() {    String version = "1.1.1";    String txt = Strings.fmt("str_abouttext", version);    ImageIcon icon =      new ImageIcon(getClass().getResource("/fish150x225.gif"));    JOptionPane.showMessageDialog(frame,                                  txt,                                  Strings.get("str_about"),                                  JOptionPane.INFORMATION_MESSAGE,                                  icon);  }  public void setIcon(JFrame frame, String baseName) {    String iconName = baseName + "32x32.gif";    if (System.getProperty( "os.name", "" ).startsWith("Win")) {      iconName = baseName + "16x16.gif";    }    String strURL = iconName;    try {      MediaTracker tracker = new MediaTracker(frame);      URL url = getClass().getResource(strURL);      if(url != null) {        Image image = frame.getToolkit().getImage(url);        tracker.addImage(image, 0);        tracker.waitForID(0);        frame.setIconImage(image);      } else {      }    } catch (Exception e) {    }  }  public ImageIcon getBundleEventIcon(int type) {    switch(type) {    case BundleEvent.INSTALLED:   return installIcon;    case BundleEvent.STARTED:     return startIcon;    case BundleEvent.STOPPED:     return stopIcon;    case BundleEvent.UNINSTALLED: return uninstallIcon;    case BundleEvent.UPDATED:     return updateIcon;    default:                      return null;    }  }}

⌨️ 快捷键说明

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