private Image getDecoratedImage(final Image image) {
    // check if we have a decorated image yet or not
    Image decoratedImage = decoratedImages.get(image);
    if (decoratedImage == null) {
      // create one
      CompositeImageDescriptor cd =
          new CompositeImageDescriptor() {

            @Override
            protected Point getSize() {
              Rectangle bounds = image.getBounds();
              return new Point(bounds.width, bounds.height);
            }

            @Override
            protected void drawCompositeImage(int width, int height) {
              drawImage(image.getImageData(), 0, 0);
              drawImage(UIIcons.OVR_CHECKEDOUT.getImageData(), 0, 0);
            }
          };
      decoratedImage = cd.createImage();
      // store it
      decoratedImages.put(image, decoratedImage);
    }
    return decoratedImage;
  }
Ejemplo n.º 2
0
  private void setHeaderImage(final Image image) {
    BusyIndicator busyLabel = getBusyLabel();
    if (busyLabel == null) {
      return;
    }

    final Point size = leftToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point titleSize = titleLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    size.x += titleSize.x + LEFT_TOOLBAR_HEADER_TOOLBAR_PADDING;
    size.y = Math.max(titleSize.y, size.y);

    // padding between toolbar and image, ensure image is at least one pixel wide to avoid SWT error
    final int padding = (size.x > 0 && !noExtraPadding) ? 10 : 1;
    final Rectangle imageBounds = (image != null) ? image.getBounds() : new Rectangle(0, 0, 0, 0);
    int tempHeight = (image != null) ? Math.max(size.y + 1, imageBounds.height) : size.y + 1;
    // avoid extra padding due to margin added by TitleRegion.VMARGIN
    final int height = (tempHeight > imageBounds.height + 5) ? tempHeight - 5 : tempHeight;

    CompositeImageDescriptor descriptor =
        new CompositeImageDescriptor() {
          @Override
          protected void drawCompositeImage(int width, int height) {
            if (image != null) {
              drawImage(
                  image.getImageData(), size.x + padding, (height - image.getBounds().height) / 2);
            }
          }

          @Override
          protected Point getSize() {
            return new Point(size.x + padding + imageBounds.width, height);
          }
        };
    Image newHeaderImage = descriptor.createImage();

    // directly set on busyLabel since getHeaderForm().getForm().setImage() does not update
    // the image if a message is currently displayed
    busyLabel.setImage(newHeaderImage);

    if (headerImage != null) {
      headerImage.dispose();
    }
    headerImage = newHeaderImage;

    // avoid extra padding due to large title font
    // TODO reset font in case tool bar is empty
    // leftToolBar.getParent().setFont(JFaceResources.getDefaultFont());
    getHeaderForm().getForm().reflow(true);
  }
Ejemplo n.º 3
0
  /**
   * Returns an {@link Image} composed of a base image decorated by another image.
   *
   * @param baseImage the base {@link Image} that should be decorated.
   * @param decorator the {@link Image} to decorate the base image.
   * @param corner the corner to place decorator image.
   * @return the resulting decorated {@link Image}.
   */
  public static Image decorateImage(
      final Image baseImage, final Image decorator, final int corner) {
    if (corner <= 0 || corner >= LAST_CORNER_KEY) {
      throw new IllegalArgumentException("Wrong decorate corner");
    }
    Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
    if (cornerDecoratedImageMap == null) {
      cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
      m_decoratedImageMap[corner] = cornerDecoratedImageMap;
    }
    Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
    if (decoratedMap == null) {
      decoratedMap = new HashMap<Image, Image>();
      cornerDecoratedImageMap.put(baseImage, decoratedMap);
    }
    //
    Image result = decoratedMap.get(decorator);
    if (result == null) {
      final Rectangle bib = baseImage.getBounds();
      final Rectangle dib = decorator.getBounds();
      final Point baseImageSize = new Point(bib.width, bib.height);
      CompositeImageDescriptor compositImageDesc =
          new CompositeImageDescriptor() {
            @Override
            protected void drawCompositeImage(int width, int height) {
              drawImage(baseImage.getImageData(), 0, 0);
              if (corner == TOP_LEFT) {
                drawImage(decorator.getImageData(), 0, 0);
              } else if (corner == TOP_RIGHT) {
                drawImage(decorator.getImageData(), bib.width - dib.width, 0);
              } else if (corner == BOTTOM_LEFT) {
                drawImage(decorator.getImageData(), 0, bib.height - dib.height);
              } else if (corner == BOTTOM_RIGHT) {
                drawImage(decorator.getImageData(), bib.width - dib.width, bib.height - dib.height);
              }
            }

            @Override
            protected Point getSize() {
              return baseImageSize;
            }
          };
      //
      result = compositImageDesc.createImage();
      decoratedMap.put(decorator, result);
    }
    return result;
  }
Ejemplo n.º 4
0
  /**
   * Returns an image composed of a base image decorated by another image
   *
   * @param baseImage Image The base image that should be decorated
   * @param decorator Image The image to decorate the base image
   * @param corner The corner to place decorator image
   * @return Image The resulting decorated image
   */
  public static Image decorateImage(
      final Image baseImage, final Image decorator, final int corner) {
    HashMap<Image, Image> decoratedMap = m_ImageToDecoratorMap.get(baseImage);
    if (decoratedMap == null) {
      decoratedMap = new HashMap<Image, Image>();
      m_ImageToDecoratorMap.put(baseImage, decoratedMap);
    }
    Image result = decoratedMap.get(decorator);
    if (result == null) {
      final Rectangle bid = baseImage.getBounds();
      final Rectangle did = decorator.getBounds();
      final Point baseImageSize = new Point(bid.width, bid.height);
      CompositeImageDescriptor compositImageDesc =
          new CompositeImageDescriptor() {
            protected void drawCompositeImage(int width, int height) {
              drawImage(baseImage.getImageData(), 0, 0);
              if (corner == TOP_LEFT) {
                drawImage(decorator.getImageData(), 0, 0);
              } else if (corner == TOP_RIGHT) {
                drawImage(decorator.getImageData(), bid.width - did.width - 1, 0);
              } else if (corner == BOTTOM_LEFT) {
                drawImage(decorator.getImageData(), 0, bid.height - did.height - 1);
              } else if (corner == BOTTOM_RIGHT) {
                drawImage(
                    decorator.getImageData(),
                    bid.width - did.width - 1,
                    bid.height - did.height - 1);
              }
            }

            protected Point getSize() {
              return baseImageSize;
            }
          };
      result = compositImageDesc.createImage();
      decoratedMap.put(decorator, result);
    }
    return result;
  }