Esempio n. 1
0
  /**
   * Write the device independent image array stored in the specified loader to the specified output
   * stream using the specified file format.
   */
  public static void save(OutputStream os, int format, ImageLoader loader) {
    if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
    if (FORMATS[format] == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
    if (loader.data == null || loader.data.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);

    LEDataOutputStream stream = new LEDataOutputStream(os);
    FileFormat fileFormat = null;
    try {
      Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[format] + FORMAT_SUFFIX);
      fileFormat = (FileFormat) clazz.newInstance();
    } catch (Exception e) {
      SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
    }
    if (format == SWT.IMAGE_BMP_RLE) {
      switch (loader.data[0].depth) {
        case 8:
          fileFormat.compression = 1;
          break;
        case 4:
          fileFormat.compression = 2;
          break;
      }
    }
    fileFormat.unloadIntoStream(loader, stream);
  }
Esempio n. 2
0
 ImageData[] loadFromByteStream() {
   int[] fileHeader = loadFileHeader();
   byte[] infoHeader = new byte[BMPHeaderFixedSize];
   try {
     inputStream.read(infoHeader);
   } catch (Exception e) {
     SWT.error(SWT.ERROR_IO, e);
   }
   width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8);
   height = (infoHeader[6] & 0xFF) | ((infoHeader[7] & 0xFF) << 8);
   bitCount = (infoHeader[10] & 0xFF) | ((infoHeader[11] & 0xFF) << 8);
   PaletteData palette = loadPalette(infoHeader);
   if (inputStream.getPosition() < fileHeader[4]) {
     // Seek to the specified offset
     try {
       inputStream.skip(fileHeader[4] - inputStream.getPosition());
     } catch (IOException e) {
       SWT.error(SWT.ERROR_IO, e);
     }
   }
   byte[] data = loadData(infoHeader);
   int type = SWT.IMAGE_OS2_BMP;
   return new ImageData[] {
     ImageData.internal_new(
         width, height, bitCount, palette, 4, data, 0, null, null, -1, -1, type, 0, 0, 0, 0)
   };
 }
Esempio n. 3
0
 /**
  * Replaces the first two elements in the parameter with values that describe the current point of
  * the path.
  *
  * @param point the array to hold the result
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the parameter is null
  *       <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public void getCurrentPoint(float[] point) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   NSPoint pt = handle.currentPoint();
   point[0] = pt.x;
   point[1] = pt.y;
 }
Esempio n. 4
0
 /**
  * Replaces the first four elements in the parameter with values that describe the smallest
  * rectangle that will completely contain the receiver (i.e. the bounding box).
  *
  * @param bounds the array to hold the result
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the parameter is null
  *       <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public void getBounds(float[] bounds) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   NSRect rect = handle.controlPointBounds();
   bounds[0] = rect.x;
   bounds[1] = rect.y;
   bounds[2] = rect.width;
   bounds[3] = rect.height;
 }
Esempio n. 5
0
 byte[] loadData(byte[] infoHeader, int stride) {
   int dataSize = height * stride;
   byte[] data = new byte[dataSize];
   try {
     if (inputStream.read(data) != dataSize) SWT.error(SWT.ERROR_INVALID_IMAGE);
   } catch (IOException e) {
     SWT.error(SWT.ERROR_IO, e);
   }
   return data;
 }
Esempio n. 6
0
 /**
  * Returns <code>true</code> if the specified point is contained by the receiver and false
  * otherwise.
  *
  * <p>If outline is <code>true</code>, the point (x, y) checked for containment in the receiver's
  * outline. If outline is <code>false</code>, the point is checked to see if it is contained
  * within the bounds of the (closed) area covered by the receiver.
  *
  * @param x the x coordinate of the point to test for containment
  * @param y the y coordinate of the point to test for containment
  * @param gc the GC to use when testing for containment
  * @param outline controls whether to check the outline or contained area of the path
  * @return <code>true</code> if the path contains the point and <code>false</code> otherwise
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the gc is null
  *       <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public boolean contains(float x, float y, GC gc, boolean outline) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   //	gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
   // TODO outline
   NSPoint point = new NSPoint();
   point.x = x;
   point.y = y;
   return handle.containsPoint(point);
 }
 /** Read a palette from the input stream. */
 PaletteData readPalette(int numColors) {
   byte[] bytes = new byte[numColors * 3];
   try {
     if (inputStream.read(bytes) != bytes.length) SWT.error(SWT.ERROR_INVALID_IMAGE);
   } catch (IOException e) {
     SWT.error(SWT.ERROR_IO, e);
   }
   RGB[] colors = new RGB[numColors];
   for (int i = 0; i < numColors; i++)
     colors[i] = new RGB(bytes[i * 3] & 0xFF, bytes[i * 3 + 1] & 0xFF, bytes[i * 3 + 2] & 0xFF);
   return new PaletteData(colors);
 }
 /**
  * Constructs a new Pattern given an image. Drawing with the resulting pattern will cause the
  * image to be tiled over the resulting area.
  *
  * <p>This operation requires the operating system's advanced graphics subsystem which may not be
  * available on some platforms.
  *
  * @param device the device on which to allocate the pattern
  * @param image the image that the pattern will draw
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or the
  *           image is null
  *       <li>ERROR_INVALID_ARGUMENT - if the image has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
  *     </ul>
  *
  * @exception SWTError
  *     <ul>
  *       <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained
  *     </ul>
  *
  * @see #dispose()
  */
 public Pattern(Device device, Image image) {
   super(device);
   if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   this.device.checkCairo();
   image.createSurface();
   handle = Cairo.cairo_pattern_create_for_surface(image.surface);
   if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
   Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_REPEAT);
   surface = image.surface;
   init();
 }
Esempio n. 9
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;
 }
 void decompressData(byte[] src, byte[] dest, int stride, int cmp) {
   if (cmp == 1) { // BMP_RLE8_COMPRESSION
     if (decompressRLE8Data(src, src.length, stride, dest, dest.length) <= 0)
       SWT.error(SWT.ERROR_INVALID_IMAGE);
     return;
   }
   if (cmp == 2) { // BMP_RLE4_COMPRESSION
     if (decompressRLE4Data(src, src.length, stride, dest, dest.length) <= 0)
       SWT.error(SWT.ERROR_INVALID_IMAGE);
     return;
   }
   SWT.error(SWT.ERROR_INVALID_IMAGE);
 }
Esempio n. 11
0
 /**
  * Read the specified input stream, and return the device independent image array represented by
  * the stream.
  */
 public ImageData[] loadFromStream(LEDataInputStream stream) {
   try {
     inputStream = stream;
     return loadFromByteStream();
   } catch (Exception e) {
     if (e instanceof IOException) {
       SWT.error(SWT.ERROR_IO, e);
     } else {
       SWT.error(SWT.ERROR_INVALID_IMAGE, e);
     }
     return null;
   }
 }
Esempio n. 12
0
 int[] loadFileHeader() {
   int[] header = new int[5];
   try {
     header[0] = inputStream.readShort();
     header[1] = inputStream.readInt();
     header[2] = inputStream.readShort();
     header[3] = inputStream.readShort();
     header[4] = inputStream.readInt();
   } catch (IOException e) {
     SWT.error(SWT.ERROR_IO, e);
   }
   if (header[0] != 0x4D42) SWT.error(SWT.ERROR_INVALID_IMAGE);
   return header;
 }
Esempio n. 13
0
 PaletteData loadPalette(byte[] infoHeader) {
   if (bitCount <= 8) {
     int numColors = 1 << bitCount;
     byte[] buf = new byte[numColors * 3];
     try {
       if (inputStream.read(buf) != buf.length) SWT.error(SWT.ERROR_INVALID_IMAGE);
     } catch (IOException e) {
       SWT.error(SWT.ERROR_IO, e);
     }
     return paletteFromBytes(buf, numColors);
   }
   if (bitCount == 16) return new PaletteData(0x7C00, 0x3E0, 0x1F);
   if (bitCount == 24) return new PaletteData(0xFF, 0xFF00, 0xFF0000);
   return new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
 }
Esempio n. 14
0
 /**
  * Finds the program that is associated with an extension. The extension may or may not begin with
  * a '.'. Note that a <code>Display</code> must already exist to guarantee that this method
  * returns an appropriate result.
  *
  * @param extension the program extension
  * @return the program or <code>null</code>
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT when extension is null
  *     </ul>
  */
 public static Program findProgram(String extension) {
   NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
   try {
     if (extension == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
     if (extension.length() == 0) return null;
     Program program = null;
     char[] chars;
     if (extension.charAt(0) != '.') {
       chars = new char[extension.length()];
       extension.getChars(0, chars.length, chars, 0);
     } else {
       chars = new char[extension.length() - 1];
       extension.getChars(1, extension.length(), chars, 0);
     }
     NSString ext = NSString.stringWithCharacters(chars, chars.length);
     if (ext != null) {
       byte[] fsRef = new byte[80];
       if (OS.LSGetApplicationForInfo(
               OS.kLSUnknownType, OS.kLSUnknownCreator, ext.id, OS.kLSRolesAll, fsRef, null)
           == OS.noErr) {
         long /*int*/ url = OS.CFURLCreateFromFSRef(OS.kCFAllocatorDefault(), fsRef);
         if (url != 0) {
           NSString bundlePath = new NSURL(url).path();
           NSBundle bundle = NSBundle.bundleWithPath(bundlePath);
           if (bundle != null) program = getProgram(bundle);
           OS.CFRelease(url);
         }
       }
     }
     return program;
   } finally {
     pool.release();
   }
 }
Esempio n. 15
0
 public Path(Device device, Path path, float flatness) {
   super(device);
   if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   flatness = Math.max(0, flatness);
   if (flatness == 0) {
     handle = new NSBezierPath(path.handle.copy().id);
   } else {
     float defaultFlatness = NSBezierPath.defaultFlatness();
     NSBezierPath.setDefaultFlatness(flatness);
     handle = path.handle.bezierPathByFlatteningPath();
     NSBezierPath.setDefaultFlatness(defaultFlatness);
   }
   if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
   init();
 }
Esempio n. 16
0
 /**
  * Sets the current point of the receiver to the point specified by (x, y). Note that this starts
  * a new sub path.
  *
  * @param x the x coordinate of the new end point
  * @param y the y coordinate of the new end point
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public void moveTo(float x, float y) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   NSPoint pt = new NSPoint();
   pt.x = x;
   pt.y = y;
   handle.moveToPoint(pt);
 }
Esempio n. 17
0
 void init(PathData data) {
   byte[] types = data.types;
   float[] points = data.points;
   for (int i = 0, j = 0; i < types.length; i++) {
     switch (types[i]) {
       case SWT.PATH_MOVE_TO:
         moveTo(points[j++], points[j++]);
         break;
       case SWT.PATH_LINE_TO:
         lineTo(points[j++], points[j++]);
         break;
       case SWT.PATH_CUBIC_TO:
         cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
         break;
       case SWT.PATH_QUAD_TO:
         quadTo(points[j++], points[j++], points[j++], points[j++]);
         break;
       case SWT.PATH_CLOSE:
         close();
         break;
       default:
         dispose();
         SWT.error(SWT.ERROR_INVALID_ARGUMENT);
     }
   }
 }
Esempio n. 18
0
  /**
   * Sets the font that the receiver will use to paint textual information for the specified cell in
   * this item to the font specified by the argument, or to the default font for that kind of
   * control if the argument is null.
   *
   * @param index the column index
   * @param font the new font (or null)
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   *
   * @since 3.0
   */
  public void setFont(int index, Font font) {
    checkWidget();
    if (font != null && font.isDisposed()) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return;
    if (cellFont == null) {
      if (font == null) return;
      cellFont = new Font[count];
    }
    Font oldFont = cellFont[index];
    if (oldFont == font) return;
    cellFont[index] = font;
    if (oldFont != null && oldFont.equals(font)) return;

    int modelIndex =
        parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
    int /*long*/ fontHandle = font != null ? font.handle : 0;
    OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_FONT, fontHandle, -1);
    /*
     * Bug in GTK.  When using fixed-height-mode,
     * row changes do not cause the row to be repainted.  The fix is to
     * invalidate the row when it is cleared.
     */
    if ((parent.style & SWT.VIRTUAL) != 0) {
      if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
        redraw();
      }
    }
    cached = true;

    if (font != null) {
      boolean customDraw =
          (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns[index].customDraw;
      if (!customDraw) {
        if ((parent.style & SWT.VIRTUAL) == 0) {
          int /*long*/ parentHandle = parent.handle;
          int /*long*/ column = 0;
          if (parent.columnCount > 0) {
            column = parent.columns[index].handle;
          } else {
            column = OS.gtk_tree_view_get_column(parentHandle, index);
          }
          if (column == 0) return;
          int /*long*/ textRenderer = parent.getTextRenderer(column);
          int /*long*/ imageRenderer = parent.getPixbufRenderer(column);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, textRenderer, display.cellDataProc, parentHandle, 0);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, imageRenderer, display.cellDataProc, parentHandle, 0);
        }
        if (parent.columnCount == 0) {
          parent.firstCustomDraw = true;
        } else {
          parent.columns[index].customDraw = true;
        }
      }
    }
  }
 /**
  * We have just read the GraphicsControl extension identifier from the input stream. Read in the
  * control information, store it, and return it.
  */
 byte[] readGraphicsControlExtension() {
   try {
     // Read size of block = 0x04.
     inputStream.read();
     // Read the control block.
     byte[] controlBlock = new byte[4];
     inputStream.read(controlBlock);
     byte bitField = controlBlock[0];
     // Store the user input field.
     // userInput = (bitField & 0x02) != 0;
     // Store the disposal method.
     disposalMethod = (bitField >> 2) & 0x07;
     // Store the delay time.
     delayTime = (controlBlock[1] & 0xFF) | ((controlBlock[2] & 0xFF) << 8);
     // Store the transparent color.
     if ((bitField & 0x01) != 0) {
       transparentPixel = controlBlock[3] & 0xFF;
     } else {
       transparentPixel = -1;
     }
     return controlBlock;
   } catch (Exception e) {
     SWT.error(SWT.ERROR_IO, e);
     return null;
   }
 }
 /** Write out a GraphicsControlBlock to describe the specified device independent image. */
 void writeGraphicsControlBlock(ImageData image) {
   try {
     outputStream.write(GIF_EXTENSION_BLOCK_ID);
     outputStream.write(GIF_GRAPHICS_CONTROL_BLOCK_ID);
     byte[] gcBlock = new byte[4];
     gcBlock[0] = 0;
     gcBlock[1] = 0;
     gcBlock[2] = 0;
     gcBlock[3] = 0;
     if (image.transparentPixel != -1) {
       gcBlock[0] = (byte) 0x01;
       gcBlock[3] = (byte) image.transparentPixel;
     }
     if (image.disposalMethod != 0) {
       gcBlock[0] |= (byte) ((image.disposalMethod & 0x07) << 2);
     }
     if (image.delayTime != 0) {
       gcBlock[1] = (byte) (image.delayTime & 0xFF);
       gcBlock[2] = (byte) ((image.delayTime >> 8) & 0xFF);
     }
     outputStream.write((byte) gcBlock.length);
     outputStream.write(gcBlock);
     outputStream.write(0); // Block terminator
   } catch (IOException e) {
     SWT.error(SWT.ERROR_IO, e);
   }
 }
Esempio n. 21
0
File: DND.java Progetto: oaperez/rap
  /**
   * Throws an appropriate exception based on the passed in error code. The <code>hresult</code>
   * argument should be either 0, or the platform specific error code.
   *
   * <p>In DND, errors are reported by throwing one of three exceptions:
   *
   * <dl>
   *   <dd>java.lang.IllegalArgumentException
   *   <dt>thrown whenever one of the API methods is invoked with an illegal argument
   *   <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)
   *   <dt>thrown whenever a recoverable error happens internally in SWT
   *   <dd>org.eclipse.swt.SWTError (extends java.lang.Error)
   *   <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT
   * </dl>
   *
   * This method provides the logic which maps between error codes and one of the above exceptions.
   *
   * @param code the DND error code.
   * @param hresult the platform specific error code.
   * @see SWTError
   * @see SWTException
   * @see IllegalArgumentException
   */
  public static void error(int code, int hresult) {
    switch (code) {
        /* OS Failure/Limit (fatal, may occur only on some platforms) */
      case DND.ERROR_CANNOT_INIT_DRAG:
        {
          String msg = DND.INIT_DRAG_MESSAGE;
          if (hresult != 0) msg += " result = " + hresult; // $NON-NLS-1$
          throw new SWTError(code, msg);
        }
      case DND.ERROR_CANNOT_INIT_DROP:
        {
          String msg = DND.INIT_DROP_MESSAGE;
          if (hresult != 0) msg += " result = " + hresult; // $NON-NLS-1$
          throw new SWTError(code, msg);
        }
      case DND.ERROR_CANNOT_SET_CLIPBOARD:
        {
          String msg = DND.CANNOT_SET_CLIPBOARD_MESSAGE;
          if (hresult != 0) msg += " result = " + hresult; // $NON-NLS-1$
          throw new SWTError(code, msg);
        }
      case DND.ERROR_INVALID_DATA:
        {
          String msg = DND.INVALID_DATA_MESSAGE;
          if (hresult != 0) msg += " result = " + hresult; // $NON-NLS-1$
          throw new SWTException(code, msg);
        }
    }

    /* Unknown/Undefined Error */
    SWT.error(code);
  }
Esempio n. 22
0
 /**
  * Searches the receiver's list starting at the given, zero-relative index until an item is found
  * that is equal to the argument, and returns the index of that item. If no item is found or the
  * starting index is out of range, returns -1.
  *
  * @param string the search item
  * @param start the zero-relative index at which to start the search
  * @return the index of the item
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the string is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public int indexOf(String string, int start) {
   checkWidget();
   if (string == null) {
     SWT.error(SWT.ERROR_NULL_ARGUMENT);
   }
   return model.indexOf(string, start);
 }
 /**
  * Unload the given image's data into the given byte stream using the given compression strategy.
  * Answer the number of bytes written. Method modified to use the passed data if it is not null.
  */
 int unloadData(ImageData image, byte[] data, OutputStream out, int comp) {
   int totalSize = 0;
   try {
     if (comp == 0) return unloadDataNoCompression(image, data, out);
     int bpl = (image.width * image.depth + 7) / 8;
     int bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes
     int imageBpl = image.bytesPerLine;
     // Compression can actually take twice as much space, in worst case
     byte[] buf = new byte[bmpBpl * 2];
     int srcOffset = imageBpl * (image.height - 1); // Start at last line
     if (data == null) data = image.data;
     totalSize = 0;
     byte[] buf2 = new byte[32768];
     int buf2Offset = 0;
     for (int y = image.height - 1; y >= 0; y--) {
       int lineSize = compress(comp, data, srcOffset, bpl, buf, y == 0);
       if (buf2Offset + lineSize > buf2.length) {
         out.write(buf2, 0, buf2Offset);
         buf2Offset = 0;
       }
       System.arraycopy(buf, 0, buf2, buf2Offset, lineSize);
       buf2Offset += lineSize;
       totalSize += lineSize;
       srcOffset -= imageBpl;
     }
     if (buf2Offset > 0) out.write(buf2, 0, buf2Offset);
   } catch (IOException e) {
     SWT.error(SWT.ERROR_IO, e);
   }
   return totalSize;
 }
Esempio n. 24
0
 /**
  * Adds the listener to the collection of listeners who will be notified when the receiver's
  * selection changes, by sending it one of the messages defined in the <code>SelectionListener
  * </code> interface.
  *
  * <p><code>widgetSelected</code> is called when the combo's list selection changes. <code>
  * widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
  *
  * @param listener the listener which should be notified
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the listener is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @see SelectionListener
  * @see #removeSelectionListener
  * @see SelectionEvent
  */
 public void addSelectionListener(SelectionListener listener) {
   checkWidget();
   if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   TypedListener typedListener = new TypedListener(listener);
   addListener(SWT.Selection, typedListener);
   addListener(SWT.DefaultSelection, typedListener);
 }
Esempio n. 25
0
 /**
  * Adds a focus listener.
  *
  * @param modifyListener the listener
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT when listener is null
  *     </ul>
  */
 public void addFocusListener(FocusListener focusListener) {
   checkWidget();
   if (focusListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   BasicTextListener typedListener = new BasicTextListener(focusListener);
   addListener(SWT.FocusOut, typedListener);
   addListener(SWT.FocusIn, typedListener);
 }
Esempio n. 26
0
  /**
   * Removes the listener from the collection of listeners who will be notified when the receiver
   * are expanded or collapsed.
   *
   * @param listener the listener which should no longer be notified
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the listener is null
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   *
   * @see ExpandListener
   * @see #addExpandListener
   */
  public void removeExpandListener(ExpandListener listener) {
    checkWidget();
    if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

    removeListener(SWT.Expand, listener);
    removeListener(SWT.Collapse, listener);
  }
Esempio n. 27
0
 /**
  * Sets the text.
  *
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the text is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setText(String text) {
   checkWidget();
   if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   this.text = text;
   strategy.update();
   redraw();
 }
Esempio n. 28
0
  /**
   * Sets the image.
   *
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the image is disposed
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   */
  public void setImage(Image image) {
    checkWidget();

    if (image != null && image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    this.image = image;
    strategy.update();
  }
Esempio n. 29
0
  /**
   * Adds the listener to the collection of listeners who will be notified when the receiver is
   * expanded or collapsed by sending it one of the messages defined in the <code>ExpandListener
   * </code> interface.
   *
   * @param listener the listener which should be notified
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the listener is null
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   *
   * @see ExpandListener
   * @see #removeExpandListener
   */
  public void addExpandListener(ExpandListener listener) {
    checkWidget();
    if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

    TypedListener typedListener = new TypedListener(listener);
    addListener(SWT.Expand, typedListener);
    addListener(SWT.Collapse, typedListener);
  }
Esempio n. 30
0
 /**
  * Sets the strategy.
  *
  * @param strategy the strategy to set
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the strategy is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 @SuppressWarnings("null")
 public void setStrategy(AbstractGroupStrategy strategy) {
   checkWidget();
   if (strategy == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   this.strategy = strategy;
   setForeground(null);
   strategy.initialize(this);
 }