@Override
 public void setMap(Map map) {
   this.map = map;
   setPreferredSize(map.getSize()); // Don't remove it.
   setSize(map.getSize()); // Don't remove it. use to SnapshotPanel
   map.addUndoableEditListener(undoManager);
   mapBounds = new Rectangle();
   mapBounds.setSize(map.getLogicalSize());
 }
 @Override
 public Point screenToMap(Point mousePoint) {
   Point p = new Point();
   p.x = mousePoint.x - bounds.x;
   p.y = mousePoint.y - bounds.y;
   return map.screenToMap(p);
 }
 @Override
 public Point mapToScreen(Point mapPoint) {
   Point p = map.mapToScreen(mapPoint);
   p.x += bounds.x;
   p.y += bounds.y;
   return p;
 }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof EditorView) || (!obj.getClass().equals(this.getClass()))) {
      return false;
    }

    AbstractEditorView other = (AbstractEditorView) obj;
    return map.equals(other.map);
  }
  protected void updateBounds() {
    Dimension mapSize = map.getSize();
    Dimension panelSize = getSize();

    bounds.x = (mapSize.width >= panelSize.width) ? 0 : (panelSize.width - mapSize.width) / 2;
    ;
    bounds.y = (mapSize.height >= panelSize.height) ? 0 : (panelSize.height - mapSize.height) / 2;

    bounds.width = mapSize.width;
    bounds.height = mapSize.height;

    repaint();
  }
  public AbstractEditorView(Map map) {
    setMap(map);

    selection = new EditorSelection();
    bounds = new Rectangle();
    Dimension d = map.getSize();
    bounds.width = d.width;
    bounds.height = d.height;

    initBufferImage();
    addComponentListener(resizeListener);

    //		setDoubleBuffered(true);
  }
 protected void drawCoordinate(Graphics2D g) {
   g.setColor(new Color(0, 0, 0)); // XXX read from preference file.
   map.drawCoordinate(0, 0, mapBounds, g);
 }
 protected void drawGrid(Graphics2D g) {
   g.setColor(new Color(0, 255, 255, 90)); // XXX read from preference file.
   map.drawGrid(0, 0, mapBounds, g);
 }
 protected void drawMap(Graphics2D g) {
   map.draw(0, 0, mapBounds, g);
 }
 private BufferedImage createImage() {
   Dimension d = map.getSize();
   return new BufferedImage(d.width + 1, d.height + 1, BufferedImage.TYPE_4BYTE_ABGR);
 }