/*
   * @see org.eclipse.jface.text.source.ISourceViewerExtension2#unconfigure()
   * @since 3.0
   */
  @Override
  public void unconfigure() {
    if (fOutlinePresenter != null) {
      fOutlinePresenter.uninstall();
      fOutlinePresenter = null;
    }
    if (fStructurePresenter != null) {
      fStructurePresenter.uninstall();
      fStructurePresenter = null;
    }
    if (fHierarchyPresenter != null) {
      fHierarchyPresenter.uninstall();
      fHierarchyPresenter = null;
    }
    if (fForegroundColor != null) {
      fForegroundColor.dispose();
      fForegroundColor = null;
    }
    if (fBackgroundColor != null) {
      fBackgroundColor.dispose();
      fBackgroundColor = null;
    }

    if (fPreferenceStore != null) fPreferenceStore.removePropertyChangeListener(this);

    super.unconfigure();

    fIsConfigured = 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();
   }
 }
Example #3
0
 @Override
 public void dispose() {
   blue.dispose();
   darkPurple.dispose();
   lightBlue.dispose();
   purple.dispose();
   red.dispose();
   super.dispose();
 }
  protected Declaration handleStyleFeature(Style style, EStructuralFeature feature) {
    Declaration declaration = CssFactory.eINSTANCE.createDeclaration();
    declaration.setProperty(feature.getName());

    GMFToCSSConverter converter = GMFToCSSConverter.instance;

    if (isString(feature)) {
      declaration.setExpression(converter.convert((String) style.eGet(feature)));
    }

    if (isInteger(feature)) {
      if (feature.getName().endsWith("Color")) {
        Color color = FigureUtilities.integerToColor((Integer) style.eGet(feature));
        declaration.setExpression(converter.convert(color));
        color.dispose();
      } else {
        declaration.setExpression(converter.convert((Integer) style.eGet(feature)));
      }
    }

    if (feature.getEType() == NotationPackage.eINSTANCE.getGradientData()) {
      declaration.setExpression(converter.convert((GradientData) style.eGet(feature)));
    }

    if (feature.getEType() instanceof EEnum) {
      declaration.setExpression(converter.convert((Enumerator) style.eGet(feature)));
    }

    if (isBoolean(feature)) {
      declaration.setExpression(converter.convert((Boolean) style.eGet(feature)));
    }

    return declaration;
  }
  /**
   * Renders a label for the given rectangle. The label is fitted into the rectangle if possible.
   *
   * @param event the paint event to work with on
   * @param text the text to render
   * @param color the color to use
   * @param bounds the rectangle bounds
   */
  protected void render(
      final PaintEvent event, final String text, final RGB color, final IRectangle<N> bounds) {
    if (text != null) {
      // quite strange to create a new font object all the time?
      // it did not work when I tried to reuse a long-living font object!
      final Font font = new Font(event.display, fontName, 16, SWT.BOLD);
      try {
        event.gc.setFont(font);
        final Color c = new Color(event.display, color);
        try {
          event.gc.setForeground(c);
        } finally {
          c.dispose();
        }

        final Point p = event.gc.textExtent(text);
        p.x = p.x * 12 / 10; // make some space
        final float scale =
            (float) Math.min(bounds.getWidth() / (double) p.x, bounds.getHeight() / (double) p.y);
        final Transform transform = new Transform(event.display);
        try {
          transform.translate(
              (int) (bounds.getX() + bounds.getWidth() / 12d),
              bounds.getY() + (bounds.getHeight() - scale * p.y) / 2);
          transform.scale(scale, scale);
          event.gc.setTransform(transform);
          event.gc.drawString(text, 0, 0, true);
        } finally {
          transform.dispose();
        }
      } finally {
        font.dispose();
      }
    }
  }
 @Override
 public void dispose() {
   if (mOutlineColor != null) {
     mOutlineColor.dispose();
     mOutlineColor = null;
   }
 }
  void resize() {
    Point size = comp.getSize();
    Image oldBackgroundImage = backgroundImage;
    backgroundImage = new Image(comp.getDisplay(), size.x, size.y);
    GC gc = new GC(backgroundImage);
    comp.getParent().drawBackground(gc, 0, 0, size.x, size.y, 0, 0);
    Color background = comp.getBackground();
    Color border = comp.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
    RGB backgroundRGB = background.getRGB();
    // TODO naive and hard coded, doesn't deal with high contrast, etc.
    Color gradientTop =
        new Color(
            comp.getDisplay(),
            backgroundRGB.red + 12,
            backgroundRGB.green + 10,
            backgroundRGB.blue + 10);
    int h = size.y;
    int curveStart = 0;
    int curve_width = 5;

    int[] curve =
        new int[] {
          0, h, 1, h, 2, h - 1, 3, h - 2, 3, 2, 4, 1, 5, 0,
        };
    int[] line1 = new int[curve.length + 4];
    int index = 0;
    int x = curveStart;
    line1[index++] = x + 1;
    line1[index++] = h;
    for (int i = 0; i < curve.length / 2; i++) {
      line1[index++] = x + curve[2 * i];
      line1[index++] = curve[2 * i + 1];
    }
    line1[index++] = x + curve_width;
    line1[index++] = 0;

    int[] line2 = new int[line1.length];
    index = 0;
    for (int i = 0; i < line1.length / 2; i++) {
      line2[index] = line1[index++] - 1;
      line2[index] = line1[index++];
    }

    // custom gradient
    gc.setForeground(gradientTop);
    gc.setBackground(background);
    gc.drawLine(4, 0, size.x, 0);
    gc.drawLine(3, 1, size.x, 1);
    gc.fillGradientRectangle(2, 2, size.x - 2, size.y - 3, true);
    gc.setForeground(background);
    gc.drawLine(2, size.y - 1, size.x, size.y - 1);
    gradientTop.dispose();

    gc.setForeground(border);
    gc.drawPolyline(line2);
    gc.dispose();
    comp.setBackgroundImage(backgroundImage);
    if (oldBackgroundImage != null) oldBackgroundImage.dispose();
  }
  /**
   * Draw the composite images.
   *
   * <p>Subclasses must implement this framework method to paint images within the given bounds
   * using one or more calls to the <code>drawImage</code> framework method.
   *
   * @param width the width
   * @param height the height
   * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int)
   */
  protected void drawCompositeImage(int width, int height) {
    Display display = Display.getDefault();

    Image image = new Image(display, ARROW_SIZE, ARROW_SIZE * 2);

    GC gc = new GC(image);

    Color triangle = createColor(SWT.COLOR_LIST_FOREGROUND, SWT.COLOR_LIST_BACKGROUND, 20, display);
    Color aliasing = createColor(SWT.COLOR_LIST_FOREGROUND, SWT.COLOR_LIST_BACKGROUND, 30, display);
    gc.setBackground(triangle);

    if (fLTR) {
      gc.fillPolygon(
          new int[] {mirror(0), 0, mirror(ARROW_SIZE), ARROW_SIZE, mirror(0), ARROW_SIZE * 2});
    } else {
      gc.fillPolygon(new int[] {ARROW_SIZE, 0, 0, ARROW_SIZE, ARROW_SIZE, ARROW_SIZE * 2});
    }

    gc.setForeground(aliasing);
    gc.drawLine(mirror(0), 1, mirror(ARROW_SIZE - 1), ARROW_SIZE);
    gc.drawLine(mirror(ARROW_SIZE - 1), ARROW_SIZE, mirror(0), ARROW_SIZE * 2 - 1);

    gc.dispose();
    triangle.dispose();
    aliasing.dispose();

    ImageData imageData = image.getImageData();
    for (int y = 1; y < ARROW_SIZE; y++) {
      for (int x = 0; x < y; x++) {
        imageData.setAlpha(mirror(x), y, 255);
      }
    }
    for (int y = 0; y < ARROW_SIZE; y++) {
      for (int x = 0; x <= y; x++) {
        imageData.setAlpha(mirror(x), ARROW_SIZE * 2 - y - 1, 255);
      }
    }

    int offset = 0;
    if (!fLTR) {
      offset = -1;
    }
    drawImage(imageData, width / 2 - ARROW_SIZE / 2 + offset, height / 2 - ARROW_SIZE - 1);

    image.dispose();
  }
 private void freeDropShadowsColors() {
   // Free colors :
   {
     for (Color c : dropShadowsColors) {
       if (c != null && !c.isDisposed()) c.dispose();
     }
   }
 }
 /*
  * @see Widget#dispose()
  */
 @Override
 public void dispose() {
   if (fErrorMsgAreaBackground != null) {
     fErrorMsgAreaBackground.dispose();
     fErrorMsgAreaBackground = null;
   }
   super.dispose();
 }
Example #11
0
  public void applyColor(ColorType type, RGB rgb) {
    Color newColor = new Color(SwtUtils.DISPLAY, rgb);
    Color oldColor = null;

    switch (type) {
      case BACKGROUND:
        {
          oldColor = iniAppearance.getColorBackground();

          for (Control control : controls) {
            if (control.isDisposed()) continue;

            control.setBackground(newColor);
          }
          for (Text chat : chatControls) {
            if (chat.isDisposed()) continue;

            chat.setBackground(newColor);
          }

          iniAppearance.setColorBackground(newColor);
          break;
        }
      case FOREGROUND:
        {
          oldColor = iniAppearance.getColorForeground();

          for (Control control : controls) {
            if (control.isDisposed()) continue;

            control.setForeground(newColor);
          }
          for (Text chat : chatControls) {
            if (chat.isDisposed()) continue;

            chat.setForeground(newColor);
          }

          iniAppearance.setColorForeground(newColor);
          break;
        }
      case LOG_BACKGROUND:
        {
          oldColor = iniAppearance.getColorLogBackground();

          for (StyledText text : logControls) {
            if (text.isDisposed()) continue;

            text.setBackground(newColor);
            text.setForeground(newColor);
          }

          iniAppearance.setColorLogBackground(newColor);
        }
    }

    if (oldColor != null) oldColor.dispose();
  }
 @Test
 public void test_setForegroundLorg_eclipse_swt_graphics_Color() {
   Color color = new Color(control.getDisplay(), 255, 0, 0);
   control.setForeground(color);
   assertEquals(color, control.getForeground());
   control.setForeground(null);
   assertTrue(!control.getForeground().equals(color));
   color.dispose();
 }
Example #13
0
  @Test
  public void testBorderColor() {
    assertNull(figure.getBorderColor());

    dmImage.setBorderColor("#010203");
    Color expected = new Color(null, 1, 2, 3);
    assertEquals(expected, figure.getBorderColor());
    expected.dispose();
  }
 @Override
 public void dispose() {
   callbacks.clear();
   for (org.eclipse.swt.graphics.Color c : colorRegistry) {
     c.dispose();
   }
   colorRegistry.clear();
   super.dispose();
 }
Example #15
0
 private void run() {
   Display.getCurrent().timerExec(-1, run);
   delayedListeners.remove(this);
   ((Control) event.widget).setBackground(bkg);
   listener.handleEvent(event);
   if (color != null) {
     color.dispose();
     color = null;
   }
 }
Example #16
0
 private void apply(GC gc, SvgGradientStop stop, boolean foreground) {
   Color c = new Color(gc.getDevice(), stop.color.red(), stop.color.green(), stop.color.blue());
   if (foreground) {
     gc.setForeground(c);
   } else {
     gc.setBackground(c);
   }
   c.dispose();
   gc.setAlpha((int) (255 * stop.opacity));
 }
 public void dispose() {
   paragraphs = null;
   selectedSegmentIndex = -1;
   savedSelectedLinkIndex = -1;
   selectableSegments = null;
   if (activeForeground != null) {
     activeForeground.dispose();
     activeForeground = null;
   }
 }
 public static void dispose() {
   Iterator<Object> it = resources.keySet().iterator();
   while (it.hasNext()) {
     Object resource = resources.get(it.next());
     if (resource instanceof Font) ((Font) resource).dispose();
     else if (resource instanceof Color) ((Color) resource).dispose();
     else if (resource instanceof Image) ((Image) resource).dispose();
     else if (resource instanceof Cursor) ((Cursor) resource).dispose();
   }
   resources.clear();
 }
  /*
   * @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;
  }
  /** @see org.eclipse.gef.tools.DirectEditManager#bringDown() */
  protected void bringDown() {
    if (proposalPopupForegroundColor != null) {
      proposalPopupForegroundColor.dispose();
      proposalPopupForegroundColor = null;
    }
    if (proposalPopupBackgroundColor != null) {
      proposalPopupBackgroundColor.dispose();
      proposalPopupBackgroundColor = null;
    }

    // myee - RATLC00523014: crashes when queued in asyncExec()
    eraseFeedback();

    initialString = new StringBuffer();

    Display.getCurrent()
        .asyncExec(
            new Runnable() {

              public void run() {
                // Content Assist hack - allow proper cleanup on childen
                // controls
                XtextDirectEditManager.super.bringDown();
              }
            });

    for (Iterator<FontDescriptor> iter = cachedFontDescriptors.iterator(); iter.hasNext(); ) {
      getResourceManager().destroyFont((FontDescriptor) iter.next());
    }
    cachedFontDescriptors.clear();

    if (actionHandler != null) {
      actionHandler.dispose();
      actionHandler = null;
    }
    if (actionBars != null) {
      restoreSavedActions(actionBars);
      actionBars.updateActionBars();
      actionBars = null;
    }
  }
Example #21
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();
       }
     }
   }
 }
Example #22
0
 void releaseWidget() {
   super.releaseWidget();
   if (layout != null) layout.dispose();
   layout = null;
   if (linkColor != null) linkColor.dispose();
   linkColor = null;
   disabledColor = null;
   offsets = null;
   ids = null;
   mnemonics = null;
   text = null;
 }
Example #23
0
 /** Disposes of all resources associated with a particular instance of the PaintExample. */
 public void dispose() {
   if (paintSurface != null) paintSurface.dispose();
   if (paintColors != null)
     for (int i = 0; i < paintColors.length; ++i) {
       final Color color = paintColors[i];
       if (color != null) color.dispose();
     }
   paintDefaultFont = null;
   paintColors = null;
   paintSurface = null;
   freeResources();
 }
Example #24
0
  @Override
  public void dispose() {
    if (mHoverStrokeColor != null) {
      mHoverStrokeColor.dispose();
      mHoverStrokeColor = null;
    }

    if (mHoverFillColor != null) {
      mHoverFillColor.dispose();
      mHoverFillColor = null;
    }

    if (mHoverSelectStrokeColor != null) {
      mHoverSelectStrokeColor.dispose();
      mHoverSelectStrokeColor = null;
    }

    if (mHoverSelectFillColor != null) {
      mHoverSelectFillColor.dispose();
      mHoverSelectFillColor = null;
    }
  }
Example #25
0
  public void setColor(java.awt.Color color) {
    if (color.equals(_awt_color)) {
      return;
    }

    Color col = new Color(_gc.getDevice(), color.getRed(), color.getGreen(), color.getBlue());
    _gc.setForeground(col);
    _gc.setBackground(col);
    _gc.setAlpha(color.getAlpha());
    if (_color != null) {
      _color.dispose();
    }
    _color = col;
    _awt_color = color;
  }
  /**
   * Returns a corner image for the specified position and color.
   *
   * <p>The returned image is cached and may not be disposed.
   *
   * @param position the wanted position of the image
   * @param rgb the wanted color
   * @return the image
   */
  public static Image getCornerImage(DecorationPosition position, RGB rgb) {
    final String key = "CORNER_IMAGE:" + position + ":" + rgb; // $NON-NLS-1$ //$NON-NLS-2$
    final ImageRegistry ir = JFaceResources.getImageRegistry();
    Image image = ir.get(key);
    if (image != null) return image;

    final Display device = Display.getDefault();
    final Color color = new Color(device, rgb);

    image = new Image(device, 5, 5);
    final GC gc = new GC(image);
    gc.setBackground(color);

    switch (position) {
      case TOP_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 0, 0, 4});
        break;
      case CENTER_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 2, 0, 4});
        break;
      case BOTTOM_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 4, 0, 4});
        break;
      case TOP_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 0, 0, 4, 4});
        break;
      case CENTER_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 2, 0, 4, 4});
        break;
      case BOTTOM_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 4, 0, 4, 4});
        break;
    }

    gc.dispose();
    color.dispose();

    /*
     * Set the transparent color
     */
    final ImageData ideaData = image.getImageData();
    final int whitePixel = ideaData.palette.getPixel(new RGB(255, 255, 255));
    ideaData.transparentPixel = whitePixel;

    ir.put(key, image);

    return image;
  }
Example #27
0
  private void updateLabels() {
    Object value = source.getPropertyValue(descriptor.getId());
    if (nameLayout != null && !nameLayout.isDisposed()) {
      nameLayout.setText(descriptor.getDisplayName());
      nameLayout.setStyle(
          new TextStyle(canvas.getFont(), canvas.getForeground(), null),
          0,
          nameLayout.getText().length());
    }
    ILabelDescriptor labelDescriptor = descriptor.getLabelDescriptor();
    ImageDescriptor image = labelDescriptor == null ? null : labelDescriptor.getImage(value);
    if (valueImage != null) {
      valueImage.dispose();
    }
    valueImage = image == null ? null : image.createImage(false, Display.getCurrent());

    ColorDescriptor color = labelDescriptor == null ? null : labelDescriptor.getForeground(value);
    if (valueColor != null) {
      valueColor.dispose();
    }
    valueColor = color == null ? null : color.createColor(Display.getCurrent());

    FontDescriptor font = labelDescriptor == null ? null : labelDescriptor.getFont(value);
    if (valueFont != null) {
      valueFont.dispose();
    }
    valueFont = font == null ? null : font.createFont(Display.getCurrent());

    if (valueLayout != null && !valueLayout.isDisposed()) {
      String valueText =
          labelDescriptor == null
              ? (value == null
                  ? "" //$NON-NLS-1$
                  : value.toString())
              : labelDescriptor.getText(value);
      if (valueText == null) valueText = ""; // $NON-NLS-1$
      valueLayout.setText(valueText);
      valueLayout.setStyle(
          new TextStyle(
              valueFont == null ? canvas.getFont() : valueFont,
              valueColor == null ? canvas.getForeground() : valueColor,
              null),
          0,
          valueText.length());
    }
    canvas.layout(true);
    canvas.redraw();
  }
Example #28
0
 /** Clean used resources. */
 public void clean() {
   if (_clippingPath != null) {
     _gc.setClipping((Rectangle) null);
     _clippingPath.dispose();
     _clippingPath = null;
     _clippingArea = null;
   }
   if (_color != null) {
     _color.dispose();
     _color = null;
   }
   if (_transform != null) {
     _gc.setTransform(null);
     _transform.dispose();
   }
 }
Example #29
0
 public void dispose() {
   if (paintSurface != null) {
     paintSurface.dispose();
   }
   if (paintColors != null) {
     for (int i = 0; i < paintColors.length; ++i) {
       final org.eclipse.swt.graphics.Color color = paintColors[i];
       if (color != null) {
         color.dispose();
       }
     }
   }
   paintDefaultFont = null;
   paintColors = null;
   paintSurface = null;
   freeResources();
 }
  @Override
  public boolean close() {
    boolean res = super.close();

    colorTestRel.dispose();
    colorRel.dispose();
    colorRelResolved.dispose();
    colorTestBackground.dispose();
    colorSelectedBackground.dispose();
    colorSelectedTestBackground.dispose();

    return res;
  }