14a15,16
> import CH.ifa.draw.util.*;
> import CH.ifa.draw.framework.*;
20,21d21
< import CH.ifa.draw.util.*;
< import CH.ifa.draw.framework.*;
36d35
< 				   KeyListener,
59c58
< 	private transient Rectangle fDamage = null;
---
> 	private transient Rectangle fDamage;
87c86
< 	private Vector fBackgrounds = null;
---
> 	private Vector fBackgrounds;
94c93
< 	private Vector fForegrounds = null;
---
> 	private Vector fForegrounds;
141c140
< 		setDisplayUpdate(new SimpleUpdateStrategy());
---
> 		setDisplayUpdate(createDisplayUpdate());
146,148c145,147
< 		addMouseListener(ml);
< 		addMouseMotionListener(mml);
< 		addKeyListener(this);
---
> 		addMouseListener(createMouseListener());
> 		addMouseMotionListener(createMouseMotionListener());
> 		addKeyListener(createKeyListener());
151,166c150,151
< 	MouseListener ml = new MouseListener() {
< 		// listener methods we are not interested in
< 		public void mouseClicked(MouseEvent e) {}
< 		public void mouseEntered(MouseEvent e) {}
< 		public void mouseExited(MouseEvent e) {}
< 		 /**
< 		 * Handles mouse down events. The event is delegated to the
< 		 * currently active tool.
< 		 * @return whether the event was handled.
< 		 */
< 		public void mousePressed(MouseEvent e) {
< 			requestFocus(); // JDK1.1
< 			Point p = constrainPoint(new Point(e.getX(), e.getY()));
< 			fLastClick = new Point(e.getX(), e.getY());
< 			tool().mouseDown(e, p.x, p.y);
< 			checkDamage();
---
> 	protected MouseListener createMouseListener() {
> 		return new DrawingViewMouseListener();
168,176c153,155
< 		/**
< 		 * Handles mouse up events. The event is delegated to the
< 		 * currently active tool.
< 		 * @return whether the event was handled.
< 		 */
< 		public void mouseReleased(MouseEvent e) {
< 			Point p = constrainPoint(new Point(e.getX(), e.getY()));
< 			tool().mouseUp(e, p.x, p.y);
< 			checkDamage();
---
> 
> 	protected MouseMotionListener createMouseMotionListener() {
> 		return  new DrawingViewMouseMotionListener();
178d156
< 	};
180,189c158,159
< 	MouseMotionListener mml = new MouseMotionListener() {
< 		/**
< 		 * Handles mouse drag events. The event is delegated to the
< 		 * currently active tool.
< 		 * @return whether the event was handled.
< 		 */
< 		public void mouseDragged(MouseEvent e) {
< 			Point p = constrainPoint(new Point(e.getX(), e.getY()));
< 			tool().mouseDrag(e, p.x, p.y);
< 			checkDamage();
---
> 	protected KeyListener createKeyListener() {
> 		return new DrawingViewKeyListener();
193,195c163
< 		 * Handles mouse move events. The event is delegated to the
< 		 * currently active tool.
< 		 * @return whether the event was handled.
---
> 	 * Factory method which can be overriden by subclasses
197,198c165,166
< 		public void mouseMoved(MouseEvent e) {
< 			tool().mouseMove(e, e.getX(), e.getY());
---
> 	protected Painter createDisplayUpdate() {
> 		return new SimpleUpdateStrategy();
200d167
< 	};
227c194
< 		if (fDrawing != null) {
---
> 		if (drawing() != null) {
229c196
< 			fDrawing.removeDrawingChangeListener(this);
---
> 			drawing().removeDrawingChangeListener(this);
233,234c200,201
< 		if (fDrawing != null) {
< 			fDrawing.addDrawingChangeListener(this);
---
> 		if (drawing() != null) {
> 			drawing().addDrawingChangeListener(this);
290c257
< 	 * Inserts a vector of figures and translates them by the
---
>      * Inserts a FigureEnumeration of figures and translates them by the
620c587
< 		// constrin to view size
---
> 		// constrain to view size
633,686d599
< 	/**
< 	 * Handles key down events. Cursor keys are handled
< 	 * by the view the other key events are delegated to the
< 	 * currently active tool.
< 	 * @return whether the event was handled.
< 	 */
< 	public void keyPressed(KeyEvent e) {
< 		int code = e.getKeyCode();
< 		if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_DELETE)) {
< 			Command cmd = new DeleteCommand("Delete", editor());
< //			cmd.viewSelectionChanged(this);
< 			if(cmd.isExecutable()) {
< 				cmd.execute();
< 			}
< 		}
< 		else if (code == KeyEvent.VK_DOWN || code == KeyEvent.VK_UP ||
< 			code == KeyEvent.VK_RIGHT || code == KeyEvent.VK_LEFT) {
< 			handleCursorKey(code);
< 		}
< 		else {
< 			tool().keyDown(e, code);
< 		}
< 		checkDamage();
< 	}
< 
< 	/**
< 	 * Handles cursor keys by moving all the selected figures
< 	 * one grid point in the cursor direction.
< 	 */
< 	protected void handleCursorKey(int key) {
< 		int dx = 0, dy = 0;
< 		int stepX = 1, stepY = 1;
< 		// should consider Null Object.
< 		if (fConstrainer != null) {
< 			stepX = fConstrainer.getStepX();
< 			stepY = fConstrainer.getStepY();
< 		}
< 
< 		switch (key) {
< 		case KeyEvent.VK_DOWN:
< 			dy = stepY;
< 			break;
< 		case KeyEvent.VK_UP:
< 			dy = -stepY;
< 			break;
< 		case KeyEvent.VK_RIGHT:
< 			dx = stepX;
< 			break;
< 		case KeyEvent.VK_LEFT:
< 			dx = -stepX;
< 			break;
< 		}
< 		moveSelection(dx, dy);
< 	}
747c660
< 		if (fBackgrounds != null && !isPrinting) {
---
> 		if ((fBackgrounds != null) && !isPrinting) {
751c664
< 		if (fForegrounds != null && !isPrinting) {
---
> 		if ((fForegrounds != null) && !isPrinting) {
768c681
< 		if (fBackgrounds != null && !isPrinting) {
---
> 		if ((fBackgrounds != null) && !isPrinting) {
771,772c684,685
< 		fDrawing.draw(g, fe);
< 		if (fForegrounds != null && !isPrinting) {
---
> 		drawing().draw(g, fe);
> 		if ((fForegrounds != null) && !isPrinting) {
794c707
< 		fDrawing.draw(g);
---
> 		drawing().draw(g);
877,878c790,791
< 		if (fDrawing != null) {
< 			fDrawing.addDrawingChangeListener(this);
---
> 		if (drawing() != null) {
> 			drawing().addDrawingChangeListener(this);
959a873,985
> 
> 	public class DrawingViewMouseListener extends MouseAdapter {
> 		 /**
> 		 * Handles mouse down events. The event is delegated to the
> 		 * currently active tool.
> 		 * @return whether the event was handled.
> 		 */
> 		public void mousePressed(MouseEvent e) {
> 			requestFocus(); // JDK1.1
> 			Point p = constrainPoint(new Point(e.getX(), e.getY()));
> 			fLastClick = new Point(e.getX(), e.getY());
> 			tool().mouseDown(e, p.x, p.y);
> 			checkDamage();
> 		}
> 
> 		/**
> 		 * Handles mouse up events. The event is delegated to the
> 		 * currently active tool.
> 		 * @return whether the event was handled.
> 		 */
> 		public void mouseReleased(MouseEvent e) {
> 			Point p = constrainPoint(new Point(e.getX(), e.getY()));
> 			tool().mouseUp(e, p.x, p.y);
> 			checkDamage();
> 		}
> 	}
> 
> 	public class DrawingViewMouseMotionListener implements MouseMotionListener {
> 		/**
> 		 * Handles mouse drag events. The event is delegated to the
> 		 * currently active tool.
> 		 * @return whether the event was handled.
> 		 */
> 		public void mouseDragged(MouseEvent e) {
> 			Point p = constrainPoint(new Point(e.getX(), e.getY()));
> 			tool().mouseDrag(e, p.x, p.y);
> 			checkDamage();
> 		}
> 
> 		/**
> 		 * Handles mouse move events. The event is delegated to the
> 		 * currently active tool.
> 		 * @return whether the event was handled.
> 		 */
> 		public void mouseMoved(MouseEvent e) {
> 			tool().mouseMove(e, e.getX(), e.getY());
> 		}
> 	}
> 
> 	public class DrawingViewKeyListener implements KeyListener {
> 		/**
> 		 * Handles key down events. Cursor keys are handled
> 		 * by the view the other key events are delegated to the
> 		 * currently active tool.
> 		 * @return whether the event was handled.
> 		 */
> 		public void keyPressed(KeyEvent e) {
> 			int code = e.getKeyCode();
> 			if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_DELETE)) {
> 				Command cmd = new DeleteCommand("Delete", editor());
> 				if (cmd.isExecutable()) {
> 					cmd.execute();
> //					cmd.viewSelectionChanged(this);
> 				}
> 			}
> 			else if ((code == KeyEvent.VK_DOWN) || (code == KeyEvent.VK_UP)
> 					|| (code == KeyEvent.VK_RIGHT) || (code == KeyEvent.VK_LEFT)) {
> 				handleCursorKey(code);
> 			}
> 			else {
> 				tool().keyDown(e, code);
> 			}
> 			checkDamage();
> 		}
> 
> 		/**
> 		 * Handles cursor keys by moving all the selected figures
> 		 * one grid point in the cursor direction.
> 		 */
> 		protected void handleCursorKey(int key) {
> 			int dx = 0, dy = 0;
> 			int stepX = 1, stepY = 1;
> 			// should consider Null Object.
> 			if (fConstrainer != null) {
> 				stepX = fConstrainer.getStepX();
> 				stepY = fConstrainer.getStepY();
> 			}
> 
> 			switch (key) {
> 			case KeyEvent.VK_DOWN:
> 				dy = stepY;
> 				break;
> 			case KeyEvent.VK_UP:
> 				dy = -stepY;
> 				break;
> 			case KeyEvent.VK_RIGHT:
> 				dx = stepX;
> 				break;
> 			case KeyEvent.VK_LEFT:
> 				dx = -stepX;
> 				break;
> 			}
> 			moveSelection(dx, dy);
> 		}
> 
>         public void keyTyped(KeyEvent event) {
>             // do nothing
>         }
> 
>         public void keyReleased(KeyEvent event) {
>             // do nothing
>         }
>     }
