width = x+port.getWidth(); height = y+port.getHeight();
width = x+viewRect.width; height = y+viewRect.height;
    public void paintComponent(Graphics g)    {        super.paintComponent(g);        BufferedImage img = model.getDisplayedImage();        if (img == null) return;        Graphics2D g2D = (Graphics2D) g;        ImagePaintingFactory.setGraphicRenderingSettings(g2D);        g2D.drawImage(img, null, 0, 0);         if (model.isUnitBar()) {            String value = model.getUnitBarValue();             if (value != null) {                int size = (int) (model.getUnitBarSize());                                Rectangle imgRect = new Rectangle(0, 0, img.getWidth(),                 		img.getHeight());                Rectangle viewRect = view.getViewport().getBounds();                JViewport port = view.getViewport();                int x = (int) port.getViewPosition().getX();                int y = (int) port.getViewPosition().getY();                int width = Math.min(x+viewRect.width, img.getWidth());                int height = Math.min(y+viewRect.height, img.getHeight());                if (imgRect.contains(viewRect)) {                    width = x+port.getWidth();                    height = y+port.getHeight();                }                                ImagePaintingFactory.paintScaleBar(g2D, width-size-10,                 										height-10, size, value);            }        }    }