Esempio n. 1
0
 public NSImage convert(final NSImage icon, final Integer width, final Integer height) {
   if (null == width || null == height) {
     log.debug(String.format("Return default size for %s", icon.name()));
     return icon;
   }
   icon.setSize(new NSSize(width, height));
   return icon;
 }
Esempio n. 2
0
 private NSImage iconForFolder(final NSImage badge, final Integer size) {
   final String name = String.format("NSFolder-%s", badge.name());
   NSImage folder = this.iconForName(name, size);
   if (null == folder) {
     folder = this.badge(badge, this.convert(FOLDER_ICON, size));
     this.put(name, folder, size);
   }
   return folder;
 }
Esempio n. 3
0
 public NSImage iconForExtension(final NSImage badge, final String extension, final Integer size) {
   final String name = extension + badge.name();
   NSImage icon = this.iconForName(name, size);
   if (null == icon) {
     icon = this.badge(badge, this.iconForExtension(extension, size));
     this.put(name, icon, size);
   }
   return icon;
 }
Esempio n. 4
0
 /**
  * Overlay badge image.
  *
  * @param badge Overlay
  * @param icon Icon
  * @return Cached icon
  */
 private NSImage badge(final NSImage badge, final NSImage icon) {
   NSImage f = NSImage.imageWithSize(icon.size());
   f.lockFocus();
   icon.drawInRect(
       new NSRect(new NSPoint(0, 0), icon.size()),
       NSZeroRect,
       NSGraphics.NSCompositeSourceOver,
       1.0f);
   badge.drawInRect(
       new NSRect(new NSPoint(0, 0), icon.size()),
       NSZeroRect,
       NSGraphics.NSCompositeSourceOver,
       1.0f);
   f.unlockFocus();
   return f;
 }
Esempio n. 5
0
 /**
  * @param name When looking for files in the application bundle, it is better (but not required)
  *     to include the filename extension in the name parameter
  * @param width Requested size
  * @param height Requested size
  * @return Cached icon
  * @see NSImage#imageNamed(String)
  * @see #convert(ch.cyberduck.ui.cocoa.application.NSImage, Integer, Integer)
  */
 protected NSImage iconForName(final String name, final Integer width, final Integer height) {
   NSImage image = this.load(name, width);
   if (null == image) {
     if (name.startsWith("/")) {
       image = NSImage.imageWithContentsOfFile(name);
     } else {
       image = NSImage.imageNamed(name);
     }
     if (null == image) {
       log.warn(String.format("No icon named %s", name));
       this.put(name, null, width);
     } else {
       // You can clear an image object from the cache explicitly by passing nil for the image
       // name.
       image.setName(null);
       this.put(name, this.convert(image, width, height), width);
     }
   }
   return image;
 }
Esempio n. 6
0
 public NSImage iconForPath(final Path item, final Integer size, final boolean overlay) {
   if (item.attributes().isSymbolicLink()) {
     final NSImage badge = this.iconForName("aliasbadge.tiff", size);
     badge.setName("aliasbadge");
     if (item.attributes().isDirectory()) {
       return this.iconForFolder(badge, size);
     }
     return this.iconForExtension(badge, item.getExtension(), size);
   }
   if (item.attributes().isFile()) {
     if (StringUtils.isEmpty(item.getExtension())) {
       if (item.attributes().getPermission().isExecutable()) {
         return this.iconForName("executable.tiff", size);
       }
     }
     return this.iconForExtension(item.getExtension(), size);
   }
   if (item.attributes().isVolume()) {
     return this.iconForName(item.getHost().getProtocol().disk(), size);
   }
   if (item.attributes().isDirectory()) {
     if (overlay) {
       if (!item.attributes().getPermission().isExecutable()) {
         final NSImage badge = this.iconForName("privatefolderbadge.tiff", size);
         badge.setName("privatefolderbadge");
         return this.iconForFolder(badge, size);
       }
       if (!item.attributes().getPermission().isReadable()) {
         if (item.attributes().getPermission().isWritable()) {
           final NSImage badge = this.iconForName("dropfolderbadge.tiff", size);
           badge.setName("dropfolderbadge");
           return this.iconForFolder(badge, size);
         }
       }
       if (!item.attributes().getPermission().isWritable()) {
         final NSImage badge = this.iconForName("readonlyfolderbadge.tiff", size);
         badge.setName("readonlyfolderbadge");
         return this.iconForFolder(badge, size);
       }
     }
     return this.iconForFolder(size);
   }
   return this.iconForName("notfound.tiff", size);
 }