nl.cloudfarming.client.fleet.machine.windows.ImagePanel Maven / Gradle / Ivy
/**
* Copyright (C) 2008-2012 AgroSense Foundation.
*
* AgroSense is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
* this software, see the FLOSS License Exception
* .
*
* AgroSense is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AgroSense. If not, see .
*/
package nl.cloudfarming.client.fleet.machine.windows;
import java.awt.Image;
import javax.swing.ImageIcon;
/**
*
* @author Timon Veenstra
*/
public class ImagePanel extends javax.swing.JPanel {
/**
* Creates new form ImagePanel
*/
public ImagePanel() {
initComponents();
}
public void setImage(ImageIcon imageIcon) {
if (imageIcon !=null){
imagePanel.setImage(imageIcon.getImage());
}else{
//FIXME TV: Load default image
}
}
private ImageIcon scale(ImageIcon imageIcon) {
if (imageIcon != null) {
int width = imageIcon.getIconWidth();
int height = imageIcon.getIconHeight();
float xScaleFactor = width / imagePanel.getPreferredSize().width;
float yScaleFactor = height / imagePanel.getPreferredSize().height;
float scaleFactor = Math.max(xScaleFactor, yScaleFactor);
int scaledWidth = Math.round(width / scaleFactor);
int scaledHeight = Math.round(height / scaleFactor);
Image scaledImage = imageIcon.getImage().getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH);
imageIcon = new ImageIcon(scaledImage);
}
return imageIcon;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
imagePanel = new org.jdesktop.swingx.JXImagePanel();
javax.swing.GroupLayout imagePanelLayout = new javax.swing.GroupLayout(imagePanel);
imagePanel.setLayout(imagePanelLayout);
imagePanelLayout.setHorizontalGroup(
imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
imagePanelLayout.setVerticalGroup(
imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(imagePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(imagePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
}// //GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private org.jdesktop.swingx.JXImagePanel imagePanel;
// End of variables declaration//GEN-END:variables
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy