Example usage for javax.swing Icon getIconHeight

List of usage examples for javax.swing Icon getIconHeight

Introduction

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

Prototype

int getIconHeight();

Source Link

Document

Returns the icon's height.

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.
 *///from ww w  .  j  a  v  a  2  s.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)// ww w  . j a  v a  2s  . c  om
 *
 * @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();
    }//w  w  w.  ja v  a 2  s.co 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;/*  w ww. j a v  a  2 s .  com*/
}

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(".");
                }// www .java  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  w w  w.  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:es.emergya.ui.base.plugins.PluggableJTabbedPane.java

private void addFloatingButtons() {
    JButton salir = new JButton();
    salir.addActionListener(new ExitHandler());

    Icon icon = LogicConstants.getIcon("header_button_exit");
    salir.setIcon(icon);//  www.j  a va 2 s. c  o  m
    if (icon != null)
        if (min_height < icon.getIconHeight())
            min_height = icon.getIconHeight();

    // Aadimos el botn de Salir
    salir.setBounds(this.getWidth() - icon.getIconWidth() - 2, 2, icon.getIconWidth(), icon.getIconHeight());
    salir.setBorderPainted(false);
    PluggableJTabbedPane.this.salir = salir.getBounds();

    // Logo de la empresa
    JLabel logo = new JLabel();
    icon = LogicConstants.getIcon("header_logo_cliente");
    if (min_height < icon.getIconHeight())
        min_height = icon.getIconHeight();

    logo.setIcon(icon);
    logo.setBounds(salir.getBounds().x - icon.getIconWidth() - 2, 2, icon.getIconWidth(), icon.getIconHeight());

    JLabel companyLogo = new JLabel();
    icon = LogicConstants.getIcon("header_logo");
    if (icon != null)
        if (min_height < icon.getIconHeight())
            min_height = icon.getIconHeight();
    companyLogo.setIcon(icon);
    companyLogo.setBounds(logo.getBounds().x - icon.getIconWidth(), 2, icon.getIconWidth(),
            icon.getIconHeight());

    botones_flotantes = new ArrayList<JComponent>();
    addFloatingButton(companyLogo);
    addFloatingButton(logo);
    addFloatingButton(salir);

    repaint();
}

From source file:TexturedPanel.java

/**
 * Creates a new TexturePaint using the provided icon.
 *///from  w w w . j a  va  2  s .  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:marytts.tools.voiceimport.DatabaseImportMain.java

protected void setupGUI() {
    // A scroll pane containing one labelled checkbox per component,
    // and a "run selected components" button below.
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridC = new GridBagConstraints();
    getContentPane().setLayout(gridBagLayout);

    JPanel checkboxPane = new JPanel();
    checkboxPane.setLayout(new BoxLayout(checkboxPane, BoxLayout.Y_AXIS));
    //checkboxPane.setPreferredSize(new Dimension(300, 300));
    int compIndex = 0;
    for (int j = 0; j < groups2Comps.length; j++) {
        String[] nextGroup = groups2Comps[j];
        JPanel groupPane = new JPanel();
        groupPane.setLayout(new BoxLayout(groupPane, BoxLayout.Y_AXIS));
        groupPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(nextGroup[0]),
                BorderFactory.createEmptyBorder(1, 1, 1, 1)));
        for (int i = 1; i < nextGroup.length; i++) {
            JButton configButton = new JButton();
            Icon configIcon = new ImageIcon(DatabaseImportMain.class.getResource("configure.png"), "Configure");
            configButton.setIcon(configIcon);
            configButton.setPreferredSize(new Dimension(configIcon.getIconWidth(), configIcon.getIconHeight()));
            configButton.addActionListener(new ConfigButtonActionListener(nextGroup[i]));
            configButton.setBorderPainted(false);
            //System.out.println("Adding checkbox for "+components[i].getClass().getName());
            checkboxes[compIndex] = new JCheckBox(nextGroup[i]);
            checkboxes[compIndex].setFocusable(true);
            //checkboxes[i].setPreferredSize(new Dimension(200, 30));
            JPanel line = new JPanel();
            line.setLayout(new BorderLayout(5, 0));
            line.add(configButton, BorderLayout.WEST);
            line.add(checkboxes[compIndex], BorderLayout.CENTER);
            groupPane.add(line);/*from  w w  w.  j a v a2 s . c  om*/
            compIndex++;
        }
        checkboxPane.add(groupPane);
    }
    gridC.gridx = 0;
    gridC.gridy = 0;
    gridC.fill = GridBagConstraints.BOTH;
    JScrollPane scrollPane = new JScrollPane(checkboxPane);
    scrollPane.setPreferredSize(new Dimension(450, 300));
    gridBagLayout.setConstraints(scrollPane, gridC);
    getContentPane().add(scrollPane);

    JButton helpButton = new JButton("Help");
    helpButton.setMnemonic(KeyEvent.VK_H);
    helpButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            displayHelpGUI();
        }
    });
    JButton settingsButton = new JButton("Settings");
    settingsButton.setMnemonic(KeyEvent.VK_S);
    settingsButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            currentComponent = "Global properties";
            displaySettingsGUI();
        }
    });
    runButton = new JButton("Run");
    runButton.setMnemonic(KeyEvent.VK_R);
    runButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            runSelectedComponents();
        }
    });

    JButton quitAndSaveButton = new JButton("Quit");
    quitAndSaveButton.setMnemonic(KeyEvent.VK_Q);
    quitAndSaveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                askIfSave();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            System.exit(0);
        }
    });

    gridC.gridy = 1;
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    //buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
    //runButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(runButton);
    //helpButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(helpButton);
    //settingsButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(settingsButton);
    //buttonPanel.add(Box.createHorizontalGlue());
    //quitAndSaveButton.setAlignmentX(JButton.RIGHT_ALIGNMENT);
    buttonPanel.add(quitAndSaveButton);
    gridBagLayout.setConstraints(buttonPanel, gridC);
    getContentPane().add(buttonPanel);

    //getContentPane().setPreferredSize(new Dimension(300, 300));
    // End program when closing window:
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            try {
                askIfSave();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            System.exit(0);
        }
    });
}

From source file:gdt.jgui.entity.webset.JWeblinkEditor.java

/**
 * Get the context locator.//from ww w.  j ava2  s . c  o m
 * @return the context locator.
 */
@Override
public String getLocator() {
    try {
        Properties locator = new Properties();
        locator.setProperty(BaseHandler.HANDLER_CLASS, getClass().getName());
        locator.setProperty(BaseHandler.HANDLER_SCOPE, JConsoleHandler.CONSOLE_SCOPE);
        locator.setProperty(JContext.CONTEXT_TYPE, getType());
        locator.setProperty(Locator.LOCATOR_TITLE, getTitle());
        if (entityLabel$ != null) {
            locator.setProperty(EntityHandler.ENTITY_LABEL, entityLabel$);
        }
        if (entityKey$ != null)
            locator.setProperty(EntityHandler.ENTITY_KEY, entityKey$);
        if (entihome$ != null)
            locator.setProperty(Entigrator.ENTIHOME, entihome$);
        if (webLinkKey$ != null)
            locator.setProperty(JWeblinksPanel.WEB_LINK_KEY, webLinkKey$);
        String icon$ = null;
        try {
            Icon icon = iconIcon.getIcon();
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage out = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), type);
            Graphics2D g2 = out.createGraphics();
            icon.paintIcon(new JPanel(), out.getGraphics(), 0, 0);
            g2.dispose();
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            ImageIO.write(out, "png", b);
            b.close();
            byte[] ba = b.toByteArray();
            icon$ = Base64.encodeBase64String(ba);
        } catch (Exception ee) {
        }
        if (icon$ == null)
            icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "edit.png");
        locator.setProperty(Locator.LOCATOR_ICON, icon$);
        return Locator.toString(locator);
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
        return null;
    }

}