Revision 344 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameGrid.java
FFrameGrid.java | ||
---|---|---|
22 | 22 |
package org.gvsig.app.project.documents.layout.fframes; |
23 | 23 |
|
24 | 24 |
import java.awt.Color; |
25 |
import java.awt.Dimension; |
|
25 | 26 |
import java.awt.Font; |
26 | 27 |
import java.awt.Graphics2D; |
27 | 28 |
import java.awt.font.TextLayout; |
... | ... | |
128 | 129 |
private IMarkerSymbol symbolPoint = (IMarkerSymbol) symbolManager |
129 | 130 |
.createSymbol(IMarkerSymbol.SYMBOL_NAME); |
130 | 131 |
private Font font = new Font("Arial", Font.PLAIN, sizeFont); |
131 |
|
|
132 |
private AffineTransform emptyTransform = new AffineTransform(); |
|
133 | 132 |
|
134 | 133 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
135 | 134 |
BufferedImage imgBase) { |
136 |
ViewPort vp = fframeViewDependence.getMapContext().getViewPort(); |
|
137 |
|
|
138 |
Rectangle2D.Double r = getBoundingBox(at); |
|
139 |
Rectangle2D rView = fframeViewDependence.getBoundingBox(at); |
|
140 |
if (r==null || rView==null) { |
|
141 |
//extent may be null, for instance if no layer has been loaded on the view |
|
142 |
return; |
|
143 |
} |
|
144 |
Envelope envelope = vp.getAdjustedEnvelope(); |
|
145 |
updateIntervals(envelope); |
|
146 |
double intervalX = getIntervalX(); |
|
147 |
double intervalY = getIntervalY(); |
|
148 |
|
|
149 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y + (r.height / 2)); |
|
150 |
|
|
151 |
double minX = envelope.getMinimum(0); |
|
152 |
double minY = envelope.getMinimum(1); |
|
153 |
|
|
154 |
// init point, in map coordinates |
|
155 |
double initPointGridWCX = Math.floor(minX / intervalX)*intervalX; |
|
156 |
double initPointGridWCY = Math.floor(minY / intervalY)*intervalY; |
|
157 |
|
|
158 |
// shift from the beginning of the map till the first point of the grid |
|
159 |
double shiftXMap = initPointGridWCX-minX; |
|
160 |
double shiftYMap = initPointGridWCY-minY; |
|
161 |
|
|
162 |
// init point, in screen coordinates (pixels) |
|
163 |
double initPointGridPxX = rView.getMinX() + (rView.getWidth() * shiftXMap) / envelope.getLength(0); |
|
164 |
double initPointGridPxY = rView.getMinY() + (rView.getHeight() * shiftYMap) / envelope.getLength(1); |
|
165 |
double intervalPxWidth = (rView.getWidth() * intervalX) / envelope.getLength(0); |
|
166 |
double intervalPxHeight = (rView.getHeight() * intervalY) / envelope.getLength(1); |
|
167 |
|
|
168 |
ISymbol symbolForMargins = null; |
|
169 |
if (isLine){ |
|
170 |
symbolForMargins = symbolLine; |
|
171 |
}else{ |
|
172 |
try { |
|
173 |
symbolForMargins = (ISymbol)symbolLine.clone(); |
|
174 |
symbolForMargins.setColor(symbolPoint.getColor()); |
|
175 |
} catch (CloneNotSupportedException e) { |
|
176 |
LOG.error("Symbol desn't support the clone method", e); |
|
177 |
} |
|
178 |
} |
|
179 |
|
|
180 |
//Draw the box |
|
181 |
drawBox(rView, g, symbolForMargins); |
|
135 |
try { |
|
136 |
Rectangle2D.Double r = getBoundingBox(at); |
|
137 |
Rectangle2D rView = fframeViewDependence.getBoundingBox(at); |
|
138 |
if (r==null || rView==null) { |
|
139 |
//extent may be null, for instance if no layer has been loaded on the view |
|
140 |
return; |
|
141 |
} |
|
142 |
ViewPort vp = (ViewPort) fframeViewDependence.getMapContext().getViewPort().clone(); |
|
182 | 143 |
|
183 |
//Draw the margins |
|
184 |
double myScale = at.getScaleX() * 0.0234; |
|
185 |
int scaledFontSize = (int) (myScale * sizeFont); |
|
186 |
Font font = new Font( |
|
187 |
this.font.getFamily(), |
|
188 |
this.font.getStyle(), |
|
189 |
scaledFontSize); |
|
190 |
|
|
191 |
drawMargins(rView, |
|
192 |
initPointGridWCX, |
|
193 |
initPointGridWCY, |
|
194 |
intervalX, |
|
195 |
intervalY, |
|
196 |
initPointGridPxX, |
|
197 |
initPointGridPxY, |
|
198 |
intervalPxWidth, |
|
199 |
intervalPxHeight, |
|
200 |
g, |
|
201 |
font, |
|
202 |
symbolForMargins); |
|
203 |
|
|
204 |
//Draw the lines or the points |
|
205 |
if (isLine) { |
|
206 |
drawLines(rView, |
|
207 |
initPointGridPxX, |
|
208 |
initPointGridPxY, |
|
209 |
intervalPxWidth, |
|
210 |
intervalPxHeight, |
|
211 |
vp, g); |
|
212 |
} else { |
|
213 |
drawPoints(rView, |
|
214 |
initPointGridPxX, |
|
215 |
initPointGridPxY, |
|
216 |
intervalPxWidth, |
|
217 |
intervalPxHeight, |
|
218 |
vp, g); |
|
219 |
} |
|
220 |
|
|
221 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y |
|
222 |
+ (r.height / 2)); |
|
144 |
vp.setOffset(new Point2D.Double(rView.getMinX(), rView.getMinY())); |
|
145 |
vp.setImageSize(new Dimension((int)Math.round(rView.getWidth()), (int)Math.round(rView.getHeight()))); |
|
146 |
vp.refreshExtent(); |
|
147 |
|
|
148 |
Envelope envelope = vp.getAdjustedEnvelope(); |
|
149 |
AffineTransform mapTransform = vp.getAffineTransform(); |
|
150 |
updateIntervals(envelope); |
|
151 |
double intervalX = getIntervalX(); |
|
152 |
double intervalY = getIntervalY(); |
|
153 |
|
|
154 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y + (r.height / 2)); |
|
155 |
|
|
156 |
double minX = envelope.getMinimum(0); |
|
157 |
double minY = envelope.getMinimum(1); |
|
158 |
double maxX = envelope.getMaximum(0); |
|
159 |
double maxY = envelope.getMaximum(1); |
|
160 |
|
|
161 |
// init point, in map coordinates |
|
162 |
double initPointGridWCX = Math.ceil(minX / intervalX)*intervalX; |
|
163 |
double initPointGridWCY = Math.ceil(minY / intervalY)*intervalY; |
|
164 |
|
|
165 |
ISymbol symbolForMargins = null; |
|
166 |
if (isLine){ |
|
167 |
symbolForMargins = symbolLine; |
|
168 |
}else{ |
|
169 |
try { |
|
170 |
symbolForMargins = (ISymbol)symbolLine.clone(); |
|
171 |
symbolForMargins.setColor(symbolPoint.getColor()); |
|
172 |
} catch (CloneNotSupportedException e) { |
|
173 |
LOG.error("Symbol desn't support the clone method", e); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
//Draw the box |
|
178 |
drawBox(rView, g, symbolForMargins); |
|
179 |
|
|
180 |
//Draw the margins |
|
181 |
double myScale = at.getScaleX() * 0.0234; // FIXME: 0.0234?? Should this depend on output resolution? |
|
182 |
int scaledFontSize = (int) (myScale * sizeFont); |
|
183 |
Font font = new Font( |
|
184 |
this.font.getFamily(), |
|
185 |
this.font.getStyle(), |
|
186 |
scaledFontSize); |
|
187 |
|
|
188 |
drawLabels(rView, |
|
189 |
initPointGridWCX, |
|
190 |
initPointGridWCY, |
|
191 |
maxX, |
|
192 |
maxY, |
|
193 |
intervalX, |
|
194 |
intervalY, |
|
195 |
mapTransform, |
|
196 |
g, |
|
197 |
font, |
|
198 |
symbolForMargins); |
|
199 |
|
|
200 |
//Draw the lines or the points |
|
201 |
if (isLine) { |
|
202 |
drawLines(rView, |
|
203 |
initPointGridWCX, |
|
204 |
initPointGridWCY, |
|
205 |
maxX, |
|
206 |
maxY, |
|
207 |
intervalX, |
|
208 |
intervalY, |
|
209 |
mapTransform, |
|
210 |
g); |
|
211 |
} else { |
|
212 |
drawPoints(initPointGridWCX, |
|
213 |
initPointGridWCY, |
|
214 |
maxX, |
|
215 |
maxY, |
|
216 |
intervalX, |
|
217 |
intervalY, |
|
218 |
mapTransform, |
|
219 |
g); |
|
220 |
} |
|
221 |
|
|
222 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y |
|
223 |
+ (r.height / 2)); |
|
224 |
} catch (CloneNotSupportedException e1) {} |
|
223 | 225 |
} |
224 |
|
|
225 |
private void drawPoints(Rectangle2D rView, |
|
226 |
double initPointGridPxX, |
|
227 |
double initPointGridPxY, |
|
228 |
double intervalPxX, |
|
229 |
double intervalPxY, |
|
230 |
ViewPort viewPort, |
|
226 |
|
|
227 |
/** |
|
228 |
* Draw the grid as point symbols |
|
229 |
* |
|
230 |
* @param minGridX The starting grid point on the x axis, in map coordinates |
|
231 |
* @param minGridY The starting grid point on the y axis, in map coordinates |
|
232 |
* @param maxGridX The maximum map point on the x axis, in map coordinates. |
|
233 |
* It may be bigger than the maximum grid point |
|
234 |
* @param maxGridY The maximum map point on the y axis, in map coordinates. |
|
235 |
* It may be bigger than the maximum grid point |
|
236 |
* @param intervalGridX The grid interval on the x axis, in map coordinates |
|
237 |
* @param intervalGridY The grid interval on the y axis, in map coordinates |
|
238 |
* @param mapTransform Transforms map coordinates to screen coordinates |
|
239 |
* @param g The graphics object to draw on |
|
240 |
*/ |
|
241 |
private void drawPoints( |
|
242 |
double minGridX, |
|
243 |
double minGridY, |
|
244 |
double maxGridX, |
|
245 |
double maxGridY, |
|
246 |
double intervalGridX, |
|
247 |
double intervalGridY, |
|
248 |
AffineTransform mapTransform, |
|
231 | 249 |
Graphics2D g) { |
232 |
double minX = rView.getMinX(); |
|
233 |
double maxX = rView.getMaxX(); |
|
234 |
double minY = rView.getMinY(); |
|
235 |
double maxY = rView.getMaxY(); |
|
236 |
double x = initPointGridPxX; |
|
237 |
double y = initPointGridPxY; |
|
238 |
|
|
239 |
while (x <= maxX) { |
|
240 |
if (x > minX) { |
|
241 |
while (y <= maxY) { |
|
242 |
if (y > minY) { |
|
243 |
Point2D p = new Point2D.Double(x, y); |
|
244 |
drawPoint(p, g); |
|
245 |
} |
|
246 |
y = y + intervalPxY; |
|
247 |
} |
|
248 |
y = initPointGridPxY; |
|
249 |
} |
|
250 |
x = x + intervalPxX; |
|
250 |
|
|
251 |
Point2D currentPoint = new Point2D.Double(minGridX, minGridY); |
|
252 |
Point2D screenPoint = new Point2D.Double(); |
|
253 |
while (currentPoint.getX() < maxGridX) { |
|
254 |
while (currentPoint.getY() < maxGridY) { |
|
255 |
mapTransform.transform(currentPoint, screenPoint); |
|
256 |
drawPoint(g, screenPoint); |
|
257 |
currentPoint.setLocation(currentPoint.getX(), currentPoint.getY()+intervalGridY); |
|
258 |
} |
|
259 |
currentPoint.setLocation(currentPoint.getX()+intervalGridX, minGridY); |
|
251 | 260 |
} |
252 | 261 |
} |
253 |
|
|
254 |
private void drawLines(Rectangle2D rView, |
|
255 |
double initPointGridPxX, |
|
256 |
double initPointGridPxY, |
|
257 |
double intervalPxX, |
|
258 |
double intervalPxY, |
|
259 |
ViewPort viewPort, |
|
262 |
|
|
263 |
/** |
|
264 |
* Draw the grid as line symbols |
|
265 |
* |
|
266 |
* @param rView The rectangle of the view, on screen coordinates |
|
267 |
* @param minGridX The starting grid point on the x axis, in map coordinates |
|
268 |
* @param minGridY The starting grid point on the y axis, in map coordinates |
|
269 |
* @param maxGridX The maximum map point on the x axis, in map coordinates. |
|
270 |
* It may be bigger than the maximum grid point |
|
271 |
* @param maxGridY The maximum map point on the y axis, in map coordinates. |
|
272 |
* It may be bigger than the maximum grid point |
|
273 |
* @param intervalGridX The grid interval on the x axis, in map coordinates |
|
274 |
* @param intervalGridY The grid interval on the y axis, in map coordinates |
|
275 |
* @param mapTransform Transforms map coordinates to screen coordinates |
|
276 |
* @param g The graphics object to draw on |
|
277 |
*/ |
|
278 |
private void drawLines(Rectangle2D rView, |
|
279 |
double minMapX, |
|
280 |
double minMapY, |
|
281 |
double maxMapX, |
|
282 |
double maxMapY, |
|
283 |
double intervalMapX, |
|
284 |
double intervalMapY, |
|
285 |
AffineTransform mapTransform, |
|
260 | 286 |
Graphics2D g) { |
261 | 287 |
double minX = rView.getMinX(); |
262 | 288 |
double maxX = rView.getMaxX(); |
263 | 289 |
double minY = rView.getMinY(); |
264 | 290 |
double maxY = rView.getMaxY(); |
265 |
double x = initPointGridPxX; |
|
266 |
double y = initPointGridPxY; |
|
267 |
|
|
291 |
double xMap = minMapX; |
|
292 |
double yMap = minMapY; |
|
293 |
|
|
294 |
// transform to screen coordinates |
|
295 |
Point2D currentPoint = new Point2D.Double(minMapX, minMapY); |
|
296 |
// transform from map coordinates to screen (pixels) coordinates |
|
297 |
mapTransform.transform(currentPoint, currentPoint); |
|
298 |
|
|
268 | 299 |
//Draw the vertical lines |
269 |
while (x < maxX) { |
|
270 |
if (x>minX) { |
|
271 |
Point2D antPoint = new Point2D.Double(x, minY - 5); |
|
272 |
Point2D p = new Point2D.Double(x, maxY + 5); |
|
273 |
drawLine(antPoint, p, g, symbolLine); |
|
274 |
antPoint = (Point2D) p.clone(); |
|
275 |
} |
|
276 |
x = x + intervalPxX; |
|
300 |
while (xMap < maxMapX) { |
|
301 |
drawLine(currentPoint.getX(), minY, currentPoint.getX(), maxY, g, symbolLine); |
|
302 |
xMap = xMap + intervalMapX; |
|
303 |
currentPoint.setLocation(xMap, minMapY); |
|
304 |
// from map coordinates to screen (pixels) |
|
305 |
mapTransform.transform(currentPoint, currentPoint); |
|
277 | 306 |
} |
278 | 307 |
//Draw the horizontal lines |
279 |
while (y <= maxY) { |
|
280 |
if (y > minY) { |
|
281 |
Point2D antPoint = new Point2D.Double(minX, y); |
|
282 |
Point2D p = new Point2D.Double(rView.getMaxX(), y); |
|
283 |
drawLine(antPoint, p, g, symbolLine); |
|
284 |
antPoint = (Point2D) p.clone(); |
|
285 |
} |
|
286 |
y = y + intervalPxY; |
|
308 |
while (yMap < maxMapY) { |
|
309 |
drawLine(minX, currentPoint.getY(), maxX , currentPoint.getY(), g, symbolLine); |
|
310 |
yMap = yMap + intervalMapY; |
|
311 |
currentPoint.setLocation(minMapX, yMap); |
|
312 |
// from map coordinates to screen (pixels) |
|
313 |
mapTransform.transform(currentPoint, currentPoint); |
|
287 | 314 |
} |
288 | 315 |
} |
289 |
|
|
290 |
private void drawMargins(Rectangle2D rView, |
|
291 |
double initPointGridMapX, |
|
292 |
double initPointGridMapY, |
|
293 |
double intervalMapX, |
|
294 |
double intervalMapY, |
|
295 |
double initPointGridPxX, |
|
296 |
double initPointGridPxY, |
|
297 |
double intervalPxX, |
|
298 |
double intervalPxY, |
|
316 |
|
|
317 |
/** |
|
318 |
* Draws the labels and the tick marks of labels |
|
319 |
* |
|
320 |
* @param rView The rectangle of the view, on screen coordinates |
|
321 |
* @param minGridX The starting grid point on the x axis, in map coordinates |
|
322 |
* @param minGridY The starting grid point on the y axis, in map coordinates |
|
323 |
* @param maxGridX The maximum map point on the x axis, in map coordinates. |
|
324 |
* It may be bigger than the maximum grid point |
|
325 |
* @param maxGridY The maximum map point on the y axis, in map coordinates. |
|
326 |
* It may be bigger than the maximum grid point |
|
327 |
* @param intervalGridX The grid interval on the x axis, in map coordinates |
|
328 |
* @param intervalGridY The grid interval on the y axis, in map coordinates |
|
329 |
* @param mapTransform Transforms map coordinates to screen coordinates |
|
330 |
* @param g The graphics object to draw on |
|
331 |
* @param font |
|
332 |
* @param symbolForMargins |
|
333 |
*/ |
|
334 |
private void drawLabels(Rectangle2D rView, |
|
335 |
double minGridX, |
|
336 |
double minGridY, |
|
337 |
double maxGridX, |
|
338 |
double maxGridY, |
|
339 |
double intervalGridX, |
|
340 |
double intervalGridY, |
|
341 |
AffineTransform mapTransform, |
|
299 | 342 |
Graphics2D g, |
300 | 343 |
Font font, |
301 | 344 |
ISymbol |
302 | 345 |
symbolForMargins) { |
303 | 346 |
AffineTransform defaultAt = g.getTransform(); |
304 | 347 |
|
305 |
double minX = rView.getMinX(); |
|
306 |
double maxX = rView.getMaxX(); |
|
307 |
double minY = rView.getMinY(); |
|
308 |
double maxY = rView.getMaxY(); |
|
309 |
double xPx = initPointGridPxX; |
|
310 |
double xMap = initPointGridMapX; |
|
311 |
|
|
312 |
double angle = RotatedTextUtils.normalizeAngle(Math.toRadians(getVertLabelRotation())); |
|
313 |
int anchor = getLabelAnchor(); |
|
314 |
// Draw vertical ticks and labels |
|
315 |
while (xPx < maxX) { |
|
316 |
if (xPx > minX) { |
|
317 |
// bottom tick |
|
318 |
drawLine(xPx, maxY + OFFSET_IN_PIXELS, xPx , maxY, g, symbolForMargins); |
|
319 |
// top tick |
|
320 |
drawLine(xPx, minY, xPx, minY - OFFSET_IN_PIXELS, g, symbolForMargins); |
|
321 |
|
|
322 |
g.rotate(angle); |
|
323 |
g.setColor(textColor); |
|
324 |
|
|
325 |
// bottom label |
|
326 |
Point2D p1 = new Point2D.Double(xPx, maxY+OFFSET_IN_PIXELS); // bottom |
|
327 |
TextLayout textaux = new TextLayout(this.labelFormat.format(xMap), font, g.getFontRenderContext()); |
|
328 |
Point2D rotatedP1 = RotatedTextUtils.getPosition(p1, textaux, angle, RotatedTextUtils.PLACEMENT_BOTTOM, anchor); |
|
329 |
textaux.draw(g, (int) (rotatedP1.getX()), (int) rotatedP1.getY()); |
|
348 |
double minX = rView.getMinX(); |
|
349 |
double maxX = rView.getMaxX(); |
|
350 |
double minY = rView.getMinY(); |
|
351 |
double maxY = rView.getMaxY(); |
|
352 |
double xMap = minGridX; |
|
353 |
double yMap = minGridY; |
|
330 | 354 |
|
331 |
// top label |
|
332 |
Point2D p2 = new Point2D.Double(xPx, minY-OFFSET_IN_PIXELS); |
|
333 |
p2.setLocation(p2.getX(), p2.getY()-OFFSET_IN_PIXELS); |
|
334 |
Point2D rotatedP2 = RotatedTextUtils.getPosition(p2, textaux, angle, RotatedTextUtils.PLACEMENT_TOP, anchor); |
|
335 |
textaux.draw(g, (int) (rotatedP2.getX()),(int) rotatedP2.getY()); |
|
336 |
g.setTransform(defaultAt); |
|
355 |
// transform to screen coordinates |
|
356 |
Point2D initGridPx = new Point2D.Double(minGridX, minGridY); |
|
357 |
mapTransform.transform(initGridPx, initGridPx); |
|
337 | 358 |
|
338 |
} |
|
339 |
xMap = xMap + intervalMapX; |
|
340 |
xPx = xPx + intervalPxX; |
|
341 |
} |
|
342 |
double yPx = initPointGridPxY; |
|
343 |
double yMap = initPointGridMapY; |
|
359 |
double xPx = initGridPx.getX(); |
|
344 | 360 |
|
345 |
angle = RotatedTextUtils.normalizeAngle(Math.toRadians(getHorizLabelRotation())); |
|
346 |
// horizontal ticks and labels |
|
347 |
while (yPx < maxY) { |
|
348 |
if (yPx > minY) { |
|
349 |
|
|
350 |
// left tick |
|
351 |
drawLine(minX - OFFSET_IN_PIXELS, yPx, minX , yPx, g, symbolForMargins); |
|
352 |
// right tick |
|
353 |
drawLine(maxX, yPx, maxX + OFFSET_IN_PIXELS, yPx, g, symbolForMargins); |
|
354 |
|
|
355 |
g.rotate(angle); |
|
356 |
g.setColor(textColor); |
|
357 |
TextLayout textaux = new TextLayout(this.labelFormat.format(yMap), font, g.getFontRenderContext()); |
|
358 |
// left label |
|
359 |
Point2D p1 = new Point2D.Double(minX-OFFSET_IN_PIXELS, yPx); |
|
360 |
Point2D rotatedP1 = RotatedTextUtils.getPosition(p1, textaux, angle, RotatedTextUtils.PLACEMENT_LEFT, anchor); |
|
361 |
textaux.draw(g, (int) (rotatedP1.getX()), (int) rotatedP1.getY()); |
|
362 |
// right label |
|
363 |
Point2D p2 = new Point2D.Double(maxX+OFFSET_IN_PIXELS, yPx); |
|
364 |
Point2D rotatedP2 = RotatedTextUtils.getPosition(p2, textaux, angle, RotatedTextUtils.PLACEMENT_RIGHT, anchor); |
|
365 |
textaux.draw(g, (int) (rotatedP2.getX()),(int) rotatedP2.getY()); |
|
366 |
g.setTransform(defaultAt); |
|
367 |
} |
|
368 |
yMap = yMap + intervalMapY; |
|
369 |
yPx = yPx + intervalPxY; |
|
370 |
} |
|
361 |
double angle = RotatedTextUtils.normalizeAngle(Math.toRadians(getVertLabelRotation())); |
|
362 |
int anchor = getLabelAnchor(); |
|
363 |
// Draw vertical ticks and labels |
|
364 |
while (xMap < maxGridX) { |
|
365 |
// bottom tick |
|
366 |
drawLine(xPx, maxY + OFFSET_IN_PIXELS, xPx , maxY, g, symbolForMargins); |
|
367 |
// top tick |
|
368 |
drawLine(xPx, minY, xPx, minY - OFFSET_IN_PIXELS, g, symbolForMargins); |
|
369 |
|
|
370 |
g.rotate(angle); |
|
371 |
g.setColor(textColor); |
|
372 |
|
|
373 |
// bottom label |
|
374 |
Point2D p1 = new Point2D.Double(xPx, maxY+OFFSET_IN_PIXELS); // bottom |
|
375 |
TextLayout textaux = new TextLayout(this.labelFormat.format(xMap), font, g.getFontRenderContext()); |
|
376 |
Point2D rotatedP1 = RotatedTextUtils.getPosition(p1, textaux, angle, RotatedTextUtils.PLACEMENT_BOTTOM, anchor); |
|
377 |
textaux.draw(g, (int) (rotatedP1.getX()), (int) rotatedP1.getY()); |
|
378 |
|
|
379 |
// top label |
|
380 |
Point2D p2 = new Point2D.Double(xPx, minY-OFFSET_IN_PIXELS); |
|
381 |
Point2D rotatedP2 = RotatedTextUtils.getPosition(p2, textaux, angle, RotatedTextUtils.PLACEMENT_TOP, anchor); |
|
382 |
textaux.draw(g, (int) (rotatedP2.getX()),(int) rotatedP2.getY()); |
|
383 |
g.setTransform(defaultAt); |
|
384 |
|
|
385 |
|
|
386 |
xMap = xMap + intervalGridX; |
|
387 |
|
|
388 |
initGridPx.setLocation(xMap, minGridY); |
|
389 |
mapTransform.transform(initGridPx, initGridPx); |
|
390 |
xPx = initGridPx.getX(); |
|
391 |
} |
|
392 |
double yPx = initGridPx.getY(); |
|
393 |
angle = RotatedTextUtils.normalizeAngle(Math.toRadians(getHorizLabelRotation())); |
|
394 |
// horizontal ticks and labels |
|
395 |
while (yMap < maxGridY) { |
|
396 |
|
|
397 |
// left tick |
|
398 |
drawLine(minX - OFFSET_IN_PIXELS, yPx, minX , yPx, g, symbolForMargins); |
|
399 |
// right tick |
|
400 |
drawLine(maxX, yPx, maxX + OFFSET_IN_PIXELS, yPx, g, symbolForMargins); |
|
401 |
|
|
402 |
g.rotate(angle); |
|
403 |
g.setColor(textColor); |
|
404 |
TextLayout textaux = new TextLayout(this.labelFormat.format(yMap), font, g.getFontRenderContext()); |
|
405 |
|
|
406 |
// left label |
|
407 |
Point2D p1 = new Point2D.Double(minX-OFFSET_IN_PIXELS, yPx); |
|
408 |
Point2D rotatedP1 = RotatedTextUtils.getPosition(p1, textaux, angle, RotatedTextUtils.PLACEMENT_LEFT, anchor); |
|
409 |
textaux.draw(g, (int) (rotatedP1.getX()), (int) rotatedP1.getY()); |
|
410 |
// right label |
|
411 |
Point2D p2 = new Point2D.Double(maxX+OFFSET_IN_PIXELS, yPx); |
|
412 |
Point2D rotatedP2 = RotatedTextUtils.getPosition(p2, textaux, angle, RotatedTextUtils.PLACEMENT_RIGHT, anchor); |
|
413 |
textaux.draw(g, (int) (rotatedP2.getX()),(int) rotatedP2.getY()); |
|
414 |
g.setTransform(defaultAt); |
|
415 |
yMap = yMap + intervalGridY; |
|
416 |
|
|
417 |
initGridPx.setLocation(minGridX, yMap); |
|
418 |
mapTransform.transform(initGridPx, initGridPx); |
|
419 |
yPx = initGridPx.getY(); |
|
420 |
} |
|
371 | 421 |
} |
372 | 422 |
|
373 | 423 |
private void drawBox(Rectangle2D mapRectangle, Graphics2D g, ISymbol symbol){ |
... | ... | |
388 | 438 |
} |
389 | 439 |
} |
390 | 440 |
|
391 |
private void drawPoint(Point2D point, Graphics2D g){ |
|
441 |
/** |
|
442 |
* Draws a point using the configured symbol |
|
443 |
* |
|
444 |
* @param g The graphics object to draw on |
|
445 |
* @param point Point to draw, in map coordinates |
|
446 |
* @param mapTransform Transforms from map coordinates to screen coordinates |
|
447 |
*/ |
|
448 |
private void drawPoint(Graphics2D g, Point2D point){ |
|
392 | 449 |
try { |
393 | 450 |
Geometry geom = |
394 | 451 |
createPoint((int) point.getX(), (int) point.getY()); |
395 |
symbolPoint.draw(g, emptyTransform, geom, null, null);
|
|
452 |
symbolPoint.draw(g, null, geom, null, null);
|
|
396 | 453 |
} catch (LocatorException e) { |
397 | 454 |
LOG.error("Error drawing the grid", e); |
398 | 455 |
} catch (CreateGeometryException e) { |
... | ... | |
411 | 468 |
LOG.error("Error drawing the grid", e); |
412 | 469 |
} |
413 | 470 |
} |
414 |
|
|
415 |
private void drawLine(Point2D startPoint, Point2D endPoint, Graphics2D g, ISymbol symbolLine){ |
|
416 |
drawLine(startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY(), g, symbolLine); |
|
417 |
} |
|
418 | 471 |
|
419 | 472 |
private Geometry createLine(int i, int j, int k, int l) |
420 | 473 |
throws LocatorException, CreateGeometryException { |
... | ... | |
617 | 670 |
* calculate them. |
618 | 671 |
* |
619 | 672 |
* @return One of {@link #FIXED_DISTANCE_MODE}, |
620 |
* {@link #NUM_DIVISIONS_HORIZ_MODE} or {@link #NUM_DIVISIONS_HORIZ_MODE}.
|
|
673 |
* {@link #NUM_DIVISIONS_HORIZ_MODE} or {@link #NUM_DIVISIONS_VERT_MODE}.
|
|
621 | 674 |
*/ |
622 | 675 |
public int getUseNumDivisions() { |
623 | 676 |
return this.useNumDivisions; |
... | ... | |
631 | 684 |
this.numDivVert = ny; |
632 | 685 |
} |
633 | 686 |
|
634 |
public int getNumDivisionHoriz() { |
|
687 |
public int getNumDivisionsHoriz() {
|
|
635 | 688 |
return this.numDivHoriz; |
636 | 689 |
} |
637 | 690 |
|
Also available in: Unified diff