Beispiel #1
0
 /**
  * Returns a device independent representation of the receiver.
  *
  * @return the PathData for the receiver
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  *
  * @see PathData
  */
 public PathData getPathData() {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   int count = handle.elementCount();
   int pointCount = 0, typeCount = 0;
   byte[] types = new byte[count];
   float[] pointArray = new float[count * 6];
   int points = OS.malloc(3 * NSPoint.sizeof);
   if (points == 0) SWT.error(SWT.ERROR_NO_HANDLES);
   NSPoint pt = new NSPoint();
   for (int i = 0; i < count; i++) {
     int element = handle.elementAtIndex_associatedPoints_(i, points);
     switch (element) {
       case OS.NSMoveToBezierPathElement:
         types[typeCount++] = SWT.PATH_MOVE_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSLineToBezierPathElement:
         types[typeCount++] = SWT.PATH_LINE_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSCurveToBezierPathElement:
         types[typeCount++] = SWT.PATH_CUBIC_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         OS.memmove(pt, points + NSPoint.sizeof, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         OS.memmove(pt, points + NSPoint.sizeof + NSPoint.sizeof, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSClosePathBezierPathElement:
         types[typeCount++] = SWT.PATH_CLOSE;
         break;
     }
   }
   OS.free(points);
   if (pointCount != pointArray.length) {
     float[] temp = new float[pointCount];
     System.arraycopy(pointArray, 0, temp, 0, pointCount);
     pointArray = temp;
   }
   PathData data = new PathData();
   data.types = types;
   data.points = pointArray;
   return data;
 }
 /**
  * Answer all program extensions in the operating system. Note that a <code>Display</code> must
  * already exist to guarantee that this method returns an appropriate result.
  *
  * @return an array of extensions
  */
 public static String[] getExtensions() {
   NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
   try {
     NSMutableSet supportedDocumentTypes = (NSMutableSet) NSMutableSet.set();
     NSWorkspace workspace = NSWorkspace.sharedWorkspace();
     NSString CFBundleDocumentTypes = NSString.stringWith("CFBundleDocumentTypes");
     NSString CFBundleTypeExtensions = NSString.stringWith("CFBundleTypeExtensions");
     NSArray array =
         new NSArray(
             OS.NSSearchPathForDirectoriesInDomains(
                 OS.NSAllApplicationsDirectory, OS.NSAllDomainsMask, true));
     int count = (int) /*64*/ array.count();
     for (int i = 0; i < count; i++) {
       NSString path = new NSString(array.objectAtIndex(i));
       NSFileManager fileManager = NSFileManager.defaultManager();
       NSDirectoryEnumerator enumerator = fileManager.enumeratorAtPath(path);
       if (enumerator != null) {
         id id;
         while ((id = enumerator.nextObject()) != null) {
           enumerator.skipDescendents();
           NSString filePath = new NSString(id.id);
           NSString fullPath = path.stringByAppendingPathComponent(filePath);
           if (workspace.isFilePackageAtPath(fullPath)) {
             NSBundle bundle = NSBundle.bundleWithPath(fullPath);
             id =
                 bundle != null
                     ? bundle.infoDictionary().objectForKey(CFBundleDocumentTypes)
                     : null;
             if (id != null) {
               NSDictionary documentTypes = new NSDictionary(id.id);
               NSEnumerator documentTypesEnumerator = documentTypes.objectEnumerator();
               while ((id = documentTypesEnumerator.nextObject()) != null) {
                 NSDictionary documentType = new NSDictionary(id.id);
                 id = documentType.objectForKey(CFBundleTypeExtensions);
                 if (id != null) {
                   supportedDocumentTypes.addObjectsFromArray(new NSArray(id.id));
                 }
               }
             }
           }
         }
       }
     }
     int i = 0;
     String[] exts = new String[(int) /*64*/ supportedDocumentTypes.count()];
     NSEnumerator enumerator = supportedDocumentTypes.objectEnumerator();
     id id;
     while ((id = enumerator.nextObject()) != null) {
       String ext = new NSString(id.id).getString();
       if (!ext.equals("*")) exts[i++] = "." + ext;
     }
     if (i != exts.length) {
       String[] temp = new String[i];
       System.arraycopy(exts, 0, temp, 0, i);
       exts = temp;
     }
     return exts;
   } finally {
     pool.release();
   }
 }