private void updateWaveform ( WaveformPreview preview ) { this . preview . set ( preview ) ; if ( preview == null ) { waveformImage . set ( null ) ; } else { BufferedImage image = new BufferedImage ( preview . segmentCount , preview . maxHeight , BufferedImage . TYPE_INT_RGB ) ; Graphics g = image . getGraphics ( ) ; g . setColor ( Color . BLACK ) ; g . fillRect ( 0 , 0 , preview . segmentCount , preview . maxHeight ) ; for ( int segment = 0 ; segment < preview . segmentCount ; segment ++ ) { g . setColor ( preview . segmentColor ( segment , false ) ) ; g . drawLine ( segment , preview . maxHeight , segment , preview . maxHeight - preview . segmentHeight ( segment , false ) ) ; if ( preview . isColor ) { // We have a front color segment to draw on top. g . setColor ( preview . segmentColor ( segment , true ) ) ; g . drawLine ( segment , preview . maxHeight , segment , preview . maxHeight - preview . segmentHeight ( segment , true ) ) ; } } waveformImage . set ( image ) ; } }
Create an image of the proper size to hold a new waveform preview image and draw it .