Exemple #1
0
  @Override
  public InputStream getInputStream() throws IOException {
    InputStream in = null;
    Device device = icon.getDevice();

    if (device instanceof RemoteDevice) {
      URL url = ((RemoteDevice) icon.getDevice()).normalizeURI(icon.getUri());

      in = url.openStream();
    }

    return in;
  }
 public static String getDeviceIcon(Device d, int maxHeight) {
   URL base = getURL(d);
   Icon icon = null;
   String url = null;
   int maxH = maxHeight == 0 ? 99999 : maxHeight, height = 0;
   for (Icon i : d.getIcons()) {
     int h = i.getHeight();
     if (h < maxH && h > height) {
       icon = i;
       height = h;
     }
   }
   try {
     url = icon != null ? new URL(base, icon.getUri().toString()).toString() : null;
   } catch (Exception e) {
   }
   LOGGER.debug("Device icon: " + url);
   return url;
 }
Exemple #3
0
 public URI getIconPath(Icon icon) {
   return URI.create(getPath(icon.getDevice()).toString() + "/" + icon.getUri().toString());
 }
  public void onRemoteDeviceComplete(@Observes @Phase.Complete RemoteDeviceDiscovery discovery) {

    RemoteDevice device = discovery.getDevice();

    Workbench.log(new LogMessage(Level.INFO, "Remote device added: " + device));

    final DeviceItem deviceItem =
        new DeviceItem(
            device,
            device.getDetails().getFriendlyName(),
            device.getDisplayString(),
            "(REMOTE) " + device.getType().getDisplayString());

    Icon usableIcon = findUsableIcon(device);

    if (usableIcon != null) {

      // We retrieve it using our own infrastructure, we know how that works and behaves

      final StreamRequestMessage iconRetrievalMsg =
          new StreamRequestMessage(
              UpnpRequest.Method.GET, device.normalizeURI(usableIcon.getUri()));

      StreamResponseMessage responseMsg = router.send(iconRetrievalMsg);

      if (responseMsg != null && !responseMsg.getOperation().isFailed()) {

        MimeType contentType =
            responseMsg
                .getHeaders()
                .getFirstHeader(UpnpHeader.Type.CONTENT_TYPE, ContentTypeHeader.class)
                .getValue();

        if (isUsableImageType(contentType)) {
          byte[] imageBody = (byte[]) responseMsg.getBody();
          if (imageBody != null) {
            ImageIcon imageIcon = new ImageIcon(imageBody);
            deviceItem.setIcon(imageIcon);
          } else {
            Workbench.log(
                Level.WARNING,
                "Icon request did not return with response body '"
                    + contentType
                    + "': "
                    + iconRetrievalMsg.getUri());
          }
        } else {
          Workbench.log(
              Level.WARNING,
              "Icon was delivered with unsupported content type '"
                  + contentType
                  + "': "
                  + iconRetrievalMsg.getUri());
        }

      } else {
        if (responseMsg != null) {
          Workbench.log(
              Level.WARNING,
              "Icon retrieval of '"
                  + iconRetrievalMsg.getUri()
                  + "' failed: "
                  + responseMsg.getOperation().getResponseDetails());
        } else {
          Workbench.log(
              Level.WARNING,
              "Icon retrieval of '"
                  + iconRetrievalMsg.getUri()
                  + "' failed, no response received.");
        }
      }
    }

    if (deviceItem.getIcon() == null) {
      deviceItem.setIcon(getUnknownDeviceIcon(deviceItem.getLabel()[0]));
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            view.addDeviceItem(deviceItem);
          }
        });
  }