Example usage for javax.swing Icon getIconWidth

List of usage examples for javax.swing Icon getIconWidth

Introduction

In this page you can find the example usage for javax.swing Icon getIconWidth.

Prototype

int getIconWidth();

Source Link

Document

Returns the icon's width.

Usage

From source file:RGBGrayFilter.java

/**
 * Returns an icon with a disabled appearance. This method is used
 * to generate a disabled icon when one has not been specified.
 *
 * @param component the component that will display the icon, may be null.
 * @param icon the icon to generate disabled icon from.
 * @return disabled icon, or null if a suitable icon can not be generated.
 *///  w w w  . ja  v  a  2s  .c  om
public static Icon getDisabledIcon(JComponent component, Icon icon) {
    if ((icon == null) || (component == null) || (icon.getIconWidth() == 0) || (icon.getIconHeight() == 0)) {
        return null;
    }
    Image img;
    if (icon instanceof ImageIcon) {
        img = ((ImageIcon) icon).getImage();
    } else {
        img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
    }

    ImageProducer producer = new FilteredImageSource(img.getSource(), new RGBGrayFilter());

    return new ImageIcon(component.createImage(producer));
}

From source file:Main.java

/**
 * Returns a window with a partially opaque progress Icon. Sets the opacity, location and size (to the given icon
 * size) (does not pack the image)/*w w  w  .  j a  va2s  .c  o m*/
 *
 * @param icon the icon to set in the progress window
 * @param opacity a float value from 0-1
 * @param x the x location of the window
 * @param y the y location of the window
 * @return a jWindow of the progress wheel
 */
public static JWindow getProgressWheelWindow(final Icon icon, final Float opacity, final int x, final int y) {
    JWindow jWindow = new JWindow() {

        {
            setOpacity(opacity);
            setLocation(x, y);
            setSize(icon.getIconWidth(), icon.getIconHeight());
            add(new JLabel(icon));
        }
    };

    return jWindow;
}

From source file:com.igormaznitsa.sciareto.ui.UiUtils.java

@Nonnull
public static Image iconToImage(@Nonnull Component context, @Nullable final Icon icon) {
    if (icon instanceof ImageIcon) {
        return ((ImageIcon) icon).getImage();
    }//from  ww  w .  ja  v  a2  s  . c  o m
    final int width = icon == null ? 16 : icon.getIconWidth();
    final int height = icon == null ? 16 : icon.getIconHeight();
    final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    if (icon != null) {
        final Graphics g = image.getGraphics();
        try {
            icon.paintIcon(context, g, 0, 0);
        } finally {
            g.dispose();
        }
    }
    return image;
}

From source file:SysTray.java

private Image getImage() throws HeadlessException {
    Icon defaultIcon = MetalIconFactory.getTreeHardDriveIcon();
    Image img = new BufferedImage(defaultIcon.getIconWidth(), defaultIcon.getIconHeight(),
            BufferedImage.TYPE_4BYTE_ABGR);
    defaultIcon.paintIcon(new Panel(), img.getGraphics(), 0, 0);
    return img;//from   w  w w .j  av  a 2 s  .  c  o m
}

From source file:com.moss.greenshell.wizard.menu.AbstractMenuItem.java

public void setIcon(Icon icon) {
    this.iconResource = null;
    if (icon != null && icon.getIconWidth() > 0) {
        if (icon instanceof ImageIcon) {
            // kind of a hack to normalize the image
            // works because most of our Icons are actually ImageIcons
            icon = new NormalizedImageIcon((((ImageIcon) icon).getImage()), 100, 100);
        } else {//from  ww w  . j a  v  a2 s.c om
            log.warn("Unable to scale icon " + icon);
        }
        this.getLabelPicture().setIcon(icon);
    } else {
        this.getLabelPicture()
                .setIcon(SwingResourceManager.getIcon(AbstractMenuItem.class, "/help-browser.png"));
    }

    //      this.getLabelPicture().setBorder(new LineBorder(Color.BLACK));
    //      qty2Label.setMinimumSize(new Dimension(100,100));
}

From source file:com.devbury.mkremote.server.QuickLaunchServiceImpl.java

public ArrayList<LaunchItem> list(String dir) {
    Base64 base64 = new Base64();
    JFileChooser chooser = new JFileChooser();
    File new_dir = newFileDir(dir);
    logger.debug("Looking for files in {}", new_dir.getAbsolutePath());
    ArrayList<LaunchItem> items = new ArrayList<LaunchItem>();
    if (isSupported()) {
        if (new_dir.isDirectory()) {
            FilenameFilter filter = new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return !name.startsWith(".");
                }//from  w  w  w. ja  v  a  2s.  co m
            };
            for (File f : new_dir.listFiles(filter)) {
                if (!f.isHidden()) {
                    LaunchItem item = new LaunchItem();
                    item.setName(f.getName());
                    item.setPath(dir);
                    if (f.isDirectory()) {
                        if (isMac() && f.getName().endsWith(".app")) {
                            item.setType(LaunchItem.FILE_TYPE);
                            item.setName(f.getName().substring(0, f.getName().length() - 4));
                        } else {
                            item.setType(LaunchItem.DIR_TYPE);
                        }
                    } else {
                        item.setType(LaunchItem.FILE_TYPE);
                    }
                    Icon icon = chooser.getIcon(f);
                    BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
                            BufferedImage.TYPE_INT_RGB);
                    icon.paintIcon(null, bi.createGraphics(), 0, 0);
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
                    try {
                        ImageIO.write(bi, "png", os);
                        item.setIcon(base64.encodeToString(os.toByteArray()));
                    } catch (IOException e) {
                        logger.debug("could not write image {}", e);
                        item.setIcon(null);
                    }
                    logger.debug("Adding LaunchItem : {}", item);
                    items.add(item);
                } else {
                    logger.debug("Skipping hidden file {}", f.getName());
                }
            }
        }
    } else {
        new Thread() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(null,
                        "We are sorry but quick launch is not supported on your platform",
                        "Quick Launch Not Supported", JOptionPane.ERROR_MESSAGE);
            }
        }.start();
    }
    return items;
}

From source file:filterviewplugin.FilterViewSettingsTab.java

private void chooseIcon(final String filterName) {
    String iconPath = mIcons.get(filterName);

    JFileChooser chooser = new JFileChooser(
            iconPath == null ? new File("") : (new File(iconPath)).getParentFile());
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    String msg = mLocalizer.msg("iconFiles", "Icon Files ({0})", "*.png,*.jpg, *.gif");
    String[] extArr = { ".png", ".jpg", ".gif" };

    chooser.setFileFilter(new ExtensionFileFilter(extArr, msg));
    chooser.setDialogTitle(mLocalizer.msg("chooseIcon", "Choose icon for '{0}'", filterName));

    Window w = UiUtilities.getLastModalChildOf(FilterViewPlugin.getInstance().getSuperFrame());

    if (chooser.showDialog(w,
            Localizer.getLocalization(Localizer.I18N_SELECT)) == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile() != null) {
            File dir = new File(FilterViewSettings.getIconDirectoryName());

            if (!dir.isDirectory()) {
                dir.mkdir();/*from   www.j  a  va  2 s  .c o m*/
            }

            String ext = chooser.getSelectedFile().getName();
            ext = ext.substring(ext.lastIndexOf('.'));

            Icon icon = FilterViewPlugin.getInstance().getIcon(chooser.getSelectedFile().getAbsolutePath());

            if (icon.getIconWidth() > MAX_ICON_WIDTH || icon.getIconHeight() > MAX_ICON_HEIGHT) {
                JOptionPane.showMessageDialog(w, mLocalizer.msg("iconSize",
                        "The icon size must be at most {0}x{1}.", MAX_ICON_WIDTH, MAX_ICON_HEIGHT));
                return;
            }

            try {
                IOUtilities.copy(chooser.getSelectedFile(), new File(dir, filterName + ext));
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            mIcons.put(filterName, filterName + ext);
            mFilterList.updateUI();
        }
    }
}

From source file:AncestorTree.java

public void paint(Graphics g) {
    Color bColor = getBackground();
    Icon icon = getIcon();

    g.setColor(bColor);//w  w  w .  j  a va  2  s  . c  o  m
    int offset = 0;
    if (icon != null && getText() != null)
        offset = (icon.getIconWidth() + getIconTextGap());
    g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1);

    if (m_selected) {
        g.setColor(m_borderSelectionColor);
        g.drawRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1);
    }

    super.paint(g);
}

From source file:TexturedPanel.java

/**
 * Creates a new TexturePaint using the provided icon.
 *//*from w w  w . j  a v  a2s .  c  o  m*/
private void setupIconPainter(Icon texture) {
    if (texture == null) {
        ourPainter = null;
        return;
    }

    int w = texture.getIconWidth();
    int h = texture.getIconHeight();

    if (w <= 0 || h <= 0) {
        ourPainter = null;
        return;
    }

    BufferedImage buff = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);

    Graphics2D g2 = buff.createGraphics();
    texture.paintIcon(this, g2, 0, 0);
    ourPainter = new TexturePaint(buff, new Rectangle(0, 0, w, h));

    g2.dispose();
}

From source file:FileTree3.java

public void paintComponent(Graphics g) {
    Color bColor = getBackground();
    Icon icon = getIcon();

    g.setColor(bColor);/*from   www .  j a  v a 2 s.  co m*/
    int offset = 0;
    if (icon != null && getText() != null)
        offset = (icon.getIconWidth() + getIconTextGap());
    g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1);

    if (m_selected) {
        g.setColor(m_borderSelectionColor);
        g.drawRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1);
    }

    super.paintComponent(g);
}