private void freeDropShadowsColors() {
   // Free colors :
   {
     for (Color c : dropShadowsColors) {
       if (c != null && !c.isDisposed()) c.dispose();
     }
   }
 }
  @Test
  public void dispose_disposesColors() {
    ColorSequence sequence = new ColorSequence(display, rgb1);
    Color color = sequence.get(0);

    sequence.dispose();

    assertTrue(color.isDisposed());
  }
 /**
  * Sets the receiver's foreground color to the color specified by the argument, or to the default
  * system color for the item if the argument is null.
  *
  * @param color the new color (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>
  */
 public void setForeground(final Color color) {
   checkWidget();
   if (color != null && color.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (!equals(foreground, color)) {
     foreground = color;
     markCached();
     parent.redraw();
   }
 }
  /*
   * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
   */
  public void widgetDisposed(DisposeEvent event) {
    if (fStatusTextFont != null && !fStatusTextFont.isDisposed()) fStatusTextFont.dispose();
    fStatusTextFont = null;
    if (fStatusTextForegroundColor != null && !fStatusTextForegroundColor.isDisposed())
      fStatusTextForegroundColor.dispose();
    fStatusTextForegroundColor = null;

    fTextFont = null;
    fShell = null;
    fText = null;
  }
Beispiel #5
0
 public void dispose(Display display) {
   Map<RGB, Color> colorTable = fDisplayTable.get(display);
   if (colorTable != null) {
     Iterator<Color> e = colorTable.values().iterator();
     while (e.hasNext()) {
       Color color = e.next();
       if (color != null && !color.isDisposed()) {
         color.dispose();
       }
     }
   }
 }
  /**
   * Test of the method <code>setTheme()</code>.
   *
   * @throws Exception handled by JUnit
   */
  public void testSetTheme() throws Exception {

    final Color color1 = lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND);
    assertNotNull(color1);

    lnf.setTheme(new DummyTheme());
    lnf.initialize();
    assertFalse(color1.isDisposed());

    final Color color2 = lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND);
    assertNull(color2);
  }
Beispiel #7
0
  /**
   * Sets the background color at the given column index in the receiver to the color specified by
   * the argument, or to the default system color for the item if the argument is null.
   *
   * @param index the column index
   * @param color the new color (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 setBackground(int index, Color color) {
    checkWidget();
    if (color != null && color.isDisposed()) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    if (_getBackground(index).equals(color)) return;
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return;
    int modelIndex =
        parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
    GdkColor gdkColor = color != null ? color.handle : null;
    OS.gtk_list_store_set(
        parent.modelHandle, handle, modelIndex + Table.CELL_BACKGROUND, gdkColor, -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 (color != 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;
        }
      }
    }
  }
 /**
  * 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();
 }
  /*
   * @see ISourceViewer#configure(SourceViewerConfiguration)
   */
  @Override
  public void configure(SourceViewerConfiguration configuration) {

    /*
     * Prevent access to colors disposed in unconfigure(), see:
     *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=53641
     *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=86177
     */
    StyledText textWidget = getTextWidget();
    if (textWidget != null && !textWidget.isDisposed()) {
      Color foregroundColor = textWidget.getForeground();
      if (foregroundColor != null && foregroundColor.isDisposed()) textWidget.setForeground(null);
      Color backgroundColor = textWidget.getBackground();
      if (backgroundColor != null && backgroundColor.isDisposed()) textWidget.setBackground(null);
    }

    super.configure(configuration);
    if (configuration instanceof JavaSourceViewerConfiguration) {
      JavaSourceViewerConfiguration javaSVCconfiguration =
          (JavaSourceViewerConfiguration) configuration;
      fOutlinePresenter = javaSVCconfiguration.getOutlinePresenter(this, false);
      if (fOutlinePresenter != null) fOutlinePresenter.install(this);

      fStructurePresenter = javaSVCconfiguration.getOutlinePresenter(this, true);
      if (fStructurePresenter != null) fStructurePresenter.install(this);

      fHierarchyPresenter = javaSVCconfiguration.getHierarchyPresenter(this, true);
      if (fHierarchyPresenter != null) fHierarchyPresenter.install(this);
    }

    if (fPreferenceStore != null) {
      fPreferenceStore.addPropertyChangeListener(this);
      initializeViewerColors();
    }

    fIsConfigured = true;
  }
 /**
  * Sets the foreground color at the given column index in the receiver to the color specified by
  * the argument, or to the default system color for the item if the argument is null.
  *
  * @param index the column index
  * @param color the new color (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>
  */
 public void setForeground(final int index, final Color color) {
   checkWidget();
   if (color != null && color.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   int count = Math.max(1, parent.getColumnCount());
   if (index >= 0 && index < count) {
     ensureData(index, count);
     if (!equals(data[index].foreground, color)) {
       data[index].foreground = color;
       markCached();
       parent.redraw();
     }
   }
 }
Beispiel #11
0
  /**
   * Test of the method <code>uninitialize()</code>.
   *
   * @throws Exception handled by JUnit
   */
  public void testUninitialize() throws Exception {

    final Color color = lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND);
    assertNotNull(color);
    final Font font = lnf.getFont(LnfKeyConstants.EMBEDDED_TITLEBAR_FONT);
    assertNotNull(font);

    lnf.uninitialize();

    assertFalse(font.isDisposed());
    assertNull(lnf.getFont(LnfKeyConstants.EMBEDDED_TITLEBAR_FONT));
    assertFalse(color.isDisposed());
    assertNull(lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND));
    assertNotSame(
        color,
        lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND)); // TODO Could be removed
  }
Beispiel #12
0
 /**
  * Sets the receiver's background color to the color specified by the argument, or to the default
  * system color for the item if the argument is null.
  *
  * @param color the new color (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 2.0
  */
 public void setBackground(Color color) {
   checkWidget();
   if (color != null && color.isDisposed()) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (_getBackground().equals(color)) return;
   GdkColor gdkColor = color != null ? color.handle : null;
   OS.gtk_list_store_set(parent.modelHandle, handle, Table.BACKGROUND_COLUMN, gdkColor, -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;
 }
Beispiel #13
0
 /**
  * Gets the foreground color.
  *
  * @return the foreground color
  */
 protected Color getForeground() {
   if (foreground.isDisposed()) {
     foreground = Display.getDefault().getSystemColor(DEFAULT_FOREGROUND);
   }
   return foreground;
 }