public void fitToBounds(int padding) {
		Rectangle viewBounds = getVisibleRect();
        Rectangle automatonBounds;
        if(drawer != null && drawer.getBounds() != null) automatonBounds = new Rectangle(drawer.getBounds());
        else automatonBounds = new Rectangle(0, 0);
		automatonBounds.grow(padding, padding);
		viewBounds.x = viewBounds.y = 0; // Just pretend...
		State[] states = drawer.getAutomaton().getStates();

		// Translate and scale each point.
		for (int i = 0; i < states.length; i++) {
			Point p = states[i].getPoint();
			p.setLocation((p.getX() - automatonBounds.getX())
					* (viewBounds.getWidth() / automatonBounds.getWidth()), (p
					.getY() - automatonBounds.getY())
					* (viewBounds.getHeight() / automatonBounds.getHeight()));
			states[i].setPoint(p);
		}
	}