📄 viewer.java
字号:
* no upper bound.
* this is probably deprecated, and will be removed in the near future
* @params zoomFactor A positive value means zoom out. A negative value
* means zoom in
* @author Mathieu van Loon
*/
public void setMapExtentByFactor(double zoomFactor) {
if(themeCount > 0 && zoomFactor != 1) {
GeoRectangle currentMap = scale.getMapExtent();
double newX, newY, newWidth, newHeight;
double tmp;
tmp = (currentMap.height*zoomFactor) - currentMap.height;
newHeight = currentMap.height+tmp;
newY = currentMap.y - (tmp/2);
tmp = (currentMap.width*zoomFactor) - currentMap.width;
newWidth = currentMap.width+tmp;
newX = currentMap.x - (tmp/2);
if(zoomFactor < 1 || fullMapExtent.contains(newX, newY, newWidth, newHeight)) {
scale.setMapExtent(new GeoRectangle(newX, newY, newWidth, newHeight));
} else {
scale.setMapExtent(fullMapExtent);
}
}
}
/**
* specify an absolute scaleFactor. This method is likely to changed
* in the near future.
* @author Mathieu van Loon
*/
public void setMapExtentByValue(double scaleFactor) {
if(themeCount > 0) {
setMapExtentByFactor(scaleFactor/scale.getScaleFactor());
}
}
/**
* Set the map extent to fit all selected features
* @since 0.6.5
*/
public void setMapExtentSelected(){
if(themeCount >0){
GeoRectangle r = getSelectionMapExtent();
if(r.getBounds().width>0){
scale.setMapExtent(r);
}
}
}
/**
* Set the scaler used to scale the map to and from the screen<p>
* probably not a good idea to use this unless you know what you are doing.<p>
* the setMapExtent is probaly what you are after
*/
public void setScale(Scaler scale_) {
scale.removeScaleChangedListener(this);
this.scale = scale_;
scale.addScaleChangedListener(this);
}
public void setProjection(Projection proj) {
scale.setProjection(proj);
}
/**
* Gets the scaler that is being used to transform the map to and from the screen
*/
public Scaler getScale() {
return this.scale;
}
/**
* Navigation tool methods
* @deprecated see the new NavigateTool object for details
*/
public void setNavigationBounds(GeoRectangle b){
if(tool instanceof NavigateTool){
((NavigateTool)tool).setNavigationBounds(b);
}
}
/**
* Navigation tool methods
* @deprecated see the new NavigateTool object for details
*/
public GeoRectangle getNavigationBounds(){
if(tool instanceof NavigateTool){
return ((NavigateTool)tool).getNavigationBounds();
}
return null;
}
/**
* Navigation tool methods
* @deprecated see the new NavigateTool object for details
*/
public void setNavigationTarget(Viewer v){
if(tool instanceof NavigateTool){
if(debug)System.out.println("V--->Setting nav target in nav tool");
((NavigateTool)tool).setTarget(v);
}
}
/**
* set which tool mode we are using
* @deprecated use setTool instead
*/
public void setToolMode(int mode){
switch(mode){
case(SELECT):
setTool(new SelectTool());
break;
case(ZOOM):
setTool(new ZoomTool());
break;
case(PAN):
setTool(new PanTool());
break;
case(NAVIGATE):
setTool(new NavigateTool());
break;
}
}
/**
* Sets the active tool for this viewer.<br>
* Call this method to change the tool for this viewer, tools available by default include
* ZoomTool,PanTool and SelectTool.
* <br> an example call would be<p>
* view.setTool(new ZoomTool());
*
* @author James Macgill JM
* @since 0.7.7.2 June 6 2000
* @param t The new tool to use.
*/
public void setTool(Tool t){
tool =t;
tool.setContext(this);
setCursor(tool.getCursor());
}
/**
* Returns the active tool being used by this viewer.
*/
public Tool getTool() {
return tool;
}
public void update(Graphics g){
paint(g);
}
public Vector getThemes(){
ThemeStack.ThemeInfo[] infos = themeStack.getOrderedThemeInfos();
Vector v = new Vector();
for(int i=0;i<infos.length;i++){
v.addElement(infos[i].getTheme());
}
return v;
}
/**
* Set a Theme to be visable or not, this will trigger a repaint.
* @param index the index of the theme that this command is refering to
* @param flag if true then set the theme visible
*/
public void setThemeIsVisible(int index,boolean flag){
themeStack.setIsVisible(themeStack.getThemeByWaight(index),flag);
}
public boolean isThemeVisible(Theme t){
return themeStack.isVisible(t);
}
/**
* Set a Theme to be visable or not, this will trigger a repaint.
* @param theme the theme that this command is refering to
* @param flag if true then set the theme visible
*/
public void setThemeIsVisible(Theme theme,boolean flag){
setThemeIsVisible(theme,flag,true);
}
/**
* Set a Theme to be visable or not.
* @param theme the theme that this command is refering to
* @param flag if true then set the theme visible
* @param update if true then trigger a repaint
*/
public void setThemeIsVisible(Theme theme,boolean flag,boolean update){
if(theme==null || !staticThemes.contains(theme)){
return;
}
/* if(flag && !visibleThemes.contains(theme)){
if(debug)System.out.println(theme+" added to vis");
visibleThemes.addElement(theme);
}
if(!flag && visibleThemes.contains(theme)){
if(debug)System.out.println(theme+" removed from vis");
visibleThemes.removeElement(theme);
}*/
themeStack.setIsVisible(theme,flag);
if(update){
updateStaticBuffer();
repaint();
notifyCompositionChanged(CompositionChangedEvent.VISIBILITY);
}
}
public Image getScreenBuffer(){
return screenBuffer;
}
/**
* Get the current mouse information.
* Covers information on the mouse pointers position in screen, geographic and projected space
* as well as the latest drag information in all three
* @return MouseStatus the current status of the mouse pointer and drag regions
*/
public MouseStatus getMouseStatus(){
return mouseStatus;
}
/**
* returns the real world values for the current
* x,y location of the mouse
*/
public double[] getMapPoint(){
return mouseStatus.map_xy;
}
/**
* return the geographical bounds of the viewer
*/
public GeoRectangle getFullMapExtent() {
return fullMapExtent;
}
/**
* returns the projected coordinate value for the current
* x,y location of the mouse
*/
public double[] getProjPoint(){
return mouseStatus.proj_xy;
}
/**
* returns the real world values for the current
* x,y location of the mouse as a GeoPoint
*/
public GeoPoint getMapGeoPoint(){
return mouseStatus.getMapPoint();
}
/**
* an internal convinence method, this simple returns a graphics object for this viewer
* preset to XORMode.
* @return Graphics a Graphics object for use by the update method in Tools.
*/
public Graphics getToolGraphics(){
toolGraphics = this.getGraphics();
toolGraphics.setXORMode(Color.blue);
return toolGraphics;
}
public void paint(java.awt.Graphics g) {
if(debug)System.out.println("V--->Painting!");
if(this.getBounds().width <=0){if(debug)System.out.println("V--->Viewer of zero Size");return;}
if(themeCount>0 && !lastSize.equals(this.getBounds())){
if(debug)System.out.println("V--->"+name+"Hey!, who changed my size!");
if(debug)System.out.println("V--->"+name+"Last "+lastSize);
if(debug)System.out.println("V--->"+name+"New "+getBounds());
Rectangle oldSize = new Rectangle(lastSize);
setupScale();
// EXPERIMENTAL CODE
// if the new & the old size have the same width & height
// there might be no reason to flush all the buffers.
if(oldSize.width!=getBounds().width || oldSize.height!=getBounds().height) {
screenBuffer=null;
panBuffer=null;
selectionBuffer=null;
if(staticBuffer!=null){
staticBuffer=null;
}
// moved by ian so rendering off screen will work
updateStaticBuffer();
if(sequenceTheme!=null){
createSequenceBuffer(sequenceTheme.length);
}
}
}
//Go through each of the themes, add them to the buffer and then plot the buffer
if(screenBuffer == null){
screenBuffer = this.createImage(getBounds().width,getBounds().height);
}
if(screenBuffer ==null)return;
if(debug)System.out.println("V--> screenBuffer "+screenBuffer);
Graphics sg = screenBuffer.getGraphics();
if(debug)System.out.println("V--> staticBuffer "+staticBuffer);
if(staticBuffer != null){
if(selectionChanged){
if(debug){System.out.println("V--->Call selections? ");}
updateSelectionBuffer();
}
if(selectionBuffer != null){
sg.drawImage(selectionBuffer,0,0,this);
}
}
//add sequeceBuffer frame x
//try{
if(sequenceBuffer!=null && sequenceBuffer[frame]!=null){
if(!sequenceFrameValid[frame]){updateSequenceBuffer(frame);}
sg.drawImage(sequenceBuffer[frame],0,0,this);
}
//sequenceTheme[frame].paintHighlight(sg,scale);//experiment
//}catch(Exception e){}
//add selections to the static buffer?
//paintSelections(sg);
paintHighlights(sg);
//add animation on top
if(animationTheme != null)
animationTheme.paintScaled(sg,scale);
//finaly add any tool related things
if(showTips && mouseStatus.isMouseStill() && mouseStatus.isPointerInside()){
String tip ="";
Enumeration e = visibleThemes.elements();
while(e.hasMoreElements()){
Theme theme = (Theme)e.nextElement();
if(isThemeVisible(theme)){
String tempTip = (theme).getTipText(getMapGeoPoint(),this.scale);
if(tempTip !=null && !tempTip.trim().equals("")){
tip = tempTip;
}
}
}
if(animationTheme !=null){
String tempTip = (animationTheme.getTipText(getMapGeoPoint(),this.scale));
if (tempTip !=null && !tempTip.trim().equals("")){
tip = tempTip;
}
}
if(!tip.trim().equals("")){paintTip(sg,tip);}
}
tool.paint(sg);
//now we can plot to screen
if(debug){System.out.println("V--->Plot to the screen");}
g.drawImage(screenBuffer,0,0,this);
}
/**
* A quick method to handle the effect of a themes contemts changing
* unfinished !!!
*/
public void themeChanged(ThemeChangedEvent tce){
if(debug)System.out.println("V--->"+name+"Update for reason code "+tce.getReason());
if(tce.getReason()==tce.GEOGRAPHY){
if(debug)System.out.println("V--->"+name+"Adding a theme to Bounds\n"+fullMapExtent);
if(fullMapExtent.height==0 || fullMapExtent.width==0){
fullMapExtent.add(((Theme)tce.getSource()).getBounds());
this.setMapExtentFull();
}
else{
fullMapExtent.add(((Theme)tce.getSource()).getBounds());
}
if(debug)System.out.println("V--->"+name+"Added a theme to Bounds\n"+fullMapExtent);
updateStaticBuffer();
}
//scale.setMapExtent(
if(tce.getReason()==tce.DATA || tce.getReason()==tce.SHADE){
updateStaticBuffer();
}
if(tce.getReason()==tce.SELECTION){
selectionChanged=true;
}
if(tce.getReason()==tce.ANIMATION){
// System.out.println("Animation Frame");
}
repaint();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -