/**
  * 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();
 }
 /**
  * Constructs a new Pattern that represents a linear, two color gradient. Drawing with the pattern
  * will cause the resulting area to be tiled with the gradient specified by the arguments.
  *
  * <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 x1 the x coordinate of the starting corner of the gradient
  * @param y1 the y coordinate of the starting corner of the gradient
  * @param x2 the x coordinate of the ending corner of the gradient
  * @param y2 the y coordinate of the ending corner of the gradient
  * @param color1 the starting color of the gradient
  * @param alpha1 the starting alpha value of the gradient
  * @param color2 the ending color of the gradient
  * @param alpha2 the ending alpha value of the gradient
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or if
  *           either color1 or color2 is null
  *       <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 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()
  * @since 3.2
  */
 public Pattern(
     Device device,
     float x1,
     float y1,
     float x2,
     float y2,
     Color color1,
     int alpha1,
     Color color2,
     int alpha2) {
   super(device);
   if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   this.device.checkCairo();
   handle = Cairo.cairo_pattern_create_linear(x1, y1, x2, y2);
   if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
   GC.setCairoPatternColor(handle, 0, color1, alpha1);
   GC.setCairoPatternColor(handle, 1, color2, alpha2);
   Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_REPEAT);
   init();
 }
 /**
  * Indicates what happens if the gradient starts or ends inside the bounds of the object(s) being
  * painted by the gradient.
  *
  * <p>Possible values are: 'pad', which says to use the terminal colors of the gradient to fill
  * the remainder of the target region, 'reflect', which says to reflect the gradient pattern
  * start-to-end, end-to-start, start-to-end, etc. continuously until the target rectangle is
  * filled, and repeat, which says to repeat the gradient pattern start-to-end, start-to-end,
  * start-to-end, etc. continuously until the target region is filled. If the attribute is not
  * specified, the effect is as if a value of 'pad' were specified.
  *
  * @see #PAD
  * @see #REFLECT
  * @see #REPEAT
  */
 public void setSpreadMethod(int method) {
   if (method != PAD && method != REFLECT && method != REPEAT) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   Cairo.cairo_pattern_set_extend(handle, method);
 }