~ubuntu-branches/ubuntu/breezy/freeguide/breezy

« back to all changes in this revision

Viewing changes to src/program/gui/viewer/ChannelJLabel.java

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2005-03-16 14:26:41 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050316142641-158peomn97t9qvhp
Tags: 0.8.5-1
* New upstream release.
* Change __ANT_DOC_DIRECTORY__ to /usr/share/doc/freeguide.
* Add sensible-browser to the list of web browsers (closes: #288518).
* Add menu entry and xpm icon (closes: #288813). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
         * Set the icon of the channel
54
54
         * @param fileName the path to the image to use as an icon
55
55
         */
56
 
        public void setIcon(String fileName) {
 
56
        public void setIcon( String fileName ) {
 
57
        
57
58
                currentIconFileName = fileName;
 
59
        
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
62
 
                 */ 
63
 
                int width;
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)));
69
 
                }
70
 
                else
71
 
                        super.setIcon(icon);
72
 
        }
 
61
                ImageIcon icon = new ImageIcon( fileName );
 
62
        
 
63
        // Force the icon to have proportions 1.36 x 1
 
64
        
 
65
                int icon_width  = icon.getIconWidth();
 
66
        int icon_height = icon.getIconHeight();
 
67
        
 
68
        int new_icon_width  = -1;
 
69
        int new_icon_height = -1;
 
70
        
 
71
                int max_height = getHeight() - getInsets().top - getInsets().bottom;
 
72
        int max_width = (int)( 1.37 * (double)max_height );
 
73
        
 
74
        double new_over_old = (double)max_width / (double)icon_width;
 
75
            
 
76
        new_icon_width  = max_width;
 
77
        new_icon_height = (int)( (double)icon_height * new_over_old );
 
78
 
 
79
        if( new_icon_height > max_height ) {
 
80
            
 
81
            double new_over_old2 = (double)max_height / (double)new_icon_height;
 
82
            
 
83
            new_icon_height = max_height;
 
84
            new_icon_width  = (int)( (double)max_width * new_over_old2 );
 
85
            
 
86
        }
 
87
        
 
88
        super.setIcon( new ImageIcon( icon.getImage().getScaledInstance(
 
89
            new_icon_width, new_icon_height, Image.SCALE_AREA_AVERAGING ) ) );
 
90
        
 
91
    }
73
92
        
74
93
        /**
75
94
         * @param id the Id of the channel
93
112
        public String getId() {
94
113
                return id;
95
114
        }
 
115
    
96
116
        /**
97
117
         * @return Returns the name.
98
118
         */
116
136
         * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
117
137
         */
118
138
        public void componentResized(ComponentEvent e) {
119
 
                if (currentIconFileName != null)
120
 
                        setIcon(currentIconFileName);
 
139
                if( currentIconFileName != null )
 
140
                        setIcon( currentIconFileName );
121
141
        }
122
142
 
123
143
        /* (non-Javadoc)
139
159
        FontMetrics myFM = this.getFontMetrics( getFont() );
140
160
        int ans = myFM.stringWidth( getText() );
141
161
        
142
 
        Icon ic = getIcon();
 
162
        Icon ic = super.getIcon();
143
163
        if( ic != null ) {
144
164
            ans += ic.getIconWidth();
145
165
        }