📄 mapview.java
字号:
package mapcenter.maptools;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import mapcenter.service.*;
import mapcenter.weihu.*;
public class MapView extends JComponent implements MouseListener, MouseMotionListener {
private Log log = LogFactory.getLog("WebGIS");
private HashMap mapTools = new HashMap();
private MapTool currTool = null;
private MapHandle mapHandle = null;
private Image buffimg = null;
private JFrame container = null;
private boolean initFlag = false;
public void init() throws Exception{
//this.setBackground(Color.white);
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.buffimg = this.createImage(this.getWidth(), this.getHeight());
this.initFlag = true;
}
public void renderMap()throws Exception{
Image image = mapHandle.render();
int marginH = (image.getWidth(null) - this.getWidth())/2;
int marginV = (image.getHeight(null) - this.getHeight())/2;
this.getGraphics().drawImage(image, -marginH, -marginV, null);
}
public void setMapHandle(MapHandle mapHandle){
this.mapHandle = mapHandle;
}
public MapHandle getMapHandle(){
return mapHandle;
}
public void setContainer(JFrame frame){
this.container = frame;
}
public JFrame getContainer(){
return this.container;
}
public Image getBuffImg(){
return buffimg;
}
public boolean isInited(){
return initFlag;
}
public void setCurrentTool(String toolName)throws Exception{
Object[] keys = mapTools.keySet().toArray();
for(int i=0; i<keys.length; i++){
MapTool mapTool = (MapTool)mapTools.get(keys[i]);
mapTool.putValue(mapTool.SMALL_ICON,mapTool.originalIcon);
}
MapTool mapTool = (MapTool)mapTools.get(toolName);
if(mapTool == null)throw new Exception("HashMap Key no find:"+toolName);
mapTool.putValue(mapTool.SMALL_ICON,mapTool.selectedIcon);
this.setCursor(mapTool.cursor);
this.currTool = mapTool;
}
public void setToolBar(MapToolBar toolbar){
ArrayList tools = toolbar.getAllTool();
int toolCount = tools.size();
for(int i=0; i<toolCount; i++){
MapTool mapTool = (MapTool)tools.get(i);
String toolName = (String)mapTool.getValue(mapTool.NAME);
mapTools.put(toolName,mapTool);
}
}
public void paint(Graphics g){
try{
//log.debug("mapview paint........");
if(isInited() == true){
Image image = mapHandle.render();
int marginH = (image.getWidth(null) - this.getWidth())/2;
int marginV = (image.getHeight(null) - this.getHeight())/2;
g.drawImage(image, -marginH, -marginV, null);
//if(currTool != null)currTool.paintOnMap(g);
}
}catch(Exception e){log.error(e);}
}
//============= MouseListener接口实现 =============
public void mouseEntered(MouseEvent evt) {
try{
if(currTool != null)currTool.mouseEntered(new MapMouse(evt));
}catch(Exception e){log.error(e);}
}
public void mouseExited(MouseEvent evt) {
try{
if(currTool != null)currTool.mouseExited(new MapMouse(evt));
}catch(Exception e){log.error(e);}
}
public void mousePressed(MouseEvent evt) {
try{
if(currTool != null)currTool.mousePressed(new MapMouse(evt));
}catch(Exception e){log.error(e);}
}
public void mouseReleased(MouseEvent evt) {
try{
if(currTool != null)currTool.mouseReleased(new MapMouse(evt));
}catch(Exception e){log.error(e);}
}
public void mouseDragged(MouseEvent evt) {
try{
if(currTool != null)currTool.mouseDragged(new MapMouse(evt));
}catch(Exception e){log.error(e);}
}
public void mouseMoved(MouseEvent evt) {
try{
if(currTool != null)currTool.mouseMoved(new MapMouse(evt));
}catch(Exception e){log.error(e);}
}
public void mouseClicked(MouseEvent evt) {
try{
if(currTool != null)currTool.mouseClicked(new MapMouse(evt));
}catch(Exception e){log.error(e);}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -