Hello
I have extended the CoordMouseMode class to have a pluggable info
formatter. To use it do something like
distanceMouseMode.class=com.bbn.openmap.event.DistanceMouseMode
distanceMouseMode.infoFormatter=com.bbn.openmap.event.CoordMouseModeDMSInfoFormatter
To create new formatters just extend the CoordMouseModeInfoFormatter.
Here is one that plots the postion in degrees, minutes format.
package com.bbn.openmap.event;
/**
* Copyright NAVICON A/S
* com_at_navicon.dk
*
* extend this class to change the coord formatting in the statusbar
*
*/
import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.MapBean;
import java.text.DecimalFormat;
import java.awt.Component;
import java.text.NumberFormat;
class CoordMouseModeDMSInfoFormatter extends CoordMouseModeInfoFormatter {
public static final String DEGREE_SIGN = "\u00b0";
public transient DecimalFormat df = new DecimalFormat("0.###");
public CoordMouseModeDMSInfoFormatter() {}
public String createCoordinateInformationLine(int x, int y,
LatLonPoint llp,
Object source) {
if (llp != null) {
return "Cursor Position (" + formatLatitude(llp.getLatitude()) + ", "
+ formatLongitude(llp.getLongitude()) + ")";// - scale (" + scale + ")";
} else {
return "Lat, Lon (" + "?" + ", "
+ "?" + ")";// - scale (" + scale + ")";
}
}
public static String formatLatitude(float latitude) {
return formatDegreesMinutes(latitude, 2, latitude < 0 ? "S" : "N");
}
public static String formatLongitude(float longitude) {
return formatDegreesMinutes(longitude, 3, longitude < 0 ? "W" :
"E");
}
public static String formatDegreesMinutes(double value, int integerDigits,
String semisphere) {
double valueAbs = Math.abs(value);
int degrees = (int) valueAbs;
double minutes = (valueAbs - degrees) * 60.0;
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);
nf.setMinimumIntegerDigits(integerDigits);
nf.setMaximumIntegerDigits(integerDigits);
String strDegrees = nf.format(degrees);
nf.setMinimumIntegerDigits(2);
nf.setMaximumIntegerDigits(2);
nf.setMinimumFractionDigits(3);
nf.setMaximumFractionDigits(3);
String strMinutes = nf.format(minutes);
return strDegrees + DEGREE_SIGN + strMinutes + "'" + semisphere;
}
}
And here is the extended CoordMouseMode.java
// **********************************************************************
//
// <copyright>
//
// BBN Technologies
// 10 Moulton Street
// Cambridge, MA 02138
// (617) 873-8000
//
// Copyright (C) BBNT Solutions LLC. All rights reserved.
//
// </copyright>
// **********************************************************************
//
// $Source:
/cvs/distapps/openmap/src/openmap/com/bbn/openmap/event/CoordMouseMode.java,v
$
// $RCSfile: CoordMouseMode.java,v $
// $Revision: 1.5.2.2 $
// $Date: 2004/10/14 18:26:44 $
// $Author: dietrick $
//
// **********************************************************************
package com.bbn.openmap.event;
import java.awt.event.MouseEvent;
import com.bbn.openmap.InformationDelegator;
import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.MapBean;
import com.bbn.openmap.util.Debug;
import com.bbn.openmap.util.PropUtils;
import java.util.Properties;
/**
* The CoordMouseMode is an abstract MouseMode extension to
* AbstractMouseMode that can be used for Modes that want to use the
* BeanContext to hook up with the InformationDelegator, and to send
* coordinate updates to be displayed in the infoline.
*/
public abstract class CoordMouseMode extends AbstractMouseMode {
/**
* The info delegator that will display the distance information
*/
public InformationDelegator infoDelegator = null;
/* defaults to CoordMouseModeInfoFormatter */
private CoordMouseModeInfoFormatter infoFormatter = null;
private static final String InfoFormatterNameProperty = "infoFormatter";
public void setProperties(String prefix, Properties props) {
super.setProperties(prefix, props);
prefix = PropUtils.getScopedPropertyPrefix(prefix);
String infoFormatterClass = props.getProperty(prefix +
InfoFormatterNameProperty,
"com.bbn.openmap.event.CoordMouseModeInfoFormatter");
System.out.println("infoFormatterClass = " + infoFormatterClass + "
prefix=" + prefix);
try {
infoFormatter =
(CoordMouseModeInfoFormatter)Class.forName(infoFormatterClass).newInstance();
} catch(ClassNotFoundException e) {
e.printStackTrace();
} catch(InstantiationException e) {
e.printStackTrace();
} catch(IllegalAccessException e) {
e.printStackTrace();
}
}
public CoordMouseMode() {}
/**
* _at_param modeID the id for the mouse mode.
* _at_param shouldConsumeEvents the mode setting, where the
* mousemode should pass the events on to other listeners
* or not, depending if one of the listeners used it or
* not.
*/
public CoordMouseMode(String modeID, boolean shouldConsumeEvents) {
super(modeID, shouldConsumeEvents);
}
/**
* Set the information delegator.
*
* _at_param id the information delegator that displays the distance
* values.
*/
public void setInfoDelegator(InformationDelegator id) {
infoDelegator = id;
}
/**
* Return the information delegator.
*/
public InformationDelegator getInfoDelegator() {
return infoDelegator;
}
/**
* Fires a mouse location to the InformationDelegator, and then
* calls the super class method which calls the MouseSupport
* method.
*
* _at_param e MouseEvent to be handled
*/
public void mouseMoved(MouseEvent e) {
fireMouseLocation(e);
super.mouseMoved(e);
}
/**
* Fires a mouse location to the InformationDelegator, and then
* calls the super class method which calls the MouseSupport
* method.
*
* _at_param e mouse event.
*/
public void mouseDragged(MouseEvent e) {
fireMouseLocation(e);
super.mouseDragged(e);
}
/**
* If the MouseMode has been made inactive, clean out any input
* that might have been made to the info line.
*/
public void setActive(boolean active) {
if (Debug.debugging("mousemode")) {
Debug.output("CoordMouseMode(" + getPrettyName()
+ "): made active (" + active + ")");
}
if (!active && infoDelegator != null) {
infoDelegator.requestInfoLine(new InfoDisplayEvent(this, "",
InformationDelegator.COORDINATE_INFO_LINE));
}
}
/**
* Sends the mouse event location, x/y and lat/lon, to the
* InformationDelegator.
*/
public void fireMouseLocation(MouseEvent e) {
int x = e.getX();
int y = e.getY();
LatLonPoint llp = null;
Debug.message("mousemodedetail",
"CoordMouseMode: firing mouse location");
if (infoDelegator != null) {
if (e.getSource() instanceof MapBean) {
llp = ((MapBean)
e.getSource()).getProjection().inverse(x, y);
}
String infoLine;
//infoLine = createCoordinateInformationLine(x, y, llp);
if ( infoFormatter == null ) {
infoFormatter = new CoordMouseModeInfoFormatter();
}
infoLine = infoFormatter.createCoordinateInformationLine(x, y,
llp, e.getSource());
// setup the info event
InfoDisplayEvent info = new InfoDisplayEvent(this, infoLine,
InformationDelegator.COORDINATE_INFO_LINE);
// ask the infoDelegator to display the info
infoDelegator.requestInfoLine(info);
}
}
/**
* Method to create the information string reflecting information
* at the LatLonPoint provided. By default, will return a string
* for the x and y, and the lat/lon. If llp is null, just the x, y
* will be returned. This method can be changed, or overridden to
* change what kind of coordinates (UTM, DMS, MGRS) are reflected
* here.
*/
protected String createCoordinateInformationLine(int x, int y,
LatLonPoint llp) {
if (llp != null) {
return "Lat, Lon (" + df.format(llp.getLatitude()) + ", "
+ df.format(llp.getLongitude()) + ") - x, y (" + x + ","
+ y + ")";
} else {
return "x, y (" + x + "," + y + ")";
}
}
/**
* Called when a CoordMouseMode is added to a BeanContext, or when
* another object is added to the BeanContext after that. The
* CoordMouseMode looks for an InformationDelegator to use to fire
* the coordinate updates. If another InforationDelegator is added
* when one is already set, the later one will replace the current
* one.
*
* _at_param someObj an object being added to the BeanContext.
*/
public void findAndInit(Object someObj) {
if (someObj instanceof InformationDelegator) {
Debug.message("mousemode",
"NavMouseMode: found InformationDelegator");
setInfoDelegator((InformationDelegator) someObj);
}
}
/**
* BeanContextMembershipListener method. Called when objects have
* been removed from the parent BeanContext. If an
* InformationDelegator is removed from the BeanContext, and it's
* the same one that is currently held, it will be removed.
*
* _at_param someObj an object being removed from the BeanContext.
*/
public void findAndUndo(Object someObj) {
if (someObj instanceof InformationDelegator) {
if (getInfoDelegator() == (InformationDelegator) someObj) {
setInfoDelegator(null);
}
}
}
}
Chris Hopkins wrote:
>
> Hi all --
>
>
>
> Is there a configurable way to change the resolution of the lat/lon
> values displayed by the information delegator? We'd like to have more
> decimal places than is currently displayed.
>
>
>
> Thanks,
>
> Chris
>
>
>
>
>
>
>
> THIS MESSAGE IS INTENDED FOR THE USE OF THE PERSON TO WHOM IT IS
> ADDRESSED. IT MAY CONTAIN INFORMATION THAT IS PRIVILEGED, CONFIDENTIAL
> AND EXEMPT FROM DISCLOSURE UNDER APPLICABLE LAW. If you are not the
> intended recipient, your use of this message for any purpose is
> strictly prohibited. If you have received this communication in error,
> please delete the message and notify the sender so that we may correct
> our records.
>
>
>
--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed Nov 28 2007 - 13:28:19 EST