Author: chatellier Date: 2010-12-10 15:18:00 +0000 (Fri, 10 Dec 2010) New Revision: 391 Log: Add map sample with ibts map Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/maps/ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/maps/CoserMap.java trunk/coser-ui/src/main/resources/maps/ trunk/coser-ui/src/main/resources/maps/ibts/ trunk/coser-ui/src/main/resources/maps/ibts/pol_ibts.shp trunk/coser-ui/src/main/resources/maps/ibts/pol_ibts.ssx Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-12-10 15:10:35 UTC (rev 390) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-12-10 15:18:00 UTC (rev 391) @@ -514,14 +514,6 @@ selectionView.setHandler(handler); handler.initSelection(selectionView); - try { - File file = new File("/home/chatellier/tmp/coser/zones.png"); - selectionView.getSelectionDetailsTab().getZonesMap().setImage(file); - - } catch(Exception e) { - e.printStackTrace(); - }; - // restore session size SwingSession session = (SwingSession)view.getContextValue(SwingSession.class); session.add(selectionView); @@ -563,13 +555,6 @@ selectionView.setHandler(handler); handler.reloadSelection(selectionView); - try { - File file = new File("/home/chatellier/tmp/coser/zones.png"); - selectionView.getSelectionDetailsTab().getZonesMap().setImage(file); - } catch(Exception e) { - e.printStackTrace(); - }; - // restore session size SwingSession session = (SwingSession)view.getContextValue(SwingSession.class); session.add(selectionView); @@ -637,13 +622,6 @@ // FIXME chatellier 20101126 il faut faire un mix de init && reload handler.initSelection(selectionView); - try { - File file = new File("/home/chatellier/tmp/coser/zones.png"); - selectionView.getSelectionDetailsTab().getZonesMap().setImage(file); - - } catch(Exception e) { - e.printStackTrace(); - }; setMainComponent(selectionView); } catch (Exception ex) { Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/maps/CoserMap.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/maps/CoserMap.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/maps/CoserMap.java 2010-12-10 15:18:00 UTC (rev 391) @@ -0,0 +1,215 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.maps; + +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.bbn.openmap.BufferedMapBean; +import com.bbn.openmap.Layer; +import com.bbn.openmap.LayerHandler; +import com.bbn.openmap.MouseDelegator; +import com.bbn.openmap.event.MapMouseMode; +import com.bbn.openmap.event.NavMouseMode; +import com.bbn.openmap.layer.GraticuleLayer; +import com.bbn.openmap.layer.shape.ShapeLayer; +import com.bbn.openmap.omGraphics.DrawingAttributes; +import com.bbn.openmap.plugin.esri.EsriLayer; + +/** + * Coser map based open openmap. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class CoserMap extends BufferedMapBean { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3134624721243512358L; + + private static Log log = LogFactory.getLog(CoserMap.class); + + protected LayerHandler layerHandler = new LayerHandler(); + + protected MapMouseMode currentMouseMode; + + protected MouseDelegator md; + + protected static final float SCALE = 9500000f; + + public CoserMap() { + setScale(SCALE); + md = new MouseDelegator(this); + md.setDefaultMouseModes(); + setActiveMouseMode(new NavMouseMode()); + layerHandler.addLayerListener(this); + initMap(); + + } + + public void setActiveMouseMode(MapMouseMode mode) { + md.setActiveMouseMode(mode); + currentMouseMode = mode; + // il faut remettre les listeners + /*for (MapMouseListener l : orderedListener) { + currentMouseMode.addMapMouseListener(l); + }*/ + } + + protected void initMap() { + + addGraticuleLayer(); + + addLayer("maps/ibts/pol_ibts.shp", "maps/ibts/pol_ibts.shp", "ff000000", "ffbdde83"); + + } + + protected void addGraticuleLayer() { + GraticuleLayer layer = new GraticuleLayer(); + Properties p = new Properties(); + // Show lat / lon spacing labels + p.setProperty("." + GraticuleLayer.ShowRulerProperty, "true"); + p.setProperty("." + GraticuleLayer.ShowOneAndFiveProperty, "true"); + // Controls when the five degree lines and one degree lines kick in + // - when there is less than the threshold of ten degree lat or lon + // lines, five degree lines are drawn. The same relationship is there + // for one to five degree lines. + p.setProperty("." + GraticuleLayer.ThresholdProperty, "5"); + // the color of 10 degree spacing lines (Hex ARGB) + p.setProperty("." + GraticuleLayer.TenDegreeColorProperty, "FF000000"); + // the color of 5 degree spacing lines (Hex ARGB) + p.setProperty("." + GraticuleLayer.FiveDegreeColorProperty, "C7009900"); + // the color of 1 degree spacing lines (ARGB) + p.setProperty("." + GraticuleLayer.OneDegreeColorProperty, "FF003300"); + // the color of the equator (ARGB) + p.setProperty("." + GraticuleLayer.EquatorColorProperty, "FFFF0000"); + // the color of the international dateline (ARGB) + p.setProperty("." + GraticuleLayer.DateLineColorProperty, "FF000099"); + // the color of the special lines (ARGB) (Tropic of Cancer, Capricorn) + p.setProperty("." + GraticuleLayer.SpecialLineColorProperty, "FF000000"); + // the color of the labels (ARGB) + p.setProperty("." + GraticuleLayer.TextColorProperty, "FF000000"); + + layer.setProperties("", p); + layerHandler.addLayer(layer); + } + + /** + * Add a new layer to the map depending on mapFile extension. + * + * @param layerId layer id + * @param mapFile absolute map fail path + * @param lineColor line color + * @param fillColor fill color + */ + protected void addLayer(String layerId, String mapFile, String lineColor, + String fillColor) { + + Layer layer = null; + // get layer depending on type + if (mapFile.endsWith(".shp")) { + layer = getShapeLayer(layerId, mapFile, lineColor, fillColor); + } + else { + if (log.isErrorEnabled()) { + log.error("Can't find layer for " + mapFile + " (unknown type)"); + } + } + + // display layer + if (layer != null) { + if (log.isDebugEnabled()) { + log.debug("Add layer " + layer); + } + layerHandler.addLayer(layer); + } + } + + /** + * Manage shp layer display. + * + * @param layerId layer id + * @param mapFile absolute map fail path + * @param lineColor line color + * @param fillColor fill color + * + * @return shape layer + * @see ShapeLayer + */ + protected Layer getShapeLayer(String layerId, String mapFile, String lineColor, + String fillColor) { + + if (log.isDebugEnabled()) { + log.debug("Get ShapeLayer with filename : " + mapFile); + } + + ShapeLayer shapeLayer = new ShapeLayer(); + Properties p = new Properties(); + p.setProperty(layerId + "." + ShapeLayer.shapeFileProperty, mapFile); + p.setProperty(layerId + "." + DrawingAttributes.linePaintProperty, lineColor); + p.setProperty(layerId + "." + DrawingAttributes.fillPaintProperty, fillColor); + shapeLayer.setProperties(layerId, p); + shapeLayer.setName(layerId); + + return shapeLayer; + } + + /** + * Manage shp layer display. + * + * @param layerId layer id + * @param mapFile absolute map fail path + * @param lineColor line color + * @param fillColor fill color + * + * @return shape layer + * @see ShapeLayer + */ + protected Layer getEsriLayer(String layerId, String mapFile, String lineColor, + String fillColor) { + + if (log.isDebugEnabled()) { + log.debug("Get ShapeLayer with filename : " + mapFile); + } + + EsriLayer layer = new EsriLayer(); + Properties p = new Properties(); + p.setProperty(layerId + "." + EsriLayer.PARAM_DBF, "maps/ibts/pol_ibts.dbf"); + p.setProperty(layerId + "." + EsriLayer.PARAM_SHP, "maps/ibts/pol_ibts.shp"); + p.setProperty(layerId + "." + EsriLayer.PARAM_SHX, "maps/ibts/pol_ibts.shx"); + p.setProperty(layerId + "." + DrawingAttributes.linePaintProperty, lineColor); + p.setProperty(layerId + "." + DrawingAttributes.fillPaintProperty, fillColor); + layer.setProperties(layerId, p); + layer.setName(layerId); + + return layer; + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/maps/CoserMap.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx 2010-12-10 15:10:35 UTC (rev 390) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx 2010-12-10 15:18:00 UTC (rev 391) @@ -259,9 +259,10 @@ <CardLayout id="detailDecisionPanelLayout" /> <JPanel id="detailDecisionPanel" layout="{detailDecisionPanelLayout}"> - <JScrollPane id="zonesScrollPane" constraints='"ZONEMAP"'> - <JXImageView id="zonesMap" /> - </JScrollPane> + <JPanel layout="{new BorderLayout()}" constraints='"ZONEMAP"'> + <com.bbn.openmap.gui.ToolPanel id='toolMap' javaBean='new com.bbn.openmap.gui.ToolPanel()' constraints='BorderLayout.NORTH' /> + <fr.ifremer.coser.ui.maps.CoserMap constraints='BorderLayout.CENTER' /> + </JPanel> <JScrollPane constraints='"SPECIESDATA"'> <org.nuiton.math.matrix.gui.MatrixPanelEditor id="matrixPanelEditor" /> </JScrollPane> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2010-12-10 15:10:35 UTC (rev 390) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2010-12-10 15:18:00 UTC (rev 391) @@ -69,7 +69,6 @@ import fr.ifremer.coser.services.ProjectService; import fr.ifremer.coser.services.PublicationService; import fr.ifremer.coser.ui.common.DataHandler; -import fr.ifremer.coser.ui.control.ControlView; import fr.ifremer.coser.ui.result.SelectionAddResultDialog; import fr.ifremer.coser.ui.selection.model.OccurrenceDensitySpecyListModel; import fr.ifremer.coser.ui.util.CoserListSelectionModel; Added: trunk/coser-ui/src/main/resources/maps/ibts/pol_ibts.shp =================================================================== (Binary files differ) Property changes on: trunk/coser-ui/src/main/resources/maps/ibts/pol_ibts.shp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/coser-ui/src/main/resources/maps/ibts/pol_ibts.ssx =================================================================== (Binary files differ) Property changes on: trunk/coser-ui/src/main/resources/maps/ibts/pol_ibts.ssx ___________________________________________________________________ Added: svn:mime-type + application/octet-stream