import java.awt.event.MouseEvent; import java.io.IOException; import java.net.UnknownHostException; import javax.swing.JOptionPane; import com.esri.arcgis.addins.desktop.Tool; import com.esri.arcgis.arcmapui.IMxDocument; import com.esri.arcgis.carto.IActiveView; import com.esri.arcgis.display.IDisplayTransformation; import com.esri.arcgis.display.IScreenDisplay; import com.esri.arcgis.framework.IApplication; import com.esri.arcgis.geometry.IPoint; import com.esri.arcgis.geometry.ISpatialReference; import com.esri.arcgis.geometry.Point; import com.esri.arcgis.geometry.SpatialReferenceEnvironment; import com.esri.arcgis.interop.AutomationException; public class HelloTool extends Tool { /** * Called when the tool is activated by clicking it. * * @exception java.io.IOException if there are interop problems. * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception. */ @Override public void activate() throws IOException, AutomationException { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent mouseEvent) { // TODO Auto-generated method stub super.mousePressed(mouseEvent); try { Point point1 = new Point(); point1.putCoords((double)mouseEvent.getX(), (double)mouseEvent.getY()); Point point2 = (Point) getMapCoordinatesFromScreenCoordinates(point1,av); String message2 = "x: " + point2.getX() + " y: " + point2.getY(); Point point3 = (Point) getScreenCoordinatesFromMapCoorindates(point1,av); String message3 = "x: " + point3.getX() + " y: " + point3.getY(); JOptionPane.showMessageDialog(null, message2, "Map Coordinates from Screen Coordinates", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, message3, "Screen Coordinates from Map Coordinates", JOptionPane.INFORMATION_MESSAGE); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } private IApplication app; private String appName; private IActiveView av; private int mapUnits = com.esri.arcgis.system.esriUnits.esriFeet; @Override public void init(IApplication app){ //Stuff in here runs right away, even if the map document doesn't have the add-in loaded. this.app = app; try { IMxDocument mxDocument = (IMxDocument)app.getDocument(); appName = app.getDocument().getTitle(); av = mxDocument.getActiveView(); } catch (AutomationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public IPoint getMapCoordinatesFromScreenCoordinates(IPoint screenPoint, IActiveView activeView)throws Exception{ if (screenPoint == null || screenPoint.isEmpty() || activeView == null) return null; int nad83HarnAZCentral = com.esri.arcgis.geometry.esriSRProjCSType.esriSRProjCS_NAD1983HARNSPCS_AZCentral; int mapUnits = com.esri.arcgis.system.esriUnits.esriFeet; SpatialReferenceEnvironment spatRef = new SpatialReferenceEnvironment(); ISpatialReference nad83HarnAZC = spatRef.createProjectedCoordinateSystem(nad83HarnAZCentral); IScreenDisplay screenDisplay = activeView.getScreenDisplay(); IDisplayTransformation displayTransformation = screenDisplay.getDisplayTransformation(); displayTransformation.setSpatialReferenceByRef(nad83HarnAZC); displayTransformation.setUnits(mapUnits); return displayTransformation.toMapPoint((int)screenPoint.getX(), (int) screenPoint.getY()); } public IPoint getScreenCoordinatesFromMapCoorindates(IPoint mapPoint, IActiveView activeView)throws Exception{ if (mapPoint == null || mapPoint.isEmpty() || activeView == null) return null; int nad83HarnAZCentral = com.esri.arcgis.geometry.esriSRProjCSType.esriSRProjCS_NAD1983HARNSPCS_AZCentral; int mapUnits = com.esri.arcgis.system.esriUnits.esriFeet; SpatialReferenceEnvironment spatRef = new SpatialReferenceEnvironment(); ISpatialReference nad83HarnAZC = spatRef.createProjectedCoordinateSystem(nad83HarnAZCentral); IScreenDisplay screenDisplay = activeView.getScreenDisplay(); IDisplayTransformation displayTransformation = screenDisplay.getDisplayTransformation(); displayTransformation.setSpatialReferenceByRef(nad83HarnAZC); displayTransformation.setUnits(mapUnits); int x[] = new int[1]; int y[] = new int[1]; displayTransformation.fromMapPoint(mapPoint, x, y); IPoint returnPoint = new Point(); returnPoint.putCoords(x[0], y[0]); return returnPoint; } }
/** * sal = Submit ActionListner * @param sal as <code>ActionListener</code>. */ void addSubmitListener(ActionListener sal){ btnSubmit.addActionListener(sal); }
myView.addSubmitListener(new AddSubmitListener());
/** * Inner class used as the ActionListener for the btnSubmit in class MyView. * @author donahuel * */ class AddSubmitListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { String description = myView.getTxtDescription().getText(); if(description.trim().equals("")){ JOptionPane.showMessageDialog(myView, "Please enter a Description.", "Title", JOptionPane.ERROR_MESSAGE); } else { // Do other stuff } } }
If you specify null, then the look and feel will pick an appropriate position for the dialog �?? generally the center of the screen �?? and the Dialog will not necessarily follow the focus behavior of any visible Frame or Dialog.
If this Window is visible, brings this Window to the front and may make it the focused Window. Places this Window at the top of the stacking order and shows it in front of any other Windows in this VM. No action will take place if this Window is not visible. Some platforms do not allow Windows which own other Windows to appear on top of those owned Windows. Some platforms may not permit this VM to place its Windows above windows of native applications, or Windows of other VMs. This permission may depend on whether a Window in this VM is already focused. Every attempt will be made to move this Window as high as possible in the stacking order; however, developers should not assume that this method will move this Window above all other windows in every situation.
Hello,
This the ONLY thread on the entire internet that discusses the problem I am having. Has there been any headway on the solution using Swing?
Thanks!
Arjun