Example usage for javax.swing ImageIcon getIconHeight

List of usage examples for javax.swing ImageIcon getIconHeight

Introduction

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

Prototype

public int getIconHeight() 

Source Link

Document

Gets the height of the icon.

Usage

From source file:gd.gui.GeneticDrawingView.java

public GeneticDrawingView(SingleFrameApplication app) {
    super(app);// w  w  w  . ja v a 2s .  c om

    initComponents();

    ResourceMap resourceMap = getResourceMap();
    ImageIcon imageIcon = resourceMap.getImageIcon("targetImageLabel.icon");
    targetImage = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    imageIcon.paintIcon(null, targetImage.getGraphics(), 0, 0);
    ProblemInstance.currentImage = targetImage;
    ProblemInstance.view = this;

    fittestDrawingView = new FittestDrawingView();
    fittestDrawingView.setVisible(false);
    fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight());

    try {
        startEvolution();
    } catch (InvalidConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:edu.ku.brc.specify.tasks.StartUpTask.java

@Override
public JPanel createSplashPanel() {
    AppPreferences ap = AppPreferences.getLocalPrefs();
    int width = ap.getInt("Startup.Image.width", 400);
    int height = ap.getInt("Startup.Image.height", 700);

    Image img = null;/*from ww w  . ja v a  2 s  .c  o  m*/
    ImageIcon bgImg = IconManager.getIcon(SPECIFY_SPLASH);
    if (bgImg.getIconWidth() > width || bgImg.getIconHeight() > height) {
        img = GraphicsUtils.getScaledImage(bgImg, width, height, true);
    } else {
        img = bgImg.getImage();
    }
    JPanel splashPanel = new JPanel(new BorderLayout());
    //splashPanel.setBackground(Color.WHITE);
    splashPanel.setOpaque(false);
    splashPanel.add(new JLabel(new ImageIcon(img)), BorderLayout.CENTER);
    return splashPanel;
}

From source file:components.ScrollDemo.java

public ScrollDemo() {
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    //Get the image to use.
    ImageIcon bee = createImageIcon("images/flyingBee.jpg");

    //Create the row and column headers.
    columnView = new Rule(Rule.HORIZONTAL, true);
    rowView = new Rule(Rule.VERTICAL, true);

    if (bee != null) {
        columnView.setPreferredWidth(bee.getIconWidth());
        rowView.setPreferredHeight(bee.getIconHeight());
    } else {/* w w w .j ava2 s .  c om*/
        columnView.setPreferredWidth(320);
        rowView.setPreferredHeight(480);
    }

    //Create the corners.
    JPanel buttonCorner = new JPanel(); //use FlowLayout
    isMetric = new JToggleButton("cm", true);
    isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11));
    isMetric.setMargin(new Insets(2, 2, 2, 2));
    isMetric.addItemListener(this);
    buttonCorner.add(isMetric);

    //Set up the scroll pane.
    picture = new ScrollablePicture(bee, columnView.getIncrement());
    JScrollPane pictureScrollPane = new JScrollPane(picture);
    pictureScrollPane.setPreferredSize(new Dimension(300, 250));
    pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black));

    pictureScrollPane.setColumnHeaderView(columnView);
    pictureScrollPane.setRowHeaderView(rowView);

    //Set the corners.
    //In theory, to support internationalization you would change
    //UPPER_LEFT_CORNER to UPPER_LEADING_CORNER,
    //LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and
    //UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER.  In practice,
    //bug #4467063 makes that impossible (in 1.4, at least).
    pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner);
    pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, new Corner());
    pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new Corner());

    //Put it in this panel.
    add(pictureScrollPane);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:FilterSample.java

public void propertyChange(PropertyChangeEvent changeEvent) {
    String changeName = changeEvent.getPropertyName();
    if (changeName.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
        File file = (File) changeEvent.getNewValue();
        if (file != null) {
            ImageIcon icon = new ImageIcon(file.getPath());
            if (icon.getIconWidth() > PREFERRED_WIDTH) {
                icon = new ImageIcon(
                        icon.getImage().getScaledInstance(PREFERRED_WIDTH, -1, Image.SCALE_DEFAULT));
                if (icon.getIconHeight() > PREFERRED_HEIGHT) {
                    icon = new ImageIcon(
                            icon.getImage().getScaledInstance(-1, PREFERRED_HEIGHT, Image.SCALE_DEFAULT));
                }//from   w w w.j  a  va  2s  .com
            }
            setIcon(icon);
        }
    }
}

From source file:edu.ku.brc.util.services.MapGrabber.java

/**
 * Retrieves a map from the web service.
 * //from www .  j a v  a 2  s.c  o m
 * @return a map image
  * @throws HttpException if network errors occur while grabbing map from service
  * @throws IOException if network errors occur while grabbing map from service
 */
public Image getMap() throws HttpException, IOException {
    log.debug("Entering MapGrabber.getMap()");
    log.debug("width=" + width + "\theight=" + height);
    double longSpread = maxLong - minLong;
    double latSpread = maxLat - minLat;
    log.debug("lat spread:  min=" + minLat + "\tmax=" + maxLat + "\trange=" + latSpread);
    log.debug("long spread: min=" + minLong + "\tmax=" + maxLong + "\trange=" + longSpread);
    if (width == null && height == null) {
        width = defaultWidth;
        height = defaultHeight;
    }

    StringBuilder url = new StringBuilder("http://");
    url.append(host);
    url.append(defaultPathAndParams);

    // set layers
    url.append("&layers=");
    url.append(layers);

    // set bounding box
    url.append("&bbox=");
    url.append(minLong);
    url.append(",");
    url.append(minLat);
    url.append(",");
    url.append(maxLong);
    url.append(",");
    url.append(maxLat);

    // set size
    url.append("&height=");
    url.append(height);
    url.append("&width=");
    url.append(width);

    Image image;
    String urlStr = url.toString();
    if (imageCache != null) {
        // check the image cache
        log.info("Asking cache to grab map image: " + urlStr);
        File imageFile = imageCache.getCacheFile(urlStr);
        if (imageFile == null) {
            // the image wasn't in the cache
            // grab it again
            urlStr = imageCache.cacheWebResource(urlStr);
            imageFile = imageCache.getCacheFile(urlStr);
        }
        //image = Toolkit.getDefaultToolkit().getImage(imageFile.getAbsolutePath());
        image = ImageIO.read(imageFile);
        if (image == null) {
            imageCache.refreshCachedWebResource(urlStr);
        }
        ImageIcon mapIcon = new ImageIcon(image);
        if (mapIcon.getIconHeight() < 0 || mapIcon.getIconWidth() < 0) {
            // since it was invalid, throw it out of the cache
            imageCache.clearItem(urlStr);
            throw new IOException(
                    "Mapping service failed to return a valid image.  Map request URL: " + urlStr);
        }
    } else {
        log.info("No image cache available.  Grabbing map internally.");
        GetMethod get = new GetMethod(urlStr);
        get.setFollowRedirects(true);
        int resultCode = httpClient.executeMethod(get);
        log.info("GET " + urlStr + " returned " + resultCode);
        log.info("Exiting MapGrabber.getMap()");
        byte[] data = get.getResponseBody();
        image = Toolkit.getDefaultToolkit().createImage(data);
        ImageIcon mapIcon = new ImageIcon(image);
        if (mapIcon.getIconHeight() < 0 || mapIcon.getIconWidth() < 0) {
            throw new IOException(
                    "Mapping service failed to return a valid image.  Map request URL: " + urlStr);
        }
    }

    return image;
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreeRenderer.java

/**
 * @param g2d//from   w w  w  .  ja  va 2s.  c o m
 * @param xc
 * @param yc
 * @param imgIcon
 * @param hitsInx
 * @return
 */
private int drawIcon(final Graphics2D g2d, final int xc, final int yc, final ImageIcon imgIcon,
        final int hitsInx) {
    g2d.drawImage(imgIcon.getImage(), xc, yc, null);
    hitRects[hitsInx].setBounds(xc, yc, imgIcon.getIconWidth(), imgIcon.getIconHeight());
    Point p = hitRects[hitsInx].getLocation();
    SwingUtilities.convertPointToScreen(p, this);
    hitRects[hitsInx].setLocation(p);
    return imgIcon.getIconWidth() + iconSep;
}

From source file:net.sourceforge.atunes.kernel.modules.tags.PropertiesFileTagAdapter.java

@Override
public ImageIcon getImage(final ILocalAudioObject audioObject, final int width, final int height) {
    String coverFileName = getFileNameForCover(audioObject);
    ImageIcon image = null;
    if (coverFileName != null && new File(coverFileName).exists()) {
        image = new ImageIcon(coverFileName);
    }/*from w  ww .j  a  v  a  2  s  . co  m*/
    if (image != null) {
        if (width == -1 || height == -1) {
            return image;
        }
        int maxSize = (image.getIconWidth() > image.getIconHeight()) ? image.getIconWidth()
                : image.getIconHeight();
        int newWidth = (int) ((float) image.getIconWidth() / (float) maxSize * width);
        int newHeight = (int) ((float) image.getIconHeight() / (float) maxSize * height);
        return ImageUtils.scaleImageBicubic(image.getImage(), newWidth, newHeight);
    }
    return image;
}

From source file:IconDemoApplet.java

private void updatePhotograph(int index, Photo pic) {
    ImageIcon icon = pic.getIcon();

    photographLabel.setToolTipText(pic.filename + ": " + icon.getIconWidth() + " X " + icon.getIconHeight());
    photographLabel.setIcon(icon);// w ww  . jav a 2  s .c o m
    photographLabel.setText("");
}

From source file:de.quadrillenschule.azocamsyncd.gui.ExploreWifiSDPanel.java

private void updateSingleView() {
    try {/*w  w  w  .  j a va  2 s  . c  o  m*/
        if (remotejTree.getSelectionPaths().length > 0) {
            TreePath tp = remotejTree.getSelectionPaths()[0];
            String mynode = tp.getLastPathComponent().toString();
            AZoFTPFile myaffilea = null;
            for (AZoFTPFile af : afs) {
                if (new String(af.dir + af.ftpFile.getName()).equals(mynode)) {
                    myaffilea = af;
                    //     GlobalProperties gp=new GlobalProperties();
                    //     gp.setProperty(GlobalProperties.CamSyncProperties.LATESTIMAGEPATH, af.dir+af.ftpFile.getName());
                    break;
                }
            }
            final AZoFTPFile myaffile = myaffilea;
            Thread imageUpdater = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        File localFile;

                        localFile = localStorage.getLocalFile(myaffile);

                        localFileNamejTextField1.setText(localFile.getAbsolutePath());
                        ImageIcon ii = new ImageIcon(localFile.toURI().toURL());

                        int mywidth = imagejLabel.getWidth();
                        int width = ii.getIconWidth();
                        int height = ii.getIconHeight();
                        if (width <= 0) {
                            imagejLabel.setText("No image to view.");
                        } else {
                            imagejLabel.setText("");
                        }
                        double factor = (double) height / (double) width;
                        Image image = ii.getImage().getScaledInstance(mywidth,
                                (int) ((double) mywidth * factor), Image.SCALE_FAST);
                        imagejLabel.setIcon(new ImageIcon(image));
                    } catch (Exception ex) {
                        imagejLabel.setText("No image to view.");
                    }
                }
            });
            imageUpdater.start();

        }
    } catch (Exception e) {

    }
}

From source file:GrafosTroleBus.java

public GrafosTroleBus() {
    setLayout(new BorderLayout());

    //definir puntos de trolebus (latitude y longitude) @autor sa

    map.put("RECREO", new String[] { "-0.2516682", "-78.521524" }); //Recreo                       
    map.put("P14", new String[] { "-0.2445098", "-78.51902" }); //Villaflora
    map.put("P15", new String[] { "-0.2396436", "-78.51698" }); //Chimbacalle N-S                      
    map.put("P16", new String[] { "-0.2378458", "-78.515976" }); //Chimbacalle S-N
    map.put("P17", new String[] { "-0.2356805", "-78.514816" }); //Colina
    map.put("P18", new String[] { "-0.234052", "-78.514237" }); //Jefferson Perez
    map.put("P19", new String[] { "-0.2312856", "-78.513627" }); //Recoleta N-S        
    map.put("P20", new String[] { "-0.2307005", "-78.513051" }); //Recoleta S-N
    map.put("P21", new String[] { "-0.2263919", "-78.513011" }); //P21 Cumanda N-S
    map.put("P22", new String[] { "-0.226424", "-78.512803" }); //P22 Cumanda S-N
    map.put("P23", new String[] { "-0.2234658", "-78.512542" }); //P23 Santo Domingo
    map.put("P24", new String[] { "-0.2185857", "-78.508601" }); //P24 Plaza del Teatro N-S
    map.put("P25", new String[] { "-0.219605", "-78.50813" }); //P25 Plaza del Teatro S-N        
    map.put("P26", new String[] { "-0.2177808", "-78.505977" }); //P26 Hermano Miguel
    map.put("P27", new String[] { "-0.2169088", "-78.50521" }); //P27 Banco Central
    map.put("P28", new String[] { "-0.214267", "-78.502999" }); //P28 La Alameda S-N
    map.put("P29", new String[] { "-0.2137705", "-78.50293" }); //P29 La Alameda N-S                       
    map.put("P30", new String[] { "-0.2084939", "-78.500255" }); //P30 Ejido N-S
    map.put("P31", new String[] { "-0.2088076", "-78.500032" }); //P31 Ejido S-N
    map.put("P32", new String[] { "-0.2047989", "-78.4988" }); //P32 La Mariscal N-S
    map.put("P33", new String[] { "-0.2041972", "-78.498491" }); //P33 La Mariscal S-N
    map.put("P34", new String[] { "-0.2009718", "-78.49715" }); //P34 Santa Clara S-N
    map.put("P35", new String[] { "-0.201056", "-78.496979" }); //P35 Santa Clara N-S
    map.put("P36", new String[] { "-0.1986325", "-78.496141" }); //P36 La Colon S-N
    map.put("P37", new String[] { "-0.1978432", "-78.495563" }); //P37 La Colon N-S
    map.put("P38", new String[] { "-0.1921587", "-78.493445" }); //P38 Cuero y Caicedo S-N
    map.put("P39", new String[] { "-0.1915098", "-78.493001" }); //P39 Cuero y Caicedo N-S                        
    map.put("P40", new String[] { "-0.1889467", "-78.492149" }); //P40 Mariana de Jess S-N
    map.put("P41", new String[] { "-0.1875567", "-78.491303" }); //P41 Mariana de Jesus N-S
    map.put("P42", new String[] { "-0.1853693", "-78.490878" }); //P42 El Floron S-N
    map.put("P43", new String[] { "-0.1846687", "-78.490403" }); //P43 El Floron N-S        
    map.put("P44", new String[] { "-0.1817679", "-78.489808" }); //P44 Carolina S-N
    map.put("P45", new String[] { "-0.1810849", "-78.489336" }); //P45 Carolina N-S
    map.put("P46", new String[] { "-0.1787274", "-78.488954" }); //P46 Estadio S-N
    map.put("P47", new String[] { "-0.1780172", "-78.488621" }); //P47 Estadio N-S
    map.put("P48", new String[] { "-0.172087", "-78.487589" }); //P48 La Y S-N
    map.put("P49", new String[] { "-0.1713146", "-78.487277" }); //P49 La Y N-S        
    map.put("LA Y", new String[] { "-0.1635504", "-78.485374" }); //Estacin La Y                              

    nodoList = new ArrayList<String>(map.keySet());

    // create a simple graph for the demo        
    graph = new DirectedSparseMultigraph<String, Number>();
    createVertices();//  w w w.  j av a2  s  . com
    createEdges();

    ImageIcon mapIcon = null;
    String imageLocation = "/mapa_quito.png";

    try {
        mapIcon = new ImageIcon(getClass().getResource(imageLocation));

        ImageWidth = mapIcon.getIconWidth();
        ImageHeight = mapIcon.getIconHeight();

    } catch (Exception ex) {
        System.err.println("Can't load \"" + imageLocation + "\"");
    }

    final ImageIcon icon = mapIcon;

    Dimension layoutSize = new Dimension(ImageWidth, ImageHeight);

    Layout<String, Number> layout = new StaticLayout<String, Number>(graph,
            new ChainedTransformer<String, Point2D>(new Transformer[] { new CityTransformer(map),
                    new LatLonPixelTransformer(new Dimension(ImageWidth, ImageHeight)) }));

    layout.setSize(layoutSize);
    vv = new VisualizationViewer<String, Number>(layout, new Dimension(MonitorWidth, MonitorHeight));

    if (icon != null) {
        vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform oldXform = g2d.getTransform();
                AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.LAYOUT).getTransform();
                AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.VIEW).getTransform();
                AffineTransform at = new AffineTransform();
                at.concatenate(g2d.getTransform());
                at.concatenate(vat);
                at.concatenate(lat);
                g2d.setTransform(at);
                g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), vv);
                g2d.setTransform(oldXform);
            }

            public boolean useTransform() {
                return false;
            }
        });
    }

    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {
        public String transform(Number edge) {
            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    add(panel);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<Object, Object>();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    final ScalingControl scaler = new CrossoverScalingControl();

    vv.scaleToLayout(scaler);

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    add(controls, BorderLayout.SOUTH);
}