Changeset 32191 in osm for applications/editors/josm/plugins/print/src/org
- Timestamp:
- 2016-05-25T21:19:27+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java
r31329 r32191 34 34 import java.awt.Graphics2D; 35 35 import java.awt.Shape; 36 import java.awt.event.ComponentListener; 36 37 import java.awt.font.FontRenderContext; 37 38 import java.awt.font.GlyphVector; … … 41 42 import java.awt.print.Printable; 42 43 import java.awt.print.PrinterException; 43 import java.util.ArrayList;44 import java.util.Collections;45 import java.util.Comparator;46 import java.util.List;47 44 48 45 import javax.swing.JPanel; … … 54 51 import org.openstreetmap.josm.gui.MapView; 55 52 import org.openstreetmap.josm.gui.layer.Layer; 56 import org.openstreetmap.josm.gui.layer.OsmDataLayer;57 53 58 54 /** … … 72 68 * resolution 73 69 */ 74 protected double g2dFactor; 75 76 /** 77 * The real MapView which is the data source 78 */ 79 protected MapView mapView; 70 protected double g2dFactor; 80 71 81 72 /** … … 89 80 public PrintableMapView() { 90 81 /* Initialize MapView with a dummy parent */ 91 super(new JPanel(), null); 82 super(new PrintableLayerManager(), new JPanel(), null); 92 83 93 84 /* Disable MapView's ComponentLister, 94 85 * as it will interfere with the main MapView. */ 95 java.awt.event.ComponentListener listeners[] = getComponentListeners();86 ComponentListener listeners[] = getComponentListeners(); 96 87 for (int i=0; i<listeners.length; i++) { 97 88 removeComponentListener(listeners[i]); 98 89 } 99 100 mapView = Main.map.mapView;101 90 } 102 91 … … 155 144 if (dim.width != width || dim.height != height) { 156 145 super.setSize(width, height); 157 zoomTo(mapView.getRealBounds()); 146 zoomTo(Main.map.mapView.getRealBounds()); 158 147 rezoomToFixedScale(); 159 148 } … … 168 157 if (dim.width != newSize.width || dim.height != newSize.height) { 169 158 super.setSize(newSize); 170 zoomTo(mapView.getRealBounds()); 159 zoomTo(Main.map.mapView.getRealBounds()); 171 160 rezoomToFixedScale(); 172 161 } … … 230 219 231 220 Bounds box = getRealBounds(); 232 List<Layer> visibleLayers = getVisibleLayersInZOrder(); 233 for (Layer l : visibleLayers) { 221 for (Layer l : getLayerManager().getVisibleLayersInZOrder()) { 234 222 if (l.getOpacity() < 1) { 235 223 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,(float)l.getOpacity())); … … 357 345 * Paint a text. 358 346 * 359 * This method will not only draw the letters but also a background 360 * which improves redability. 347 * This method will not only draw the letters but also a background which improves redability. 361 348 * 362 349 * @param g2d the graphics context to use for painting … … 365 352 * @param y the y coordinate 366 353 */ 367 368 354 public void paintText(Graphics2D g2d, String text, int x, int y) { 369 AffineTransform ax = g2d.getTransform(); 370 g2d.translate(x,y); 371 372 FontRenderContext frc = g2d.getFontRenderContext(); 373 GlyphVector gv = g2d.getFont().createGlyphVector(frc, text); 374 Shape textOutline = gv.getOutline(); 375 376 g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); 377 g2d.setColor(Color.WHITE); 378 g2d.draw(textOutline); 379 380 g2d.setStroke(new BasicStroke()); 381 g2d.setColor(Color.BLACK); 382 g2d.drawString(text, 0, 0); 383 384 g2d.setTransform(ax); 385 } 386 387 /** 388 * Get the active layer 389 * 390 * This method is implemented in MapView but we need at this instance. 391 */ 392 @Override 393 public Layer getActiveLayer() { 394 return mapView.getActiveLayer(); 395 } 396 397 /** 398 * Get the position of a particular layer in the stack of layers 399 * 400 * This method is implemented in MapView but we need at this instance. 401 */ 402 @Override 403 public int getLayerPos(Layer layer) { 404 return mapView.getLayerPos(layer); 405 } 406 407 /** 408 * This method is implemented in MapView but protected. 409 * 410 * The algorithm is slightly modified. 411 */ 412 @Override 413 public List<Layer> getVisibleLayersInZOrder() { 414 ArrayList<Layer> layers = new ArrayList<>(); 415 for (Layer l: mapView.getAllLayersAsList()) { 416 if (l.isVisible()) { 417 layers.add(l); 418 } 419 } 420 Collections.sort( 421 layers, 422 new Comparator<Layer>() { 423 @Override 424 public int compare(Layer l2, Layer l1) { // l1 and l2 swapped! 425 if (l1 instanceof OsmDataLayer && l2 instanceof OsmDataLayer) { 426 if (l1 == getActiveLayer()) return -1; 427 if (l2 == getActiveLayer()) return 1; 428 return Integer.valueOf(getLayerPos(l1)). 429 compareTo(getLayerPos(l2)); 430 } else 431 return Integer.valueOf(getLayerPos(l1)). 432 compareTo(getLayerPos(l2)); 433 } 434 } 435 ); 436 return layers; 355 AffineTransform ax = g2d.getTransform(); 356 g2d.translate(x, y); 357 358 FontRenderContext frc = g2d.getFontRenderContext(); 359 GlyphVector gv = g2d.getFont().createGlyphVector(frc, text); 360 Shape textOutline = gv.getOutline(); 361 362 g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); 363 g2d.setColor(Color.WHITE); 364 g2d.draw(textOutline); 365 366 g2d.setStroke(new BasicStroke()); 367 g2d.setColor(Color.BLACK); 368 g2d.drawString(text, 0, 0); 369 370 g2d.setTransform(ax); 437 371 } 438 372 }
Note:
See TracChangeset
for help on using the changeset viewer.