Example usage for javax.swing ImageIcon getImage

List of usage examples for javax.swing ImageIcon getImage

Introduction

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

Prototype

@Transient
public Image getImage() 

Source Link

Document

Returns this icon's Image.

Usage

From source file:org.pentaho.reporting.designer.core.ReportDesignerFrame.java

public ReportDesignerFrame() throws XulException {
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    final ImageIcon icon = IconLoader.getInstance().getProductIcon();
    if (icon != null) {
        setIconImage(icon.getImage());
    }// ww w .j a  va2  s . c  o m

    setTitle(Messages.getString("ReportDesignerFrame.Title"));
    addWindowListener(new WindowCloseHandler());

    viewController = new FrameViewController(this);
    context = new DefaultReportDesignerContext(viewController);
    viewController.initializeXulDesignerFrame(context);

    welcomePane = new WelcomePane(ReportDesignerFrame.this, getContext());
    fieldSelectorPaletteDialog = new FieldSelectorPaletteDialog(ReportDesignerFrame.this, getContext());

    statusBar = new StatusBar(context);

    reportEditorPane = new FancyTabbedPane();
    reportEditorPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    reportEditorPane.getModel().addChangeListener(new ReportTabActivationHandler());
    reportEditorPane.addMouseListener(new ReportTabPanePopupHandler());

    dockingPane = new GlobalPane(false);
    dockingPane.setMainComponent(reportEditorPane);

    attributeEditorPanel = new ElementPropertiesPanel();
    attributeEditorPanel.setAllowAttributeCard(true);
    attributeEditorPanel.setReportDesignerContext(context);

    treePanel = new TreeSidePanel(context, attributeEditorPanel);

    initializeToolWindows();

    paletteToolBar = createPaletteToolBar();

    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(context.getToolBar("main-toolbar"), BorderLayout.NORTH); // NON-NLS
    contentPane.add(dockingPane, BorderLayout.CENTER);
    contentPane.add(statusBar, BorderLayout.SOUTH);
    contentPane.add(paletteToolBar, BorderLayout.WEST);
    setContentPane(contentPane);

    setJMenuBar(createMenuBar());
    setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new DefaultDropTargetListener()));

    context.addPropertyChangeListener(ReportDesignerContext.ACTIVE_CONTEXT_PROPERTY,
            new ReportTabActivationHandler());
    context.addPropertyChangeListener(ReportDesignerContext.STATUS_TEXT_PROPERTY, new StatusTextHandler());
    context.addPropertyChangeListener(ReportDesignerContext.PAGE_PROPERTY, new PageTextHandler());
    context.addPropertyChangeListener(ReportDesignerContext.REPORT_RENDER_CONTEXT_PROPERTY,
            new ReportEditorContextHandler());

    Toolkit.getDefaultToolkit().addAWTEventListener(new DragSelectionToggleHandler(), AWTEvent.KEY_EVENT_MASK);

    if (MacOSXIntegration.MAC_OS_X) {
        try {
            final AboutAction aboutAction = new AboutAction();
            aboutAction.setReportDesignerContext(context);

            final SettingsAction settingsAction = new SettingsAction();
            settingsAction.setReportDesignerContext(context);

            final QuitAction quitAction = new QuitAction();
            quitAction.setReportDesignerContext(context);

            final OpenReportAction openReportAction = new OpenReportAction();
            openReportAction.setReportDesignerContext(context);

            MacOSXIntegration.setOpenFileAction(openReportAction);
            MacOSXIntegration.setAboutAction(aboutAction);
            MacOSXIntegration.setPreferencesAction(settingsAction);
            MacOSXIntegration.setQuitAction(quitAction);
        } catch (Throwable e) {
            DebugLog.log("Failed to activate MacOS-X integration", e); // NON-NLS
        }
    }

    visibleElementsUpdateHandler = new VisibleElementsUpdateHandler();
    WorkspaceSettings.getInstance().addSettingsListener(visibleElementsUpdateHandler);
}

From source file:org.pentaho.reporting.engine.classic.demo.ancient.demo.swingicons.SwingIconsDemoTableModel.java

/**
 * Reads an icon from the jar file./*from  w  ww  .  j a v  a2s  .c om*/
 *
 * @param in the input stream.
 * @return The image.
 */
private Image getImage(final InputStream in) {
    Image result = null;
    final ByteArrayOutputStream byteIn = new ByteArrayOutputStream();
    try {
        IOUtils.getInstance().copyStreams(in, byteIn);
        final ImageIcon temp = new ImageIcon(byteIn.toByteArray());
        result = temp.getImage();
    } catch (IOException e) {
        logger.warn("Unable to read the ZIP-Entry", e);
    }
    return result;
}

From source file:org.pentaho.ui.xul.swing.tags.SwingHbox.java

public void setBackground(String src) {
    this.background = src;
    URL url = SwingImage.class.getClassLoader()
            .getResource(this.domContainer.getXulLoader().getRootDir() + src);

    // Then try to see if we can get the fully qualified file
    if (url == null) {
        try {//w w  w  .ja  v a 2  s . com
            url = new File(src).toURL();
        } catch (MalformedURLException e) {
            // do nothing and let the null url get caught below.
        }
    }

    if (url == null) {
        logger.error("Could not find resource: " + src);
        return;
    }
    final ImageIcon ico = new ImageIcon(url);

    container.addComponentListener(new ComponentListener() {

        public void componentHidden(ComponentEvent arg0) {
        }

        public void componentMoved(ComponentEvent arg0) {
        }

        public void componentResized(ComponentEvent arg0) {
            container.getGraphics().drawImage(ico.getImage(), 0, 0, container);
        }

        public void componentShown(ComponentEvent arg0) {
        }

    });
}

From source file:org.pentaho.ui.xul.swing.tags.SwingVbox.java

public void setBackground(String src) {
    this.background = src;
    URL url = SwingImage.class.getClassLoader()
            .getResource(this.domContainer.getXulLoader().getRootDir() + src);

    // Then try to see if we can get the fully qualified file
    if (url == null) {
        try {//from w ww  .java2s  . c o  m
            url = new File(src).toURL();
        } catch (MalformedURLException e) {
            // do nothing and let the null url get caught below.
        }
    }

    if (url == null) {
        logger.error("Could not find resource: " + src);
        return;
    }
    final ImageIcon ico = new ImageIcon(url);
    backgroundImage = ico.getImage();

}

From source file:org.pentaho.ui.xul.swing.tags.SwingWindow.java

public void setAppicon(String icon) {
    try {// w  ww.j  a  va 2  s.c o  m
        this.appicon = icon;
        URL url = SwingButton.class.getClassLoader()
                .getResource(this.xulContainer.getXulLoader().getRootDir() + icon);

        ImageIcon ico = new ImageIcon(url);
        if (ico.getImage() != null) {
            frame.setIconImage(ico.getImage());
        }
    } catch (Exception e) {
        logger.error("Error loading application icon: " + icon, e);
    }
}

From source file:org.sbs.util.ImageCompress.java

/**
 * gif//from  w  ww. java2 s. co  m
 * 
 * @param originalFile
 *            
 * @param resizedFile
 *            ?
 * @param newWidth
 *            
 * @param newHeight
 *             -1?
 * @param quality
 *             ()
 * @throws IOException
 */
public void resize(File originalFile, File resizedFile, int newWidth, int newHeight, float quality)
        throws IOException {
    if (quality < 0 || quality > 1) {
        throw new IllegalArgumentException("Quality has to be between 0 and 1");
    }
    ImageIcon ii = new ImageIcon(originalFile.getCanonicalPath());
    Image i = ii.getImage();
    Image resizedImage = null;
    int iWidth = i.getWidth(null);
    int iHeight = i.getHeight(null);
    if (newHeight == -1) {
        if (iWidth > iHeight) {
            resizedImage = i.getScaledInstance(newWidth, (newWidth * iHeight) / iWidth, Image.SCALE_SMOOTH);
        } else {
            resizedImage = i.getScaledInstance((newWidth * iWidth) / iHeight, newWidth, Image.SCALE_SMOOTH);
        }
    } else {
        resizedImage = i.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
    }
    // This code ensures that all the pixels in the image are loaded.
    Image temp = new ImageIcon(resizedImage).getImage();
    // Create the buffered image.
    BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    // Copy image to buffered image.
    Graphics g = bufferedImage.createGraphics();
    // Clear background and paint the image.
    g.setColor(Color.white);
    g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null));
    g.drawImage(temp, 0, 0, null);
    g.dispose();
    // Soften.
    float softenFactor = 0.05f;
    float[] softenArray = { 0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0,
            softenFactor, 0 };
    Kernel kernel = new Kernel(3, 3, softenArray);
    ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    bufferedImage = cOp.filter(bufferedImage, null);
    // Write the jpeg to a file.
    FileOutputStream out = FileUtils.openOutputStream(resizedFile);
    // Encodes image as a JPEG data stream
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bufferedImage);
    param.setQuality(quality, true);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(bufferedImage);
}

From source file:org.shelloid.vpt.agent.App.java

private Image createImage(String imgpath) throws IOException {
    ImageIcon ico = new ImageIcon(getClass().getResource(imgpath));
    return ico.getImage();
}

From source file:org.sonarlint.intellij.config.global.SonarQubeServerEditor.java

private void setIcon() {
    try {/*  ww  w.  j  ava  2 s  . c  o m*/
        ImageIcon sonarQubeIcon = ResourceLoader.getIcon(ResourceLoader.ICON_SONARQUBE_32);
        super.getPeer().getWindow().setIconImage(sonarQubeIcon.getImage());
    } catch (Exception e) {
        // ignore and don't set icon
    }
}

From source file:org.tros.torgo.Main.java

public static void loadIcon(Window frame) {
    try {//  w w  w.  j  a va2 s.  c  o m
        java.util.Enumeration<URL> resources = ClassLoader.getSystemClassLoader()
                .getResources(IMAGE_ICON_CLASS_PATH);
        ImageIcon ico = new ImageIcon(resources.nextElement());
        frame.setIconImage(ico.getImage());
    } catch (IOException ex) {
        org.tros.utils.logging.Logging.getLogFactory().getLogger(Main.class).warn(null, ex);
    }
}

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/*from   w  w w. j ava 2  s . 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();
}