/**
* 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.bench;
import java.awt.AWTEvent;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import chunmap.app.MapCtrl;
import chunmap.app.tools.navigate.PanTool;
import chunmap.app.tools.navigate.ZoomTool;
/**
* 插件管理容器
* @author chunquedong
*
*/
public class OperateManager{
private final List<Tool> plugs;
private Tool currentPlug;
private MapCtrl mapBox;
private CommandStack commandManager;
public OperateManager(MapCtrl mapBox,Component component) {
plugs = new ArrayList<Tool>();
this.mapBox = mapBox;
commandManager=new CommandStack();
addPlug(new PanTool());
addPlug(new ZoomTool());
ComponentUtils.bindEvent(this, component);
}
//--------------------------------------------------------管理命令
public void executeCommand(Command cmd){
commandManager.execute(cmd);
}
public void undo(){commandManager.undo();}
public void redo(){commandManager.redo();}
//--------------------------------------------------------管理插件
public void setAllInactive() {
for (Tool p : plugs) {
p.setActive(false);
}
}
public void onEvent(AWTEvent event, EventType type) {
for (Tool p : plugs) {
if(p.isActive()){
if(!p.actionEvent(event, type))return;
}
}
if(currentPlug!=null){
currentPlug.actionEvent(event, type);
}
}
public void addPlug(Tool p) {
plugs.add(p);
p.onAdd(mapBox);
}
public void remove(Tool p) {
plugs.remove(p);
p.onRemove();
}
public Tool getPlug(String id) {
for (Tool p : plugs) {
if (p.getId() == id) {
return p;
}
}
return null;
}
public Tool getCurrentPlug() {
return currentPlug;
}
public void setCurrentPlug(Tool currentPlug) {
this.currentPlug = currentPlug;
currentPlug.onAdd(mapBox);
}
}