当前位置: 首页>>代码示例>>Java>>正文


Java GraphicsUtilities.createCompatibleTranslucentImage方法代码示例

本文整理汇总了Java中org.jdesktop.swingx.graphics.GraphicsUtilities.createCompatibleTranslucentImage方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsUtilities.createCompatibleTranslucentImage方法的具体用法?Java GraphicsUtilities.createCompatibleTranslucentImage怎么用?Java GraphicsUtilities.createCompatibleTranslucentImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdesktop.swingx.graphics.GraphicsUtilities的用法示例。


在下文中一共展示了GraphicsUtilities.createCompatibleTranslucentImage方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paint

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
 * Overriden paint method to take into account the alpha setting
 * @param g
 */
@Override
public void paint(Graphics g) {
    float a = getAlpha();
    if (a == 1) {
        super.paint(g);
    } else {
        //the component is translucent, so we need to render to
        //an intermediate image before painting
        BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(getWidth(), getHeight());
        Graphics2D gfx = img.createGraphics();
        super.paint(gfx);
        gfx.dispose();
        Graphics2D g2d = (Graphics2D)g;
        Composite oldComp = g2d.getComposite();
        Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, a);
        g2d.setComposite(alphaComp);
        g2d.drawImage(img, null, 0, 0);
        g2d.setComposite(oldComp);
    }
}
 
开发者ID:freeseawind,项目名称:littleluck,代码行数:25,代码来源:JXPanel.java

示例2: createShadow

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
public static Shadow createShadow(Image source, int x, int y, boolean paintSource, int shadowSize) {
  int size = shadowSize;
  final float w = source.getWidth(null);
  final float h = source.getHeight(null);
  float ratio = w / h;
  float deltaX = size;
  float deltaY = size / ratio;

  final Image scaled = source.getScaledInstance((int)(w + deltaX), (int)(h + deltaY), Image.SCALE_SMOOTH);

  final BufferedImage s =
    GraphicsUtilities.createCompatibleTranslucentImage(scaled.getWidth(null), scaled.getHeight(null));
  final Graphics2D graphics = (Graphics2D)s.getGraphics();
  graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  graphics.drawImage(scaled, 0, 0, null);

  final BufferedImage shadow = new ShadowRenderer(size, .25f, Color.black).createShadow(s);
  if (paintSource) {
    final Graphics imgG = shadow.getGraphics();
    final double d = size * 0.5;
    imgG.drawImage(source, (int)(size + d), (int)(size + d / ratio), null);
  }

  return new Shadow(shadow, x - size - 5, y - size + 2);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ShadowBorderPainter.java

示例3: getStaticImage

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
 * This method is used to show an image during message showing
 * @return image to show
 */
Image getStaticImage() {
  final JFrame myOffScreenFrame = new JFrame() ;
  myOffScreenFrame.add(mySheetPanel);
  myOffScreenFrame.getRootPane().setDefaultButton(myDefaultButton);

  final BufferedImage image = (SystemInfo.isJavaVersionAtLeast("1.7")) ?
                              UIUtil.createImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT, BufferedImage.TYPE_INT_ARGB) :
                              GraphicsUtilities.createCompatibleTranslucentImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT);

  Graphics g = image.createGraphics();
  mySheetPanel.paint(g);

  g.dispose();

  myOffScreenFrame.dispose();
  return image;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:SheetController.java

示例4: getSubImage

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
 * Returns a new BufferedImage that represents a subregion of the given
 * BufferedImage.  (Note that this method does not use
 * BufferedImage.getSubimage(), which will defeat image acceleration
 * strategies on later JDKs.)
 */
private BufferedImage getSubImage(BufferedImage img,
                                  int x, int y, int w, int h) {
    BufferedImage ret = GraphicsUtilities.createCompatibleTranslucentImage(w, h);
    Graphics2D g2 = ret.createGraphics();
    
    try {
        g2.drawImage(img,
                     0, 0, w, h,
                     x, y, x+w, y+h,
                     null);
    } finally {
        g2.dispose();
    }
    
    return ret;
}
 
开发者ID:sing-group,项目名称:aibench-project,代码行数:23,代码来源:DropShadowBorder.java

示例5: getStaticImage

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
 * This method is used to show an image during message showing
 * @return image to show
 */
Image getStaticImage() {
  final JFrame myOffScreenFrame = new JFrame() ;
  myOffScreenFrame.add(mySheetPanel);
  myOffScreenFrame.getRootPane().setDefaultButton(myDefaultButton);

  final BufferedImage image = (SystemInfo.isJavaVersionAtLeast("1.7")) ?
                              UIUtil.createImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT, BufferedImage.TYPE_INT_ARGB) :
                              GraphicsUtilities.createCompatibleTranslucentImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT);

  Graphics g = image.createGraphics();
  mySheetPanel.paint(g);

  g.dispose();

  myOffScreenFrame.remove(mySheetPanel);

  myOffScreenFrame.dispose();
  return image;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:24,代码来源:SheetController.java

示例6: matchLabelBorderToButtons

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
private void matchLabelBorderToButtons() {
    Insets insets = new Insets(4, 6, 4, 6);
    Dimension buttonSize = prevButton.getPreferredSize();
    prevButton.setSize(buttonSize);

    BufferedImage image = GraphicsUtilities.
            createCompatibleTranslucentImage(
                 buttonSize.width, buttonSize.height);
    prevButton.paint(image.getGraphics());
    BufferedImage labelTopImage = GraphicsUtilities.
            createCompatibleTranslucentImage(
                 buttonSize.width - insets.left - insets.right,
                 insets.top);
    labelTopImage.getGraphics().drawImage(image, 0, 0,
            buttonSize.width - insets.left - insets.right,
            insets.top,
            insets.left, 0,
            buttonSize.width - insets.right, insets.top,
            null,
            null);

    BufferedImage labelBottomImage = GraphicsUtilities.createCompatibleTranslucentImage(buttonSize.width - insets.left - insets.right,
            insets.bottom);
    labelBottomImage.getGraphics().drawImage(image, 0, 0,
            buttonSize.width - insets.left - insets.right, insets.top,
            insets.left, buttonSize.height - insets.bottom,
            buttonSize.width - insets.right, buttonSize.height,
            null,
            null);

    statusLabel.setBorder(new CenterLabelBorder(labelTopImage, labelBottomImage));
    needLabelBorder = false;
}
 
开发者ID:freeseawind,项目名称:littleluck,代码行数:34,代码来源:SnippetNavigator.java

示例7: initShadowImage

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
private void initShadowImage() {

    final BufferedImage mySheetStencil = GraphicsUtilities.createCompatibleTranslucentImage(SHEET_WIDTH, SHEET_HEIGHT);

    Graphics2D g2 = mySheetStencil.createGraphics();
    g2.setColor(new JBColor(Gray._255, Gray._0));
    g2.fillRect(0, 0, SHEET_WIDTH, SHEET_HEIGHT);
    g2.dispose();

    ShadowRenderer renderer = new ShadowRenderer();
    renderer.setSize(SHADOW_BORDER);
    renderer.setOpacity(.80f);
    renderer.setColor(new JBColor(JBColor.BLACK, Gray._10));
    myShadowImage = renderer.createShadow(mySheetStencil);
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:SheetController.java

示例8: paint

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
public final void paint(Graphics2D g, T obj, int width, int height) {
    if (g == null) {
        throw new NullPointerException("The Graphics2D must be supplied");
    }

    if (!isVisible() || width < 1 || height < 1) {
        return;
    }

    configureGraphics(g);

    //paint to a temporary image if I'm caching, or if there are filters to apply
    if (shouldUseCache() || filters.length > 0) {
        validate(obj);
        BufferedImage cache = cachedImage == null ? null : cachedImage.get();
        boolean invalidCache = null == cache ||
                cache.getWidth() != width ||
                cache.getHeight() != height;

        if (cacheCleared || invalidCache || isDirty()) {
            //rebuild the cacheable. I do this both if a cacheable is needed, and if any
            //filters exist. I only *save* the resulting image if caching is turned on
            if (invalidCache) {
                cache = GraphicsUtilities.createCompatibleTranslucentImage(width, height);
            }
            Graphics2D gfx = cache.createGraphics();

            try {
                gfx.setClip(0, 0, width, height);

                if (!invalidCache) {
                    // If we are doing a repaint, but we didn't have to
                    // recreate the image, we need to clear it back
                    // to a fully transparent background.
                    Composite composite = gfx.getComposite();
                    gfx.setComposite(AlphaComposite.Clear);
                    gfx.fillRect(0, 0, width, height);
                    gfx.setComposite(composite);
                }

                configureGraphics(gfx);
                doPaint(gfx, obj, width, height);
            } finally {
                gfx.dispose();
            }

            for (BufferedImageOp f : getFilters()) {
                cache = f.filter(cache, null);
            }

            //only save the temporary image as the cacheable if I'm caching
            if (shouldUseCache()) {
                cachedImage = new SoftReference<BufferedImage>(cache);
                cacheCleared = false;
            }
        }

        g.drawImage(cache, 0, 0, null);
    } else {
        //can't use the cacheable, so just paint
        doPaint(g, obj, width, height);
    }

    //painting has occured, so restore the dirty bit to false
    setDirty(false);
}
 
开发者ID:teddyted,项目名称:iSeleda,代码行数:70,代码来源:AbstractPainter.java

示例9: paint

import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
public final void paint(Graphics2D g, T obj, int width, int height) {
    if (g == null) {
        throw new NullPointerException("The Graphics2D must be supplied");
    }

    if(!isVisible() || width < 1 || height < 1) {
        return;
    }

    configureGraphics(g);

    //paint to a temporary image if I'm caching, or if there are filters to apply
    if (shouldUseCache() || filters.length > 0) {
        validate(obj);
        BufferedImage cache = cachedImage == null ? null : cachedImage.get();
        boolean invalidCache = null == cache || 
                                    cache.getWidth() != width || 
                                    cache.getHeight() != height;

        if (cacheCleared || invalidCache || isDirty()) {
            //rebuild the cacheable. I do this both if a cacheable is needed, and if any
            //filters exist. I only *save* the resulting image if caching is turned on
            if (invalidCache) {
                cache = GraphicsUtilities.createCompatibleTranslucentImage(width, height);
            }
            Graphics2D gfx = cache.createGraphics();
            
            try {
                gfx.setClip(0, 0, width, height);

                if (!invalidCache) {
                    // If we are doing a repaint, but we didn't have to
                    // recreate the image, we need to clear it back
                    // to a fully transparent background.
                    Composite composite = gfx.getComposite();
                    gfx.setComposite(AlphaComposite.Clear);
                    gfx.fillRect(0, 0, width, height);
                    gfx.setComposite(composite);
                }

                configureGraphics(gfx);
                doPaint(gfx, obj, width, height);
            } finally {
                gfx.dispose();
            }

            for (BufferedImageOp f : getFilters()) {
                cache = f.filter(cache, null);
            }

            //only save the temporary image as the cacheable if I'm caching
            if (shouldUseCache()) {
                cachedImage = new SoftReference<BufferedImage>(cache);
                cacheCleared = false;
            }
        }

        g.drawImage(cache, 0, 0, null);
    } else {
        //can't use the cacheable, so just paint
        doPaint(g, obj, width, height);
    }

    //painting has occured, so restore the dirty bit to false
    setDirty(false);
}
 
开发者ID:sing-group,项目名称:aibench-project,代码行数:70,代码来源:AbstractPainter.java


注:本文中的org.jdesktop.swingx.graphics.GraphicsUtilities.createCompatibleTranslucentImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。