📄 mapviewui.java
字号:
* Erase old points if (null != oldCursors) { repaint(oldCursors[0] -
* cursorSize, oldCursors[1] - cursorSize, 2 cursorSize, 2 cursorSize); } //
* Paint new points repaint(cursors[0] - cursorSize, cursors[1] -
* cursorSize, 2 cursorSize, 2 cursorSize); }
*
* private void setEndPoint() { int[] cursors = {getCursorX(),
* getCursorY()}; int[] oldCursors = transformFromReal(endPoint); endPoint =
* transformFromView(cursors); endPointSelected = true; if (null !=
* oldCursors) { repaint(oldCursors[0] - cursorSize, oldCursors[1] -
* cursorSize, 2 cursorSize, 2 cursorSize); } repaint(cursors[0] -
* cursorSize, cursors[1] - cursorSize, 2 cursorSize, 2 cursorSize); }
*/
private static String floatToString(Float f, int num) {
String floatValue = f.toString();
if (floatValue.indexOf('.') >= 0
&& (floatValue.indexOf('.') + num + 1 < floatValue.length())) {
return floatValue.substring(0, floatValue.indexOf('.') + num + 1);
} else {
return floatValue;
}
}
public void paint(Graphics g) {
int oldColor = g.getColor();
// Clear screen
g.setColor(0xFFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(oldColor);
if (null != wmsImg) {
// System.out.println("************ Current scale: " +
// getCurrentScale());
// System.out.println("****** Cursor (x, y) = (" + cursorX + ", " +
// cursorY + ")");
if (isDragging) {
g.drawImage(wmsImg, pointerEndX - pointerStartX, pointerEndY
- pointerStartY, Graphics.TOP | Graphics.LEFT);
} else {
g.drawImage(wmsImg, 0, 0, Graphics.TOP | Graphics.LEFT);
}
g.setFont(smallFont);
g.setColor(0x0000FF);
g.drawString("1/" + floatToString(getCurrentScale(), 3), 0,
getHeight(), Graphics.BOTTOM | Graphics.LEFT);
int[] cursors = { getCursorX(), getCursorY() };
Float[] real = transformFromView(cursors);
g.drawString("lat:" + floatToString(real[1], 3) + " lon:"
+ floatToString(real[0], 3), getWidth(), getHeight(),
Graphics.BOTTOM + Graphics.RIGHT);
// Reset to default Font and color
g.setFont(Font.getDefaultFont());
g.setColor(oldColor);
/*
* // Draw startpoint, end point if (startPointSelected) {
* g.setColor(0x00FF00); int[] startCursor =
* transformFromReal(getStartPoint()); g.fillArc(startCursor[0] -
* cursorSize / 2, startCursor[1] - cursorSize / 2, cursorSize,
* cursorSize, 0, 360); g.setColor(oldColor); } if
* (endPointSelected) { g.setColor(0xFF0000); int[] endCursor =
* transformFromReal(getEndPoint()); g.fillArc(endCursor[0] -
* cursorSize / 2, endCursor[1] - cursorSize / 2, cursorSize,
* cursorSize, 0, 360); g.setColor(oldColor); }
*/
// Draw my location
if (isLocated && isInside(myLocation, boundingBox)) {
g.setColor(0xFF0000);
g.setStrokeStyle(Graphics.DOTTED);
int[] myLocationPoint = transformFromReal(myLocation);
g.fillArc(myLocationPoint[0] - cursorSize, myLocationPoint[1]
- cursorSize, cursorSize * 2, cursorSize * 2, 0, 360);
g.setColor(oldColor);
g.setStrokeStyle(Graphics.SOLID);
}
g.setColor(0x0000FF);
g.drawChar('+', cursorX, cursorY + (cursorSize / 2),
Graphics.BASELINE | Graphics.HCENTER);
g.setColor(oldColor);
} else {
uiController.getMapRequested();
}
}
public void pointerDragged(int x, int y) {
cursorX = x;
cursorY = y;
if (isDragging) {
pointerEndX = x;
pointerEndY = y;
} else {
isDragging = true;
pointerStartX = x;
pointerStartY = y;
}
repaint();
}
public void pointerReleased(int x, int y) {
cursorX = x;
cursorY = y;
if (isDragging) {
pointerEndX = x;
pointerEndY = y;
int intDx = pointerEndX - pointerStartX;
int intDy = pointerEndY - pointerStartY;
// if distance is more than 1 pixel, then update map
if (Math.abs(intDx) > 0 || Math.abs(intDy) > 0) {
previousAction = NO_ACTION;
int[] pointersStart = { pointerStartX, pointerStartY };
int[] pointersEnd = { pointerEndX, pointerEndY };
Float[] pointersStartReal = transformFromView(pointersStart);
Float[] pointersEndReal = transformFromView(pointersEnd);
Float dx = pointersEndReal[0].Sub(pointersStartReal[0]);
Float dy = pointersEndReal[1].Sub(pointersStartReal[1]);
// update bouding box
boundingBox[0] = boundingBox[0].Sub(dx);
boundingBox[1] = boundingBox[1].Sub(dy);
boundingBox[2] = boundingBox[2].Sub(dx);
boundingBox[3] = boundingBox[3].Sub(dy);
/*
* if (isViewPath) { uiController.viewPathRequested(); } else {
*/
uiController.updateMapRequested();
// }
} else {
// if distance is less than 1, then consider pointer press
pointerPressed(x, y);
}
}
isDragging = false;
}
public void pointerPressed(int x, int y) {
int oldCursorX = cursorX;
int oldCursorY = cursorY;
isDragging = false;
cursorX = x;
cursorY = y;
// repaintCursor(oldCursorX, oldCursorY);
// repaintCursor();
repaint();
}
public void keyPressed(int keyCode) {
switch (keyCode) {
case KEY_NUM2:
moveUp();
/*
* if (isViewPath) { uiController.viewPathRequested(); } else {
*/
uiController.updateMapRequested();
// }
break;
case KEY_NUM8:
moveDown();
// if (isViewPath) {
// uiController.viewPathRequested();
// } else {
uiController.updateMapRequested();
// }
break;
case KEY_NUM4:
moveLeft();
// if (isViewPath) {
// uiController.viewPathRequested();
// } else {
uiController.updateMapRequested();
// }
break;
case KEY_NUM6:
moveRight();
// if (isViewPath) {
// uiController.viewPathRequested();
// } else {
uiController.updateMapRequested();
// }
break;
/*
* case KEY_NUM1: // isViewPath = false; setStartPoint(); break; case
* KEY_NUM3: // isViewPath = false; setEndPoint(); break;
*/
case KEY_NUM5:
uiController.selectInfoLayerRequested();
break;
default:
int action = getGameAction(keyCode);
switch (action) {
case LEFT:
moveCursorLeft();
break;
case RIGHT:
moveCursorRight();
break;
case UP:
moveCursorUp();
break;
case DOWN:
moveCursorDown();
break;
default:
break;
}
break;
}
}
protected void keyRepeated(int keyCode) {
keyPressed(keyCode);
}
public void commandAction(Command command, Displayable displayable) {
if (command == refreshCommand) {
// if (isViewPath) {
// uiController.viewPathRequested();
// } else {
uiController.updateMapRequested();
// }
} else if (command == zoomInCommand) {
zoomIn();
// if (isViewPath) {
// uiController.viewPathRequested();
// } else {
uiController.updateMapRequested();
// }
} else if (command == zoomOutCommand) {
zoomOut();
// if (isViewPath) {
// uiController.viewPathRequested();
// } else {
uiController.updateMapRequested();
// }
} else if (command == resetCommand) {
// isViewPath = false;
uiController.getMapRequested();
} else if (command == recenterCommand) {
previousAction = NO_ACTION;
int[] cursors = { getCursorX(), getCursorY() };
reCenter(cursors);
// if (isViewPath) {
// uiController.viewPathRequested();
// } else {
uiController.updateMapRequested();
// }
} else if (command == backCommand) {
// isViewPath = false;
isViewFeature = false;
// uiController.layerListRequested();
uiController.backToSortLayerListUI();
} /*
* else if (command == findPathCommand) { isViewPath = false;
* isViewFeature = false; uiController.findPathRequested(); }
*/
else if (command == whereAmICommand) {
isLocated = false;
uiController.lbsInfoRequested();
} else if (command == getFeatureInfoCommand) {
uiController.selectInfoLayerRequested();
} else if (command == searchFeatureCommand) {
if (isViewFeature) {
uiController.searchResultUIRequested();
} else {
isViewFeature = false;
uiController.searchUIRequested();
}
} else if (command == saveToFileCommand) {
uiController.browseFileSystemRequested();
} else if (command == helpCommand) {
uiController.helpRequested();
} else {
// isViewPath = false;
isViewFeature = false;
uiController.commandAction(command, displayable);
}
}
private Float getBoxWidth() {
return Float.abs(boundingBox[2].Sub(boundingBox[0]));
}
private Float getBoxHeight() {
return Float.abs(boundingBox[3].Sub(boundingBox[1]));
}
/**
* @return Returns the cursorX.
* @uml.property name="cursorX"
*/
private int getCursorX() {
return cursorX;
}
/**
* @return Returns the cursorY.
* @uml.property name="cursorY"
*/
private int getCursorY() {
return cursorY;
}
// Get X, Y in pixel for GetFeatureInfo
public int getX() {
return getCursorX();
}
public int getY() {
return (getHeight() - getCursorY());
}
/**
* @return Returns the startPoint.
* @uml.property name="startPoint"
*/
/*
* public Float[] getStartPoint() { if (!startPointSelected) return null;
* return startPoint; }
*/
/**
* @return Returns the endPoint.
* @uml.property name="endPoint"
*/
/*
* public Float[] getEndPoint() { if (!endPointSelected) return null; return
* endPoint; }
*/
/*
* public String getFindPathLayer() { try { return
* (uiController.getModel().getPreferences().getFindPathLayer()); } catch
* (ApplicationException e) { e.printStackTrace(); return ""; } }
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -