/**
   * 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);
  }
Exemple #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)
   };
 }
Exemple #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;
 }
  private static class TextNavigable extends WorkaroundNavigable {
    static final boolean BUG_106024_TEXT_SELECTION =
        "win32".equals(SWT.getPlatform()) // $NON-NLS-1$
            // on carbon, getCaretPosition() always returns getSelection().x
            || "carbon".equals(SWT.getPlatform()); // $NON-NLS-1$

    private final Text fText;

    public TextNavigable(Text text) {
      fText = text;
      // workaround for bug 106024:
      if (BUG_106024_TEXT_SELECTION) {
        fLastSelection = getSelection();
        fCaretPosition = fLastSelection.y;
        fText.addKeyListener(
            new KeyAdapter() {
              public void keyReleased(KeyEvent e) {
                selectionChanged();
              }
            });
        fText.addMouseListener(
            new MouseAdapter() {
              public void mouseUp(MouseEvent e) {
                selectionChanged();
              }
            });
      }
    }

    public Control getControl() {
      return fText;
    }

    public String getText() {
      return fText.getText();
    }

    public void setText(String text) {
      fText.setText(text);
    }

    public Point getSelection() {
      return fText.getSelection();
    }

    public int getCaretPosition() {
      if (BUG_106024_TEXT_SELECTION) {
        selectionChanged();
        return fCaretPosition;
      } else {
        return fText.getCaretPosition();
      }
    }

    public void setSelection(int start, int end) {
      fText.setSelection(start, end);
    }
  }
Exemple #5
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;
 }
Exemple #6
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;
 }
Exemple #7
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);
 }
 /**
  * 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();
 }
 /** 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);
 }
Exemple #10
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);
 }
Exemple #12
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;
   }
 }
Exemple #13
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;
 }
  static Font createFont(Device device, int style) {
    Font font;
    if (SWT.getPlatform().equals("win32")) {
      font = new Font(device, "Arial", 9, style);
    } else if (SWT.getPlatform().equals("gtk")) {
      font = new Font(device, "Helvetica", 9, style);
    } else if (SWT.getPlatform().equals("cocoa")) {
      font = new Font(device, "Helvetica", 12, style);
    } else {
      font = new Font(device, "Verdana", 9, style);
    }

    return font;
  }
Exemple #15
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);
 }
Exemple #16
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);
 }
  /**
   * Creates an instance of a ControlExample embedded inside the supplied parent Composite.
   *
   * @param parent the container of the example
   */
  public ControlExample(Composite parent) {
    initResources();
    tabFolder = new TabFolder(parent, SWT.NONE);
    tabs = createTabs();
    for (Tab tab : tabs) {
      TabItem item = new TabItem(tabFolder, SWT.NONE);
      item.setText(tab.getTabText());
      item.setControl(tab.createTabFolderPage(tabFolder));
      item.setData(tab);
    }

    /* Workaround: if the tab folder is wider than the screen,
     * Mac platforms clip instead of somehow scrolling the tab items.
     * We try to recover some width by using shorter tab names. */
    Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = parent.getMonitor().getClientArea();
    boolean isMac = SWT.getPlatform().equals("cocoa");
    if (size.x > monitorArea.width && isMac) {
      TabItem[] tabItems = tabFolder.getItems();
      for (int i = 0; i < tabItems.length; i++) {
        tabItems[i].setText(tabs[i].getShortTabText());
      }
    }
    startup = false;
  }
 @Test
 public void test_setBackgroundLorg_eclipse_swt_graphics_Color() {
   Color color = new Color(control.getDisplay(), 255, 0, 0);
   control.setBackground(color);
   assertEquals(
       "getBackground not equal color after setBackground(color)", color, control.getBackground());
   control.setBackground(null);
   assertTrue(
       "getBackground unchanged after setBackground(null)",
       !control.getBackground().equals(color));
   color.dispose();
   // Skipping test run for GTK, already failing on GTK3. May be related to bug 421836
   if (!"gtk".equals(SWT.getPlatform())) {
     // With alpha zero
     color = new Color(control.getDisplay(), 255, 0, 0, 0);
     control.setBackground(color);
     assertEquals(
         "getBackground not equal color after setBackground(color) with 0 alpha",
         color,
         control.getBackground());
     control.setBackground(null);
     assertTrue(
         "getBackground unchanged after setBackground(null)",
         !control.getBackground().equals(color));
     color.dispose();
   }
 }
  private void refresh(final boolean repopulateCombo) {
    if (combo == null || combo.isDisposed()) {
      return;
    }
    // $TODO GTK workaround
    try {
      if (diagram == null || domain == null) {
        combo.setEnabled(false);
        combo.setText(StringUtil.EMPTY_STRING);
      } else {
        if (repopulateCombo) {
          combo.setItems(getPickableConcerns());
        }

        String currentConcern = StringUtil.EMPTY_STRING;
        if (getDiagram().getCurrentConcern() != null) {
          currentConcern = getDiagram().getCurrentConcern().getName();
        }
        final int index = combo.indexOf(currentConcern);
        if (index == -1 || forceSetText) {
          combo.setText(currentConcern);
        } else {
          combo.select(index);
        }
        combo.setEnabled(true);
      }
    } catch (final SWTException exception) {
      if (!"gtk".equals(SWT.getPlatform())) { // $NON-NLS-1$
        throw exception;
      }
    }
  }
Exemple #20
0
  /**
   * 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);
  }
Exemple #21
0
  /**
   * Replaces the following style attributes of the font definition of the <code>html</code>
   * element:
   *
   * <ul>
   *   <li>font-size
   *   <li>font-weight
   *   <li>font-style
   *   <li>font-family
   * </ul>
   *
   * The font's name is used as font family, a <code>sans-serif</code> default font family is
   * appended for the case that the given font name is not available.
   *
   * <p>If the listed font attributes are not contained in the passed style list, nothing happens.
   *
   * @param styles CSS style definitions
   * @param fontData the font information to use
   * @return the modified style definitions
   * @since 3.3
   */
  public static String convertTopLevelFont(String styles, FontData fontData) {
    boolean bold = (fontData.getStyle() & SWT.BOLD) != 0;
    boolean italic = (fontData.getStyle() & SWT.ITALIC) != 0;

    // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=155993
    String size =
        Integer.toString(fontData.getHeight())
            + ("carbon".equals(SWT.getPlatform())
                ? "px"
                : "pt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    String family = "'" + fontData.getName() + "',sans-serif"; // $NON-NLS-1$ //$NON-NLS-2$
    styles =
        styles.replaceFirst(
            "(html\\s*\\{.*(?:\\s|;)font-size:\\s*)\\d+pt(\\;?.*\\})",
            "$1" + size + "$2"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    styles =
        styles.replaceFirst(
            "(html\\s*\\{.*(?:\\s|;)font-weight:\\s*)\\w+(\\;?.*\\})",
            "$1"
                + (bold ? "bold" : "normal")
                + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    styles =
        styles.replaceFirst(
            "(html\\s*\\{.*(?:\\s|;)font-style:\\s*)\\w+(\\;?.*\\})",
            "$1"
                + (italic ? "italic" : "normal")
                + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    styles =
        styles.replaceFirst(
            "(html\\s*\\{.*(?:\\s|;)font-family:\\s*).+?(;.*\\})",
            "$1" + family + "$2"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    return styles;
  }
  /**
   * 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);
  }
  /**
   * 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();
  }
 /**
  * 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;
 }
 /**
  * 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();
 }
Exemple #26
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);
     }
   }
 }
Exemple #27
0
  private static void init() {
    BOLD = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
    ITALIC = JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);
    BOLD_ITALIC =
        new Font(
            Display.getCurrent(), getModifiedFontData(ITALIC.getFontData(), SWT.BOLD | SWT.ITALIC));

    Font defaultFont = JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
    FontData[] defaultData = defaultFont.getFontData();
    if (defaultData != null && defaultData.length == 1) {
      FontData data =
          new FontData(
              defaultData[0].getName(), defaultData[0].getHeight(), defaultData[0].getStyle());

      if ("win32".equals(SWT.getPlatform())) { // $NON-NLS-1$
        // NOTE: Windows only, for: data.data.lfStrikeOut = 1;
        try {
          Field dataField = data.getClass().getDeclaredField("data"); // $NON-NLS-1$
          Object dataObject = dataField.get(data);
          Class<?> clazz = dataObject.getClass().getSuperclass();
          Field strikeOutFiled = clazz.getDeclaredField("lfStrikeOut"); // $NON-NLS-1$
          strikeOutFiled.set(dataObject, (byte) 1);
          CommonFonts.STRIKETHROUGH = new Font(Display.getCurrent(), data);
        } catch (Throwable t) {
          // ignore
        }
      }
    }
    if (CommonFonts.STRIKETHROUGH == null) {
      CommonFonts.HAS_STRIKETHROUGH = false;
      CommonFonts.STRIKETHROUGH = defaultFont;
    } else {
      CommonFonts.HAS_STRIKETHROUGH = true;
    }
  }
Exemple #28
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);
 }
Exemple #29
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);
 }
Exemple #30
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();
 }