53
53
* Set the icon of the channel
54
54
* @param fileName the path to the image to use as an icon
56
public void setIcon(String fileName) {
56
public void setIcon( String fileName ) {
57
58
currentIconFileName = fileName;
58
60
// Create the icon from the file
59
ImageIcon icon = new ImageIcon(fileName);
60
/* Verify the icon isn't taller than the pannel, resize otherwise.
61
* We don't check the width as it isn't usually a problem
64
int maxheight = this.getHeight()-this.getInsets().top-this.getInsets().bottom;
65
//System.err.println(icon.getIconHeight()+" - "+maxheight);
66
if (icon.getIconHeight()>maxheight) {
67
width =icon.getIconWidth()*maxheight/icon.getIconHeight();
68
super.setIcon(new ImageIcon(icon.getImage().getScaledInstance(width,maxheight,Image.SCALE_AREA_AVERAGING)));
61
ImageIcon icon = new ImageIcon( fileName );
63
// Force the icon to have proportions 1.36 x 1
65
int icon_width = icon.getIconWidth();
66
int icon_height = icon.getIconHeight();
68
int new_icon_width = -1;
69
int new_icon_height = -1;
71
int max_height = getHeight() - getInsets().top - getInsets().bottom;
72
int max_width = (int)( 1.37 * (double)max_height );
74
double new_over_old = (double)max_width / (double)icon_width;
76
new_icon_width = max_width;
77
new_icon_height = (int)( (double)icon_height * new_over_old );
79
if( new_icon_height > max_height ) {
81
double new_over_old2 = (double)max_height / (double)new_icon_height;
83
new_icon_height = max_height;
84
new_icon_width = (int)( (double)max_width * new_over_old2 );
88
super.setIcon( new ImageIcon( icon.getImage().getScaledInstance(
89
new_icon_width, new_icon_height, Image.SCALE_AREA_AVERAGING ) ) );
75
94
* @param id the Id of the channel
116
136
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
118
138
public void componentResized(ComponentEvent e) {
119
if (currentIconFileName != null)
120
setIcon(currentIconFileName);
139
if( currentIconFileName != null )
140
setIcon( currentIconFileName );