Example usage for javax.swing ImageIcon getIconWidth

List of usage examples for javax.swing ImageIcon getIconWidth

Introduction

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

Prototype

public int getIconWidth() 

Source Link

Document

Gets the width of the icon.

Usage

From source file:org.openconcerto.task.TodoListPanel.java

private void setIconForColumn(int i, ImageIcon icon) {

    TableCellRenderer renderer = new JComponentTableCellRenderer(icon);
    TableColumnModel columnModel = this.t.getColumnModel();
    TableColumn column = columnModel.getColumn(i);
    column.setHeaderRenderer(renderer);//from  w  ww  .  j a  v a2 s . c  om
    column.setMaxWidth(icon.getIconWidth() + 16);
    column.setMinWidth(icon.getIconWidth() + 8);
}

From source file:org.projectforge.core.CreateImageDimensions.java

public static void main(final String[] args) throws IOException {
    log.info("Create dimension file of all webapp images.");
    final List<ImageDimension> dimensions = new ArrayList<ImageDimension>();
    for (final String subDir : SUB_DIRS) {
        final String path = PATH + subDir;
        final Collection<File> files = FileUtils.listFiles(new File(path), IMAGE_SUFFIXES, true);
        final File absolutePathFile = new File(PATH);
        final String absolutePath = absolutePathFile.getAbsolutePath();
        for (final File file : files) {
            final Image image = Toolkit.getDefaultToolkit().getImage(file.getAbsolutePath());
            final ImageIcon icon = new ImageIcon(image);
            final String filename = file.getAbsolutePath().substring(absolutePath.length() + 1);
            final ImageDimension dimension = new ImageDimension(filename, icon.getIconWidth(),
                    icon.getIconHeight());
            dimensions.add(dimension);/*from  w  ww .ja v  a2 s .  c om*/
        }
    }
    final FileWriter writer = new FileWriter(DIMENSION_FILE);
    final XmlObjectWriter xmlWriter = new XmlObjectWriter();
    final AliasMap aliasMap = new AliasMap();
    aliasMap.put(ArrayList.class, "images");
    xmlWriter.setAliasMap(aliasMap);
    final String xml = xmlWriter.writeToXml(dimensions, true);
    writer.append(XmlHelper.XML_HEADER);
    writer.append(xml);
    IOUtils.closeQuietly(writer);
    log.info("Creation of dimension file done: " + DIMENSION_FILE);
}

From source file:org.richie.codeGen.ui.GenAndPreviewUI.java

/**
 * ??/*  w w  w  .j  a v  a2  s.  c  o  m*/
 * 
 * @param fileName
 * @param fileContent
 */
private void addPreviewTablePanel(String fileName, String fileContent) {
    final JScrollPane content = new JScrollPane();
    JTextArea viewTextArea = new JTextArea();
    viewTextArea.setText(fileContent);
    content.setViewportView(viewTextArea);
    JPanel tab = new JPanel();
    tab.setOpaque(false);
    JLabel tabLabel = new JLabel(fileName);
    ImageIcon closeXIcon = new ImageIcon(ClassLoader.getSystemResource("resources/images/close.gif"));
    JButton tabCloseButton = new JButton(closeXIcon);
    tabCloseButton.setToolTipText("close");
    tabCloseButton.setBorder(null);
    tabCloseButton.setContentAreaFilled(false);
    tabCloseButton.setPreferredSize(new Dimension(closeXIcon.getIconWidth(), closeXIcon.getIconHeight()));
    tabCloseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int closeTabNumber = mainPanel.indexOfComponent(content);
            mainPanel.removeTabAt(closeTabNumber);
        }
    });

    tab.add(tabLabel, BorderLayout.WEST);
    tab.add(tabCloseButton, BorderLayout.EAST);

    mainPanel.addTab(null, content);
    mainPanel.setTabComponentAt(mainPanel.getTabCount() - 1, tab);
    mainPanel.setSelectedComponent(content);
}

From source file:org.vulpe.view.tags.Functions.java

/**
 * This method takes in an image as a byte array (currently supports GIF,
 * JPG, PNG and possibly other formats) and resizes it to have a width no
 * greater than the pMaxWidth parameter in pixels. It converts the image to
 * a standard quality JPG and returns the byte array of that JPG image.
 *
 * @param imageData//  www  .  j  a v a 2s.  c  o  m
 *            the image data.
 * @param maxWidth
 *            the max width in pixels, 0 means do not scale.
 * @return the resized JPG image.
 * @throws IOException
 *             if the image could not be manipulated correctly.
 */
public static byte[] resizeImageAsJPG(final byte[] imageData, final int maxWidth) throws IOException {
    // Create an ImageIcon from the image data
    final ImageIcon imageIcon = new ImageIcon(imageData);
    int width = imageIcon.getIconWidth();
    if (width == maxWidth) {
        return imageData;
    }
    int height = imageIcon.getIconHeight();
    LOG.debug("imageIcon width: " + width + "  height: " + height);
    // If the image is larger than the max width, we need to resize it
    if (maxWidth > 0 && width > maxWidth) {
        // Determine the shrink ratio
        final double ratio = (double) maxWidth / imageIcon.getIconWidth();
        LOG.debug("resize ratio: " + ratio);
        height = (int) (imageIcon.getIconHeight() * ratio);
        width = maxWidth;
        LOG.debug("imageIcon post scale width: " + width + "  height: " + height);
    }
    // Create a new empty image buffer to "draw" the resized image into
    final BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    // Create a Graphics object to do the "drawing"
    final Graphics2D g2d = bufferedImage.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    // Draw the resized image
    g2d.drawImage(imageIcon.getImage(), 0, 0, width, height, null);
    g2d.dispose();
    // Now our buffered image is ready
    // Encode it as a JPEG
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);
    encoder.encode(bufferedImage);
    return baos.toByteArray();
}

From source file:org.wings.SImageIcon.java

public SImageIcon(ImageIcon image, String mimeType) {
    if (image == null)
        throw new IllegalArgumentException("SImageIcon needs an Argument that's not null");

    img = image;/*  ww w  .j av  a2  s.c o m*/
    url = new SimpleURL(SessionManager.getSession().getExternalizeManager().externalize(image, mimeType));
    setIconWidth(image.getIconWidth());
    setIconHeight(image.getIconHeight());
}

From source file:org.yccheok.jstock.gui.NewBrokingFirmJDialog.java

private void loadImage(File file) {
    ImageIcon imageIcon = new ImageIcon(file.getAbsolutePath());

    if (imageIcon.getIconWidth() <= 0 || imageIcon.getIconHeight() <= 0)
        return;//from  w  ww.  jav  a  2 s.  com

    this.setLogo(imageIcon.getImage());
}

From source file:output.TikzTex.java

/**
 * Use PDF-Latex to parse the .tex file//from w w w. j  a v a2  s  .  com
 * @param file the source File containing the Data
 * @throws IOException
 */
public void genPdf(File file) throws IOException {
    ProcessBuilder pb = new ProcessBuilder("pdflatex", "-shell-escape", file.getAbsolutePath());
    File directory = new File(outputDir);
    pb.directory(directory);

    Process p;
    try {
        p = pb.start();
        // We need to parse the Error and the Output generated by pdflatex
        StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR");
        StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT");
        errorGobbler.start();
        outputGobbler.start();
        // Wait until its done
        int exitVal = p.waitFor();

        // Spawn a Frame with the Image
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        String imgPath = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 4) + ".png";
        ImageIcon icon = new ImageIcon(imgPath);
        // resize
        Image img = icon.getImage();
        double ratio = (double) icon.getIconWidth() / icon.getIconHeight();
        Image newimg = img.getScaledInstance((int) (Math.round(600 * ratio)), 600, java.awt.Image.SCALE_SMOOTH);
        icon = new ImageIcon(newimg);
        JLabel imgLabel = new JLabel(icon);
        JScrollPane scrollPanel = new JScrollPane(imgLabel);

        frame.getContentPane().add(scrollPanel);
        frame.setSize(1280, 720);
        frame.setVisible(true);
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:sturesy.core.backend.services.ImageService.java

/**
 * Encodes the Image into a Base64-encoded String
 * // w  w w .  ja  va  2s . c  o  m
 * @return Base64-encoded String
 */
public String encodeImage(ImageIcon _questionImage) {
    if (_questionImage == null)
        return "";

    BufferedImage bi = new BufferedImage(_questionImage.getIconWidth(), _questionImage.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage(_questionImage.getImage(), 0, 0, null);
    g2.dispose();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        ImageIO.write(bi, "png", baos);

        baos.flush();
    } catch (IOException e) {
        Log.error("error converting image to bytearray", e);
    } finally {
        try {
            baos.close();
        } catch (IOException e) {
        }
    }

    return Base64.encodeBase64String(baos.toByteArray());
}

From source file:sturesy.export.jaxb.adapter.ImageAdapter.java

@Override
public String marshal(ImageIcon v) throws Exception {
    if (v.getIconHeight() != -1 && v.getIconWidth() != -1) {
        ImageService imageservice = new ImageService();
        return imageservice.encodeImage(v);
    } else {// w  w w.j a v  a2s . c o m
        return "";
    }
}

From source file:us.mn.state.dot.tms.client.camera.FTPStream.java

/** Create an image icon from image data */
protected ImageIcon createIcon(byte[] idata) {
    ImageIcon icon = new ImageIcon(idata);
    if (icon.getIconWidth() == size.width && icon.getIconHeight() == size.height)
        return icon;
    Image im = icon.getImage().getScaledInstance(size.width, size.height, Image.SCALE_FAST);
    return new ImageIcon(im);
}