Changeset 10968 in josm for trunk/src/org
- Timestamp:
- 2016-09-06T23:50:40+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapViewState.java
r10910 r10968 23 23 import org.openstreetmap.josm.data.projection.Projection; 24 24 import org.openstreetmap.josm.gui.download.DownloadDialog; 25 import org.openstreetmap.josm.tools.CheckParameterUtil; 25 26 import org.openstreetmap.josm.tools.bugreport.BugReport; 26 27 … … 80 81 * @param scale The scale to use 81 82 * @param topLeft The top left corner in east/north space. 82 */ 83 private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft) { 83 * @param topLeftInWindow The top left point in window 84 * @param topLeftOnScreen The top left point on screen 85 */ 86 private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft, 87 Point topLeftInWindow, Point topLeftOnScreen) { 88 CheckParameterUtil.ensureParameterNotNull(projection, "projection"); 89 CheckParameterUtil.ensureParameterNotNull(topLeft, "topLeft"); 90 CheckParameterUtil.ensureParameterNotNull(topLeftInWindow, "topLeftInWindow"); 91 CheckParameterUtil.ensureParameterNotNull(topLeftOnScreen, "topLeftOnScreen"); 92 84 93 this.projecting = projection; 85 94 this.scale = scale; … … 88 97 this.viewWidth = viewWidth; 89 98 this.viewHeight = viewHeight; 90 topLeftInWindow = new Point(0, 0); 91 topLeftOnScreen = new Point(0, 0); 92 } 93 94 private MapViewState(EastNorth topLeft, MapViewState mapViewState) { 95 this.projecting = mapViewState.projecting; 96 this.scale = mapViewState.scale; 97 this.topLeft = topLeft; 98 99 viewWidth = mapViewState.viewWidth; 100 viewHeight = mapViewState.viewHeight; 101 topLeftInWindow = mapViewState.topLeftInWindow; 102 topLeftOnScreen = mapViewState.topLeftOnScreen; 103 } 104 105 private MapViewState(double scale, MapViewState mapViewState) { 106 this.projecting = mapViewState.projecting; 107 this.scale = scale; 108 this.topLeft = mapViewState.topLeft; 109 110 viewWidth = mapViewState.viewWidth; 111 viewHeight = mapViewState.viewHeight; 112 topLeftInWindow = mapViewState.topLeftInWindow; 113 topLeftOnScreen = mapViewState.topLeftOnScreen; 114 } 115 116 private MapViewState(JComponent position, MapViewState mapViewState) { 117 this.projecting = mapViewState.projecting; 118 this.scale = mapViewState.scale; 119 this.topLeft = mapViewState.topLeft; 120 121 viewWidth = position.getWidth(); 122 viewHeight = position.getHeight(); 123 topLeftInWindow = new Point(); 124 // better than using swing utils, since this allows us to use the mehtod if no screen is present. 99 this.topLeftInWindow = topLeftInWindow; 100 this.topLeftOnScreen = topLeftOnScreen; 101 } 102 103 private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft) { 104 this(projection, viewWidth, viewHeight, scale, topLeft, new Point(0, 0), new Point(0, 0)); 105 } 106 107 private MapViewState(EastNorth topLeft, MapViewState mvs) { 108 this(mvs.projecting, mvs.viewWidth, mvs.viewHeight, mvs.scale, topLeft, mvs.topLeftInWindow, mvs.topLeftOnScreen); 109 } 110 111 private MapViewState(double scale, MapViewState mvs) { 112 this(mvs.projecting, mvs.viewWidth, mvs.viewHeight, scale, mvs.topLeft, mvs.topLeftInWindow, mvs.topLeftOnScreen); 113 } 114 115 private MapViewState(JComponent position, MapViewState mvs) { 116 this(mvs.projecting, position.getWidth(), position.getHeight(), mvs.scale, mvs.topLeft, 117 findTopLeftInWindow(position), findTopLeftOnScreen(position)); 118 } 119 120 private MapViewState(Projecting projecting, MapViewState mvs) { 121 this(projecting, mvs.viewWidth, mvs.viewHeight, mvs.scale, mvs.topLeft, mvs.topLeftInWindow, mvs.topLeftOnScreen); 122 } 123 124 private static Point findTopLeftInWindow(JComponent position) { 125 Point result = new Point(); 126 // better than using swing utils, since this allows us to use the method if no screen is present. 125 127 Container component = position; 126 128 while (component != null) { 127 topLeftInWindow.x += component.getX();128 topLeftInWindow.y += component.getY();129 result.x += component.getX(); 130 result.y += component.getY(); 129 131 component = component.getParent(); 130 132 } 133 return result; 134 } 135 136 private static Point findTopLeftOnScreen(JComponent position) { 131 137 try { 132 topLeftOnScreen =position.getLocationOnScreen();138 return position.getLocationOnScreen(); 133 139 } catch (RuntimeException e) { 134 140 throw BugReport.intercept(e).put("position", position).put("parent", position::getParent); 135 141 } 136 }137 138 private MapViewState(Projecting projecting, MapViewState mapViewState) {139 this.projecting = projecting;140 this.scale = mapViewState.scale;141 this.topLeft = mapViewState.topLeft;142 143 viewWidth = mapViewState.viewWidth;144 viewHeight = mapViewState.viewHeight;145 topLeftInWindow = mapViewState.topLeftInWindow;146 topLeftOnScreen = mapViewState.topLeftOnScreen;147 142 } 148 143 … … 574 569 575 570 MapViewEastNorthPoint(EastNorth eastNorth) { 571 CheckParameterUtil.ensureParameterNotNull(eastNorth, "eastNorth"); 576 572 this.eastNorth = eastNorth; 577 573 }
Note:
See TracChangeset
for help on using the changeset viewer.