Re: [OpenMap Users] Custom SelectMouseMode

From: Adam Brightwell <adam.brightwell_at_gmail.com>
Date: Fri, 19 Dec 2008 10:48:34 -0500

Sure... You will need to implement your own method of selection since mine
is VERY specific to my application. I have put a comment where it should go.
Also, most if not all of this is available in the NavMouseMode source. I
just simply replaced the "zoom to rectangle" code with my "select graphics
in rectangle" code, with some other minor changes. Also, you will have to
use create your own subclass of FilterSupport to make the filtering of
graphics work properly (in otherwords, not making them disappear). Don
mentioned something about it in response to this...
http://www.openmap.org/mailArchives/openmap-users/2004-09/3377.html I am not
sure if there is a better way to do this now seeing as how the post if from
2004. I'd be interested to learn though. Code is below in combination with
the mousePressed in my previous post. Cheers, Adam public void
mouseDragged(MouseEvent e) { super.mouseDragged(e); if (e.getSource()
instanceof MapBean) { // clean up the old rectangle, since point2 has the
old // value. paintRectangle((MapBean) e.getSource(), point1, point2); //
paint new rectangle point2 = e.getPoint(); paintRectangle((MapBean)
e.getSource(), point1, point2); } } public void mouseReleased(MouseEvent e)
{ if (Debug.debugging("mousemode")) { Debug.output(getID() +
"|NavMouseMode.mouseReleased()"); } Object obj = e.getSource();
mouseSupport.fireMapMouseReleased(e); if ((obj instanceof MapBean) && point1
!= null && point2 != null) { synchronized (this) { // Determine the height
and width of the selection rectangle. int width = Math.abs(point2.x -
point1.x); int height = Math.abs(point2.y - point1.y); // Create the
selection rectangle. Rectangle rect = new Rectangle(point1.x < point2.x ?
point1.x : point2.x, point1.y < point2.y ? point1.y : point2.y, width,
height); // DO FILTERING/SELECTING HERE!!!!!!! // Reset the selection
rectangle points. point1 = null; point2 = null; // Repaint the map bean.
This will make the selection rectangle // disappear. ((MapBean)
e.getSource()).repaint(); super.mouseClicked(e); } } } protected void
paintRectangle(Graphics g, Point pt1, Point pt2) { if (pt1 != null && pt2 !=
null) { Graphics2D g2 = (Graphics2D) g; Stroke stroke = new BasicStroke(1,
BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0);
g2.setStroke(stroke); g2.setXORMode(java.awt.Color.lightGray);
g2.setColor(java.awt.Color.darkGray); int width = Math.abs(pt2.x - pt1.x);
int height = Math.abs(pt2.y - pt1.y); if (width == 0) width++; if (height ==
0) height++; g2.drawRect(pt1.x < pt2.x ? pt1.x : pt2.x, pt1.y < pt2.y ?
pt1.y : pt2.y, width, height); } } protected void paintRectangle(MapBean
map, Point pt1, Point pt2) { if (map != null) {
paintRectangle(map.getGraphics(), pt1, pt2); } } public void
listenerPaint(Graphics g) { // will be properly rejected if point1, point2
== null paintRectangle(g, point1, point2); }

On Fri, Dec 19, 2008 at 10:18 AM, Benito, Robert P. <rbenito_at_mitre.org>wrote:

> Hi Adam,
>
>
>
> Can you please provide the code that does goal 1?
>
>
>
> Thanks,
> Pat
>
>
>
> *From:* owner-openmap-users_at_bbn.com [mailto:owner-openmap-users_at_bbn.com] *On
> Behalf Of *adam.brightwell_at_gmail.com
> *Sent:* Friday, December 19, 2008 10:07 AM
> *To:* openmap-users_at_bbn.com
> *Subject:* [OpenMap Users] Custom SelectMouseMode
>
>
>
> My goal is to implement a SelectMouseMode that will allow me to do the
> following:
>
> 1) Draw a rectangle around graphics on the map I would like to select.
>
> 2) Select individual graphics by double-clicking them.
>
> 3) Edit (use grab points) on editable graphics when graphic is selected.
>
> I have made the following progress:
>
> 1) Can draw rectangle and select graphics.
>
> 2) Can select graphics with double-click.
>
> My problems surround using the grab points. When "pressing" the mouse
> button on a grab point and dragging, the mouse does not interact with the
> grab point it starts drawing the rectangle again due to the logic associated
> with the mouse being clicked once. I am essentially following the steps from
> the NavMouseMode to draw the rectangle and sub-classing SelectMouseMode. See
> below. Any suggestions?
>
> public void mousePressed(MouseEvent e) {
> boolean isMapBean = (e.getSource() instanceof MapBean);
> e.getComponent().requestFocus();
>
> if (isMapBean) {
> if (isMapBean && e.getClickCount() == 1) {
> point1 = e.getPoint();
> point2 = null;
> } else if (e.getClickCount() == 2) {
> mouseSupport.fireMapMousePressed(e);
> }
> }
> }
>


--
[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 Fri Dec 19 2008 - 10:49:41 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT