svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / toolselectrgb / SelectRGBListener.java @ 19224
History | View | Annotate | Download (2.21 KB)
1 | 16591 | nbrodin | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | */
|
||
19 | package org.gvsig.rastertools.toolselectrgb; |
||
20 | |||
21 | import java.awt.geom.Point2D; |
||
22 | import java.awt.image.BufferedImage; |
||
23 | |||
24 | import com.iver.andami.PluginServices; |
||
25 | import com.iver.cit.gvsig.fmap.MapControl; |
||
26 | import com.iver.cit.gvsig.fmap.tools.SelectImageListenerImpl; |
||
27 | import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
||
28 | /**
|
||
29 | 19177 | bsanchez | * Extensi?n de la clase SelectImageListenerImple de FMap. Esta clase permite
|
30 | * capturar el evento de la selecci?n de un punto RGB sobre la vista
|
||
31 | *
|
||
32 | 19224 | bsanchez | * 22/02/2008
|
33 | * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
||
34 | 19177 | bsanchez | */
|
35 | 16591 | nbrodin | public class SelectRGBListener extends SelectImageListenerImpl { |
36 | 19224 | bsanchez | private ISelectRGB selectRGB;
|
37 | 16591 | nbrodin | |
38 | /**
|
||
39 | * Contructor
|
||
40 | * @param mapCtrl
|
||
41 | */
|
||
42 | 19224 | bsanchez | public SelectRGBListener(MapControl mapCtrl, ISelectRGB selectRGB) {
|
43 | 16591 | nbrodin | super(mapCtrl);
|
44 | 19224 | bsanchez | this.selectRGB = selectRGB;
|
45 | 16591 | nbrodin | } |
46 | |||
47 | /* (non-Javadoc)
|
||
48 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
||
49 | */
|
||
50 | public void point(PointEvent event) { |
||
51 | super.point(event);
|
||
52 | |||
53 | 19224 | bsanchez | Point2D point2D = event.getPoint();
|
54 | 16591 | nbrodin | |
55 | if (PluginServices.getMainFrame() != null) |
||
56 | 19177 | bsanchez | PluginServices.getMainFrame().enableControls(); |
57 | |||
58 | 19224 | bsanchez | BufferedImage image = mapCtrl.getImage();
|
59 | int value = image.getRGB((int) point2D.getX(), (int) point2D.getY()); |
||
60 | int r = (value >> 16) & 0xff; |
||
61 | int g = (value >> 8) & 0xff; |
||
62 | int b = value & 0xff; |
||
63 | |||
64 | selectRGB.actionRGBSelected(r, g, b); |
||
65 | 16591 | nbrodin | } |
66 | } |