@Override
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);

        updateScaleX();

        final HiResInterval viewInterval = getInterval();

        Dimension newSize = null;
        try 
        {
            RenderingVisitor visitor = new RenderingVisitor( (Graphics2D) g );
            visitor.render( reader );
            newSize = visitor.getEstimatedSize();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }

        final SelectedInterval lastSelection = intervalHelper.getLastSelection();
        if ( lastSelection != null ) 
        {
            HiResInterval selectedInterval = intervalHelper.getLastSelectionModelObject();
            if ( selectedInterval != null && viewInterval.contains( selectedInterval.start ) && viewInterval.containsEndInclusive( selectedInterval.end ) )
            {
                int xmin = modelToView( selectedInterval.start);
                int xmax = modelToView( selectedInterval.end);
                intervalHelper.paintSelection( g , xmin,xmax,getCanvasHeight() );
            }
        }
        
        if ( newSize != null && ! newSize.equals( myPreferredSize ) ) 
        {
            myPreferredSize = newSize;       
            revalidate();
        }
    }