Package chunmap.app

Source Code of chunmap.app.MapCtrlImpl

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.app;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;

import chunmap.app.bench.Command;
import chunmap.app.bench.OperateManager;
import chunmap.app.bench.Tool;
import chunmap.util.CMEventListenerList;
import chunmap.util.Function;
import chunmap.view.Map;
import chunmap.view.View;
import chunmap.view.layer.LayerCollection;
/**
* combine all together
* @author yangjiandong
*
*/
public class MapCtrlImpl implements MapCtrl{
 
  private Map map;
  private Image bufferImage;
  //private RenderThread thread;
  private OperateManager operateManager;
  private Component component;
 
  public CMEventListenerList listeners=new CMEventListenerList();

  public MapCtrlImpl(Component component) {
    super();
    this.component=component;
    init(component.getWidth(), component.getHeight());
    operateManager=new OperateManager(this,component);
  }
 
  private void init(int width, int height) {
   
    map = new Map(width, height);
    bufferImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   
//    thread = new RenderThread();
//    thread.addListener(new RenderListener() {
//      @Override
//      public void renderFinished() {
//        makeBuffer();
//      }
//    });
  }

  private void makeBuffer() {
    Image nimage = (Image)map.getPainter().getData();
    bufferImage.getGraphics().drawImage(nimage, 0, 0, null);
    bufferImage.flush();
    component.repaint();
  }

 

  @Override
  public void refreshMap() {
    //thread.startRender(map);
    map.render();
    makeBuffer();
  }

  @Override
  public Image getBufferImage() {
    return bufferImage;
  }
 
  //---------------------------------------------------------代理

  @Override
  public LayerCollection getLayerCollection() {
    return map.getLayerCollection();
  }

  @Override
  public View getView() {
    return map.getView();
  }

  @Override
  public void fullView() {
    map.fullView();
  }

  @Override
  public void executeCommand(Command cmd) {
    operateManager.executeCommand(cmd);   
  }

  @Override
  public void addPlug(Tool plug) {
    operateManager.addPlug(plug)
  }

  @Override
  public Tool getPlug(String id) {
    return operateManager.getPlug(id);
  }

  @Override
  public void redo() {
    operateManager.redo();   
  }

  @Override
  public void undo() {
    operateManager.undo();   
  }

  @Override
  public boolean imageUpdate(Image img, int infoflags, int x, int y,
      int w, int h) {
    return component.imageUpdate(img, infoflags, x, y, w, h);
  }

  @Override
  public Graphics getGraphics(){
    return component.getGraphics();
  }

  @Override
  public void setCurrentPlug(Tool plug) {
    operateManager.setCurrentPlug(plug);
  }

  @Override
  public Image getOriginImage() {
    return (Image)map.getPainter().getData();
  }

  @Override
  public Graphics getBufferGraphics() {
    return bufferImage.getGraphics();
  }

  @Override
  public void resetSize(int width, int height) {
    map.resetSize(width, height);
        init(width, height);
  }

  @Override
  public void addListener(Function func) {
    listeners.add(func);
  }

}
TOP

Related Classes of chunmap.app.MapCtrlImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.