gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / multiresolution / ResolutionLevelListener.java @ 1311
History | View | Annotate | Download (5.18 KB)
1 | 680 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.raster.tools.app.basic.tool.multiresolution; |
||
23 | |||
24 | import java.awt.Component; |
||
25 | import java.awt.Image; |
||
26 | import java.awt.event.MouseEvent; |
||
27 | import java.awt.geom.Point2D; |
||
28 | |||
29 | import javax.swing.JOptionPane; |
||
30 | |||
31 | 1174 | nbrodin | import org.gvsig.andami.IconThemeHelper; |
32 | 680 | nbrodin | import org.gvsig.andami.PluginServices; |
33 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
34 | import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
||
35 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
36 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
37 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
38 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
39 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
40 | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
||
41 | import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
||
42 | import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener; |
||
43 | import org.gvsig.raster.fmap.layers.Multiresolution; |
||
44 | import org.slf4j.Logger; |
||
45 | import org.slf4j.LoggerFactory; |
||
46 | |||
47 | /**
|
||
48 | * <p>Inherits {@link ResolutionLevelListenerImpl ResolutionLevelListenerImpl} enabling/disabling special
|
||
49 | * controls for managing the data selected.</p>
|
||
50 | *
|
||
51 | * @see ResolutionLevelListenerImpl
|
||
52 | *
|
||
53 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
54 | */
|
||
55 | public class ResolutionLevelListener implements PointListener { |
||
56 | 1311 | nbrodin | private static final Logger logger = LoggerFactory.getLogger(ResolutionLevelListener.class); |
57 | private Image izoomin = null; |
||
58 | 680 | nbrodin | |
59 | /*
|
||
60 | * (non-Javadoc)
|
||
61 | * @see org.gvsig.fmap.mapcontrol.tools.ResolutionLevelListenerImpl#point(org.gvsig.fmap.mapcontrol.tools.Events.PointEvent)
|
||
62 | */
|
||
63 | 1174 | nbrodin | @SuppressWarnings("deprecation") |
64 | 680 | nbrodin | public void point(PointEvent event) throws BehaviorException { |
65 | //Selects active window
|
||
66 | IWindow theView = PluginServices.getMDIManager().getActiveWindow(); |
||
67 | if(!(theView instanceof AbstractViewPanel)) { |
||
68 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this.getClass(), "window_not_valid")); |
||
69 | return;
|
||
70 | } |
||
71 | |||
72 | //Gets the multiresolution layer
|
||
73 | MapControl mapCtrl = ((AbstractViewPanel)theView).getMapControl(); |
||
74 | FLayers layers = mapCtrl.getMapContext().getLayers(); |
||
75 | Multiresolution lyrMultires = null;
|
||
76 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
77 | if(layers.getLayer(i).isActive() &&
|
||
78 | layers.getLayer(i) instanceof Multiresolution &&
|
||
79 | ((Multiresolution)layers.getLayer(i)).isEnabledMultiresolution()) { |
||
80 | lyrMultires = (Multiresolution)layers.getLayer(i); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | //Shows a message if the layer doesn't exist or there aren't any selected
|
||
85 | if(lyrMultires == null) { |
||
86 | boolean thereAreLayersSelected = false; |
||
87 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
88 | if(layers.getLayer(i).isActive())
|
||
89 | thereAreLayersSelected = true;
|
||
90 | } |
||
91 | String message = null; |
||
92 | if(!thereAreLayersSelected)
|
||
93 | message = PluginServices.getText(this.getClass(), "there_arent_selected"); |
||
94 | else
|
||
95 | message = PluginServices.getText(this.getClass(), "no_resolution_level"); |
||
96 | |||
97 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), message); |
||
98 | return;
|
||
99 | } |
||
100 | |||
101 | //Left button. Zoom +
|
||
102 | if(event.getEvent().getButton() == MouseEvent.BUTTON1) { |
||
103 | if(!lyrMultires.increaseZoomLevel()) {
|
||
104 | 1129 | nbrodin | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this.getClass(), "max_zoom_reached")); |
105 | 680 | nbrodin | return;
|
106 | } |
||
107 | } |
||
108 | |||
109 | //Right button. Zoom -
|
||
110 | if(event.getEvent().getButton() == MouseEvent.BUTTON3) { |
||
111 | if(!lyrMultires.decreaseZoomLevel()) {
|
||
112 | 1129 | nbrodin | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this.getClass(), "min_zoom_reached")); |
113 | 680 | nbrodin | return;
|
114 | } |
||
115 | } |
||
116 | |||
117 | ViewPort viewPort = mapCtrl.getMapContext().getViewPort(); |
||
118 | Point2D center = viewPort.toMapPoint(event.getPoint());
|
||
119 | Envelope r; |
||
120 | try {
|
||
121 | r = lyrMultires.getCoordsInLevel(center, lyrMultires.getZoomLevel(), |
||
122 | viewPort.getImageWidth(), viewPort.getImageHeight()); |
||
123 | } catch (CreateEnvelopeException e) {
|
||
124 | return;
|
||
125 | } |
||
126 | |||
127 | viewPort.setEnvelope(r); |
||
128 | |||
129 | if (PluginServices.getMainFrame() != null) |
||
130 | PluginServices.getMainFrame().enableControls(); |
||
131 | } |
||
132 | |||
133 | public void pointDoubleClick(PointEvent event) throws BehaviorException { |
||
134 | } |
||
135 | |||
136 | public boolean cancelDrawing() { |
||
137 | logger.debug("cancelDrawing true");
|
||
138 | return true; |
||
139 | } |
||
140 | |||
141 | public Image getImageCursor() { |
||
142 | 1311 | nbrodin | if(izoomin == null) |
143 | izoomin = IconThemeHelper.getImage("point-cursor");
|
||
144 | 680 | nbrodin | return izoomin;
|
145 | } |
||
146 | } |