false
* @return The virtual nodes property.
* @see Rendering#render(DataSet, boolean, Bounds)
*/
public boolean isVirtualNodesEnabled() {
return virtualNodesEnabled;
}
/**
* Moves the layer to the given new position. No event is fired, but repaints
* according to the new Z-Order of the layers.
*
* @param layer The layer to move
* @param pos The new position of the layer
*/
public void moveLayer(Layer layer, int pos) {
layerManager.moveLayer(layer, pos);
}
@Override
public void layerOrderChanged(LayerOrderChangeEvent e) {
AudioPlayer.reset();
repaint();
}
/**
* Paints the given layer to the graphics object, using the current state of this map view.
* @param layer The layer to draw.
* @param g A graphics object. It should have the width and height of this component
* @throws IllegalArgumentException If the layer is not part of this map view.
* @since 11226
*/
public void paintLayer(Layer layer, Graphics2D g) {
try {
LayerPainter painter = registeredLayers.get(layer);
if (painter == null) {
Logging.warn("Cannot paint layer, it is not registered: {0}", layer);
return;
}
MapViewRectangle clipBounds = getState().getViewArea(g.getClipBounds());
MapViewGraphics paintGraphics = new MapViewGraphics(this, g, clipBounds);
if (layer.getOpacity() < 1) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) layer.getOpacity()));
}
painter.paint(paintGraphics);
g.setPaintMode();
} catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException t) {
BugReport.intercept(t).put("layer", layer).warn();
}
}
/**
* Draw the component.
*/
@Override
public void paint(Graphics g) {
try {
if (!prepareToDraw()) {
return;
}
} catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
BugReport.intercept(e).put("center", this::getCenter).warn();
return;
}
try {
drawMapContent(g);
} catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
throw BugReport.intercept(e).put("visibleLayers", layerManager::getVisibleLayersInZOrder)
.put("temporaryLayers", temporaryLayers);
}
super.paint(g);
}
private void drawMapContent(Graphics g) {
Listtrue
if the view can be drawn, false
otherwise.
*/
public boolean prepareToDraw() {
updateLocationState();
if (initialViewport != null) {
zoomTo(initialViewport);
initialViewport = null;
}
if (getCenter() == null)
return false; // no data loaded yet.
// if the position was remembered, we need to adjust center once before repainting
if (oldLoc != null && oldSize != null) {
Point l1 = getLocationOnScreen();
final EastNorth newCenter = new EastNorth(
getCenter().getX()+ (l1.x-oldLoc.x - (oldSize.width-getWidth())/2.0)*getScale(),
getCenter().getY()+ (oldLoc.y-l1.y + (oldSize.height-getHeight())/2.0)*getScale()
);
oldLoc = null; oldSize = null;
zoomTo(newCenter);
}
return true;
}
@Override
public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
if (Main.map != null) {
/* This only makes the buttons look disabled. Disabling the actions as well requires
* the user to re-select the tool after i.e. moving a layer. While testing I found
* that I switch layers and actions at the same time and it was annoying to mind the
* order. This way it works as visual clue for new users */
// FIXME: This does not belong here.
for (final AbstractButton b: Main.map.allMapModeButtons) {
MapMode mode = (MapMode) b.getAction();
final boolean activeLayerSupported = mode.layerIsSupported(layerManager.getActiveLayer());
if (activeLayerSupported) {
Main.registerActionShortcut(mode, mode.getShortcut()); //fix #6876
} else {
Main.unregisterShortcut(mode.getShortcut());
}
b.setEnabled(activeLayerSupported);
}
}
AudioPlayer.reset();
repaint();
}
/**
* Adds a new temporary layer.
*
* A temporary layer is a layer that is painted above all normal layers. Layers are painted in the order they are added.
*
* @param mvp The layer to paint.
* @return
* This is the only safe method to find changes to the map view, since many components call MapView.repaint() directly.
* @author Michael Zangl
* @since 10600 (functional interface)
*/
@FunctionalInterface
public interface RepaintListener {
/**
* Called when any repaint method is called (using default arguments if required).
* @param tm see {@link JComponent#repaint(long, int, int, int, int)}
* @param x see {@link JComponent#repaint(long, int, int, int, int)}
* @param y see {@link JComponent#repaint(long, int, int, int, int)}
* @param width see {@link JComponent#repaint(long, int, int, int, int)}
* @param height see {@link JComponent#repaint(long, int, int, int, int)}
*/
void repaint(long tm, int x, int y, int width, int height);
}
private final transient CopyOnWriteArrayListtrue
if the layer was added.
*/
public boolean addTemporaryLayer(MapViewPaintable mvp) {
synchronized (temporaryLayers) {
boolean added = temporaryLayers.add(mvp);
if (added) {
invalidatedListener.addTo(mvp);
}
repaint();
return added;
}
}
/**
* Removes a layer previously added as temporary layer.
* @param mvp The layer to remove.
* @return true
if that layer was removed.
*/
public boolean removeTemporaryLayer(MapViewPaintable mvp) {
synchronized (temporaryLayers) {
boolean removed = temporaryLayers.remove(mvp);
if (removed) {
invalidatedListener.removeFrom(mvp);
}
repaint();
return removed;
}
}
/**
* Gets a list of temporary layers.
* @return The layers in the order they are added.
*/
public List