use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class EditGeoreferencedImageOverlay method paintComponent.
@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
super.paintComponent(viewport, graphics);
final GeoreferencedImageLayer layer = this.layer;
final GeoreferencedImage image = this.image;
final BoundingBox moveImageBoundingBox = this.moveImageBoundingBox;
if (layer != null && layer.isVisible() && layer.isExists() && image != null) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory();
final boolean showOriginalImage = layer.isShowOriginalImage();
final BoundingBox imageBoundingBox = getImageBoundingBox();
BoundingBox boundingBox = imageBoundingBox;
BoundingBox outlineBoundingBox = boundingBox;
if (moveImageBoundingBox != null) {
if (showOriginalImage) {
boundingBox = moveImageBoundingBox;
}
outlineBoundingBox = moveImageBoundingBox;
}
final GeoreferencedImage cachedImage = getCachedImage(boundingBox);
GeoreferencedImageLayerRenderer.renderAlpha(viewport, graphics, cachedImage, false, layer.getOpacity() / 255.0, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
GeoreferencedImageLayerRenderer.renderDifferentCoordinateSystem(viewport, graphics, imageBoundingBox);
if (outlineBoundingBox != null && !outlineBoundingBox.isEmpty()) {
final Polygon imageBoundary = outlineBoundingBox.convert(getViewportGeometryFactory()).toPolygon(1);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
viewport.drawGeometryOutline(imageBoundary, STYLE_BOX_OUTLINE);
MarkerStyleRenderer.renderMarkerVertices(viewport, graphics, imageBoundary, STYLE_BOX_CORNER);
final List<MappedLocation> tiePoints = image.getTiePoints();
final int tiePointCount = tiePoints.size();
final GeometryFactory viewGeometryFactory = getGeometryFactory();
if (tiePointCount > 0) {
for (final MappedLocation mappedLocation : tiePoints) {
LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
if (line != null) {
line = line.convertGeometry(viewportGeometryFactory);
try (BaseCloseable transformCloseable1 = viewport.setUseModelCoordinates(graphics, true)) {
TIE_POINT_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
}
}
}
for (final MappedLocation mappedLocation : tiePoints) {
LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
if (line != null) {
line = line.convertGeometry(viewportGeometryFactory);
TIE_POINT_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
}
}
}
if (!showOriginalImage) {
final double width = image.getImageWidth() - 1;
final double height = image.getImageHeight() - 1;
final double[] targetCoordinates = MappedLocation.toModelCoordinates(image, boundingBox, true, 0, height, width, height, width, 0, 0, 0, 0, height);
final LineString line = viewGeometryFactory.lineString(2, targetCoordinates);
GeometryStyleRenderer.renderLineString(viewport, graphics, line, STYLE_IMAGE_LINE);
}
}
final MappedLocation moveTiePoint = getMoveTiePoint();
if (moveTiePoint != null) {
final LineString line = moveTiePoint.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
Vertex vertex;
if (this.moveTiePointSource) {
vertex = line.getVertex(0);
} else {
vertex = line.getToVertex(0);
}
TIE_POINT_CLOSE_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, vertex);
}
}
}
drawXorGeometry(graphics);
}
use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method paintComponent.
@Override
public void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
final GeometryFactory geometryFactory2dFloating = getViewportGeometryFactory2d();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (isOverlayAction(ACTION_MOVE_GEOMETRY) && this.moveGeometryStart != null) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
for (final CloseLocation location : this.moveGeometryLocations) {
Geometry geometry = location.getGeometry();
final GeometryFactory geometryFactory = location.getGeometryFactory();
final Point from = this.moveGeometryStart.convertGeometry(geometryFactory);
final Point to = this.moveGeometryEnd.convertGeometry(geometryFactory);
final double deltaX = to.getX() - from.getX();
final double deltaY = to.getY() - from.getY();
geometry = geometry.edit(editor -> editor.move(deltaX, deltaY));
GEOMETRY_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, geometry);
GEOMETRY_VERTEX_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, geometry);
}
}
} else if (this.addGeometryEditor != null) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
final Geometry addGeometry = this.addGeometryEditor.getCurrentGeometry();
GEOMETRY_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, addGeometry);
GEOMETRY_VERTEX_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, addGeometry);
}
}
if (this.moveGeometryStart == null) {
final List<CloseLocation> mouseOverLocations = getMouseOverLocations();
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
for (final CloseLocation location : mouseOverLocations) {
final Geometry geometry = location.getGeometry();
GEOMETRY_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, geometry);
}
}
for (final CloseLocation location : mouseOverLocations) {
final Geometry geometry = location.getGeometry();
GEOMETRY_VERTEX_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, geometry);
if (!isOverlayAction(ACTION_MOVE_GEOMETRY) && !this.addGeometryEditVerticesStart && !this.editGeometryVerticesStart) {
final Vertex vertex = location.getVertex();
if (vertex == null) {
final MarkerStyle style = MarkerStyle.marker("xLine", 9, WebColors.Blue, 3, WebColors.Blue);
final double orientation = location.getSegment().getOrientaton();
final Point pointOnLine = location.getViewportPoint();
MarkerStyleRenderer.renderMarker(viewport, graphics, pointOnLine, style, orientation);
} else {
GEOMETRY_CLOSE_VERTEX_RENDERER.paintSelected(viewport, graphics, geometryFactory2dFloating, vertex);
}
}
}
}
drawXorGeometry(graphics);
}
use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class MapPanel method setBoundingBox.
public synchronized void setBoundingBox(final BoundingBox boundingBox) {
Invoke.later(() -> {
if (this.settingBoundingBox.isFalse()) {
try (BaseCloseable settingBoundingBox = this.settingBoundingBox.closeable(true)) {
final BoundingBox oldBoundingBox = getBoundingBox();
final double oldUnitsPerPixel = getUnitsPerPixel();
final boolean zoomPreviousEnabled = isZoomPreviousEnabled();
final boolean zoomNextEnabled = isZoomNextEnabled();
final BoundingBox resizedBoundingBox = this.viewport.setBoundingBox(boundingBox);
if (this.project != null) {
this.project.setViewBoundingBox(resizedBoundingBox);
// setScale(this.viewport.getScale());
synchronized (this.zoomHistory) {
if (this.updateZoomHistory.isTrue() && !this.viewport.isComponentResizing()) {
BoundingBox currentBoundingBox = null;
if (this.zoomHistoryIndex > -1) {
currentBoundingBox = this.zoomHistory.get(this.zoomHistoryIndex);
if (!currentBoundingBox.equals(resizedBoundingBox)) {
while (this.zoomHistory.size() > this.zoomHistoryIndex + 1) {
this.zoomHistory.removeLast();
}
for (int i = this.zoomHistory.size() - 1; i > this.zoomHistoryIndex; i++) {
this.zoomHistory.remove(i);
}
this.zoomHistory.add(resizedBoundingBox);
this.zoomHistoryIndex = this.zoomHistory.size() - 1;
if (this.zoomHistory.size() > 50) {
this.zoomHistory.removeFirst();
this.zoomHistoryIndex--;
}
}
} else {
this.zoomHistory.add(resizedBoundingBox);
this.zoomHistoryIndex = 0;
}
}
}
firePropertyChange("unitsPerPixel", oldUnitsPerPixel, getUnitsPerPixel());
firePropertyChange("boundingBox", oldBoundingBox, resizedBoundingBox);
firePropertyChange("zoomPreviousEnabled", zoomPreviousEnabled, isZoomPreviousEnabled());
firePropertyChange("zoomNextEnabled", zoomNextEnabled, isZoomNextEnabled());
repaint();
}
}
}
});
}
use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class MarkerStyleRenderer method renderMarker.
public static void renderMarker(final Viewport2D viewport, final Geometry geometry, final MarkerStyle style) {
try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
@SuppressWarnings("deprecation") final Graphics2D graphics = viewport.getGraphics();
if (graphics != null && geometry != null) {
if ("vertices".equals(style.getMarkerPlacementType())) {
renderMarkerVertices(viewport, graphics, geometry, style);
} else if ("segments".equals(style.getMarkerPlacementType())) {
renderMarkerSegments(viewport, graphics, geometry, style);
} else {
for (int i = 0; i < geometry.getGeometryCount(); i++) {
final Geometry part = geometry.getGeometry(i);
if (part instanceof Point) {
final Point point = (Point) part;
renderMarker(viewport, graphics, point, style, 0);
} else if (part instanceof LineString) {
final LineString line = (LineString) part;
renderMarker(viewport, graphics, line, style);
} else if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
renderMarker(viewport, graphics, polygon, style);
}
}
}
}
}
}
use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class TextMarker method render.
@Override
public void render(final Viewport2D viewport, final Graphics2D graphics, final MarkerStyle style, final double modelX, final double modelY, double orientation) {
try (BaseCloseable transformCloseable = new CloseableAffineTransform(graphics)) {
Viewport2D.setUseModelCoordinates(viewport, graphics, false);
final Quantity<Length> markerHeight = style.getMarkerHeight();
final double mapHeight = Viewport2D.toDisplayValue(viewport, markerHeight);
final String orientationType = style.getMarkerOrientationType();
if ("none".equals(orientationType)) {
orientation = 0;
}
final int fontSize = (int) mapHeight;
if (this.font == null || this.font.getSize() != fontSize) {
this.font = Fonts.newFont(this.textFaceName, 0, fontSize);
}
final FontRenderContext fontRenderContext = graphics.getFontRenderContext();
final GlyphVector glyphVector = this.font.createGlyphVector(fontRenderContext, this.text);
final Shape shape = glyphVector.getOutline();
final GeneralPath newShape = new GeneralPath(shape);
final Rectangle2D bounds = newShape.getBounds2D();
final double shapeWidth = bounds.getWidth();
final double shapeHeight = bounds.getHeight();
Viewport2D.translateModelToViewCoordinates(viewport, graphics, modelX, modelY);
final double markerOrientation = style.getMarkerOrientation();
orientation = -orientation + markerOrientation;
if (orientation != 0) {
graphics.rotate(Math.toRadians(orientation));
}
final Quantity<Length> deltaX = style.getMarkerDx();
final Quantity<Length> deltaY = style.getMarkerDy();
double dx = Viewport2D.toDisplayValue(viewport, deltaX);
double dy = Viewport2D.toDisplayValue(viewport, deltaY);
dy -= bounds.getY();
final String verticalAlignment = style.getMarkerVerticalAlignment();
if ("bottom".equals(verticalAlignment)) {
dy -= shapeHeight;
} else if ("auto".equals(verticalAlignment) || "middle".equals(verticalAlignment)) {
dy -= shapeHeight / 2.0;
}
final String horizontalAlignment = style.getMarkerHorizontalAlignment();
if ("right".equals(horizontalAlignment)) {
dx -= shapeWidth;
} else if ("auto".equals(horizontalAlignment) || "center".equals(horizontalAlignment)) {
dx -= shapeWidth / 2;
}
graphics.translate(dx, dy);
if (style.setMarkerFillStyle(viewport, graphics)) {
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
graphics.setFont(this.font);
graphics.drawString(this.text, 0, 0);
}
}
}
Aggregations