use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class EditGeoreferencedImageOverlay method setLayer.
public void setLayer(final GeoreferencedImageLayer layer) {
final GeoreferencedImageLayer oldLayer = this.layer;
if (oldLayer != layer) {
clear();
this.layer = layer;
final Viewport2D viewport = getViewport();
setGeometryFactory(viewport.getGeometryFactory());
setEnabled(layer != null);
if (layer != null) {
this.image = layer.getImage();
setImageBoundingBox(layer.getBoundingBox());
}
if (oldLayer != null) {
oldLayer.setEditable(false);
}
}
firePropertyChange("layer", oldLayer, layer);
}
use of com.revolsys.swing.map.Viewport2D 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.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class SelectRecordsOverlay method selectBoxFinish.
private boolean selectBoxFinish(final MouseEvent event) {
if (event.getButton() == this.selectBoxButton && this.selectBoxX1 != -1) {
if (clearOverlayAction(ACTION_SELECT_RECORDS)) {
final MapPanel map = getMap();
final GeometryFactory geometryFactory = map.getGeometryFactory();
BoundingBox boundingBox = geometryFactory.newBoundingBox(this.selectBoxX1, this.selectBoxY1, this.selectBoxX2, this.selectBoxY2);
final Viewport2D viewport = getViewport();
final double minSize = viewport.getModelUnitsPerViewUnit() * 10;
final double width = boundingBox.getWidth();
double deltaX = 0;
if (width < minSize) {
deltaX = (minSize - width) / 2;
}
final double height = boundingBox.getWidth();
double deltaY = 0;
if (height < minSize) {
deltaY = (minSize - height) / 2;
}
boundingBox = boundingBox.expand(deltaX, deltaY);
if (!boundingBox.isEmpty()) {
doSelectRecords(event, boundingBox);
}
selectBoxClear();
if (isMouseInMap()) {
setSelectCursor(event);
}
event.consume();
repaint();
return true;
}
}
return false;
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class Print method actionPerformed.
@Override
public void actionPerformed(final ActionEvent event) {
final Project project = Project.get();
final Viewport2D viewport = project.getViewport();
final PrinterJob job = PrinterJob.getPrinterJob();
final PageFormat format = job.defaultPage();
format.setOrientation(PageFormat.PORTRAIT);
final Paper paper = format.getPaper();
paper.setImageableArea(29, 29, format.getWidth() - 58, format.getHeight() - 58);
format.setPaper(paper);
if (this.printService != null) {
try {
job.setPrintService(this.printService);
} catch (final PrinterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
final BoundingBox boundingBox = viewport.getBoundingBox();
final MapPageable pageable = new MapPageable(project, boundingBox, format, 20000, 300, 200);
job.setPageable(pageable);
final boolean doPrint = job.printDialog();
if (doPrint) {
this.printService = job.getPrintService();
Invoke.background("Print", () -> {
try {
job.print();
} catch (final Exception e) {
Logs.error(this, "Unable to print", e);
}
});
}
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class SinglePage method print.
public static void print() {
final Project project = Project.get();
final Viewport2D viewport = project.getViewport();
final int viewWidth = viewport.getViewWidthPixels();
final int viewHeight = viewport.getViewHeightPixels();
final BoundingBox boundingBox = viewport.getBoundingBox();
final double scaleForVisible = viewport.getScaleForVisible();
final PrinterJob job = PrinterJob.getPrinterJob();
job.setJobName(project.getName());
final PageFormat format = job.defaultPage();
final PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
if (boundingBox.getAspectRatio() > 1) {
format.setOrientation(PageFormat.LANDSCAPE);
// printAttributes.add(OrientationRequested.LANDSCAPE);
} else {
format.setOrientation(PageFormat.PORTRAIT);
// printAttributes.add(OrientationRequested.PORTRAIT);
}
final SinglePage pageable = new SinglePage(project, boundingBox, viewWidth, viewHeight, scaleForVisible);
job.setPageable(pageable);
final boolean doPrint = job.printDialog();
if (doPrint) {
Invoke.background("Print", () -> {
try {
job.print();
} catch (final PrinterAbortException e) {
} catch (final Exception e) {
Logs.error(SinglePage.class, "Unable to print", e);
}
});
}
}
Aggregations