Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.Image


    return image;
  }
 
  public static Image getFlagByAddress(String address,FlagSize size) {
    InputStream stream = FlagPack.getFlagAsInputStreamByIP(address, size);
    Image image = new Image(SWTThread.getDisplay(),stream);
    try {
      stream.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here


  public static Image getImage(FileQuality fileQuality) {
    String path = UIImageRepository.getImagePath(fileQuality);
    InputStream input_stream = (SWTImageRepository.class.getClassLoader().getResourceAsStream(path));
    if ( input_stream == null )
      input_stream = (SWTImageRepository.class.getClassLoader().getResourceAsStream("org/jmule/ui/resources/image_not_found.png"));
    Image image = new Image(SWTThread.getDisplay(),input_stream);
    try {
      input_stream.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

        lFileName = lFile.getName();
      }
      if (lFileName != null && lFileName.length() > 0) {
        String lExtension = Util.stripName(lFileName);
        if (lExtension != null && lImageMap.get(lExtension) == null) {
          Image lImage = getImage(lExtension);
          if (lImage != null) {
            lImageMap.put(lExtension, lImage);
          }
        }
      }
View Full Code Here

 
  private void destroyImageMap() {
    Collection<Image> lValues = mImageMap.values();
    Iterator<Image> lIt = lValues.iterator();
    while (lIt.hasNext()) {
      Image lImage = (Image) lIt.next();
      lImage.dispose();
    }
  }
View Full Code Here

    Program lProgram = ContentAssociation.getOSAssociation(lExtension);
    if (lProgram != null) {
      try {
        ImageData lData = lProgram.getImageData();
        if (lData != null) {
          return new Image(null, lData);
        }
      } catch (ArrayIndexOutOfBoundsException aio) {
        // CB TODO This is a SWT bug, have to report with SWT.
      }
    }
View Full Code Here

    if (rect.width == 0 || rect.height == 0)
      return;

    boolean shortenText = false;
    String t = text;
    Image img = image;
    int availableWidth = Math.max(0, rect.width - 2 * hIndent);
    Point extent = getTotalSize(img, t);
    if (extent.x > availableWidth) {
      availableWidth -= img != null ? img.getBounds().width : 0;
      extent = getTotalSize(img, t);
      if (extent.x > availableWidth) {
        shortenText = true;
      }
    }

    GC gc = event.gc;
    String[] lines = text == null ? null : splitString(text);

    // shorten the text
    if (shortenText) {
      extent.x = 0;
      for (int i = 0; i < lines.length; i++) {
        Point e = gc.textExtent(lines[i], DRAW_FLAGS);
        if (e.x > availableWidth) {
          lines[i] = shortenText(gc, lines[i], availableWidth);
          extent.x = Math.max(extent.x, getTotalSize(null, lines[i]).x);
        } else {
          extent.x = Math.max(extent.x, e.x);
        }
      }
      if (appToolTipText == null) {
        super.setToolTipText(text);
      }
    } else {
      super.setToolTipText(appToolTipText);
    }

    // determine horizontal position
    int x = rect.x + hIndent;
    if (align == SWT.CENTER) {
      x = (rect.width - extent.x) / 2;
    }
    if (align == SWT.RIGHT) {
      x = rect.width - hIndent - extent.x;
    }

    // draw a background image behind the text
    try {
      if (backgroundImage != null) {
        // draw a background image behind the text
        Rectangle imageRect = backgroundImage.getBounds();
        // tile image to fill space
        gc.setBackground(getBackground());
        gc.fillRectangle(rect);
        int xPos = 0;
        while (xPos < rect.width) {
          int yPos = 0;
          while (yPos < rect.height) {
            gc.drawImage(backgroundImage, xPos, yPos);
            yPos += imageRect.height;
          }
          xPos += imageRect.width;
        }
      } else if (gradientColors != null) {
        // draw a gradient behind the text
        final Color oldBackground = gc.getBackground();
        if (gradientColors.length == 1) {
          if (gradientColors[0] != null)
            gc.setBackground(gradientColors[0]);
          gc.fillRectangle(0, 0, rect.width, rect.height);
        } else {
          final Color oldForeground = gc.getForeground();
          Color lastColor = gradientColors[0];
          if (lastColor == null)
            lastColor = oldBackground;
          int pos = 0;
          for (int i = 0; i < gradientPercents.length; ++i) {
            gc.setForeground(lastColor);
            lastColor = gradientColors[i + 1];
            if (lastColor == null)
              lastColor = oldBackground;
            gc.setBackground(lastColor);
            if (gradientVertical) {
              final int gradientHeight = (gradientPercents[i] * rect.height / 100) - pos;
              gc.fillGradientRectangle(0, pos, rect.width, gradientHeight, true);
              pos += gradientHeight;
            } else {
              final int gradientWidth = (gradientPercents[i] * rect.width / 100) - pos;
              gc.fillGradientRectangle(pos, 0, gradientWidth, rect.height, false);
              pos += gradientWidth;
            }
          }
          if (gradientVertical && pos < rect.height) {
            gc.setBackground(getBackground());
            gc.fillRectangle(0, pos, rect.width, rect.height - pos);
          }
          if (!gradientVertical && pos < rect.width) {
            gc.setBackground(getBackground());
            gc.fillRectangle(pos, 0, rect.width - pos, rect.height);
          }
          gc.setForeground(oldForeground);
        }
        gc.setBackground(oldBackground);
      } else {
        if (background != null || (getStyle() & SWT.DOUBLE_BUFFERED) == 0) {
          gc.setBackground(getBackground());
          gc.fillRectangle(rect);
        }
      }
    } catch (SWTException e) {
      if ((getStyle() & SWT.DOUBLE_BUFFERED) == 0) {
        gc.setBackground(getBackground());
        gc.fillRectangle(rect);
      }
    }

    // draw border
    int style = getStyle();
    if ((style & SWT.SHADOW_IN) != 0 || (style & SWT.SHADOW_OUT) != 0) {
      paintBorder(gc, rect);
    }

    // draw the image
    if (img != null) {
      Rectangle imageRect = img.getBounds();
      gc.drawImage(img, 0, 0, imageRect.width, imageRect.height, x, (rect.height - imageRect.height) / 2, imageRect.width, imageRect.height);
      x += imageRect.width + GAP;
      extent.x -= imageRect.width + GAP;
    }
    // draw the text
View Full Code Here

      /* Dispose old first */
      if (fColorImage != null)
        fColorImage.dispose();

      fColorImage = new Image(getShell().getDisplay(), 32, 10);
      GC gc = new GC(fColorImage);

      gc.setBackground(color);
      gc.fillRectangle(0, 0, 32, 10);

View Full Code Here

    /* Indicate Error */
    if (bookmark.isErrorLoading()) {

      /* Overlay with Error Icon if required */
      if (favicon != null) {
        Image faviconImg = OwlUI.getImage(fResources, favicon);
        DecorationOverlayIcon overlay = new DecorationOverlayIcon(faviconImg, OwlUI.getImageDescriptor("icons/ovr16/error.gif"), IDecoration.BOTTOM_RIGHT); //$NON-NLS-1$
        return OwlUI.getImage(fResources, overlay);
      }

      /* Default Error Icon */
      return fBookMarkErrorIcon;
    }

    /* Use normal Icon */
    Image icon = favicon != null ? OwlUI.getImage(fResources, favicon) : fBookMarkIcon;

    /* Overlay if News are *new* */
    if (hasNew) {
      DecorationOverlayIcon overlay = new DecorationOverlayIcon(icon, OwlUI.getImageDescriptor("icons/ovr16/new.gif"), IDecoration.BOTTOM_RIGHT); //$NON-NLS-1$
      return OwlUI.getImage(fResources, overlay);
View Full Code Here

        item.setSelection(false);
    }
  }

  private Image createColorImage(RGB color) {
    Image img = OwlUI.createColorImage(fParent.getDisplay(), color);
    fImagesToDispose.add(img);

    return img;
  }
View Full Code Here

   * used.
   */
  public static Image createColorImage(Display display, RGB rgb) {
    Color color = new Color(display, rgb);

    Image image = new Image(display, 12, 12);

    GC gc = new GC(image);

    gc.setBackground(color);
    gc.fillRectangle(0, 0, 12, 12);
View Full Code Here

TOP

Related Classes of org.eclipse.swt.graphics.Image

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.