/** * Called as some kind of destructor when the last layer has been removed. Delegates the call to * all Destroyables within this component (e.g. MapModes) */ public void destroy() { MapView.removeLayerChangeListener(this); dialogsPanel.destroy(); for (int i = 0; i < toolBarActions.getComponentCount(); ++i) { if (toolBarActions.getComponent(i) instanceof Destroyable) { ((Destroyable) toolBarActions.getComponent(i)).destroy(); } } for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) { if (toolBarToggle.getComponent(i) instanceof Destroyable) { ((Destroyable) toolBarToggle.getComponent(i)).destroy(); } } // MapFrame gets destroyed when the last layer is removed, but the status line background // thread that collects the information doesn't get destroyed automatically. if (statusLine.thread != null) { try { statusLine.thread.interrupt(); } catch (Exception e) { e.printStackTrace(); } } mapView.destroy(); }
/** * Checks if the given segment is in the visible area. NOTE: This will return true for a small * number of non-visible segments. * * @param ls The segment to check * @return true if the segment is visible */ protected boolean isSegmentVisible(Node n1, Node n2) { Point p1 = mv.getPoint(n1); Point p2 = mv.getPoint(n2); if ((p1.x < 0) && (p2.x < 0)) return false; if ((p1.y < 0) && (p2.y < 0)) return false; if ((p1.x > mv.getWidth()) && (p2.x > mv.getWidth())) return false; if ((p1.y > mv.getHeight()) && (p2.y > mv.getHeight())) return false; return true; }
private void paintBox(Graphics g, MapView mv, EastNorthBound img, Color color) { Point[] croppedPoint = new Point[5]; croppedPoint[0] = mv.getPoint(img.min); croppedPoint[1] = mv.getPoint(new EastNorth(img.min.east(), img.max.north())); croppedPoint[2] = mv.getPoint(img.max); croppedPoint[3] = mv.getPoint(new EastNorth(img.max.east(), img.min.north())); croppedPoint[4] = croppedPoint[0]; for (int i = 0; i < 4; i++) { g.setColor(color); g.drawLine( croppedPoint[i].x, croppedPoint[i].y, croppedPoint[i + 1].x, croppedPoint[i + 1].y); } }
/** * @param zoom level of the tile * @return how many pixels of the screen occupies one pixel of the tile */ private double getTileToScreenRatio(int zoom) { MapView mv = Main.map.mapView; LatLon topLeft = mv.getLatLon(0, 0); LatLon botLeft = mv.getLatLon(0, tileSource.getTileSize()); TileXY topLeftTile = tileSource.latLonToTileXY(topLeft.toCoordinate(), zoom); ICoordinate north = tileSource.tileXYToLatLon(topLeftTile.getXIndex(), topLeftTile.getYIndex(), zoom); ICoordinate south = tileSource.tileXYToLatLon(topLeftTile.getXIndex(), topLeftTile.getYIndex() + 1, zoom); return Math.abs((north.getLat() - south.getLat()) / (topLeft.lat() - botLeft.lat())); }
public void addLayer(Layer layer, boolean showOnButtonList, String icon) { if (layer instanceof MapViewerLayer) { minZoom = Math.max(((MapViewerLayer) layer).getMinZoomLevel(), getMinZoom()); maxZoom = Math.min(((MapViewerLayer) layer).getMaxZoomLevel(), getMaxZoom()); if (zoomFactor > maxZoom || zoomFactor < minZoom) { zoomFactor = (maxZoom + minZoom) / 2; } zoomTo(center, zoom2Scale(zoomFactor)); } if (showOnButtonList) { JToggleButton b = new JToggleButton(layer.name, LogicConstants.getIcon(icon), layer.visible); // b.setVerticalTextPosition(SwingConstants.BOTTOM); // b.setHorizontalTextPosition(SwingConstants.CENTER); b.setActionCommand(layer.name); b.addActionListener(layerControlListener); layerControls.add(b); layerControlPanel.removeAll(); layerControlPanel.add(Box.createHorizontalStrut(10)); for (JToggleButton bt : layerControls) { layerControlPanel.add(bt); layerControlPanel.add(Box.createHorizontalGlue()); } layerControlPanel.updateUI(); } super.addLayer(layer); }
/** * @param newCenter {@link EastNorth} of the new center * @param zoomFactor The OSM zoom facto to zoom to */ public void zoomToFactor(EastNorth newCenter, int zoomFactor) { if (zoomFactor < getMinZoom() || zoomFactor > getMaxZoom()) { return; } this.zoomFactor = zoomFactor; super.zoomTo(newCenter, zoom2Scale(zoomFactor)); }
/** * Draws a circle around the node * * @param n The node * @param color The circle color */ public void drawNode(Node n, Color color) { Point p = mv.getPoint(n); g.setColor(color); if (selected) { g.fillOval(p.x - 5, p.y - 5, 10, 10); } else g.drawOval(p.x - 5, p.y - 5, 10, 10); }
@Override public void zoomChanged() { MapView mv = Main.map.mapView; Bounds bbox = mv.getLatLonBounds(mv.getBounds()); // Have the user changed view since last time if (active && (lastBbox == null || !lastBbox.equals(bbox))) { if (task != null) { task.cancel(); } // wait 500ms before downloading in case the user is in the middle // of a pan/zoom task = new Task(bbox); timer.schedule(task, Main.pref.getInteger("plugin.continuos_download.wait_time", 500)); lastBbox = bbox; } }
/** * Called as some kind of destructor when the last layer has been removed. Delegates the call to * all Destroyables within this component (e.g. MapModes) */ @Override public void destroy() { MapView.removeLayerChangeListener(this); dialogsPanel.destroy(); Main.pref.removePreferenceChangeListener(sidetoolbarPreferencesChangedListener); for (int i = 0; i < toolBarActions.getComponentCount(); ++i) { if (toolBarActions.getComponent(i) instanceof Destroyable) { ((Destroyable) toolBarActions.getComponent(i)).destroy(); } } for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) { if (toolBarToggle.getComponent(i) instanceof Destroyable) { ((Destroyable) toolBarToggle.getComponent(i)).destroy(); } } statusLine.destroy(); mapView.destroy(); }
public void setProjectionBounds(ProjectionBounds bounds) { view_bounds = bounds; if (bounds.maxEast - bounds.minEast > max_east_west) { max_east_west = bounds.maxEast - bounds.minEast; /* We need to set the parent MapView's bounds (i.e. * zoom level) to the same as ours max possible * bounds to avoid WMSLayer thinking we're zoomed * out more than we are or it'll pop up an annoying * "requested area is too large" popup. */ EastNorth parent_center = parent.getCenter(); parent.zoomTo( new ProjectionBounds( new EastNorth(parent_center.east() - max_east_west / 2, parent_center.north()), new EastNorth(parent_center.east() + max_east_west / 2, parent_center.north()))); /* Request again because NavigatableContent adds * a border just to be sure. */ ProjectionBounds new_bounds = parent.getProjectionBounds(); max_east_west = new_bounds.maxEast - new_bounds.minEast; } Point vmin = getPoint(bounds.getMin()); Point vmax = getPoint(bounds.getMax()); int w = vmax.x + 1; int h = vmin.y + 1; if (w <= ground_width && h <= ground_height) { graphics.setClip(0, 0, w, h); return; } if (w > ground_width) ground_width = w; if (h > ground_height) ground_height = h; ground_image = new BufferedImage(ground_width, ground_height, BufferedImage.TYPE_INT_RGB); graphics = ground_image.createGraphics(); graphics.setClip(0, 0, w, h); }
/** If layer is the OSM Data layer, remove all errors */ @Override public void layerRemoved(Layer oldLayer) { if (oldLayer instanceof OsmDataLayer && Main.isDisplayingMapView() && !Main.main.hasEditLayer()) { Main.main.removeLayer(this); } else if (oldLayer == this) { MapView.removeLayerChangeListener(this); OsmValidator.errorLayer = null; } }
public FakeMapView(MapView parent, double scale) { super( null, null, null); // TODO MapView constructor contains registering listeners and other code, that // probably shouldn't be called in fake map view this.parent = parent; this.scale = scale; ProjectionBounds parent_bounds = parent.getProjectionBounds(); max_east_west = parent_bounds.maxEast - parent_bounds.minEast; }
/** * Draw all primitives in this layer but do not draw modified ones (they are drawn by the edit * layer). Draw nodes last to overlap the ways they belong to. */ @Override public void paint(final Graphics g, final MapView mv) { boolean active = true; boolean inactive = false; boolean virtual = false; // draw the hatched area for non-downloaded region. only draw if we're // the active // and bounds are defined; don't draw for inactive layers or loaded GPX // files etc if (active && Main.pref.getBoolean("draw.data.downloaded_area", true) && !data.dataSources.isEmpty()) { // initialize area with current viewport Rectangle b = Main.map.mapView.getBounds(); // on some platforms viewport bounds seem to be offset from the // left, // over-grow it just to be sure b.grow(100, 100); Area a = new Area(b); // now succesively subtract downloaded areas for (DataSource src : data.dataSources) { if (src.bounds != null && !src.bounds.min.equals(src.bounds.max)) { EastNorth en1 = Main.proj.latlon2eastNorth(src.bounds.min); EastNorth en2 = Main.proj.latlon2eastNorth(src.bounds.max); Point p1 = mv.getPoint(en1); Point p2 = mv.getPoint(en2); Rectangle r = new Rectangle( Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); a.subtract(new Area(r)); } } // paint remainder ((Graphics2D) g).setPaint(hatched); ((Graphics2D) g).fill(a); } SimplePaintVisitor painter; if (Main.pref.getBoolean("draw.wireframe")) painter = new SimplePaintVisitor(); else painter = new MapPaintVisitor(); painter.setGraphics(g); painter.setNavigatableComponent(mv); painter.inactive = inactive; painter.visitAll(data, virtual); // Main.map.conflictDialog.paintConflicts(g, mv); }
/** Restores the previous settings in the download dialog. */ public void restoreSettings() { cbDownloadOsmData.setSelected(Main.pref.getBoolean("download.osm", true)); cbDownloadGpxData.setSelected(Main.pref.getBoolean("download.gps", false)); cbNewLayer.setSelected(Main.pref.getBoolean("download.newlayer", false)); cbStartup.setSelected(isAutorunEnabled()); int idx = Main.pref.getInteger("download.tab", 0); if (idx < 0 || idx > tpDownloadAreaSelectors.getTabCount()) { idx = 0; } tpDownloadAreaSelectors.setSelectedIndex(idx); if (Main.isDisplayingMapView()) { MapView mv = Main.map.mapView; currentBounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0)); boundingBoxChanged(currentBounds, null); } else { Bounds bounds = getSavedDownloadBounds(); if (bounds != null) { currentBounds = bounds; boundingBoxChanged(currentBounds, null); } } }
@Override public void removeLayer(Layer layer) { super.removeLayer(layer); int index = -1; for (int i = 0; i < layerControls.size(); i++) { if (layerControls.get(i).getActionCommand().equals(layer.name)) { index = i; break; } } if (index != -1) layerControls.remove(index); layerControlPanel.updateUI(); }
@Override public void paint(Graphics2D g, MapView mv, Bounds box) { LatLon min = box.getMin(); LatLon max = box.getMax(); Envelope envelope2 = new Envelope( Math.min(min.lat(), max.lat()), Math.max(min.lat(), max.lat()), Math.min(min.lon(), max.lon()), Math.max(min.lon(), max.lon())); ReferencedEnvelope mapArea = new ReferencedEnvelope(envelope2, crsOSMI); renderer.setInteractive(false); renderer.paint(g, mv.getBounds(), mapArea); bIsChanged = false; }
/** * Constructs a new <code>RecentRelationsAction</code>. * * @param editButton edit button */ public RecentRelationsAction(SideButton editButton) { this.editButton = editButton; arrow = editButton.createArrow(this); arrow.setToolTipText(tr("List of recent relations")); Main.main.undoRedo.addCommandQueueListener(this); MapView.addLayerChangeListener(this); enableArrow(); shortcut = Shortcut.registerShortcut( "relationeditor:editrecentrelation", tr("Relation Editor: {0}", tr("Open recent relation")), KeyEvent.VK_ESCAPE, Shortcut.SHIFT); Main.registerActionShortcut( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { EditRelationAction.launchEditor(getLastRelation()); } }, shortcut); }
private void hook_up_mouse_events() { mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON1) return; if (isVisible()) { Main.map.mapView.repaint(); } } @Override public void mouseReleased(MouseEvent ev) { if (ev.getButton() != MouseEvent.BUTTON1) return; if (!isVisible()) return; for (int i = data.size() - 1; i >= 0; --i) { ImageEntry e = data.get(i); if (e.getPos() == null) { continue; } Point p = Main.map.mapView.getPoint(e.getPos()); Rectangle r; if (e.thumbnail != null) { Dimension d = scaledDimension(e.thumbnail); r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); } else { r = new Rectangle( p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2, icon.getIconWidth(), icon.getIconHeight()); } if (r.contains(ev.getPoint())) { currentPhoto = i; ImageViewerDialog.showImage(GeoImageLayer.this, e); Main.map.repaint(); break; } } } }; mapModeListener = new MapModeChangeListener() { public void mapModeChange(MapMode oldMapMode, MapMode newMapMode) { if (newMapMode instanceof org.openstreetmap.josm.actions.mapmode.SelectAction) { Main.map.mapView.addMouseListener(mouseAdapter); } else { Main.map.mapView.removeMouseListener(mouseAdapter); } } }; MapFrame.addMapModeChangeListener(mapModeListener); mapModeListener.mapModeChange(null, Main.map.mapMode); MapView.addLayerChangeListener( new LayerChangeListener() { public void activeLayerChange(Layer oldLayer, Layer newLayer) { if (newLayer == GeoImageLayer.this) { // only in select mode it is possible to click the images Main.map.selectSelectTool(false); } } public void layerAdded(Layer newLayer) {} public void layerRemoved(Layer oldLayer) { if (oldLayer == GeoImageLayer.this) { if (thumbsloader != null) { thumbsloader.stop = true; } Main.map.mapView.removeMouseListener(mouseAdapter); MapFrame.removeMapModeChangeListener(mapModeListener); currentPhoto = -1; data.clear(); data = null; // stop listening to layer change events MapView.removeLayerChangeListener(this); } } }); }
@Override public void hookUpMapView() { mouseAdapter = new MouseAdapter() { private boolean isMapModeOk() { return Main.map.mapMode == null || isSupportedMapMode(Main.map.mapMode); } @Override public void mousePressed(MouseEvent e) { if (e.getButton() != MouseEvent.BUTTON1) return; if (isVisible() && isMapModeOk()) { Main.map.mapView.repaint(); } } @Override public void mouseReleased(MouseEvent ev) { if (ev.getButton() != MouseEvent.BUTTON1) return; if (data == null || !isVisible() || !isMapModeOk()) return; for (int i = data.size() - 1; i >= 0; --i) { ImageEntry e = data.get(i); if (e.getPos() == null) { continue; } Point p = Main.map.mapView.getPoint(e.getPos()); Rectangle r; if (useThumbs && e.hasThumbnail()) { Dimension d = scaledDimension(e.getThumbnail()); r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); } else { r = new Rectangle( p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2, icon.getIconWidth(), icon.getIconHeight()); } if (r.contains(ev.getPoint())) { clearOtherCurrentPhotos(); currentPhoto = i; ImageViewerDialog.showImage(GeoImageLayer.this, e); Main.map.repaint(); break; } } } }; mapModeListener = new MapModeChangeListener() { @Override public void mapModeChange(MapMode oldMapMode, MapMode newMapMode) { if (newMapMode == null || isSupportedMapMode(newMapMode)) { Main.map.mapView.addMouseListener(mouseAdapter); } else { Main.map.mapView.removeMouseListener(mouseAdapter); } } }; MapFrame.addMapModeChangeListener(mapModeListener); mapModeListener.mapModeChange(null, Main.map.mapMode); MapView.addLayerChangeListener( new LayerChangeListener() { @Override public void activeLayerChange(Layer oldLayer, Layer newLayer) { if (newLayer == GeoImageLayer.this) { // only in select mode it is possible to click the images Main.map.selectSelectTool(false); } } @Override public void layerAdded(Layer newLayer) {} @Override public void layerRemoved(Layer oldLayer) { if (oldLayer == GeoImageLayer.this) { stopLoadThumbs(); Main.map.mapView.removeMouseListener(mouseAdapter); MapFrame.removeMapModeChangeListener(mapModeListener); currentPhoto = -1; if (data != null) { data.clear(); } data = null; // stop listening to layer change events MapView.removeLayerChangeListener(this); } } }); Main.map.mapView.addPropertyChangeListener(this); if (Main.map.getToggleDialog(ImageViewerDialog.class) == null) { ImageViewerDialog.newInstance(); Main.map.addToggleDialog(ImageViewerDialog.getInstance()); } }
/** * Checks if the given node is in the visible area. * * @param n The node to check for visibility * @return true if the node is visible */ protected boolean isNodeVisible(Node n) { Point p = mv.getPoint(n); return !((p.x < 0) || (p.y < 0) || (p.x > mv.getWidth()) || (p.y > mv.getHeight())); }
@Override public void paint(Graphics2D g, MapView mv, Bounds box) { final int iconHeight = ImageProvider.ImageSizes.SMALLICON.getAdjustedHeight(); final int iconWidth = ImageProvider.ImageSizes.SMALLICON.getAdjustedWidth(); for (Note note : noteData.getNotes()) { Point p = mv.getPoint(note.getLatLon()); ImageIcon icon; if (note.getId() < 0) { icon = ImageProvider.get("dialogs/notes", "note_new", ImageProvider.ImageSizes.SMALLICON); } else if (note.getState() == State.CLOSED) { icon = ImageProvider.get("dialogs/notes", "note_closed", ImageProvider.ImageSizes.SMALLICON); } else { icon = ImageProvider.get("dialogs/notes", "note_open", ImageProvider.ImageSizes.SMALLICON); } int width = icon.getIconWidth(); int height = icon.getIconHeight(); g.drawImage(icon.getImage(), p.x - (width / 2), p.y - height, Main.map.mapView); } if (noteData.getSelectedNote() != null) { StringBuilder sb = new StringBuilder("<html>"); sb.append(tr("Note")).append(' ').append(noteData.getSelectedNote().getId()); for (NoteComment comment : noteData.getSelectedNote().getComments()) { String commentText = comment.getText(); // closing a note creates an empty comment that we don't want to show if (commentText != null && !commentText.trim().isEmpty()) { sb.append("<hr/>"); String userName = XmlWriter.encode(comment.getUser().getName()); if (userName == null || userName.trim().isEmpty()) { userName = "******"; } sb.append(userName); sb.append(" on "); sb.append( DateUtils.getDateFormat(DateFormat.MEDIUM).format(comment.getCommentTimestamp())); sb.append(":<br/>"); String htmlText = XmlWriter.encode(comment.getText(), true); htmlText = htmlText.replace( "
", "<br/>"); // encode method leaves us with entity instead of \n htmlText = htmlText.replace("/", "/\u200b"); // zero width space to wrap long URLs (see #10864) sb.append(htmlText); } } sb.append("</html>"); JToolTip toolTip = new JToolTip(); toolTip.setTipText(sb.toString()); Point p = mv.getPoint(noteData.getSelectedNote().getLatLon()); g.setColor(ColorHelper.html2color(Main.pref.get("color.selected"))); g.drawRect(p.x - (iconWidth / 2), p.y - iconHeight, iconWidth - 1, iconHeight - 1); int tx = p.x + (iconWidth / 2) + 5; int ty = p.y - iconHeight - 1; g.translate(tx, ty); // Carried over from the OSB plugin. Not entirely sure why it is needed // but without it, the tooltip doesn't get sized correctly for (int x = 0; x < 2; x++) { Dimension d = toolTip.getUI().getPreferredSize(toolTip); d.width = Math.min(d.width, mv.getWidth() / 2); if (d.width > 0 && d.height > 0) { toolTip.setSize(d); try { toolTip.paint(g); } catch (IllegalArgumentException e) { // See #11123 - https://bugs.openjdk.java.net/browse/JDK-6719550 // Ignore the exception, as Netbeans does: // http://hg.netbeans.org/main-silver/rev/c96f4d5fbd20 Main.error(e, false); } } } g.translate(-tx, -ty); } }
/** * Change the operating map mode for the view. Will call unregister on the old MapMode and * register on the new one. Now this function also verifies if new map mode is correct mode for * current layer and does not change mode in such cases. * * @param newMapMode The new mode to set. * @return {@code true} if mode is really selected */ public boolean selectMapMode(MapMode newMapMode) { return selectMapMode(newMapMode, mapView.getActiveLayer()); }
/** * Constructs a new {@code MapFrame}. * * @param contentPane The content pane used to register shortcuts in its {@link * javax.swing.InputMap} and {@link javax.swing.ActionMap} * @param viewportData the initial viewport of the map. Can be null, then the viewport is derived * from the layer data. */ public MapFrame(JPanel contentPane, ViewportData viewportData) { setSize(400, 400); setLayout(new BorderLayout()); mapView = new MapView(contentPane, viewportData); new FileDrop(mapView); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); leftPanel = new JPanel(); leftPanel.setLayout(new GridBagLayout()); leftPanel.add(mapView, GBC.std().fill()); splitPane.setLeftComponent(leftPanel); dialogsPanel = new DialogsPanel(splitPane); splitPane.setRightComponent(dialogsPanel); /** All additional space goes to the mapView */ splitPane.setResizeWeight(1.0); /** Some beautifications. */ splitPane.setDividerSize(5); splitPane.setBorder(null); splitPane.setUI( new BasicSplitPaneUI() { @Override public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { @Override public void setBorder(Border b) {} }; } }); // JSplitPane supports F6 and F8 shortcuts by default, but we need them for Audio actions splitPane .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), new Object()); splitPane .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), new Object()); add(splitPane, BorderLayout.CENTER); dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS)); dialogsPanel.setPreferredSize( new Dimension(Main.pref.getInteger("toggleDialogs.width", DEF_TOGGLE_DLG_WIDTH), 0)); dialogsPanel.setMinimumSize(new Dimension(24, 0)); mapView.setMinimumSize(new Dimension(10, 0)); // toolBarActions, map mode buttons addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this))); addMapMode(new IconToggleButton(new LassoModeAction(), true)); addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this))); addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this))); addMapMode(new IconToggleButton(new DeleteAction(this), true)); addMapMode(new IconToggleButton(new ParallelWayAction(this), true)); addMapMode(new IconToggleButton(new ExtrudeAction(this), true)); addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), false)); toolBarActionsGroup.setSelected(allMapModeButtons.get(0).getModel(), true); toolBarActions.setFloatable(false); // toolBarToggles, toggle dialog buttons LayerListDialog.createInstance(this); addToggleDialog(LayerListDialog.getInstance()); addToggleDialog(propertiesDialog = new PropertiesDialog()); addToggleDialog(selectionListDialog = new SelectionListDialog()); addToggleDialog(relationListDialog = new RelationListDialog()); addToggleDialog(new CommandStackDialog()); addToggleDialog(new UserListDialog()); addToggleDialog(new HistoryDialog(), true); addToggleDialog(conflictDialog = new ConflictDialog()); addToggleDialog(validatorDialog = new ValidatorDialog()); addToggleDialog(filterDialog = new FilterDialog()); addToggleDialog(new ChangesetDialog(), true); addToggleDialog(new MapPaintDialog()); toolBarToggle.setFloatable(false); // status line below the map statusLine = new MapStatus(this); MapView.addLayerChangeListener(this); boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null; if (unregisterTab) { for (JComponent c : allDialogButtons) c.setFocusTraversalKeysEnabled(false); for (JComponent c : allMapModeButtons) c.setFocusTraversalKeysEnabled(false); } }
@Override public void paint(Graphics2D g, MapView mv, Bounds bounds) { int width = Main.map.mapView.getWidth(); int height = Main.map.mapView.getHeight(); Rectangle clip = g.getClipBounds(); if (useThumbs) { if (null == offscreenBuffer || offscreenBuffer.getWidth() != width // reuse the old buffer if possible || offscreenBuffer.getHeight() != height) { offscreenBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); updateOffscreenBuffer = true; } if (updateOffscreenBuffer) { Graphics2D tempG = offscreenBuffer.createGraphics(); tempG.setColor(new Color(0, 0, 0, 0)); Composite saveComp = tempG.getComposite(); tempG.setComposite(AlphaComposite.Clear); // remove the old images tempG.fillRect(0, 0, width, height); tempG.setComposite(saveComp); for (ImageEntry e : data) { if (e.getPos() == null) { continue; } Point p = mv.getPoint(e.getPos()); if (e.thumbnail != null) { Dimension d = scaledDimension(e.thumbnail); Rectangle target = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); if (clip.intersects(target)) { tempG.drawImage(e.thumbnail, target.x, target.y, target.width, target.height, null); } } else { // thumbnail not loaded yet icon.paintIcon( mv, tempG, p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2); } } updateOffscreenBuffer = false; } g.drawImage(offscreenBuffer, 0, 0, null); } else { for (ImageEntry e : data) { if (e.getPos() == null) { continue; } Point p = mv.getPoint(e.getPos()); icon.paintIcon(mv, g, p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2); } } if (currentPhoto >= 0 && currentPhoto < data.size()) { ImageEntry e = data.get(currentPhoto); if (e.getPos() != null) { Point p = mv.getPoint(e.getPos()); if (e.thumbnail != null) { Dimension d = scaledDimension(e.thumbnail); g.setColor(new Color(128, 0, 0, 122)); g.fillRect(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); } else { if (e.getExifImgDir() != null) { double arrowlength = 25; double arrowwidth = 18; double dir = e.getExifImgDir(); // Rotate 90 degrees CCW double headdir = (dir < 90) ? dir + 270 : dir - 90; double leftdir = (headdir < 90) ? headdir + 270 : headdir - 90; double rightdir = (headdir > 270) ? headdir - 270 : headdir + 90; double ptx = p.x + Math.cos(Math.toRadians(headdir)) * arrowlength; double pty = p.y + Math.sin(Math.toRadians(headdir)) * arrowlength; double ltx = p.x + Math.cos(Math.toRadians(leftdir)) * arrowwidth / 2; double lty = p.y + Math.sin(Math.toRadians(leftdir)) * arrowwidth / 2; double rtx = p.x + Math.cos(Math.toRadians(rightdir)) * arrowwidth / 2; double rty = p.y + Math.sin(Math.toRadians(rightdir)) * arrowwidth / 2; g.setColor(Color.white); int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx}; int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty}; g.fillPolygon(xar, yar, 4); } selectedIcon.paintIcon( mv, g, p.x - selectedIcon.getIconWidth() / 2, p.y - selectedIcon.getIconHeight() / 2); } } } }
@Override public void paint(Graphics g) { Main.mapView = this; if (follow != null) { follow(); } try { super.paint(g); // Esto ya llama a paintComponents } catch (ConcurrentModificationException ex) { log.warn("Redibujando, datos aun no cargados..."); return; } // ============= DEBUG DEBAJO DE ESTA LINEA ================ // g.drawString( // "zoom: " + zoomFactor + ", angle:" + Math.toDegrees(angle), // 300, 15); // g.drawString((Runtime.getRuntime().freeMemory() / (1024 * 1024)) // + "M / " + (Runtime.getRuntime().totalMemory() / (1024 * 1024)) // + "M", 20, getHeight() - 5); // Rectangle r = getBoundingBox(); // // g.drawRect(r.x + 200, r.y + 200, r.width - 400, r.height - 400); // LatLon tl, br; // tl = getLatLon(r.x, r.y); // br = getLatLon(r.x + r.width, r.y + r.height); // UTM u = new UTM(); // // EastNorth etl = u.latlon2eastNorth(tl); // // EastNorth ebr = u.latlon2eastNorth(br); // EastNorth etl = Main.proj.latlon2eastNorth(tl); // EastNorth ebr = Main.proj.latlon2eastNorth(br); // Point pmi, pma; // pmi = getPoint(etl); // pma = getPoint(ebr); // Rectangle draw = new Rectangle(pmi.x, pma.y, pma.x - pmi.x, pma.y - // pmi.y); // g.setColor(Color.GREEN); // g.drawRect(draw.x + 201, draw.y + 201, draw.width - 402, draw.height // - 402); // g.drawString("+ " + draw, getWidth() / 2, 300); // g.setColor(Color.RED); // g.drawRect(200, 200, getWidth() - 400, getHeight() - 400); // g.setColor(Color.RED); // Point p = getPoint(Main.proj.latlon2eastNorth(getLatLon(getWidth() / // 2, // getHeight() / 2 - 200))); // g.fillOval(p.x - 10, p.y - 10, 20, 20); // g.setColor(Color.BLACK); // g.fillRect(getWidth() / 2 - 5, getHeight() / 2 - 5, 10, 10); // EastNorth mi = getEastNorth(0, getHeight() - 1); // EastNorth ma = getEastNorth(getWidth() - 1, 0); // Point pmi, pma; // pmi = getPoint(mi); // pma = getPoint(ma); // Rectangle r = new Rectangle(pmi.x, pma.y, pma.x - pmi.x, pmi.y - // pma.y); // g.drawString("+ " + r, getWidth() / 2, 300); // g.drawRect(r.x + 200, r.y + 200, r.width - 400, r.height - 400); // LatLon ll = getLatLon(getWidth()/2, getHeight()/2); // g.drawString("+ " + ll.lat() + " x " + ll.lon(), getWidth()/2, // getHeight()/2); // drawCompass(g); }
Point getPoint(LatLon p) { return mv.getPoint(p); }
/** * Draws a line around the segment * * @param s The segment * @param color The color */ public void drawSegment(Node n1, Node n2, Color color) { drawSegment(mv.getPoint(n1), mv.getPoint(n2), color); }
public ChartImage(ImageryInfo info) { super(info); MapView.addZoomChangeListener(this); zoomChanged(); }
@Override public void paint(Graphics2D g, MapView mv, Bounds bounds) { int width = mv.getWidth(); int height = mv.getHeight(); Rectangle clip = g.getClipBounds(); if (useThumbs) { if (!thumbsLoaded) { startLoadThumbs(); } if (null == offscreenBuffer || offscreenBuffer.getWidth() != width // reuse the old buffer if possible || offscreenBuffer.getHeight() != height) { offscreenBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); updateOffscreenBuffer = true; } if (updateOffscreenBuffer) { Graphics2D tempG = offscreenBuffer.createGraphics(); tempG.setColor(new Color(0, 0, 0, 0)); Composite saveComp = tempG.getComposite(); tempG.setComposite(AlphaComposite.Clear); // remove the old images tempG.fillRect(0, 0, width, height); tempG.setComposite(saveComp); if (data != null) { for (ImageEntry e : data) { if (e.getPos() == null) { continue; } Point p = mv.getPoint(e.getPos()); if (e.hasThumbnail()) { Dimension d = scaledDimension(e.getThumbnail()); Rectangle target = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); if (clip.intersects(target)) { tempG.drawImage( e.getThumbnail(), target.x, target.y, target.width, target.height, null); } } else { // thumbnail not loaded yet icon.paintIcon( mv, tempG, p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2); } } } updateOffscreenBuffer = false; } g.drawImage(offscreenBuffer, 0, 0, null); } else if (data != null) { for (ImageEntry e : data) { if (e.getPos() == null) { continue; } Point p = mv.getPoint(e.getPos()); icon.paintIcon(mv, g, p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2); } } if (currentPhoto >= 0 && currentPhoto < data.size()) { ImageEntry e = data.get(currentPhoto); if (e.getPos() != null) { Point p = mv.getPoint(e.getPos()); int imgWidth; int imgHeight; if (useThumbs && e.hasThumbnail()) { Dimension d = scaledDimension(e.getThumbnail()); imgWidth = d.width; imgHeight = d.height; } else { imgWidth = selectedIcon.getIconWidth(); imgHeight = selectedIcon.getIconHeight(); } if (e.getExifImgDir() != null) { // Multiplier must be larger than sqrt(2)/2=0.71. double arrowlength = Math.max(25, Math.max(imgWidth, imgHeight) * 0.85); double arrowwidth = arrowlength / 1.4; double dir = e.getExifImgDir(); // Rotate 90 degrees CCW double headdir = (dir < 90) ? dir + 270 : dir - 90; double leftdir = (headdir < 90) ? headdir + 270 : headdir - 90; double rightdir = (headdir > 270) ? headdir - 270 : headdir + 90; double ptx = p.x + Math.cos(Math.toRadians(headdir)) * arrowlength; double pty = p.y + Math.sin(Math.toRadians(headdir)) * arrowlength; double ltx = p.x + Math.cos(Math.toRadians(leftdir)) * arrowwidth / 2; double lty = p.y + Math.sin(Math.toRadians(leftdir)) * arrowwidth / 2; double rtx = p.x + Math.cos(Math.toRadians(rightdir)) * arrowwidth / 2; double rty = p.y + Math.sin(Math.toRadians(rightdir)) * arrowwidth / 2; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(new Color(255, 255, 255, 192)); int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx}; int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty}; g.fillPolygon(xar, yar, 4); g.setColor(Color.black); g.setStroke(new BasicStroke(1.2f)); g.drawPolyline(xar, yar, 3); } if (useThumbs && e.hasThumbnail()) { g.setColor(new Color(128, 0, 0, 122)); g.fillRect(p.x - imgWidth / 2, p.y - imgHeight / 2, imgWidth, imgHeight); } else { selectedIcon.paintIcon(mv, g, p.x - imgWidth / 2, p.y - imgHeight / 2); } } } }
/** Constructs a new Validator layer */ public ValidatorLayer() { super(tr("Validation errors")); MapView.addLayerChangeListener(this); }