Author: echatellier Date: 2017-03-16 11:47:47 +0100 (Thu, 16 Mar 2017) New Revision: 4402 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4402 Log: fixes #8734: Modification de la finesse de la r?\195?\169solution spatiale Added: trunk/src/main/java/fr/ifremer/isisfish/map/DatabaseDataProvider.java trunk/src/main/java/fr/ifremer/isisfish/map/MapDataProvider.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/SpatialChangeDataProvider.java Modified: trunk/src/main/java/fr/ifremer/isisfish/map/CellSelectionLayer.java trunk/src/main/java/fr/ifremer/isisfish/map/IsisMapBean.java trunk/src/main/java/fr/ifremer/isisfish/map/ZoneDelimiterLayer.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/input/cell/CellHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion/FisheryRegionHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/port/PortHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/zone/ZoneBasicsHandler.java trunk/src/main/resources/i18n/isis-fish_en_GB.properties trunk/src/main/resources/i18n/isis-fish_fr_FR.properties Modified: trunk/src/main/java/fr/ifremer/isisfish/map/CellSelectionLayer.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/map/CellSelectionLayer.java 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/map/CellSelectionLayer.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -73,9 +73,9 @@ /** Multi selection enabled. */ public static final int MULT_SELECTION = 2; - public CellSelectionLayer(FisheryRegion fisheryRegion, int selectionMode) + public CellSelectionLayer(MapDataProvider mapDataProvider, int selectionMode) throws TopiaException { - super(fisheryRegion); + super(mapDataProvider); this.selectionMode = selectionMode; } @@ -132,10 +132,8 @@ for (OMGraphic rectg : allRect) { OMRect rect = (OMRect)rectg; // Si le carre est selectionne, on rajoute ses coordonnees au vector results - if (rect.getFillPaint() != null - && !rect.isClear(rect.getFillPaint())) { - result.add(new LatLonPoint.Double(rect.getSouthLat(), rect - .getWestLon())); + if (rect.getFillPaint() != null && !rect.isClear(rect.getFillPaint())) { + result.add(new LatLonPoint.Double(rect.getSouthLat(), rect.getWestLon())); } } return result; @@ -174,8 +172,9 @@ if (select.getFillPaint() == null || select.isClear(select.getFillPaint())) { // Si on est en mode SINGLE_SELECTION, on deselectionne tous les carres avant. - if (getSelectionMode() == SINGLE_SELECTION) + if (getSelectionMode() == SINGLE_SELECTION) { unSelectAll(); + } // on selectionne le carre en lui mettant une couleur de fond select.setFillPaint(Color.green); } @@ -340,7 +339,7 @@ } /** - * Invoked when the mouse tton has been moved on a component + * Invoked when the mouse button has been moved on a component * (with no buttons no down). * @param e MouseListener MouseEvent to handle. * @return true if the listener was able to process the event. Added: trunk/src/main/java/fr/ifremer/isisfish/map/DatabaseDataProvider.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/map/DatabaseDataProvider.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/map/DatabaseDataProvider.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -0,0 +1,79 @@ +package fr.ifremer.isisfish.map; + +import fr.ifremer.isisfish.IsisFishDAOHelper; +import fr.ifremer.isisfish.IsisFishRuntimeException; +import fr.ifremer.isisfish.entities.Cell; +import fr.ifremer.isisfish.entities.CellDAO; +import fr.ifremer.isisfish.entities.FisheryRegion; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; + +import java.util.List; + +public class DatabaseDataProvider extends MapDataProvider { + + protected FisheryRegion fisheryRegion; + + public DatabaseDataProvider(FisheryRegion fisheryRegion) { + this.fisheryRegion = fisheryRegion; + } + + @Override + public float getMinLongitude() { + return fisheryRegion.getMinLongitude(); + } + + @Override + public float getMaxLongitude() { + return fisheryRegion.getMaxLongitude(); + } + + @Override + public float getMinLatitude() { + return fisheryRegion.getMinLatitude(); + } + + @Override + public float getMaxLatitude() { + return fisheryRegion.getMaxLatitude(); + } + + @Override + public float getCellLengthLongitude() { + return fisheryRegion.getCellLengthLongitude(); + } + + @Override + public float getCellLengthLatitude() { + return fisheryRegion.getCellLengthLatitude(); + } + + @Override + public List<Cell> getCell() { + return fisheryRegion.getCell(); + } + + @Override + public List<String> getMapFilePath() { + return fisheryRegion.getMapFilePath(); + } + + @Override + public List<Cell> findAllByCoordinates(float latitude, float longitude) { + return getCellDAO().findAllByProperties("latitude", + latitude, "longitude", longitude); + } + + protected TopiaContext getTopiaContext() { + TopiaContext result = fisheryRegion.getTopiaContext(); + if (result == null) { + throw new IsisFishRuntimeException( + "Can't get topiaContext from FisheryRegion"); + } + return result; + } + + protected CellDAO getCellDAO() throws TopiaException { + return IsisFishDAOHelper.getCellDAO(getTopiaContext()); + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/map/DatabaseDataProvider.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/src/main/java/fr/ifremer/isisfish/map/IsisMapBean.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/map/IsisMapBean.java 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/map/IsisMapBean.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2002 - 2014 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2002 - 2017 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -38,7 +38,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import com.bbn.openmap.Layer; @@ -62,22 +61,11 @@ import com.bbn.openmap.proj.coords.LatLonPoint; import fr.ifremer.isisfish.IsisFish; -import fr.ifremer.isisfish.IsisFishDAOHelper; -import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.entities.Cell; -import fr.ifremer.isisfish.entities.CellDAO; import fr.ifremer.isisfish.entities.FisheryRegion; /** - * IsisMapBean.java - * - * Created: 16 mai 2005 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ + * IsisMapBean. */ public class IsisMapBean extends OverlayMapPanel { @@ -87,7 +75,7 @@ /** to use log facility, just put in your code: log.info("..."); */ private static Log log = LogFactory.getLog(IsisMapBean.class); - protected FisheryRegion fisheryRegion = null; + protected MapDataProvider mapDataProvider; protected float pasMailleLatitude; protected float pasMailleLongitude; protected float minLatitude; @@ -163,32 +151,31 @@ } /** - * Get the value of region. - * @return value of region. + * @deprecated since 4.4.1 use now {@link MapDataProvider} */ - public FisheryRegion getFisheryRegion() { - return fisheryRegion; + @Deprecated + public void setFisheryRegion(FisheryRegion fisheryRegion) { + setMapDataProvider(new DatabaseDataProvider(fisheryRegion)); } - public void setFisheryRegion(FisheryRegion fisheryRegion) { + public void setMapDataProvider(MapDataProvider mapDataProvider) { if (log.isDebugEnabled()) { - log.debug("current fishery is now: " + fisheryRegion + " old was: " - + this.fisheryRegion); + log.debug("Current provider is now: " + mapDataProvider + " old was: " + this.mapDataProvider); } try { - FisheryRegion oldFisheryRegion = this.fisheryRegion; - this.fisheryRegion = fisheryRegion; - if (fisheryRegion == null) { + MapDataProvider oldDataProvider = this.mapDataProvider; + this.mapDataProvider = mapDataProvider; + if (mapDataProvider == null) { layerHandler.removeAll(); } else { - if (!fisheryRegion.equals(oldFisheryRegion)) { - pasMailleLatitude = fisheryRegion.getCellLengthLatitude(); - pasMailleLongitude = fisheryRegion.getCellLengthLongitude(); - minLatitude = fisheryRegion.getMinLatitude(); - minLongitude = fisheryRegion.getMinLongitude(); - maxLatitude = fisheryRegion.getMaxLatitude(); - maxLongitude = fisheryRegion.getMaxLongitude(); + if (!mapDataProvider.equals(oldDataProvider)) { + pasMailleLatitude = mapDataProvider.getCellLengthLatitude(); + pasMailleLongitude = mapDataProvider.getCellLengthLongitude(); + minLatitude = mapDataProvider.getMinLatitude(); + minLongitude = mapDataProvider.getMinLongitude(); + maxLatitude = mapDataProvider.getMaxLatitude(); + maxLongitude = mapDataProvider.getMaxLongitude(); initMap(); } } @@ -199,19 +186,6 @@ } } - protected TopiaContext getTopiaContext() { - TopiaContext result = getFisheryRegion().getTopiaContext(); - if (result == null) { - throw new IsisFishRuntimeException( - "Can't get topiaContext from FisheryRegion"); - } - return result; - } - - protected CellDAO getCellDAO() throws TopiaException { - return IsisFishDAOHelper.getCellDAO(getTopiaContext()); - } - /** * Retourne la liste des mailles selectionnées. * @@ -224,8 +198,7 @@ for (LatLonPoint llp : pts) { List<Cell> cells = null; try { - cells = getCellDAO().findAllByProperties("latitude", - llp.getLatitude(), "longitude", llp.getLongitude()); + cells = mapDataProvider.findAllByCoordinates(llp.getLatitude(), llp.getLongitude()); } catch (TopiaException eee) { log.warn("Can't find cell for this point: " + llp, eee); } @@ -587,7 +560,7 @@ } protected void addZoneDelimiterLayer() throws TopiaException { - ZoneDelimiterLayer layer = new ZoneDelimiterLayer(fisheryRegion); + ZoneDelimiterLayer layer = new ZoneDelimiterLayer(mapDataProvider); addMapComponent(layer); } @@ -626,7 +599,7 @@ // ajout des shapes boolean shapeLoaded = false; - for (String filename : getFisheryRegion().getMapFilePath()) { + for (String filename : mapDataProvider.getMapFilePath()) { if (!StringUtils.isEmpty(filename)) { if (log.isDebugEnabled()) { log.debug(t("isisfish.message.load.map", filename)); @@ -640,7 +613,7 @@ if (log.isDebugEnabled()) { log.debug("Can't load custom map, load default one"); } - // a pas reussi a charger les fichiers demandés, on charge la + // createNewCells pas reussi createNewCells charger les fichiers demandés, on charge la // carte du monde String filename = IsisFish.config.getDefaultMapFilename(); addLayer(filename, filename, lineColor, fillColor); @@ -677,7 +650,7 @@ public void addSelectionLayer() { try { - activeSelectionLayer = new CellSelectionLayer(fisheryRegion, getSelectionMode()); + activeSelectionLayer = new CellSelectionLayer(mapDataProvider, getSelectionMode()); addMapMouseListener(activeSelectionLayer); addMapComponent(activeSelectionLayer); } catch (TopiaException eee) { Added: trunk/src/main/java/fr/ifremer/isisfish/map/MapDataProvider.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/map/MapDataProvider.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/map/MapDataProvider.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -0,0 +1,65 @@ +package fr.ifremer.isisfish.map; + +/* + * #%L + * ISIS-Fish + * %% + * Copyright (C) 2017 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 Public License for more details. + * + * You should have received createNewCells copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.isisfish.entities.Cell; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public abstract class MapDataProvider { + + protected Set<ProviderChangeListener> providerChangeListeners = new HashSet<>(); + + public abstract float getMinLongitude(); + + public abstract float getMaxLongitude(); + + public abstract float getMinLatitude(); + + public abstract float getMaxLatitude(); + + public abstract float getCellLengthLongitude(); + + public abstract float getCellLengthLatitude(); + + public abstract List<String> getMapFilePath(); + + public abstract List<Cell> findAllByCoordinates(float latitude, float longitude); + + public abstract List<Cell> getCell(); + + void addProviderChangeListener(ProviderChangeListener listener) { + providerChangeListeners.add(listener); + } + + void removeProviderChangeListener(ProviderChangeListener listener) { + providerChangeListeners.remove(listener); + } + + interface ProviderChangeListener { + void cellsChanged(Collection<Cell> cells); + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/map/MapDataProvider.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/src/main/java/fr/ifremer/isisfish/map/ZoneDelimiterLayer.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/map/ZoneDelimiterLayer.java 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/map/ZoneDelimiterLayer.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2002 - 2010 Ifremer, CodeLutin + * Copyright (C) 2002 - 2017 Ifremer, CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,18 +25,6 @@ package fr.ifremer.isisfish.map; -import java.awt.Color; -import java.awt.Graphics; -import java.util.Collection; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.event.TopiaTransactionEvent; -import org.nuiton.topia.event.TopiaTransactionListener; -import org.nuiton.topia.persistence.TopiaEntity; - import com.bbn.openmap.Layer; import com.bbn.openmap.event.ProjectionEvent; import com.bbn.openmap.omGraphics.OMGraphic; @@ -43,10 +31,15 @@ import com.bbn.openmap.omGraphics.OMGraphicList; import com.bbn.openmap.omGraphics.OMRect; import com.bbn.openmap.proj.Projection; - import fr.ifremer.isisfish.entities.Cell; -import fr.ifremer.isisfish.entities.FisheryRegion; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; +import java.awt.Color; +import java.awt.Graphics; +import java.util.Collection; + /** * ZoneDelimiterLayer. * @@ -55,8 +48,7 @@ * @author <a href="mailto:seb.regnier@free.fr"></a> * @version $Revision$ */ -public class ZoneDelimiterLayer extends Layer implements - TopiaTransactionListener { //ZoneDelimiterLayer +public class ZoneDelimiterLayer extends Layer implements MapDataProvider.ProviderChangeListener { //ZoneDelimiterLayer /** serialVersionUID. */ private static final long serialVersionUID = 1127201121371123690L; @@ -73,20 +65,17 @@ protected float pasMailleLatitude; protected float pasMailleLongitude; - protected FisheryRegion fisheryRegion; + protected MapDataProvider mapDataProvider; protected Collection<Cell> cells; - public ZoneDelimiterLayer(FisheryRegion fisheryRegion) - throws TopiaException { - this.fisheryRegion = fisheryRegion; + public ZoneDelimiterLayer(MapDataProvider mapDataProvider) throws TopiaException { + this.mapDataProvider = mapDataProvider; - this.pasMailleLatitude = fisheryRegion.getCellLengthLatitude(); - this.pasMailleLongitude = fisheryRegion.getCellLengthLongitude(); + this.pasMailleLatitude = mapDataProvider.getCellLengthLatitude(); + this.pasMailleLongitude = mapDataProvider.getCellLengthLongitude(); - cells = fisheryRegion.getCell(); - TopiaContext topiaContext = fisheryRegion.getTopiaContext(); - topiaContext.addTopiaTransactionListener(this); - //TopiaEntityListener(Cell.class, this); + cells = mapDataProvider.getCell(); + mapDataProvider.addProviderChangeListener(this); this.setVisible(true); generateGraphics(); @@ -146,10 +135,9 @@ (float) (cell.getLongitude() + pasMailleLongitude), OMGraphic.LINETYPE_STRAIGHT); if (cell.isLand()) { - omrect.setLinePaint(new Color(Color.red.getRed(), Color.red - .getGreen(), Color.red.getBlue(), 0));//completement transparent + omrect.setLinePaint(new Color(Color.RED.getRed(), Color.RED.getGreen(), Color.RED.getBlue(), 0)); //completement transparent } else { - omrect.setLinePaint(Color.red); + omrect.setLinePaint(Color.RED); } omrect.setVisible(true); graphics.add(omrect); @@ -159,7 +147,7 @@ protected void refresh() { try { - cells = fisheryRegion.getCell(); + cells = mapDataProvider.getCell(); generateGraphics(); repaint(); } catch (TopiaException eee) { @@ -180,19 +168,26 @@ } @Override - public void commit(TopiaTransactionEvent event) { + public void cellsChanged(Collection<Cell> cells) { + // on rafraichi que si on commit au moins un Cell + refresh(); + } + + /*public void commit(TopiaTransactionEvent event) { for (TopiaEntity e : event.getEntities()) { - if (event.isModification(e) - && Cell.class.isAssignableFrom(e.getClass())) { + if (event.isModification(e) && Cell.class.isAssignableFrom(e.getClass())) { // on rafraichi que si on commit au moins un Cell refresh(); break; } } - } + }*/ - @Override + + + /*@Override public void rollback(TopiaTransactionEvent event) { // nothing to do - } + }*/ + } // ZoneDelimiterLayer Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx 2017-03-16 10:47:47 UTC (rev 4402) @@ -120,11 +120,11 @@ } } -/** +/* * Mettre a jour la region dans une map si necessaire. * * @param map la map a mettre a jour si necessaire - */ + * protected void refreshRegionInMap(fr.ifremer.isisfish.map.IsisMapBean map) { FisheryRegion fisheryRegion = map.getFisheryRegion(); FisheryRegion regionFromContext = getFisheryRegion(); @@ -134,7 +134,7 @@ } map.setFisheryRegion(regionFromContext); } -} +}*/ /** * Method appelée par l'arbre de navigation et le gestionnaire Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -44,7 +44,9 @@ import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import fr.ifremer.isisfish.entities.FisheryRegionImpl; import fr.ifremer.isisfish.logging.RegionChangeLogger; +import fr.ifremer.isisfish.ui.input.spatial.AskNewSpatialUI; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -115,6 +117,7 @@ public InputHandler(InputUI inputUI) { this.inputUI = inputUI; + //inputUI.setContextValue(this); } /** @@ -131,7 +134,7 @@ * * @param name region name to load */ - protected void loadRegion(String name) { + public void loadRegion(String name) { if (log.isDebugEnabled()) { log.debug("Load region " + name); } @@ -657,8 +660,7 @@ FisheryTreeNode newNode = null; if (newNode != null) { newNode = (FisheryTreeNode)typeNodeLoador.createNode(topiaEntity, null); - } - else { + } else { // FIXME echatellier 20110418 cas non résolu du node "population" // pour lequel on n'a pas le loador newNode = new FisheryTreeNode(nodeClass, topiaEntity.getTopiaId(), null, null); @@ -708,12 +710,10 @@ if (parentNode.getInternalClass().equals(Species.class)) { // cas selection du noeud type "Population" speciesId = parentNode.getId(); - } - else if (parentNode.getParent().getInternalClass().equals(Species.class)) { + } else if (parentNode.getParent().getInternalClass().equals(Species.class)) { // cas où on est deja sur une population speciesId = parentNode.getParent().getId(); - } - else { + } else { throw new IsisFishRuntimeException("Not selected tree node"); } @@ -729,4 +729,30 @@ return result; } + + /** + * Changement de la resolution spatiale. + */ + public void changeSpatialResolution() { + InputSaveVerifier inputSaveVerifier = inputUI.getContextValue(InputSaveVerifier.class); + if (inputSaveVerifier.checkEdit() != JOptionPane.CANCEL_OPTION) { + AskNewSpatialUI askNewSpatialUI = new AskNewSpatialUI(inputUI); + + FisheryRegion fisheryRegion = inputUI.getContextValue(FisheryRegion.class); + FisheryRegion newFisheryRegion = new FisheryRegionImpl(); + newFisheryRegion.setName(fisheryRegion.getName()); + newFisheryRegion.setCellLengthLatitude(fisheryRegion.getCellLengthLatitude()); + newFisheryRegion.setCellLengthLongitude(fisheryRegion.getCellLengthLongitude()); + newFisheryRegion.setMaxLatitude(fisheryRegion.getMaxLatitude()); + newFisheryRegion.setMaxLongitude(fisheryRegion.getMaxLongitude()); + newFisheryRegion.setMinLatitude(fisheryRegion.getMinLatitude()); + newFisheryRegion.setMinLongitude(fisheryRegion.getMinLongitude()); + askNewSpatialUI.setContextValue(newFisheryRegion, "newFisheryRegion"); + askNewSpatialUI.setBean(newFisheryRegion); + + askNewSpatialUI.pack(); + askNewSpatialUI.setLocationRelativeTo(inputUI); + askNewSpatialUI.setVisible(true); + } + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx 2017-03-16 10:47:47 UTC (rev 4402) @@ -5,7 +5,7 @@ $Id$ $HeadURL$ %% - Copyright (C) 2009 - 2015 Ifremer, Code Lutin + Copyright (C) 2009 - 2017 Ifremer, Code Lutin %% This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -38,10 +38,11 @@ <JMenu text="isisfish.common.region" id="menuRegion"> <JMenuItem id="menuRegionImport" text="isisfish.input.menu.importRegion" onActionPerformed="handler.importRegion()" /> <JMenuItem id="menuRegionImportRename" text="isisfish.input.menu.importRenameRegion" onActionPerformed="handler.importRegionAndRename()" /> - <JMenuItem text="isisfish.input.menu.importRegionSimulation" onActionPerformed="handler.importRegionFromSimulation()" enabled="false"/> + <JMenuItem id="menuRegionImportSimulation" text="isisfish.input.menu.importRegionSimulation" onActionPerformed="handler.importRegionFromSimulation()" enabled="false"/> <JMenuItem id="menuRegionExport" text="isisfish.input.menu.exportRegion" enabled='{isRegionLoaded()}' onActionPerformed="handler.exportRegion()" /> <JMenuItem id="menuExportJson" text="isisfish.input.menu.exportJson" enabled='{isRegionLoaded()}' onActionPerformed="handler.exportEntityJson()" /> <JMenuItem id="menuImportJson" text="isisfish.input.menu.importJson" enabled='{isRegionLoaded()}' onActionPerformed="handler.importEntityJson()" /> + <JMenuItem id="menuChangeResolution" text="isisfish.input.menu.changeResolution" enabled='{isRegionLoaded()}' onActionPerformed="handler.changeSpatialResolution()" /> <JMenuItem id="menuRegionCopy" text="isisfish.input.menu.copyRegion" enabled='{isRegionLoaded()}' onActionPerformed="handler.copyRegion()" /> <JSeparator/> <JMenuItem text="isisfish.input.menu.removeLocaly" enabled='{isRegionLoaded()}' onActionPerformed="handler.removeRegion(false)" /> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/cell/CellHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/cell/CellHandler.java 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/cell/CellHandler.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -34,6 +34,7 @@ import com.bbn.openmap.event.SelectMouseMode; import fr.ifremer.isisfish.entities.Cell; +import fr.ifremer.isisfish.entities.FisheryRegion; import fr.ifremer.isisfish.map.CellSelectionLayer; import fr.ifremer.isisfish.map.OpenMapEvents; import fr.ifremer.isisfish.ui.input.InputContentHandler; @@ -96,6 +97,8 @@ } inputContentUI.fieldCell.setModel(cellModel); init = false; + // hack because fishery region is not binded + inputContentUI.getCellMap().setFisheryRegion(inputContentUI.getContextValue(FisheryRegion.class)); } }); } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion/FisheryRegionHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion/FisheryRegionHandler.java 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion/FisheryRegionHandler.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -3,7 +3,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2015 Ifremer, Codelutin + * Copyright (C) 2015 - 2017 Ifremer, Codelutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -67,8 +67,6 @@ } protected void afterInit() { - //cellMap.init(cellMapInfo); - inputContentUI.setButtonTitle(t("isisfish.input.continueCells")); inputContentUI.setNextPath(n("isisfish.input.tree.cells")); @@ -79,13 +77,6 @@ } if (evt.getNewValue() != null) { setFieldMapfilesModel(inputContentUI.getBean()); - /* numberEditor is not working - fieldLatMin.init(); - fieldLatMax.init(); - fieldLongMin.init(); - fieldLongMax.init(); - fieldCellLengthLatitude.init(); - fieldCellLengthLongitude.init();*/ } } }); @@ -233,10 +224,6 @@ } } - /*protected void cellFile() { - getInputAction().loadCellFile(fieldCellFile.getText()); - }*/ - protected void check() { checkFisheryRegion(inputContentUI.getBean()); inputContentUI.setInfoText(t("isisfish.message.check.finished")); @@ -285,20 +272,6 @@ try { TopiaContext isisContext = fisheryRegion.getTopiaContext(); - // frame.setInfoText(t("isisfish.message.checking.cell")); - int latNumber = Math - .round((fisheryRegion.getMaxLatitude() - fisheryRegion - .getMinLatitude()) - / fisheryRegion.getCellLengthLatitude()); - int lonNumber = Math - .round((fisheryRegion.getMaxLongitude() - fisheryRegion - .getMinLongitude()) - / fisheryRegion.getCellLengthLongitude()); - - // frame.setProgressMin(0); - // frame.setProgressMax(latNumber * lonNumber); - int progresscpt = 0; - // il faut peut-etre creer ou supprimer des mailles CellPointcomparator cellPointcomparator = new CellPointcomparator(); CellDAO cellPS = IsisFishDAOHelper.getCellDAO(isisContext); @@ -306,18 +279,15 @@ Collections.sort(cells, cellPointcomparator); Point2D.Float point = new Point2D.Float(); - for (float lati = fisheryRegion.getMinLatitude(); lati < fisheryRegion - .getMaxLatitude(); lati += fisheryRegion - .getCellLengthLatitude()) { + for (float lati = fisheryRegion.getMinLatitude(); lati < fisheryRegion.getMaxLatitude(); + lati += fisheryRegion.getCellLengthLatitude()) { lati = Math.round(lati * 1000f); lati = lati / 1000.0f; - for (float longi = fisheryRegion.getMinLongitude(); longi < fisheryRegion - .getMaxLongitude(); longi += fisheryRegion - .getCellLengthLongitude()) { + for (float longi = fisheryRegion.getMinLongitude(); longi < fisheryRegion.getMaxLongitude(); + longi += fisheryRegion.getCellLengthLongitude()) { longi = Math.round(longi * 1000f) / 1000.0f; point.setLocation(lati, longi); - int position = Collections.binarySearch(cells, point, - cellPointcomparator); + int position = Collections.binarySearch(cells, point, cellPointcomparator); if (position >= 0) { // deja existant on l'enleve de la liste, et on ne cree rien cells.remove(position); @@ -330,7 +300,6 @@ cell.setLand(false); cell.update(); } - // frame.setProgressValue(++progresscpt); } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/port/PortHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/port/PortHandler.java 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/port/PortHandler.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -33,6 +33,7 @@ import com.bbn.openmap.event.SelectMouseMode; import fr.ifremer.isisfish.entities.Cell; +import fr.ifremer.isisfish.entities.FisheryRegion; import fr.ifremer.isisfish.map.CellSelectionLayer; import fr.ifremer.isisfish.map.OpenMapEvents; import fr.ifremer.isisfish.ui.input.InputContentHandler; @@ -83,6 +84,8 @@ } fillCellList(); + // hack because fishery region is not binded + inputContentUI.getPortMap().setFisheryRegion(inputContentUI.getContextValue(FisheryRegion.class)); } }); } Added: trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialHandler.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialHandler.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -0,0 +1,217 @@ +/* + * #%L + * ISIS-Fish + * %% + * Copyright (C) 2017 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.input.spatial; + +import fr.ifremer.isisfish.entities.Cell; +import fr.ifremer.isisfish.entities.CellImpl; +import fr.ifremer.isisfish.entities.FisheryRegion; +import fr.ifremer.isisfish.entities.Port; +import fr.ifremer.isisfish.entities.Zone; +import fr.ifremer.isisfish.util.CellPointcomparator; + +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Handler for new fishery region resolution dialog. + */ +public class AskNewSpatialHandler { + + protected AskNewSpatialUI ui; + + public AskNewSpatialHandler(AskNewSpatialUI ui) { + this.ui = ui; + } + + public void performSpatialChange() { + FisheryRegion currentFisheryRegion = ui.getContextValue(FisheryRegion.class); + + // compute new cells + FisheryRegion newFisheryRegion = this.ui.getBean(); + List<Cell> newCells = createNewCells(newFisheryRegion, currentFisheryRegion); + + // compute new zones + Map<Zone, List<Cell>> zoneMap = createNewZones(newCells, newFisheryRegion, currentFisheryRegion); + Map<Port, Cell> portMap = createNewPorts(newCells, newFisheryRegion, currentFisheryRegion); + + // display next view + ChangeSpatialPreviewUI changeSpatialPreviewUI = new ChangeSpatialPreviewUI(this.ui); + changeSpatialPreviewUI.getHandler().setOldFisheryRegion(currentFisheryRegion); + changeSpatialPreviewUI.getHandler().setNewFisheryRegion(newFisheryRegion); + changeSpatialPreviewUI.getHandler().setCells(newCells); + changeSpatialPreviewUI.getHandler().setZoneMap(zoneMap); + changeSpatialPreviewUI.getHandler().setPortMap(portMap); + changeSpatialPreviewUI.getHandler().completeSetup(); + changeSpatialPreviewUI.pack(); + changeSpatialPreviewUI.setLocationRelativeTo(this.ui); + changeSpatialPreviewUI.setVisible(true); + + this.ui.dispose(); + } + + /** + * Create new cells for new resolution and use old region {@code isLand()} info. + * + * @param newFisheryRegion new fichery region + * @param currentFisheryRegion old fishery region (for matching) + * @return new cells + */ + protected List<Cell> createNewCells(FisheryRegion newFisheryRegion, FisheryRegion currentFisheryRegion) { + List<Cell> currentCells = currentFisheryRegion.getCell(); + + CellPointcomparator cellPointcomparator = new CellPointcomparator(); + Collections.sort(currentCells, cellPointcomparator); + List<Cell> cells = new ArrayList<>(); + + Rectangle2D.Float intersect = new Rectangle2D.Float(); + + for (float lati = newFisheryRegion.getMinLatitude(); lati < newFisheryRegion.getMaxLatitude(); + lati += newFisheryRegion.getCellLengthLatitude()) { + lati = Math.round(lati * 1000f); + lati = lati / 1000.0f; + for (float longi = newFisheryRegion.getMinLongitude(); longi < newFisheryRegion.getMaxLongitude(); + longi += newFisheryRegion.getCellLengthLongitude()) { + longi = Math.round(longi * 1000f) / 1000.0f; + + // n'existe pas on la cree + Cell cell = new CellImpl(); + cell.setName("La" + lati + "Lo" + longi); + cell.setLatitude(lati); + cell.setLongitude(longi); + cell.setLand(false); + cells.add(cell); + + Rectangle2D.Float cellRect = new Rectangle2D.Float(cell.getLatitude(), cell.getLongitude(), + newFisheryRegion.getCellLengthLatitude(), newFisheryRegion.getCellLengthLongitude()); + for (Cell currentCell : currentCells) { + Rectangle2D.Float curCellRect = new Rectangle2D.Float(currentCell.getLatitude(), + currentCell.getLongitude(), currentFisheryRegion.getCellLengthLatitude(), + currentFisheryRegion.getCellLengthLongitude()); + double overlap = intersectPercentage(cellRect, curCellRect, intersect); + + if (overlap >= 0.5) { + cell.setLand(currentCell.isLand()); + } + } + } + } + return cells; + } + + /** + * Create new zones filled with cells from new region. + * + * @param newCells new cells + * @param newFisheryRegion new region + * @param currentFisheryRegion old region + * @return map between current zone and new cell for this zone + */ + protected Map<Zone, List<Cell>> createNewZones(List<Cell> newCells, FisheryRegion newFisheryRegion, FisheryRegion currentFisheryRegion) { + Map<Zone, List<Cell>> zonesAndNewCells = new HashMap<>(); + List<Zone> zones = currentFisheryRegion.getZone(); + Rectangle2D.Float intersect = new Rectangle2D.Float(); + + for (Zone zone : zones) { + List<Cell> zoneNewCells = new ArrayList<>(); + for (Cell newCell : newCells) { + Rectangle2D.Float newCellRect = new Rectangle2D.Float(newCell.getLatitude(), newCell.getLongitude(), + newFisheryRegion.getCellLengthLatitude(), newFisheryRegion.getCellLengthLongitude()); + for (Cell currentCell : zone.getCell()) { + Rectangle2D.Float currentCellRect = new Rectangle2D.Float(currentCell.getLatitude(), currentCell.getLongitude(), + currentFisheryRegion.getCellLengthLatitude(), currentFisheryRegion.getCellLengthLongitude()); + double overlap = intersectPercentage(newCellRect, currentCellRect, intersect); + if (overlap >= 0.5) { + zoneNewCells.add(newCell); + } + } + } + zonesAndNewCells.put(zone, zoneNewCells); + } + + return zonesAndNewCells; + } + + /** + * Create new port filled with cell from new region. + * + * @param newCells new cells + * @param newFisheryRegion new region + * @param currentFisheryRegion old region + * @return map between current ports and new cell for this zone + */ + protected Map<Port, Cell> createNewPorts(List<Cell> newCells, FisheryRegion newFisheryRegion, FisheryRegion currentFisheryRegion) { + Map<Port, Cell> portsAndNewCells = new HashMap<>(); + List<Port> ports = currentFisheryRegion.getPort(); + Rectangle2D.Float intersect = new Rectangle2D.Float(); + + for (Port port : ports) { + + Cell currentCell = port.getCell(); + if (currentCell != null) { + Cell portNewCell = null; + double bestMatch = Double.MIN_VALUE; + + Rectangle2D.Float currentCellRect = new Rectangle2D.Float(currentCell.getLatitude(), currentCell.getLongitude(), + currentFisheryRegion.getCellLengthLatitude(), currentFisheryRegion.getCellLengthLongitude()); + for (Cell newCell : newCells) { + Rectangle2D.Float newCellRect = new Rectangle2D.Float(newCell.getLatitude(), newCell.getLongitude(), + newFisheryRegion.getCellLengthLatitude(), newFisheryRegion.getCellLengthLongitude()); + double overlap = intersectPercentage(newCellRect, currentCellRect, intersect); + if (overlap >= bestMatch) { + portNewCell = newCell; + bestMatch = overlap; + } + } + + portsAndNewCells.put(port, portNewCell); + } + + } + + return portsAndNewCells; + } + + /** + * Intersection percentage between two rectangle (comparative to the min area of the two rectangle). + * + * @param r1 first rect + * @param r2 second rect + * @param intersect computed intersection + * @return intersection percentage + */ + protected double intersectPercentage(Rectangle2D.Float r1, Rectangle2D.Float r2, Rectangle2D.Float intersect) { + Rectangle2D.intersect(r1, r2, intersect); + double result = 0; + double fr1 = r1.getWidth() * r1.getHeight(); // area of "r1" + double fr2 = r2.getWidth() * r2.getHeight(); // area of "r2" + double fr = Math.min(fr1, fr2); + if (fr > 0 && intersect.getWidth() > 0 && intersect.getHeight() > 0) { + double f = intersect.getWidth() * intersect.getHeight(); // area of "r" - overlap + result = f / fr; // overlap percentage + } + return result; + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialHandler.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Copied: trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialUI.jaxx (from rev 4395, trunk/src/main/java/fr/ifremer/isisfish/ui/input/species/SpeciesUI.jaxx) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialUI.jaxx (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/AskNewSpatialUI.jaxx 2017-03-16 10:47:47 UTC (rev 4402) @@ -0,0 +1,103 @@ +<!-- + #%L + IsisFish + + $Id$ + $HeadURL$ + %% + Copyright (C) 2017 Ifremer, Code Lutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<JFrame layout='{new BorderLayout()}' title="isisfish.input.menu.changeResolution"> + + <!-- bean property --> + <fr.ifremer.isisfish.entities.FisheryRegion id='bean' javaBean='null' /> + + <AskNewSpatialHandler id="handler" constructorParams="this" /> + + <Table constraints='BorderLayout.CENTER'> + <row> + <cell columns='3'> + <JLabel text="isisfish.fisheryRegion.area"/> + </cell> + </row> + <row> + <cell> + <JLabel text="isisfish.fisheryRegion.latitude.min"/> + </cell> + <cell fill='horizontal' weightx='1.0'> + <JTextField id="fieldLatMin" text='{String.valueOf(getBean().getMinLatitude())}' decorator='boxed' + onKeyReleased='getBean().setMinLatitude(Float.parseFloat(fieldLatMin.getText()))'/> + </cell> + </row> + <row> + <cell> + <JLabel text="isisfish.fisheryRegion.latitude.max"/> + </cell> + <cell fill='horizontal' weightx='1.0'> + <JTextField id="fieldLatMax" text='{String.valueOf(getBean().getMaxLatitude())}' decorator='boxed' + onKeyReleased='getBean().setMaxLatitude(Float.parseFloat(fieldLatMax.getText()))'/> + </cell> + </row> + <row> + <cell> + <JLabel text="isisfish.fisheryRegion.longitude.min"/> + </cell> + <cell fill='horizontal' weightx='1.0'> + <JTextField id="fieldLongMin" text='{String.valueOf(getBean().getMinLongitude())}' decorator='boxed' + onKeyReleased='getBean().setMinLongitude(Float.parseFloat(fieldLongMin.getText()))'/> + </cell> + </row> + <row> + <cell> + <JLabel text="isisfish.fisheryRegion.longitude.max"/> + </cell> + <cell fill='horizontal' weightx='1.0'> + <JTextField id="fieldLongMax" text='{String.valueOf(getBean().getMaxLongitude())}' decorator='boxed' + onKeyReleased='getBean().setMaxLongitude(Float.parseFloat(fieldLongMax.getText()))'/> + </cell> + </row> + <row> + <cell columns='3'> + <JLabel text="isisfish.fisheryRegion.spatial"/> + </cell> + </row> + <row> + <cell> + <JLabel text="isisfish.fisheryRegion.latitude"/> + </cell> + <cell fill='horizontal' weightx='1.0'> + <JTextField id="fieldCellLengthLatitude" text='{String.valueOf(getBean().getCellLengthLatitude())}' decorator='boxed' + onKeyReleased='getBean().setCellLengthLatitude(Float.parseFloat(fieldCellLengthLatitude.getText()))'/> + </cell> + </row> + <row> + <cell> + <JLabel text="isisfish.fisheryRegion.longitude"/> + </cell> + <cell fill='horizontal' weightx='1.0'> + <JTextField id="fieldCellLengthLongitude" text='{String.valueOf(getBean().getCellLengthLongitude())}' decorator='boxed' + onKeyReleased='getBean().setCellLengthLongitude(Float.parseFloat(fieldCellLengthLongitude.getText()))'/> + </cell> + </row> + <row> + <cell anchor='east' columns="2"> + <JButton text="isisfish.changeSpatial.changeSpatial" onActionPerformed="handler.performSpatialChange()"/> + </cell> + </row> + </Table> +</JFrame> Added: trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewHandler.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewHandler.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -0,0 +1,234 @@ +/* + * #%L + * ISIS-Fish + * %% + * Copyright (C) 2017 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.input.spatial; + +import static org.nuiton.i18n.I18n.t; + +import com.bbn.openmap.event.SelectMouseMode; +import fr.ifremer.isisfish.IsisFishDAOHelper; +import fr.ifremer.isisfish.entities.Cell; +import fr.ifremer.isisfish.entities.CellDAO; +import fr.ifremer.isisfish.entities.FisheryRegion; +import fr.ifremer.isisfish.entities.Port; +import fr.ifremer.isisfish.entities.Zone; +import fr.ifremer.isisfish.map.CellSelectionLayer; +import fr.ifremer.isisfish.map.DatabaseDataProvider; +import fr.ifremer.isisfish.map.OpenMapEvents; +import fr.ifremer.isisfish.ui.input.InputSaveVerifier; +import fr.ifremer.isisfish.ui.input.InputUI; +import fr.ifremer.isisfish.ui.models.common.GenericComboModel; +import jaxx.runtime.JAXXUtil; + +import javax.swing.JOptionPane; +import java.awt.event.MouseEvent; +import java.util.List; +import java.util.Map; + +/** + * Handler fro preview spatial change UI. + */ +public class ChangeSpatialPreviewHandler { + + protected ChangeSpatialPreviewUI inputUI; + + protected Map<Zone, List<Cell>> zoneMap; + + protected Map<Port, Cell> portMap; + + protected List<Cell> cells; + + protected FisheryRegion oldFisheryRegion; + + protected FisheryRegion newFisheryRegion; + + public ChangeSpatialPreviewHandler(ChangeSpatialPreviewUI inputUI) { + this.inputUI = inputUI; + } + + public void setCells(List<Cell> cells) { + this.cells = cells; + } + + public void setZoneMap(Map<Zone, List<Cell>> zoneMap) { + this.zoneMap = zoneMap; + } + + public void setPortMap(Map<Port, Cell> portMap) { + this.portMap = portMap; + } + + public void setNewFisheryRegion(FisheryRegion newFisheryRegion) { + this.newFisheryRegion = newFisheryRegion; + } + + public void setOldFisheryRegion(FisheryRegion oldFisheryRegion) { + this.oldFisheryRegion = oldFisheryRegion; + } + + public void completeSetup() { + initMapClick(); + initMapProviders(); + } + + /** + * Configure click behaviour on maps. + */ + protected void initMapClick() { + new OpenMapEvents(inputUI.currentZoneMap, new SelectMouseMode(true), CellSelectionLayer.NO_SELECTION) { + @Override + public boolean mouseClicked(MouseEvent e) { + return false; + } + }; + new OpenMapEvents(inputUI.currentPortMap, new SelectMouseMode(true), CellSelectionLayer.NO_SELECTION) { + @Override + public boolean mouseClicked(MouseEvent e) { + return false; + } + }; + new OpenMapEvents(inputUI.newZoneMap, new SelectMouseMode(false), CellSelectionLayer.MULT_SELECTION) { + @Override + public boolean mouseClicked(MouseEvent e) { + Zone selectedValue = (Zone)inputUI.currentZones.getSelectedItem(); + zoneMap.put(selectedValue, inputUI.newZoneMap.getSelectedCells()); + return false; + } + }; + new OpenMapEvents(inputUI.newPortMap, new SelectMouseMode(false), CellSelectionLayer.SINGLE_SELECTION) { + @Override + public boolean mouseClicked(MouseEvent e) { + Port selectedValue = (Port)inputUI.currentPorts.getSelectedItem(); + List<Cell> selectedCells = inputUI.newPortMap.getSelectedCells(); + if (!selectedCells.isEmpty()) { + portMap.put(selectedValue, selectedCells.get(0)); + } + return false; + } + }; + } + + /** + * Configure data provider for maps. + */ + protected void initMapProviders() { + List<Zone> zones = oldFisheryRegion.getZone(); + List<Port> ports = oldFisheryRegion.getPort(); + inputUI.currentZones.setModel(new GenericComboModel<>(zones)); + inputUI.currentZoneMap.setMapDataProvider(new DatabaseDataProvider(oldFisheryRegion)); + inputUI.currentPorts.setModel(new GenericComboModel<>(ports)); + inputUI.currentPortMap.setMapDataProvider(new DatabaseDataProvider(oldFisheryRegion)); + + SpatialChangeDataProvider spatialChangeDataProvider = new SpatialChangeDataProvider(newFisheryRegion, cells); + inputUI.newZoneMap.setMapDataProvider(spatialChangeDataProvider); + inputUI.newPortMap.setMapDataProvider(spatialChangeDataProvider); + } + + /** + * Action when a zone is selected in combo. + */ + public void currentZoneChanged() { + Zone selectedValue = (Zone) inputUI.currentZones.getSelectedItem(); + inputUI.currentZoneMap.setSelectedCells(selectedValue.getCell()); + + List<Cell> newCells = zoneMap.get(selectedValue); + inputUI.newZoneMap.setSelectedCells(newCells); + } + + /** + * Action when a port is selected in combo. + */ + public void currentPortChanged() { + Port selectedValue = (Port)inputUI.currentPorts.getSelectedItem(); + inputUI.currentPortMap.setSelectedCells(selectedValue.getCell()); + + Cell newPort = portMap.get(selectedValue); + inputUI.newPortMap.setSelectedCells(newPort); + } + + /** + * Ask fro user to perform database change and commit. + */ + public void valid() { + int response = JOptionPane.showConfirmDialog(inputUI, t("isisfish.changeSpatial.confirmvalidmessage"), + t("isisfish.changeSpatial.confirmvalidtitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + if (response == JOptionPane.YES_OPTION) { + swapPortAndZoneCells(); + oldFisheryRegion.getTopiaContext().commitTransaction(); + + InputSaveVerifier inputSaveVerifier = inputUI.getContextValue(InputSaveVerifier.class); + inputSaveVerifier.cancel(); + + InputUI parentInputUI = inputUI.getContextValue(InputUI.class, JAXXUtil.PARENT); + + parentInputUI.getHandler().loadRegion(oldFisheryRegion.getName()); + close(); + } + } + + /** + * Cancel and close UI. + */ + public void close() { + inputUI.dispose(); + } + + /** + * Perform swap in database between current cell and new cell for zone and region. + */ + protected void swapPortAndZoneCells() { + CellDAO cellDAO = IsisFishDAOHelper.getCellDAO(oldFisheryRegion.getTopiaContext()); + + // update region spatial + oldFisheryRegion.setCellLengthLatitude(newFisheryRegion.getCellLengthLatitude()); + oldFisheryRegion.setCellLengthLongitude(newFisheryRegion.getCellLengthLongitude()); + oldFisheryRegion.setMaxLatitude(newFisheryRegion.getMaxLatitude()); + oldFisheryRegion.setMaxLongitude(newFisheryRegion.getMaxLongitude()); + oldFisheryRegion.setMinLatitude(newFisheryRegion.getMinLatitude()); + oldFisheryRegion.setMinLongitude(newFisheryRegion.getMinLongitude()); + oldFisheryRegion.update(); + + // delete old cells + List<Cell> currentCells = oldFisheryRegion.getCell(); + cellDAO.deleteAll(currentCells); + + // create new cells + for (Cell cell : cells) { + cellDAO.create(cell); + } + + // update current zones + for (Map.Entry<Zone, List<Cell>> zoneListEntry : zoneMap.entrySet()) { + Zone zone = zoneListEntry.getKey(); + List<Cell> newCell = zoneListEntry.getValue(); + + zone.clearCell(); + zone.addAllCell(newCell); + } + + // update current ports + for (Map.Entry<Port, Cell> portCellEntry : portMap.entrySet()) { + Port port = portCellEntry.getKey(); + Cell newCell = portCellEntry.getValue(); + port.setCell(newCell); + } + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewHandler.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewUI.jaxx (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/ChangeSpatialPreviewUI.jaxx 2017-03-16 10:47:47 UTC (rev 4402) @@ -0,0 +1,89 @@ +<!-- + #%L + IsisFish + + $Id: SpeciesUI.jaxx 4395 2017-02-23 08:32:39Z echatellier $ + $HeadURL: http://svn.codelutin.com/isis-fish/trunk/src/main/java/fr/ifremer/isisfish/u... $ + %% + Copyright (C) 2017 Ifremer, Code Lutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<JFrame layout='{new BorderLayout()}' title="isisfish.changeSpatial.preview"> + + <ChangeSpatialPreviewHandler id="handler" constructorParams="this" /> + + <JLabel constraints='BorderLayout.NORTH' text="isisfish.changeSpatial.description" /> + + <JTabbedPane constraints='BorderLayout.CENTER'> + <tab title='isisfish.common.zones'> + <JPanel layout="{new BorderLayout()}"> + <JPanel constraints='BorderLayout.NORTH' layout="{new BorderLayout()}"> + <JLabel constraints='BorderLayout.WEST' text="isisfish.common.zone" /> + <JComboBox id="currentZones" genericType="fr.ifremer.isisfish.entities.Zone" + onItemStateChanged="handler.currentZoneChanged()" constraints='BorderLayout.CENTER' /> + </JPanel> + <JSplitPane constraints='BorderLayout.CENTER'> + <JPanel layout='{new BorderLayout()}'> + <fr.ifremer.isisfish.map.IsisMapBean id='currentZoneMap' + javaBean='new fr.ifremer.isisfish.map.IsisMapBean()' + selectionMode="{fr.ifremer.isisfish.map.CellSelectionLayer.MULT_SELECTION}" + decorator='boxed' constraints='BorderLayout.CENTER'/> + <JLabel id="currentZoneCells" constraints='BorderLayout.SOUTH' text="" /> + </JPanel> + <JPanel layout='{new BorderLayout()}'> + <fr.ifremer.isisfish.map.IsisMapBean id='newZoneMap' + javaBean='new fr.ifremer.isisfish.map.IsisMapBean()' + selectionMode="{fr.ifremer.isisfish.map.CellSelectionLayer.MULT_SELECTION}" + decorator='boxed' constraints='BorderLayout.CENTER'/> + <JLabel id="newZoneCells" constraints='BorderLayout.SOUTH' text="" /> + </JPanel> + </JSplitPane> + </JPanel> + </tab> + <tab title='isisfish.common.ports'> + <JPanel layout="{new BorderLayout()}"> + <JPanel constraints='BorderLayout.NORTH' layout="{new BorderLayout()}"> + <JLabel constraints='BorderLayout.WEST' text="isisfish.common.port" /> + <JComboBox id="currentPorts" genericType="fr.ifremer.isisfish.entities.Port" + onItemStateChanged="handler.currentPortChanged()" constraints='BorderLayout.CENTER' /> + </JPanel> + <JSplitPane constraints='BorderLayout.CENTER'> + <JPanel layout='{new BorderLayout()}'> + <fr.ifremer.isisfish.map.IsisMapBean id='currentPortMap' + javaBean='new fr.ifremer.isisfish.map.IsisMapBean()' + selectionMode="{fr.ifremer.isisfish.map.CellSelectionLayer.MULT_SELECTION}" + decorator='boxed' constraints='BorderLayout.CENTER'/> + <JLabel id="currentPortCell" constraints='BorderLayout.SOUTH' text="" /> + </JPanel> + <JPanel layout='{new BorderLayout()}'> + <fr.ifremer.isisfish.map.IsisMapBean id='newPortMap' + javaBean='new fr.ifremer.isisfish.map.IsisMapBean()' + selectionMode="{fr.ifremer.isisfish.map.CellSelectionLayer.MULT_SELECTION}" + decorator='boxed' constraints='BorderLayout.CENTER'/> + <JLabel id="newPortCell" constraints='BorderLayout.SOUTH' text="" /> + </JPanel> + </JSplitPane> + </JPanel> + </tab> + </JTabbedPane> + + <JPanel layout='{new java.awt.FlowLayout(java.awt.FlowLayout.TRAILING)}' constraints='BorderLayout.SOUTH'> + <JButton text="isisfish.changeSpatial.valid" onActionPerformed="handler.valid()" /> + <JButton text="isisfish.changeSpatial.cancel" onActionPerformed="handler.close()" /> + </JPanel> + +</JFrame> Added: trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/SpatialChangeDataProvider.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/SpatialChangeDataProvider.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/SpatialChangeDataProvider.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -0,0 +1,95 @@ +/* + * #%L + * ISIS-Fish + * %% + * Copyright (C) 2017 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.input.spatial; + +import fr.ifremer.isisfish.entities.Cell; +import fr.ifremer.isisfish.entities.FisheryRegion; +import fr.ifremer.isisfish.map.MapDataProvider; + +import java.util.ArrayList; +import java.util.List; + +/** + * Provider used to provide static data from {@code List} of {@code Cell} instead of database. + */ +public class SpatialChangeDataProvider extends MapDataProvider { + + protected FisheryRegion fisheryRegion; + + protected List<Cell> cells; + + public SpatialChangeDataProvider(FisheryRegion fisheryRegion, List<Cell> cells) { + this.fisheryRegion = fisheryRegion; + this.cells = cells; + } + + @Override + public float getMinLongitude() { + return fisheryRegion.getMinLongitude(); + } + + @Override + public float getMaxLongitude() { + return fisheryRegion.getMaxLongitude(); + } + + @Override + public float getMinLatitude() { + return fisheryRegion.getMinLatitude(); + } + + @Override + public float getMaxLatitude() { + return fisheryRegion.getMaxLatitude(); + } + + @Override + public float getCellLengthLongitude() { + return fisheryRegion.getCellLengthLongitude(); + } + + @Override + public float getCellLengthLatitude() { + return fisheryRegion.getCellLengthLatitude(); + } + + @Override + public List<Cell> getCell() { + return cells; + } + + @Override + public List<String> getMapFilePath() { + return fisheryRegion.getMapFilePath(); + } + + @Override + public List<Cell> findAllByCoordinates(float latitude, float longitude) { + List<Cell> filteredCells = new ArrayList<>(); + for (Cell cell : cells) { + if (cell.getLatitude() == latitude && cell.getLongitude() == longitude) { + filteredCells.add(cell); + } + } + return filteredCells; + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/input/spatial/SpatialChangeDataProvider.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/zone/ZoneBasicsHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/zone/ZoneBasicsHandler.java 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/zone/ZoneBasicsHandler.java 2017-03-16 10:47:47 UTC (rev 4402) @@ -31,6 +31,7 @@ import javax.swing.event.ListSelectionEvent; +import fr.ifremer.isisfish.entities.FisheryRegion; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -58,12 +59,11 @@ new OpenMapEvents(inputContentUI.zoneMap, new SelectMouseMode(false), CellSelectionLayer.MULT_SELECTION) { @Override public boolean mouseClicked(MouseEvent e) { - boolean result = false; if (inputContentUI.getBean() != null) { // impossible de desactiver la carte :( inputContentUI.getBean().setCell(inputContentUI.zoneMap.getSelectedCells()); setZoneCells(); } - return result; + return false; } }; @@ -78,6 +78,8 @@ } setZoneCells(); + // hack because fishery region is not binded + inputContentUI.getZoneMap().setFisheryRegion(inputContentUI.getContextValue(FisheryRegion.class)); } }); } @@ -104,7 +106,7 @@ } } - // sroll to visible + // scroll to visible if (firstIndex != -1) { inputContentUI.zoneCells.ensureIndexIsVisible(firstIndex); } @@ -116,7 +118,7 @@ public void zoneCellsChange(ListSelectionEvent event) { // sans ca, ca boucle (modification depuis la carte) if (event.getValueIsAdjusting()) { - // pas a faie dans le cas d'une AS + // pas a faire dans le cas d'une AS if (inputContentUI.isActive()) { List<Cell> cells = new ArrayList<>(inputContentUI.zoneCells.getSelectedValuesList()); inputContentUI.getBean().setCell(cells); Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties =================================================================== --- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2017-03-16 10:47:47 UTC (rev 4402) @@ -102,6 +102,13 @@ isisfish.cell.longitude=Longitude isisfish.cell.name=Name isisfish.change.equation=Can't change equation +isisfish.changeSpatial.cancel=Cancel +isisfish.changeSpatial.changeSpatial=Change resolution +isisfish.changeSpatial.confirmvalidmessage=You are about to replace all region's cells with new cells.\nDo you confirm this action ? +isisfish.changeSpatial.confirmvalidtitle=Validation +isisfish.changeSpatial.description=You can tune the cell presets made for zones and ports before completing the spatial resolution change. +isisfish.changeSpatial.preview=Change resolution (preview) +isisfish.changeSpatial.valid=Valid isisfish.commit.message=Enter commit message isisfish.common.add=Add isisfish.common.apply=Apply @@ -143,6 +150,7 @@ isisfish.common.populationGroup=Population group isisfish.common.populations=Populations isisfish.common.port=Port +isisfish.common.ports=Ports isisfish.common.prev=Previous isisfish.common.region=Region isisfish.common.remove=Remove @@ -162,6 +170,7 @@ isisfish.common.warn=warn isisfish.common.year=year isisfish.common.zone=Zone +isisfish.common.zones=Zones isisfish.config.cache.backend.factory.class.description=Cache backend class to use for simulation isisfish.config.category.communityvcs=Community VCS isisfish.config.category.communityvcs.description=Community VCS repository @@ -477,6 +486,7 @@ isisfish.input.createNewRegion=Create isisfish.input.map.copytoclicboard=Copy to clipboard isisfish.input.menu.addRegion=Add region +isisfish.input.menu.changeResolution=Changer spatial resolution isisfish.input.menu.commit=Commit change isisfish.input.menu.copyRegion=Copy region isisfish.input.menu.exportJson=Export current object in JSON Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties =================================================================== --- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2017-03-16 10:47:09 UTC (rev 4401) +++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2017-03-16 10:47:47 UTC (rev 4402) @@ -1,4 +1,3 @@ -%s\ has\ a\ discrete\ domain,\ this\ is\ not\ acceptable\ for\ this\ method.= %s\ has\ a\ non\ uniform\ distribution,\ this\ is\ not\ acceptable\ for\ this\ method.= Add\ to\ default\ queue= Analyse\ plan\ error,\ too\ many\ simulation\ for\ %s\ \:\ %s= @@ -102,6 +101,13 @@ isisfish.cell.longitude=Longitude isisfish.cell.name=Nom isisfish.change.equation=Ne peut pas changer l'équation +isisfish.changeSpatial.cancel=Annuler +isisfish.changeSpatial.changeSpatial=Changer la résolution +isisfish.changeSpatial.confirmvalidmessage=Vous êtes sur le point de remplacer toutes les mailles de la région par de nouvelle mailles.\nConfirmer vous cette action ? +isisfish.changeSpatial.confirmvalidtitle=Validation +isisfish.changeSpatial.description=Vous pouvez affiner les présélections de mailles effectuées pour les zones et les ports avant de terminer la modification de résolution spatiale. +isisfish.changeSpatial.preview=Changement de résolution (Aperçu) +isisfish.changeSpatial.valid=Valider isisfish.commit.message=Entrer un message de commit isisfish.common.add=Ajouter isisfish.common.apply=Appliquer @@ -143,6 +149,7 @@ isisfish.common.populationGroup=Groupe de population isisfish.common.populations=Populations isisfish.common.port=Port +isisfish.common.ports=Ports isisfish.common.prev=Précédent isisfish.common.region=Région isisfish.common.remove=Supprimer @@ -162,6 +169,7 @@ isisfish.common.warn=Warning isisfish.common.year=année isisfish.common.zone=Zone +isisfish.common.zones=Zones isisfish.config.cache.backend.factory.class.description=Implantation du cache à utiliser pour les simulations isisfish.config.category.communityvcs=VCS Communauté isisfish.config.category.communityvcs.description=Dépôt contenant les scripts de la communautés @@ -477,6 +485,7 @@ isisfish.input.createNewRegion=Créer isisfish.input.map.copytoclicboard=Copier vers de presse-papiers isisfish.input.menu.addRegion=Ajouter une région +isisfish.input.menu.changeResolution=Changer la résolution spatiale isisfish.input.menu.commit=Sauvegarder les changements isisfish.input.menu.copyRegion=Copier région isisfish.input.menu.exportJson=Exporter l'objet courant en JSON