use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class SaveAsPdf method save.
public static void save() {
final Project project = Project.get();
final String directory = "/Users/paustin/Downloads/";
final File file = new File(directory, project.getName() + ".pdf");
try {
final PDDocument document = new PDDocument();
final Viewport2D viewport = project.getViewport();
BoundingBox boundingBox = viewport.getBoundingBox();
final int width = viewport.getViewWidthPixels();
final int height = viewport.getViewHeightPixels();
final int srid = boundingBox.getCoordinateSystemId();
if (srid == 3857) {
boundingBox = boundingBox.convert(boundingBox.getGeometryFactory().getGeographicGeometryFactory());
}
final PDRectangle pageSize = new PDRectangle(width, height);
final PDPage page = new PDPage(pageSize);
try (PdfViewport pdfViewport = new PdfViewport(document, page, project, width, height, boundingBox)) {
final LayerRenderer<? extends Layer> renderer = project.getRenderer();
renderer.render(pdfViewport);
}
document.addPage(page);
final PDDocumentCatalog catalog = document.getDocumentCatalog();
final PDMetadata metadata = new PDMetadata(document);
catalog.setMetadata(metadata);
// jempbox version
final XMPMetadata xmp = new XMPMetadata();
final XMPSchemaDublinCore xmpSchema = new XMPSchemaDublinCore(xmp);
xmp.addSchema(xmpSchema);
xmpSchema.setAbout("");
metadata.importXMPMetadata(xmp);
document.save(file);
} catch (final Throwable e) {
Logs.error(SaveAsPdf.class, "Unable to create PDF " + file, e);
}
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class ZoomOverlay method panStart.
public boolean panStart(final MouseEvent event, final boolean drag) {
if (this.panX1 == -1) {
boolean pan = false;
final int button = event.getButton();
if (button == MouseEvent.BUTTON2) {
pan = true;
this.panButton = MouseEvent.BUTTON2;
} else if (!drag && button == MouseEvent.BUTTON1 && !hasOverlayAction()) {
if (event.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
pan = true;
this.panButton = MouseEvent.BUTTON1;
}
}
if (pan) {
if (setOverlayAction(ACTION_PAN)) {
final Viewport2D viewport = getViewport();
final int width = viewport.getViewWidthPixels();
final int height = viewport.getViewHeightPixels();
if (width > 0 && height > 0) {
final JComponent parent = (JComponent) getParent();
this.panImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
final Graphics2D graphics = (Graphics2D) this.panImage.getGraphics();
try {
final Insets insets = parent.getInsets();
graphics.translate(-insets.left, -insets.top);
graphics.setColor(Color.WHITE);
graphics.fillRect(insets.left, insets.top, width, height);
parent.paintComponents(graphics);
} finally {
graphics.dispose();
}
this.panX1 = this.panX2 = event.getX();
this.panY1 = this.panY2 = event.getY();
final MapPanel map = getMap();
map.setVisibleOverlay(this);
}
return true;
}
}
return false;
} else {
return true;
}
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class ZoomOverlay method mouseClicked.
@Override
public void mouseClicked(final MouseEvent event) {
if (canOverrideOverlayAction(ACTION_ZOOM)) {
final int button = event.getButton();
// Double click
if (event.getClickCount() == 2) {
final int x = event.getX();
final int y = event.getY();
int numSteps = 0;
if (button == MouseEvent.BUTTON1 && !hasOverlayAction() || button == MouseEvent.BUTTON2) {
// Left or middle button, zoom in
numSteps = -1;
} else if (button == MouseEvent.BUTTON3) {
// Right mouse button, zoom out
numSteps = 1;
}
if (numSteps != 0) {
final Viewport2D viewport = getViewport();
final Point mapPoint = viewport.toModelPoint(x, y);
final MapPanel map = getMap();
map.zoom(mapPoint, numSteps);
event.consume();
}
}
}
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class SelectRecordsOverlay method refreshImageSelected.
private GeoreferencedImage refreshImageSelected() {
final Viewport2D viewport = getViewport();
if (viewport != null) {
final int width = viewport.getViewWidthPixels();
final int height = viewport.getViewHeightPixels();
if (width > 0 && height > 0) {
try (final ImageViewport imageViewport = new ImageViewport(viewport, BufferedImage.TYPE_INT_ARGB_PRE);
BaseCloseable transformCloseable = imageViewport.setUseModelCoordinates(true)) {
final Graphics2D graphics = imageViewport.getGraphics();
final Project project = getProject();
refreshImageRenderer(imageViewport, project);
refreshImageSelectedAndHighlighted(imageViewport, graphics, project);
return imageViewport.getGeoreferencedImage();
}
}
}
return null;
}
use of com.revolsys.swing.map.Viewport2D in project com.revolsys.open by revolsys.
the class SelectRecordsOverlay method paintSelectBox.
protected void paintSelectBox(final Graphics2D graphics2d) {
if (this.selectBoxX1 != -1) {
final Viewport2D viewport = getViewport();
final Point2D from = viewport.toViewPoint(this.selectBoxX1, this.selectBoxY1);
final Point2D to = viewport.toViewPoint(this.selectBoxX2, this.selectBoxY2);
final double x1 = from.getX();
final double x2 = to.getX();
final int x = (int) Math.min(x1, x2);
final int width = (int) Math.abs(x1 - x2);
final double y1 = from.getY();
final double y2 = to.getY();
final int y = (int) Math.min(y1, y2);
final int height = (int) Math.abs(y1 - y2);
graphics2d.setColor(COLOR_BOX);
graphics2d.setStroke(BOX_STROKE);
graphics2d.drawRect(x, y, width, height);
graphics2d.setPaint(COLOR_BOX_TRANSPARENT);
graphics2d.fillRect(x, y, width, height);
}
}
Aggregations