@Override
    protected void paintComponent(Graphics g) {
        
        Graphics2D g2 = (Graphics2D)g;
        super.paintComponent(g2);
        
        if (settings != null) {
            if (settings.originalImage() != null && settings.originalDimension() != null &&
                    settings.viewRatio() != null &&  settings.viewTopLeftRatio() != null) {
                
                if (rescale) {
                    targetDimension = GuiImageManipulator.scaleToWindow(
                                        settings.originalDimension(), this.getSize());
                    targetPoint = GuiImageManipulator.balanceInWindow(
                                        targetDimension, this.getSize());
                    viewDimension.setSize(settings.viewRatio().getX() * targetDimension.getWidth(),
                                          settings.viewRatio().getY() * targetDimension.getHeight());
                    scaledImage = settings.originalImage().getScaledInstance(targetDimension.width,
                                                                             targetDimension.height,
                                                                             Image.SCALE_SMOOTH);
                    rescale = false;
                }
                assert scaledImage != null;
                g2.drawImage(scaledImage, targetPoint.x, targetPoint.y, null);
                
                int viewWidth = (int) (targetDimension.getWidth() * settings.viewRatio().getX());
                int viewHeight = (int) (targetDimension.getHeight() * settings.viewRatio().getY());
                
                int viewTLX = (int) (targetPoint.getX() - targetDimension.getWidth()
                                        * settings.viewTopLeftRatio().getX());
                int viewTLY = (int) (targetPoint.getY() - targetDimension.getHeight()
                                        * settings.viewTopLeftRatio().getY());
                
                g2.setColor(new Color(128, 128, 128, 64));
                g2.fillRect(viewTLX, viewTLY, viewWidth, viewHeight);
                
            }
        }
        
    }