Tony CHEMIT pushed to branch feature/refactor_ui at ultreiaio / ird-observe Commits: 617ddef4 by Tony CHEMIT at 2017-10-12T19:58:37+02:00 yes, use TripMap API from toolkit - - - - - 20 changed files: - client-configuration/src/main/java/fr/ird/observe/client/configuration/ClientConfig.java - client/pom.xml - client/src/main/java/fr/ird/observe/client/ObserveMainUI.jaxx - − client/src/main/java/fr/ird/observe/client/action/tripMap/ExportPngUIAction.java - − client/src/main/java/fr/ird/observe/client/action/tripMap/TripMapActionSupport.java - − client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomItUIAction.java - − client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomMoinsUIAction.java - − client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomPlusUIAction.java - − client/src/main/java/fr/ird/observe/client/form/TripUI.java - client/src/main/java/fr/ird/observe/client/form/open/longline/TripLonglineUIHandler.java - client/src/main/java/fr/ird/observe/client/form/open/seine/TripSeineUIHandler.java - − client/src/main/java/fr/ird/observe/client/util/tripMap/ObserveMapPane.java - − client/src/main/java/fr/ird/observe/client/util/tripMap/ObserveMapPaneLegendItem.java - − client/src/main/java/fr/ird/observe/client/util/tripMap/ObserverMapPanLegendDrawer.java - − client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapContentBuilder.java - − client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUI.jaxx - − client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUI.jcss - − client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUIHandler.java - − dto/src/main/java/fr/ird/observe/dto/data/TripMapDto.java - pom.xml Changes: ===================================== client-configuration/src/main/java/fr/ird/observe/client/configuration/ClientConfig.java ===================================== --- a/client-configuration/src/main/java/fr/ird/observe/client/configuration/ClientConfig.java +++ b/client-configuration/src/main/java/fr/ird/observe/client/configuration/ClientConfig.java @@ -28,6 +28,7 @@ import com.google.gson.Gson; import fr.ird.observe.client.constants.CreationMode; import fr.ird.observe.client.constants.DbMode; import fr.ird.observe.dto.FloatingObjectPreset; +import fr.ird.observe.dto.data.TripMapConfig; import fr.ird.observe.dto.presets.RemoteDataSourceConfiguration; import fr.ird.observe.dto.presets.ServerDataSourceConfiguration; import java.beans.PropertyChangeListener; @@ -62,7 +63,7 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - dev@tchemit.fr * @since 1.0 */ -public class ClientConfig extends GeneratedClientConfig { +public class ClientConfig extends GeneratedClientConfig implements TripMapConfig { /** le pattern du fichier de sauvegarde d'une base locale */ private static final String BACKUP_DB_PATTERN = "obstuna-local-%1$tF--%1$tk-%1$tM-%1$tS.sql.gz"; @@ -455,7 +456,7 @@ public class ClientConfig extends GeneratedClientConfig { public void setRemoteDataSourceConfigurations(RemoteDataSourceConfiguration[] configurations) { String option = new Gson().toJson(configurations); get().setOption(ClientConfigOption.REMOTE_DATA_SOURCE_CONFIGURATIONS.getKey(), option); - remoteDataSourceConfigurationList=null; + remoteDataSourceConfigurationList = null; } ImmutableList<ServerDataSourceConfiguration> serverDataSourceConfigurationList; @@ -511,7 +512,7 @@ public class ClientConfig extends GeneratedClientConfig { public void setServerDataSourceConfigurations(ServerDataSourceConfiguration[] configurations) { String option = new Gson().toJson(configurations); get().setOption(ClientConfigOption.SERVER_DATA_SOURCE_CONFIGURATIONS.getKey(), option); - serverDataSourceConfigurationList=null; + serverDataSourceConfigurationList = null; } private final SimpleDateFormat dateFormat = new SimpleDateFormat(); ===================================== client/pom.xml ===================================== --- a/client/pom.xml +++ b/client/pom.xml @@ -79,6 +79,16 @@ </releases> </repository> </repositories> + <pluginRepositories> + <pluginRepository> + <id>geotools-repository</id> + <url>http://download.osgeo.org/webdav/geotools</url> + <releases> + <enabled>true</enabled> + <checksumPolicy>fail</checksumPolicy> + </releases> + </pluginRepository> + </pluginRepositories> <dependencyManagement> <dependencies> @@ -402,10 +412,10 @@ <groupId>io.ultreia.java4all.jaxx</groupId> <artifactId>jaxx-runtime-swing-application</artifactId> </dependency> - <dependency> + <!--dependency> <groupId>io.ultreia.java4all.jaxx</groupId> <artifactId>jaxx-runtime-swing-session</artifactId> - </dependency> + </dependency--> <dependency> <groupId>io.ultreia.java4all.jaxx</groupId> <artifactId>jaxx-runtime-swing-wizard</artifactId> @@ -418,10 +428,10 @@ <groupId>io.ultreia.java4all.jaxx</groupId> <artifactId>jaxx-widgets-error</artifactId> </dependency> - <dependency> + <!--dependency> <groupId>io.ultreia.java4all.jaxx</groupId> <artifactId>jaxx-widgets-hidor</artifactId> - </dependency> + </dependency--> <dependency> <groupId>io.ultreia.java4all.jaxx</groupId> <artifactId>jaxx-widgets-gis</artifactId> @@ -529,10 +539,10 @@ <groupId>org.swinglabs.swingx</groupId> <artifactId>swingx-core</artifactId> </dependency> - <dependency> + <!--dependency> <groupId>org.swinglabs.swingx</groupId> <artifactId>swingx-painters</artifactId> - </dependency> + </dependency--> <dependency> <groupId>org.swinglabs.swingx</groupId> <artifactId>swingx-common</artifactId> @@ -552,10 +562,10 @@ <artifactId>h2</artifactId> </dependency> - <dependency> + <!--dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> - </dependency> + </dependency--> <!-- FreeMarker --> <dependency> @@ -567,26 +577,32 @@ <dependency> <groupId>org.geotools</groupId> <artifactId>gt-swing</artifactId> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-api</artifactId> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-main</artifactId> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-render</artifactId> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-referencing</artifactId> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-opengis</artifactId> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.geotools</groupId> @@ -601,6 +617,7 @@ <dependency> <groupId>com.vividsolutions</groupId> <artifactId>jts</artifactId> + <scope>runtime</scope> </dependency> <dependency> @@ -688,6 +705,13 @@ </goals> </execution> </executions> + <dependencies> + <dependency> + <groupId>org.geotools</groupId> + <artifactId>gt-swing</artifactId> + <version>${geoToolsVersion}</version> + </dependency> + </dependencies> </plugin> <plugin> ===================================== client/src/main/java/fr/ird/observe/client/ObserveMainUI.jaxx ===================================== --- a/client/src/main/java/fr/ird/observe/client/ObserveMainUI.jaxx +++ b/client/src/main/java/fr/ird/observe/client/ObserveMainUI.jaxx @@ -169,30 +169,40 @@ public void registerAction(AbstractButton editor) { actionMap.registerAction(editor); } +@Override public void displayInfo(String text) { status.setStatus(text); } +@Override public void displayInfo(String title, String text) { JOptionPanes.displayInfo(this, title, text); } +@Override public void displayWarning(String title, String text) { JOptionPanes.displayWarning(this, title, text); } +@Override public int askUser(String title, String message, int typeMessage, Object[] options, int defaultOption) { return JOptionPanes.askUser(this, title, message, typeMessage, options, defaultOption); } +@Override public int askUser(String title, Object message, int typeMessage, Object[] options, int defaultOption) { return JOptionPanes.askUser(this, title, message, typeMessage, options, defaultOption); } +@Override public int askUser(JOptionPane pane, String title, Object[] options) { return JOptionPanes.askUser(this, pane, title, options); } +@Override +public void setBusy(boolean busy) { + model.setBusy(busy); +} ]]> </script> ===================================== client/src/main/java/fr/ird/observe/client/action/tripMap/ExportPngUIAction.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/action/tripMap/ExportPngUIAction.java +++ /dev/null @@ -1,80 +0,0 @@ -package fr.ird.observe.client.action.tripMap; - -/*- - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import fr.ird.observe.client.ObserveClientTechnicalException; -import fr.ird.observe.client.ObserveMainUI; -import fr.ird.observe.client.util.tripMap.TripMapUI; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import javax.imageio.ImageIO; -import javax.swing.KeyStroke; -import org.nuiton.jaxx.widgets.file.JaxxFileChoosers; - - -import static org.nuiton.i18n.I18n.t; - -/** - * Created by tchemit on 25/08/17. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class ExportPngUIAction extends TripMapActionSupport { - - public static final String ACTION_NAME = ExportPngUIAction.class.getName(); - - public ExportPngUIAction(ObserveMainUI mainUI) { - super(mainUI, - ACTION_NAME, - t("observe.content.map.action.exportPng"), - t("observe.content.map.action.exportPng.tip"), - "save", - KeyStroke.getKeyStroke("ctrl pressed S")); - } - - @Override - protected void actionPerformed(TripMapUI view) { - - File file = JaxxFileChoosers.chooseFile( - view, - t("observe.content.map.export.chooseFile.title"), - t("observe.content.map.export.chooseFile.ok"), - null, - "^.+\\.png|.+\\.PNG$", - t("observe.content.map.export.chooseFile.png")); - - if (file != null && JaxxFileChoosers.confirmOverwriteFileIfExist(view, file)) { - - BufferedImage im = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_ARGB); - view.paint(im.getGraphics()); - try { - ImageIO.write(im, "PNG", file); - } catch (IOException e) { - throw new ObserveClientTechnicalException("unable to export map ", e); - } - - displayInfo(t("observe.content.map.export.success", file)); - } - } -} ===================================== client/src/main/java/fr/ird/observe/client/action/tripMap/TripMapActionSupport.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/action/tripMap/TripMapActionSupport.java +++ /dev/null @@ -1,83 +0,0 @@ -package fr.ird.observe.client.action.tripMap; - -/*- - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import fr.ird.observe.client.action.UIActionSupport; -import fr.ird.observe.client.ObserveMainUI; -import fr.ird.observe.client.form.TripUI; -import fr.ird.observe.client.util.tripMap.TripMapUI; -import java.awt.event.ActionEvent; -import javax.swing.JComponent; -import javax.swing.KeyStroke; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Created by tchemit on 25/08/17. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public abstract class TripMapActionSupport extends UIActionSupport { - - /** Logger. */ - private static final Log log = LogFactory.getLog(TripMapActionSupport.class); - - private TripMapUI ui; - protected ActionEvent e; - - protected abstract void actionPerformed(TripMapUI ui); - - TripMapActionSupport(ObserveMainUI mainUI, String actionCommandKey, String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) { - super(mainUI, actionCommandKey, label, shortDescription, actionIcon, acceleratorKey); - } - - public void setUi(TripMapUI ui) { - this.ui = ui; - } - - @Override - public final void actionPerformed(ActionEvent e) { - if (!canExecuteAction()) { - return; - } - this.e = e; - - if (ui != null) { - actionPerformed(ui); - return; - } - TripUI source = (TripUI) e.getSource(); - actionPerformed(source.getTripMap()); - } - - private boolean canExecuteAction() { - JComponent editor = getEditor(); - if ((editor == null || (editor.isVisible() && editor.isEnabled() && editor.isShowing()))) { - return true; - } - if (log.isInfoEnabled()) { - log.info("Disabled action: " + getActionCommandKey() + " :: " + this); - } - return false; - } -} ===================================== client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomItUIAction.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomItUIAction.java +++ /dev/null @@ -1,61 +0,0 @@ -package fr.ird.observe.client.action.tripMap; - -/*- - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import fr.ird.observe.client.ObserveMainUI; -import fr.ird.observe.client.util.tripMap.TripMapUI; -import javax.swing.KeyStroke; -import org.geotools.geometry.jts.ReferencedEnvelope; -import org.geotools.swing.JMapPane; - - -import static org.nuiton.i18n.I18n.t; - -/** - * Created by tchemit on 25/08/17. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class ZoomItUIAction extends TripMapActionSupport { - - public static final String ACTION_NAME = ZoomItUIAction.class.getName(); - - public ZoomItUIAction(ObserveMainUI mainUI) { - super(mainUI, - ACTION_NAME, - t("observe.content.map.action.zoomIt"), - t("observe.content.map.action.zoomIt.tip"), - "center", - KeyStroke.getKeyStroke("ctrl pressed I")); - } - - @Override - protected void actionPerformed(TripMapUI view) { - - ReferencedEnvelope tripArea = view.getHandler().getTripArea(); - if (!tripArea.isEmpty()) { - JMapPane mapPane = view.getObserveMapPane(); - mapPane.setDisplayArea(tripArea); - } - } -} ===================================== client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomMoinsUIAction.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomMoinsUIAction.java +++ /dev/null @@ -1,72 +0,0 @@ -package fr.ird.observe.client.action.tripMap; - -/*- - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import fr.ird.observe.client.ObserveMainUI; -import fr.ird.observe.client.util.tripMap.TripMapUI; -import fr.ird.observe.client.util.tripMap.TripMapUIHandler; -import java.awt.Point; -import javax.swing.KeyStroke; -import org.geotools.geometry.jts.ReferencedEnvelope; - - -import static fr.ird.observe.client.util.tripMap.TripMapUIHandler.ZOOM_STEP_RATIO; -import static org.nuiton.i18n.I18n.t; - -/** - * Created by tchemit on 25/08/17. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class ZoomMoinsUIAction extends TripMapActionSupport { - - public static final String ACTION_NAME = ZoomMoinsUIAction.class.getName(); - - public ZoomMoinsUIAction(ObserveMainUI mainUI) { - super(mainUI, - ACTION_NAME, - t("observe.content.map.action.zoomMoins"), - t("observe.content.map.action.zoomMoins.tip"), - "center", - KeyStroke.getKeyStroke("ctrl pressed L")); - } - - @Override - protected void actionPerformed(TripMapUI view) { - - TripMapUIHandler handler = view.getHandler(); - ReferencedEnvelope tripArea = handler.getTripArea(); - - if (!tripArea.isEmpty()) { - int notches = 1; - ReferencedEnvelope displayArea = view.getObserveMapPane().getDisplayArea(); - double w = displayArea.getMedian(0); - double h = displayArea.getMedian(1); - Point zoomCenter = new Point((int) w, (int) h); - handler.setZoomCenter(zoomCenter); - handler.setZoomRatio(handler.getZoomRatio() * (1 + (ZOOM_STEP_RATIO * notches * -1))); - handler.zoomApply(); - } - - } -} ===================================== client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomPlusUIAction.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/action/tripMap/ZoomPlusUIAction.java +++ /dev/null @@ -1,72 +0,0 @@ -package fr.ird.observe.client.action.tripMap; - -/*- - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import fr.ird.observe.client.ObserveMainUI; -import fr.ird.observe.client.util.tripMap.TripMapUI; -import fr.ird.observe.client.util.tripMap.TripMapUIHandler; -import java.awt.Point; -import javax.swing.KeyStroke; -import org.geotools.geometry.jts.ReferencedEnvelope; - - -import static fr.ird.observe.client.util.tripMap.TripMapUIHandler.ZOOM_STEP_RATIO; -import static org.nuiton.i18n.I18n.t; - -/** - * Created by tchemit on 25/08/17. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class ZoomPlusUIAction extends TripMapActionSupport { - - public static final String ACTION_NAME = ZoomPlusUIAction.class.getName(); - - public ZoomPlusUIAction(ObserveMainUI mainUI) { - super(mainUI, - ACTION_NAME, - t("observe.content.map.action.zoomPlus"), - t("observe.content.map.action.zoomPlus.tip"), - "zoomPlus", - KeyStroke.getKeyStroke("ctrl pressed P")); - } - - @Override - protected void actionPerformed(TripMapUI view) { - - TripMapUIHandler handler = view.getHandler(); - ReferencedEnvelope tripArea = handler.getTripArea(); - - if (!tripArea.isEmpty()) { - int notches = 1; - ReferencedEnvelope displayArea = view.getObserveMapPane().getDisplayArea(); - double w = displayArea.getMedian(0); - double h = displayArea.getMedian(1); - Point zoomCenter = new Point((int) w, (int) h); - handler.setZoomCenter(zoomCenter); - handler.setZoomRatio(handler.getZoomRatio() * (1 - (ZOOM_STEP_RATIO * notches * -1))); - handler.zoomApply(); - } - - } -} ===================================== client/src/main/java/fr/ird/observe/client/form/TripUI.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/form/TripUI.java +++ /dev/null @@ -1,39 +0,0 @@ -package fr.ird.observe.client.form; - -/*- - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import fr.ird.observe.client.util.tripMap.TripMapUI; - -/** - * Created by tchemit on 25/08/17. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public interface TripUI { - - TripMapUI getTripMap(); - - Boolean getBuildTripMap(); - - void setBuildTripMap(Boolean buildTripMap); -} ===================================== client/src/main/java/fr/ird/observe/client/form/open/longline/TripLonglineUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/form/open/longline/TripLonglineUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/form/open/longline/TripLonglineUIHandler.java @@ -87,7 +87,7 @@ class TripLonglineUIHandler extends ObserveOpenDataFormUIHandler<TripLonglineDto ClientConfig config = ObserveClientApplicationContext.get().getConfig(); tripMap.getHandler().setConfig(config); - tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); + tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), mainUI.getActionMap()); //FIXME!!! Use a action (shared with TripSeineHandler) getUi().getMainTabbedPane().addChangeListener(e -> { @@ -102,7 +102,7 @@ class TripLonglineUIHandler extends ObserveOpenDataFormUIHandler<TripLonglineDto try { TripMapUI tripMap11 = ui.getTripMap(); TripMapDto tripLonglineMap = model.getService().getTripLonglineMap(getModel().getSelectedId()); - tripMap11.getHandler().doOpenMap(tripLonglineMap); + tripMap11.getHandler().doOpenMap(mainUI, tripLonglineMap); } finally { ObserveClientApplicationContext.get().getMainUI().getModel().setBusy(false); } ===================================== client/src/main/java/fr/ird/observe/client/form/open/seine/TripSeineUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/form/open/seine/TripSeineUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/form/open/seine/TripSeineUIHandler.java @@ -84,7 +84,7 @@ class TripSeineUIHandler extends ObserveOpenDataFormUIHandler<TripSeineDto, Trip ClientConfig config = ObserveClientApplicationContext.get().getConfig(); tripMap.getHandler().setConfig(config); - tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); + tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), mainUI.getActionMap()); ui.getMainTabbedPane().addChangeListener(e -> { JTabbedPane tripSeineTabPane = (JTabbedPane) e.getSource(); @@ -99,7 +99,7 @@ class TripSeineUIHandler extends ObserveOpenDataFormUIHandler<TripSeineDto, Trip try { TripMapUI tripMap11 = ui.getTripMap(); TripMapDto tripSeineMap = model.getService().getTripSeineMap(getModel().getSelectedId()); - tripMap11.getHandler().doOpenMap(tripSeineMap); + tripMap11.getHandler().doOpenMap(mainUI, tripSeineMap); } finally { ObserveClientApplicationContext.get().getMainUI().getModel().setBusy(false); } ===================================== client/src/main/java/fr/ird/observe/client/util/tripMap/ObserveMapPane.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/util/tripMap/ObserveMapPane.java +++ /dev/null @@ -1,362 +0,0 @@ -package fr.ird.observe.client.util.tripMap; - -/* - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import com.google.common.collect.Lists; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Point; -import java.awt.Polygon; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.geotools.geometry.jts.ReferencedEnvelope; -import org.geotools.renderer.lite.RendererUtilities; -import org.geotools.styling.FeatureTypeStyle; -import org.geotools.styling.Rule; -import org.geotools.styling.Style; -import org.geotools.swing.JMapPane; -import org.geotools.swing.event.MapPaneAdapter; -import org.geotools.swing.event.MapPaneEvent; - - -import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public class ObserveMapPane extends JMapPane { - - private static final long serialVersionUID = 1L; - private static final Log log = LogFactory.getLog(ObserveMapPane.class); - - protected static final int MARGIN = 10; - - protected static final int SCALE_HEIGHT = 15; - protected static final int SCALE_WIDTH_MAX = 200; - - protected static final int METERS_BY_MILES = 1852; - - protected int scaleWidth; - - protected String labelScaleUp; - - protected double rotation; - - public ObserveMapPane() { - labelScaleUp = "0 m"; - scaleWidth = 100; - rotation = 0; - addMapPaneListener(new MapPaneAdapter() { - @Override - public void onDisplayAreaChanged(MapPaneEvent ev) { - updateScale(); - } - }); - legendItems = Lists.newArrayList(); - - } - - - protected void updateScale() { - ReferencedEnvelope displayArea = getDisplayArea(); - double dpi = 2.54 / 100; // pour avoir l'echélle en metre/pixel - - try { - double meterPerPixel = RendererUtilities.calculateScale(displayArea, getWidth(), getHeight(), dpi); - - double maxWidthMeter = SCALE_WIDTH_MAX * meterPerPixel; - - double maxWidthMiles = maxWidthMeter / METERS_BY_MILES; - - int nbDigit = (int) Math.floor(Math.log10(maxWidthMiles)); - - int firstDigit = (int) Math.floor(maxWidthMiles / Math.pow(10, nbDigit)); // le premier chiffre significatif - - int useFirstDigit; - - if (firstDigit >= 5) { - useFirstDigit = 5; - } else if (firstDigit >= 2) { - useFirstDigit = 2; - } else { - useFirstDigit = 1; - } - - long scaleInMiles = useFirstDigit * (long) Math.pow(10, nbDigit); - - scaleWidth = (int) Math.round(scaleInMiles * METERS_BY_MILES / meterPerPixel); - - labelScaleUp = String.format("%,d " + t("observe.content.map.miles"), scaleInMiles); - - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("error", e); - } - } - } - - protected void paintScale(Graphics graphics) { - graphics.setColor(Color.BLACK); - - FontMetrics fm = graphics.getFontMetrics(); - - Rectangle2D textArea = fm.getStringBounds(labelScaleUp, graphics); - - int labelLeft = getWidth() - MARGIN * 2 - scaleWidth - (int) textArea.getWidth(); - - graphics.drawString(labelScaleUp, labelLeft, getHeight() - MARGIN); - - int scalesEndX = getWidth() - MARGIN; - - int scaleStartX = scalesEndX - scaleWidth; - - int scalesEndY = getHeight() - MARGIN; - - int scaleStartY = scalesEndY - SCALE_HEIGHT; - - graphics.drawLine(scaleStartX, scaleStartY, scaleStartX, scalesEndY); - graphics.drawLine(scaleStartX, scalesEndY, scalesEndX, scalesEndY); - graphics.drawLine(scalesEndX, scalesEndY, scalesEndX, scaleStartY); - - } - - protected static int AXIS_LENGTH = 30; - - protected static int SUB_AXIS_LENGTH = 5; - - protected static int CENTER_MARGIN = 50; - - protected static int INTER_AXIS_TEXT = 3; - - protected static double FONT_SIZE = 12; - - - protected void paintCompass(Graphics graphics) { - - Point center = new Point(getWidth() - CENTER_MARGIN, CENTER_MARGIN); - - Font font = graphics.getFont(); - Font fontRatio = font.deriveFont((float) (FONT_SIZE)); - graphics.setFont(fontRatio); - - FontMetrics fm = graphics.getFontMetrics(); - - for (CardinalPoint cardinalPoint : CardinalPoint.values()) { - - Point2D direction = cardinalPoint.getDirection(rotation, AXIS_LENGTH, center); - - Point2D sommet1 = cardinalPoint.getDirection(rotation - Math.PI / 4, SUB_AXIS_LENGTH, center); - - Point2D sommet2 = cardinalPoint.getDirection(rotation + Math.PI / 4, SUB_AXIS_LENGTH, center); - - - Polygon polygon = new Polygon(); - polygon.addPoint((int) center.getX(), (int) center.getY()); - polygon.addPoint((int) direction.getX(), (int) direction.getY()); - polygon.addPoint((int) sommet2.getX(), (int) sommet2.getY()); - graphics.fillPolygon(polygon); - - graphics.drawLine((int) sommet1.getX(), (int) sommet1.getY(), (int) direction.getX(), (int) direction.getY()); - - Rectangle2D textArea = fm.getStringBounds(cardinalPoint.getLabel(), graphics); - - // on cherche la ditance entre le centre du text et sa bordure dans le direction donné - double l = cardinalPoint.distanceCenterBorder(rotation, textArea); - - Point2D textCenter = cardinalPoint.getDirection(rotation, AXIS_LENGTH + INTER_AXIS_TEXT + l, center); - - graphics.drawString( - cardinalPoint.getLabel(), - (int) (textCenter.getX() - textArea.getWidth() / 2), - (int) (textCenter.getY() + textArea.getHeight() / 2)); - } - - } - - - protected static int LEGEND_MARGIN = 3; - - protected List<ObserveMapPaneLegendItem> legendItems; - - public List<ObserveMapPaneLegendItem> getLegendItems() { - return legendItems; - } - - public void setLegendItems(List<ObserveMapPaneLegendItem> legendItems) { - this.legendItems = legendItems; - } - - protected void paintLegend(Graphics graphics) { - - if (legendItems != null) { - - int x = 0; - int y = getHeight() - ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT * legendItems.size() - 2 * LEGEND_MARGIN; - - ObserverMapPanLegendDrawer drawer = new ObserverMapPanLegendDrawer(); - - FontMetrics fm = graphics.getFontMetrics(); - - int maxLabelWidth = 0; - - for (ObserveMapPaneLegendItem item : legendItems) { - Rectangle2D labelArea = fm.getStringBounds(item.getLabel(), graphics); - - maxLabelWidth = Math.max((int) labelArea.getWidth(), maxLabelWidth); - - } - - int legendWidth = ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH + maxLabelWidth + ObserveMapPaneLegendItem.LEGEND_MARGIN * 2; - - graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND); - graphics.fillRect( - x, - y, - legendWidth, - LEGEND_MARGIN); - - y += LEGEND_MARGIN; - - for (ObserveMapPaneLegendItem item : legendItems) { - - graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND); - graphics.fillRect( - x, - y, - legendWidth, - ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT); - - BufferedImage symbole = new BufferedImage( - ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH, - ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT, - BufferedImage.TYPE_INT_ARGB); - - Style style = item.getStyle(); - - for (FeatureTypeStyle featureTypeStyle : style.featureTypeStyles()) { - - for (Rule rule : featureTypeStyle.rules()) { - - if (rule.getFilter().evaluate(item.getSimpleFeature())) { - - drawer.drawDirect(symbole, item.getSimpleFeature(), rule); - - } - } - } - - graphics.drawImage(symbole, x + LEGEND_MARGIN, y, null); - - graphics.setColor(Color.BLACK); - - int labelMarginBottom = ((ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT - fm.getHeight()) / 2) + fm.getDescent(); - - graphics.drawString(item.getLabel(), - x + LEGEND_MARGIN + ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH, - y + ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT - labelMarginBottom); - - y += ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT; - - } - - graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND); - graphics.fillRect( - x, - y, - legendWidth, - LEGEND_MARGIN); - - } - - } - - - @Override - public void paint(Graphics graphics) { - - super.paint(graphics); - - paintScale(graphics); - - paintCompass(graphics); - - paintLegend(graphics); - - } - - protected enum CardinalPoint { - NORTH(-1, 0, 0, -1, n("observe.content.map.north")), - SOUTH(1, 0, 0, 1, n("observe.content.map.south")), - WEST(0, -1, 1, 0, n("observe.content.map.west")), - EST(0, 1, -1, 0, n("observe.content.map.east")); - - protected int matrix00; - protected int matrix01; - protected int matrix10; - protected int matrix11; - protected String label; - - CardinalPoint(int matrix00, int matrix01, int matrix10, int matrix11, String label) { - this.matrix00 = matrix00; - this.matrix01 = matrix01; - this.matrix10 = matrix10; - this.matrix11 = matrix11; - this.label = label; - } - - public Point2D.Double getDirection(double angle, double length, Point center) { - - double x = Math.sin(angle) * length; - double y = Math.cos(angle) * length; - - double deltaX = matrix00 * x + matrix01 * y; - double deltaY = matrix10 * x + matrix11 * y; - - return new Point2D.Double(center.getX() + deltaX, center.getY() + deltaY); - } - - // on cherche la ditance entre le centre du text et sa bordure dans le direction donné - public double distanceCenterBorder(double angle, Rectangle2D textArea) { - - double x = Math.sin(angle); - double y = Math.cos(angle); - - double deltaW = Math.abs(textArea.getWidth() / 2 / (matrix00 * x + matrix01 * y)); - double deltaH = Math.abs(textArea.getHeight() / 2 / (matrix10 * x + matrix11 * y)); - - return Math.min(deltaH, deltaW); - } - - public String getLabel() { - return t(label); - } - } - -} ===================================== client/src/main/java/fr/ird/observe/client/util/tripMap/ObserveMapPaneLegendItem.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/util/tripMap/ObserveMapPaneLegendItem.java +++ /dev/null @@ -1,88 +0,0 @@ -package fr.ird.observe.client.util.tripMap; - -/* - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import com.vividsolutions.jts.geom.Coordinate; -import java.awt.Color; -import org.geotools.styling.Style; -import org.opengis.feature.simple.SimpleFeature; - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public class ObserveMapPaneLegendItem { - - protected static final int LEGEND_ITEM_HEIGHT = 20; - protected static final int LEGEND_SYMBOL_WIDTH = 50; - protected static final int LEGEND_MARGIN = 5; - protected static final Color LEGEND_BACKGROUND = new Color(1f, 1f, 1f, 0.8f); - - - public static Coordinate[] lineCoordinates() { - Coordinate[] coordinates = new Coordinate[2]; - coordinates[0] = new Coordinate(LEGEND_MARGIN, LEGEND_ITEM_HEIGHT / 2); - coordinates[1] = new Coordinate(LEGEND_SYMBOL_WIDTH - LEGEND_MARGIN, LEGEND_ITEM_HEIGHT / 2); - return coordinates; - } - - public static Coordinate pointCoordinates() { - return new Coordinate(LEGEND_SYMBOL_WIDTH / 2, LEGEND_ITEM_HEIGHT / 2); - } - - - protected SimpleFeature simpleFeature; - - protected Style style; - - protected String label; - - public ObserveMapPaneLegendItem(SimpleFeature simpleFeature, Style style, String label) { - this.simpleFeature = simpleFeature; - this.style = style; - this.label = label; - } - - public SimpleFeature getSimpleFeature() { - return simpleFeature; - } - - public void setSimpleFeature(SimpleFeature simpleFeature) { - this.simpleFeature = simpleFeature; - } - - public Style getStyle() { - return style; - } - - public void setStyle(Style style) { - this.style = style; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } -} ===================================== client/src/main/java/fr/ird/observe/client/util/tripMap/ObserverMapPanLegendDrawer.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/util/tripMap/ObserverMapPanLegendDrawer.java +++ /dev/null @@ -1,110 +0,0 @@ -package fr.ird.observe.client.util.tripMap; - -/* - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import com.vividsolutions.jts.geom.Geometry; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Stroke; -import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import org.geotools.geometry.jts.LiteShape; -import org.geotools.legend.Drawer; -import org.geotools.styling.LineSymbolizer; -import org.geotools.styling.Rule; -import org.geotools.styling.SLD; -import org.geotools.styling.Symbolizer; -import org.opengis.feature.simple.SimpleFeature; - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public class ObserverMapPanLegendDrawer { - - protected final Drawer drawer; - - - public ObserverMapPanLegendDrawer() { - drawer = Drawer.create(); - - } - - public void drawDirect(BufferedImage bi, SimpleFeature feature, Rule rule) { - AffineTransform affineTransform = new AffineTransform(); - - LiteShape shape = new LiteShape(null, affineTransform, false); - for (Symbolizer symbolizer : rule.getSymbolizers()) { - if (symbolizer instanceof LineSymbolizer) { - LineSymbolizer lineSymbolizer = (LineSymbolizer) symbolizer; - - Geometry geometry = findGeometry(feature, lineSymbolizer); - if (geometry != null) { - - Graphics graphics = bi.getGraphics(); - Graphics2D g = (Graphics2D) graphics; - - shape.setGeometry(geometry); - - - Color c = SLD.color(lineSymbolizer); - int w = SLD.width(lineSymbolizer); - float[] lineDash = SLD.lineDash(lineSymbolizer); - if (c != null && w > 0) { - g.setColor(c); - - Stroke str = new BasicStroke( - w, - BasicStroke.CAP_SQUARE, - BasicStroke.JOIN_MITER, - 10.0f, lineDash, 0.0f - ); - g.setStroke(str); - - g.draw(shape); - } - } - } else { - drawer.drawFeature(bi, feature, affineTransform, false, symbolizer, null, shape); - } - - } - - - } - - protected Geometry findGeometry(SimpleFeature feature, LineSymbolizer lineSymbolizer) { - String geomName = lineSymbolizer.getGeometryPropertyName(); - - Geometry geom; - if (geomName == null) { - geom = (Geometry) feature.getDefaultGeometry(); - } else { - geom = (Geometry) feature.getAttribute(geomName); - } - return geom; - } - - -} ===================================== client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapContentBuilder.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapContentBuilder.java +++ /dev/null @@ -1,476 +0,0 @@ -package fr.ird.observe.client.util.tripMap; - -/* - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; -import fr.ird.observe.client.I18nEnumHelper; -import fr.ird.observe.client.ObserveClientTechnicalException; -import fr.ird.observe.dto.data.TripMapPoint; -import fr.ird.observe.dto.data.TripMapPointType; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateUtils; -import org.geotools.data.FileDataStore; -import org.geotools.data.FileDataStoreFinder; -import org.geotools.data.simple.SimpleFeatureSource; -import org.geotools.factory.CommonFactoryFinder; -import org.geotools.feature.DefaultFeatureCollection; -import org.geotools.feature.simple.SimpleFeatureBuilder; -import org.geotools.feature.simple.SimpleFeatureTypeBuilder; -import org.geotools.geometry.jts.JTSFactoryFinder; -import org.geotools.map.FeatureLayer; -import org.geotools.map.Layer; -import org.geotools.map.MapContent; -import org.geotools.referencing.CRS; -import org.geotools.styling.NamedLayer; -import org.geotools.styling.SLD; -import org.geotools.styling.SLDParser; -import org.geotools.styling.Style; -import org.geotools.styling.StyleFactory; -import org.geotools.styling.StyledLayer; -import org.geotools.styling.StyledLayerDescriptor; -import org.geotools.styling.UserLayer; -import org.opengis.feature.simple.SimpleFeature; -import org.opengis.feature.simple.SimpleFeatureType; -import org.opengis.referencing.FactoryException; - - -import static org.nuiton.i18n.I18n.t; - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public class TripMapContentBuilder { - - public static final String TRIP_LINES_LAYER_NAME = "Trip lines"; - public static final String TRIP_LONGLINE_FISHING_ZONE_LAYER_NAME = "Trip longline zone"; - public static final String TRIP_LONGLINE_LINE_LAYER_NAME = "Trip longline line"; - public static final String TRIP_POINTS_LAYER_NAME = "Trip points"; - - protected static final Set<TripMapPointType> TRIP_MAP_POINT_TYPES_IN_LEGEND = ImmutableSet.of( - TripMapPointType.seineActivityInHarbour, - TripMapPointType.seineActivityWithFreeSchoolType, - TripMapPointType.seineActivityWithObjectSchoolType, - TripMapPointType.longlineActivityInHarbour, - TripMapPointType.longlineActivityWithSettingStart, - TripMapPointType.longlineActivityWithSettingEnd, - TripMapPointType.longlineActivityWithHaulingStart, - TripMapPointType.longlineActivityWithHaulingEnd, - TripMapPointType.longlineActivityWithStation, - TripMapPointType.longlineActivityWithInteraction); - - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM"); - - protected StyledLayerDescriptor styledLayerDescriptor; - protected final MapContent mapContent; - protected final List<ObserveMapPaneLegendItem> legendItems; - - public TripMapContentBuilder() { - mapContent = new MapContent(); - legendItems = Lists.newArrayList(); - } - - public MapContent getMapContent() { - return mapContent; - } - - public List<ObserveMapPaneLegendItem> getLegendItems() { - return legendItems; - } - - public void setStyledLayerDescriptor(File styleFile) throws FileNotFoundException { - - StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null); - - SLDParser stylereader = new SLDParser(styleFactory, styleFile); - - styledLayerDescriptor = stylereader.parseSLD(); - } - - public void addLayer(File layerFile) throws IOException { - FileDataStore store = FileDataStoreFinder.getDataStore(layerFile); - SimpleFeatureSource featureSource = store.getFeatureSource(); - Style style = SLD.createSimpleStyle(featureSource.getSchema()); - style = findStyle(styledLayerDescriptor, store.getNames().get(0).getLocalPart(), null, style); - Layer layer = new FeatureLayer(featureSource, style, layerFile.getName()); - mapContent.addLayer(layer); - } - - public void addTripLine(List<TripMapPoint> tripMapPoints) throws FactoryException { - - GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); - - SimpleFeatureTypeBuilder lineFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); - lineFeatureTypeBuilder.setName("lineBuilder"); - lineFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); - lineFeatureTypeBuilder.add("line", LineString.class); - lineFeatureTypeBuilder.add("label", String.class); - lineFeatureTypeBuilder.add("type", String.class); - - SimpleFeatureType lineFeatureType = lineFeatureTypeBuilder.buildFeatureType(); - SimpleFeatureBuilder lineBuilder = new SimpleFeatureBuilder(lineFeatureType); - - DefaultFeatureCollection linesFeatures = new DefaultFeatureCollection(); - - List<Coordinate> coordinatesByDay = null; - - TripMapPoint previousPoint = null; - - for (TripMapPoint point : tripMapPoints) { - if (previousPoint == null) { - coordinatesByDay = Lists.newLinkedList(); - } else if (!DateUtils.isSameDay(previousPoint.getTime(), point.getTime())) { - - if (coordinatesByDay.size() > 1) { - LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0])); - lineBuilder.add(line); - lineBuilder.add(DATE_FORMAT.format(previousPoint.getTime())); - lineBuilder.add("tripDay"); - SimpleFeature feature = lineBuilder.buildFeature(null); - - linesFeatures.add(feature); - } - - - Coordinate[] coordinates = { - new Coordinate(previousPoint.getLongitude(), previousPoint.getLatitude()), - new Coordinate(point.getLongitude(), point.getLatitude()), - }; - LineString lineBetweenTwoDays = geometryFactory.createLineString(coordinates); - lineBuilder.add(lineBetweenTwoDays); - lineBuilder.add(DateFormat.getDateInstance().format(previousPoint.getTime())); - lineBuilder.add("tripBetweenTwoDays"); - linesFeatures.add(lineBuilder.buildFeature(null)); - - coordinatesByDay = Lists.newLinkedList(); - } - - Coordinate coordinate = new Coordinate(point.getLongitude(), point.getLatitude()); - coordinatesByDay.add(coordinate); - - previousPoint = point; - } - - if (coordinatesByDay != null && coordinatesByDay.size() > 1) { - LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0])); - lineBuilder.add(line); - lineBuilder.add(DATE_FORMAT.format(previousPoint.getTime())); - lineBuilder.add("tripDay"); - linesFeatures.add(lineBuilder.buildFeature(null)); - } - - Style styleLines = findStyle(styledLayerDescriptor, TRIP_LINES_LAYER_NAME, null); - - if (!linesFeatures.isEmpty()) { - Layer layerLines = new FeatureLayer(linesFeatures, styleLines, TRIP_LINES_LAYER_NAME); - mapContent.addLayer(layerLines); - } - - - // add line in legend - LineString line = geometryFactory.createLineString(ObserveMapPaneLegendItem.lineCoordinates()); - lineBuilder.add(line); - lineBuilder.add(""); - lineBuilder.add("tripDay"); - - ObserveMapPaneLegendItem legendTripDay = new ObserveMapPaneLegendItem( - lineBuilder.buildFeature(null), - styleLines, - t("observe.content.map.legend.tripDay")); - legendItems.add(legendTripDay); - - lineBuilder.add(line); - lineBuilder.add(""); - lineBuilder.add("tripBetweenTwoDays"); - ObserveMapPaneLegendItem legendTripBetweenTwoDays = new ObserveMapPaneLegendItem( - lineBuilder.buildFeature(null), - styleLines, - t("observe.content.map.legend.tripBetweenTwoDays")); - legendItems.add(legendTripBetweenTwoDays); - - } - - public void addLonglineFishingZone(List<TripMapPoint> tripMapPoints) throws FactoryException { - GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); - - SimpleFeatureTypeBuilder polygonFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); - polygonFeatureTypeBuilder.setName("longlineFishingZoneBuilder"); - polygonFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); - polygonFeatureTypeBuilder.add("zone", Polygon.class); - polygonFeatureTypeBuilder.add("label", String.class); - polygonFeatureTypeBuilder.add("type", String.class); - - SimpleFeatureType polygonFeatureType = polygonFeatureTypeBuilder.buildFeatureType(); - SimpleFeatureBuilder polygonBuilder = new SimpleFeatureBuilder(polygonFeatureType); - - DefaultFeatureCollection polygonsFeatures = new DefaultFeatureCollection(); - - for (int indexPoint = 3; indexPoint < tripMapPoints.size(); indexPoint++) { - if (tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithHaulingEnd) - && tripMapPoints.get(indexPoint - 1).getType().equals(TripMapPointType.longlineActivityWithHaulingStart) - && tripMapPoints.get(indexPoint - 2).getType().equals(TripMapPointType.longlineActivityWithSettingEnd) - && tripMapPoints.get(indexPoint - 3).getType().equals(TripMapPointType.longlineActivityWithSettingStart)) { - - Coordinate[] coordinates = { - new Coordinate(tripMapPoints.get(indexPoint - 3).getLongitude(), tripMapPoints.get(indexPoint - 3).getLatitude()), - new Coordinate(tripMapPoints.get(indexPoint - 2).getLongitude(), tripMapPoints.get(indexPoint - 2).getLatitude()), - new Coordinate(tripMapPoints.get(indexPoint - 1).getLongitude(), tripMapPoints.get(indexPoint - 1).getLatitude()), - new Coordinate(tripMapPoints.get(indexPoint).getLongitude(), tripMapPoints.get(indexPoint).getLatitude()), - new Coordinate(tripMapPoints.get(indexPoint - 3).getLongitude(), tripMapPoints.get(indexPoint - 3).getLatitude()) - }; - - - Polygon polygon = geometryFactory.createPolygon(coordinates); - //polygon = (Polygon) polygon.convexHull(); // permet de transformer un poliqgone croisé en polygon convex - polygonBuilder.add(polygon); - polygonBuilder.add(DATE_FORMAT.format(tripMapPoints.get(indexPoint - 3).getTime())); - polygonBuilder.add("longlineFishingZone"); - SimpleFeature feature = polygonBuilder.buildFeature(null); - polygonsFeatures.add(feature); - - } - } - - if (!polygonsFeatures.isEmpty()) { - Style styleLines = findStyle(styledLayerDescriptor, TRIP_LONGLINE_FISHING_ZONE_LAYER_NAME, null); - Layer layerLines = new FeatureLayer(polygonsFeatures, styleLines, TRIP_LONGLINE_FISHING_ZONE_LAYER_NAME); - mapContent.addLayer(layerLines); - } - } - - public void addLonglineLine(List<TripMapPoint> tripMapPoints) throws FactoryException { - GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); - - SimpleFeatureTypeBuilder lineFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); - lineFeatureTypeBuilder.setName("longlineSettingBuilder"); - lineFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); - lineFeatureTypeBuilder.add("line", LineString.class); - lineFeatureTypeBuilder.add("type", String.class); - - SimpleFeatureType lineFeatureType = lineFeatureTypeBuilder.buildFeatureType(); - SimpleFeatureBuilder lineBuilder = new SimpleFeatureBuilder(lineFeatureType); - - DefaultFeatureCollection linesFeatures = new DefaultFeatureCollection(); - - List<Coordinate> defaultLineCoordinates = Lists.newLinkedList(); - - for (int indexPoint = 0; indexPoint < tripMapPoints.size(); indexPoint++) { - if (indexPoint > 1 && tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithSettingEnd) - && tripMapPoints.get(indexPoint - 1).getType().equals(TripMapPointType.longlineActivityWithSettingStart) - || tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithHaulingEnd) - && tripMapPoints.get(indexPoint - 1).getType().equals(TripMapPointType.longlineActivityWithHaulingStart)) { - - Coordinate[] coordinates = { - new Coordinate(tripMapPoints.get(indexPoint - 1).getLongitude(), tripMapPoints.get(indexPoint - 1).getLatitude()), - new Coordinate(tripMapPoints.get(indexPoint).getLongitude(), tripMapPoints.get(indexPoint).getLatitude()), - }; - - boolean setting = tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithSettingEnd); - LineString lineString = geometryFactory.createLineString(coordinates); - lineBuilder.add(lineString); - lineBuilder.add(setting ? "setting" : "hauling"); - SimpleFeature feature = lineBuilder.buildFeature(null); - linesFeatures.add(feature); - - defaultLineCoordinates.clear(); - } - - if (!(tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithSettingEnd) - || tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithHaulingStart))) { - - defaultLineCoordinates.add(new Coordinate(tripMapPoints.get(indexPoint).getLongitude(), tripMapPoints.get(indexPoint).getLatitude())); - - } - - if ((tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithSettingStart) - || indexPoint == tripMapPoints.size() - 1) && defaultLineCoordinates.size() > 1) { - - LineString lineString = geometryFactory.createLineString(defaultLineCoordinates.toArray(new Coordinate[0])); - lineBuilder.add(lineString); - lineBuilder.add("trip"); - SimpleFeature feature = lineBuilder.buildFeature(null); - linesFeatures.add(feature); - - defaultLineCoordinates.clear(); - - } - - - } - - Style styleLines = findStyle(styledLayerDescriptor, TRIP_LONGLINE_LINE_LAYER_NAME, null); - if (!linesFeatures.isEmpty()) { - Layer layerLines = new FeatureLayer(linesFeatures, styleLines, TRIP_LONGLINE_LINE_LAYER_NAME); - mapContent.addLayer(layerLines); - } - - // add line in legend - LineString line = geometryFactory.createLineString(ObserveMapPaneLegendItem.lineCoordinates()); - lineBuilder.add(line); - lineBuilder.add("setting"); - - ObserveMapPaneLegendItem legendTripDay = new ObserveMapPaneLegendItem( - lineBuilder.buildFeature(null), - styleLines, - t("observe.content.map.legend.setting")); - legendItems.add(legendTripDay); - - line = geometryFactory.createLineString(ObserveMapPaneLegendItem.lineCoordinates()); - lineBuilder.add(line); - lineBuilder.add("hauling"); - - legendTripDay = new ObserveMapPaneLegendItem( - lineBuilder.buildFeature(null), - styleLines, - t("observe.content.map.legend.hauling")); - legendItems.add(legendTripDay); - - - } - - - public void addPoints(List<TripMapPoint> tripMapPoints) throws FactoryException { - - GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); - - SimpleFeatureTypeBuilder pointFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); - pointFeatureTypeBuilder.setName("point Builder"); - pointFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); - pointFeatureTypeBuilder.add("point", Point.class); - pointFeatureTypeBuilder.add("label", String.class); - pointFeatureTypeBuilder.add("pointType", String.class); - - SimpleFeatureType pointFeatureType = pointFeatureTypeBuilder.buildFeatureType(); - SimpleFeatureBuilder pointBuilder = new SimpleFeatureBuilder(pointFeatureType); - - DefaultFeatureCollection pointsFeatures = new DefaultFeatureCollection(); - - Style stylePoints = findStyle(styledLayerDescriptor, TRIP_POINTS_LAYER_NAME, null); - - Set<TripMapPointType> pointTypeInLegend = Sets.newHashSet(); - - for (TripMapPoint tripMapPoint : tripMapPoints) { - Coordinate coordinate = new Coordinate(tripMapPoint.getLongitude(), tripMapPoint.getLatitude()); - - TripMapPointType type = tripMapPoint.getType(); - - Point point = geometryFactory.createPoint(coordinate); - pointBuilder.add(point); - pointBuilder.add(DATE_FORMAT.format(tripMapPoint.getTime())); - pointBuilder.add(type.name()); - pointsFeatures.add(pointBuilder.buildFeature(null)); - - // add point in legend - if (TRIP_MAP_POINT_TYPES_IN_LEGEND.contains(type) && !pointTypeInLegend.contains(type)) { - point = geometryFactory.createPoint(ObserveMapPaneLegendItem.pointCoordinates()); - pointBuilder.add(point); - pointBuilder.add(""); - pointBuilder.add(type.name()); - - ObserveMapPaneLegendItem legendPoint = new ObserveMapPaneLegendItem( - pointBuilder.buildFeature(null), - stylePoints, - I18nEnumHelper.getLabel(type)); - legendItems.add(legendPoint); - pointTypeInLegend.add(type); - } - - } - - if (!pointsFeatures.isEmpty()) { - Layer pointsLayer = new FeatureLayer(pointsFeatures, stylePoints, TRIP_POINTS_LAYER_NAME); - mapContent.addLayer(pointsLayer); - } - - } - - - protected Style findStyle(StyledLayerDescriptor styledLayerDescriptor, final String layerName, String styleName, Style defaultStyle) { - - Optional<StyledLayer> styledLayerOptional = styledLayerDescriptor.layers().stream().filter(input -> input.getName().equals(layerName)).findFirst(); - - Style style = defaultStyle; - - if (styledLayerOptional.isPresent()) { - - StyledLayer styledLayer = styledLayerOptional.get(); - - Style[] styles = new Style[0]; - - if (styledLayer instanceof UserLayer) { - - styles = ((UserLayer) styledLayer).getUserStyles(); - - } else if (styledLayer instanceof NamedLayer) { - - styles = ((NamedLayer) styledLayer).getStyles(); - - } - - if (styles.length == 1) { - - style = styles[0]; - - } else { - - for (Style styleTmp : styles) { - - if (StringUtils.isBlank(styleName) && styleTmp.isDefault() - || styleTmp.getName().equals(styleName)) { - - style = styleTmp; - } - } - } - } - - return style; - - } - - protected Style findStyle(StyledLayerDescriptor styledLayerDescriptor, final String layerName, String styleName) { - - Style style = findStyle(styledLayerDescriptor, layerName, styleName, null); - - if (style == null) { - throw new ObserveClientTechnicalException(String.format("No style found for layer name '%s' and style name '%s'", layerName, styleName)); - } - return style; - - } - -} ===================================== client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUI.jaxx deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUI.jaxx +++ /dev/null @@ -1,45 +0,0 @@ -<!-- - #%L - ObServe :: Client - %% - Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - %% - 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% - --> -<JPanel id="tripMap" layout="{new BorderLayout()}"> - - <import> - fr.ird.observe.client.action.tripMap.ExportPngUIAction - fr.ird.observe.client.action.tripMap.ZoomItUIAction - fr.ird.observe.client.action.tripMap.ZoomMoinsUIAction - fr.ird.observe.client.action.tripMap.ZoomPlusUIAction - java.awt.CardLayout - </import> - - <CardLayout id="contentLayout"/> - <JToolBar constraints="BorderLayout.NORTH"> - <JButton id='zoomIt'/> - <JButton id='zoomPlus'/> - <JButton id='zoomMoins'/> - <JButton id='exportPng'/> - </JToolBar> - - <JPanel id="content" layout="{contentLayout}" constraints="BorderLayout.CENTER"> - <JLabel id="waitLoadingLabel"/> - <ObserveMapPane id='observeMapPane'/> - </JPanel> - -</JPanel> ===================================== client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUI.jcss deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUI.jcss +++ /dev/null @@ -1,44 +0,0 @@ -/* - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -#waitLoadingLabel { - text: "observe.content.map.waitLoading"; - horizontalAlignment : {JLabel.CENTER}; - verticalAlignment : {JLabel.CENTER}; - enabled: false; -} - -#zoomIt { - _observeAction:{ZoomItUIAction.ACTION_NAME}; -} - -#zoomMoins { - _observeAction:{ZoomMoinsUIAction.ACTION_NAME}; -} - -#zoomPlus { - _observeAction:{ZoomPlusUIAction.ACTION_NAME}; -} - -#exportPng { - _observeAction:{ExportPngUIAction.ACTION_NAME}; -} ===================================== client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUIHandler.java deleted ===================================== --- a/client/src/main/java/fr/ird/observe/client/util/tripMap/TripMapUIHandler.java +++ /dev/null @@ -1,379 +0,0 @@ -package fr.ird.observe.client.util.tripMap; - -/* - * #%L - * ObServe :: Client - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import com.google.common.collect.Lists; -import fr.ird.observe.client.ObserveClientApplicationContext; -import fr.ird.observe.client.ObserveClientTechnicalException; -import fr.ird.observe.client.configuration.ClientConfig; -import fr.ird.observe.client.action.ObserveActionMap; -import fr.ird.observe.client.action.tripMap.TripMapActionSupport; -import fr.ird.observe.dto.IdHelper; -import fr.ird.observe.dto.data.TripMapDto; -import fr.ird.observe.dto.data.TripMapPoint; -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.io.File; -import java.util.List; -import java.util.Objects; -import javax.swing.AbstractButton; -import javax.swing.InputMap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.geotools.geometry.DirectPosition2D; -import org.geotools.geometry.jts.ReferencedEnvelope; -import org.geotools.swing.JMapPane; -import org.geotools.swing.event.MapPaneEvent; -import org.geotools.swing.event.MapPaneListener; -import org.nuiton.jaxx.runtime.spi.UIHandler; - - -import static fr.ird.observe.client.form.FormUIHandler.OBSERVE_ACTION; - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public class TripMapUIHandler implements UIHandler<TripMapUI> { - - public static final double ZOOM_STEP_RATIO = 0.1; - - private static final Log log = LogFactory.getLog(TripMapUIHandler.class); - - private TripMapUI ui; - private ClientConfig config; - private ReferencedEnvelope tripArea; - private boolean rendererRunning; - private double zoomRatio = 1; - private Point zoomCenter; - - public void setConfig(ClientConfig config) { - this.config = config; - - JMapPane mapPane = getObserveMapPane(); - mapPane.setBackground(config.getMapBackgroundColor()); - } - - private ObserveMapPane getObserveMapPane() { - return ui.getObserveMapPane(); - } - - public void doOpenMap(TripMapDto tripMapDto) { - - try { - flipContent(); - ObserveClientApplicationContext.get().getMainUI().getModel().setBusy(true); - - ObserveMapPane mapPane = getObserveMapPane(); - - if (mapPane.getMapContent() != null) { - // appeler pour libéré les listeners - mapPane.getMapContent().dispose(); - } - - List<TripMapPoint> tripMapPoints = Lists.newArrayList(tripMapDto.getPoints()); - - - TripMapContentBuilder mapContentBuilder = new TripMapContentBuilder(); - mapContentBuilder.setStyledLayerDescriptor(config.getMapStyleFile()); - - for (File layerFile : config.getMapLayerFiles()) { - mapContentBuilder.addLayer(layerFile); - } - - if (IdHelper.isSeineId(tripMapDto.getId())) { - - mapContentBuilder.addTripLine(tripMapPoints); - - } else if (IdHelper.isLonglineId(tripMapDto.getId())) { - - mapContentBuilder.addLonglineFishingZone(tripMapPoints); - mapContentBuilder.addLonglineLine(tripMapPoints); - - } - - mapContentBuilder.addPoints(tripMapPoints); - - // set zoom - tripArea = new ReferencedEnvelope(); - for (TripMapPoint point : tripMapPoints) { - tripArea.expandToInclude(new DirectPosition2D(point.getLongitude(), point.getLatitude())); - } - tripArea.expandBy(1.1); - - mapPane.setMapContent(mapContentBuilder.getMapContent()); - mapPane.setLegendItems(mapContentBuilder.getLegendItems()); - - } catch (Exception e) { - throw new ObserveClientTechnicalException("Unable to load trip map activity points", e); - } finally { - ObserveClientApplicationContext.get().getMainUI().getModel().setBusy(false); - } - - } - - private void flipContent() { - ui.getContentLayout().first(ui.getContent()); - } - - public void doCloseMap() { - flipContent(); - } - - public void zoomApply() { - if (zoomRatio != 1 && !rendererRunning) { - - JMapPane mapPane = getObserveMapPane(); - - ReferencedEnvelope displayArea = mapPane.getDisplayArea(); - - double deltaWidth = displayArea.getWidth() * (zoomRatio - 1); - double deltaHeight = displayArea.getHeight() * (zoomRatio - 1); - - double ratioLeft = zoomCenter.getX() * 1d / mapPane.getWidth(); - - // l'axe de Y est inversé entre le référentiel du composant swing et le référentiel géographique - double ratioTop = 1 - (zoomCenter.getY() * 1d / mapPane.getHeight()); - - double deltaLeft = deltaWidth * ratioLeft; - double deltaRight = deltaLeft - deltaWidth; - - double deltaTop = deltaHeight * ratioTop; - double deltaBottom = deltaTop - deltaHeight; - - if (log.isDebugEnabled()) { - log.debug(String.format("Map mouse zoom (zoom ratio : %s, deltaLeft : %s, deltaRight : %s, deltaTop : %s, deltaBottom : %s)", - zoomRatio, deltaLeft, deltaRight, deltaRight, deltaBottom)); - } - - ReferencedEnvelope newDisplayArea = new ReferencedEnvelope( - displayArea.getMinX() + deltaLeft, - displayArea.getMaxX() + deltaRight, - displayArea.getMinY() + deltaTop, - displayArea.getMaxY() + deltaBottom, - displayArea.getCoordinateReferenceSystem() - ); - // -230 is the good value (don't ask me why ?) - if (newDisplayArea.getLowerCorner().getOrdinate(0) > -230) { - mapPane.setDisplayArea(newDisplayArea); - } - - zoomRatio = 1; - - } - - } - - @Override - public void beforeInit(TripMapUI ui) { - this.ui = ui; - } - - @Override - public void afterInit(TripMapUI ui) { - - ObserveMapPane mapPane = getObserveMapPane(); - - MouseMapListener mouseMapListener = new MouseMapListener(); - mapPane.addMouseWheelListener(mouseMapListener); - mapPane.addMouseMotionListener(mouseMapListener); - mapPane.addMouseListener(mouseMapListener); - mapPane.addMapPaneListener(new TripMapListener()); - - rendererRunning = false; - - } - - public void init(InputMap inputMap) { - ObserveActionMap actionMap = ObserveClientApplicationContext.get().getActionMap(); - - init(actionMap, inputMap, ui.zoomIt); - init(actionMap, inputMap, ui.zoomMoins); - init(actionMap, inputMap, ui.zoomPlus); - init(actionMap, inputMap, ui.exportPng); - - } - - public ReferencedEnvelope getTripArea() { - return tripArea; - } - - public double getZoomRatio() { - return zoomRatio; - } - - public void setZoomRatio(double zoomRatio) { - this.zoomRatio = zoomRatio; - } - - public void setZoomCenter(Point zoomCenter) { - this.zoomCenter = zoomCenter; - } - - private class MouseMapListener implements MouseWheelListener, MouseListener, MouseMotionListener { - - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - int notches = e.getWheelRotation(); - zoomRatio = zoomRatio * (1 + (ZOOM_STEP_RATIO * notches * -1)); - zoomCenter = e.getPoint(); - zoomApply(); - } - - @Override - public void mouseClicked(MouseEvent e) { - - } - - Point2D startPointInWorld; - AffineTransform startScreenToWorldTransform; - ReferencedEnvelope startDisplayArea; - - @Override - public void mousePressed(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1) { - startMove(e.getPoint()); - } - } - - @Override - public void mouseReleased(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1) { - endMove(e.getPoint()); - } - } - - @Override - public void mouseEntered(MouseEvent e) { - - } - - @Override - public void mouseExited(MouseEvent e) { - - } - - @Override - public void mouseDragged(MouseEvent e) { -// endMove(e.getPoint()); - } - - @Override - public void mouseMoved(MouseEvent e) { - - } - - void startMove(Point2D startPointInScreen) { - JMapPane mapPane = getObserveMapPane(); - - startDisplayArea = mapPane.getDisplayArea(); - - startScreenToWorldTransform = mapPane.getScreenToWorldTransform(); - - startPointInWorld = new Point2D.Double(); - - startScreenToWorldTransform.transform(startPointInScreen, startPointInWorld); - - } - - void endMove(Point2D endPointInScreen) { - - Point2D endPointInWorld = new Point2D.Double(); - - startScreenToWorldTransform.transform(endPointInScreen, endPointInWorld); - - double transX = startPointInWorld.getX() - endPointInWorld.getX(); - double transY = startPointInWorld.getY() - endPointInWorld.getY(); - - ReferencedEnvelope endDisplayArea = new ReferencedEnvelope(startDisplayArea); - - endDisplayArea.translate(transX, transY); - - JMapPane mapPane = getObserveMapPane(); - - mapPane.setDisplayArea(endDisplayArea); - - if (log.isDebugEnabled()) { - log.debug(String.format("Translate (x : %s, y : %s)", transX, transY)); - } - } - } - - protected class TripMapListener implements MapPaneListener { - - boolean firstRendering; - - @Override - public void onNewMapContent(MapPaneEvent ev) { - firstRendering = true; - } - - @Override - public void onDisplayAreaChanged(MapPaneEvent ev) { - } - - @Override - public void onRenderingStarted(MapPaneEvent ev) { - rendererRunning = true; - } - - @Override - public void onRenderingStopped(MapPaneEvent ev) { - rendererRunning = false; - if (firstRendering) { - - if (!tripArea.isEmpty()) { - JMapPane mapPane = getObserveMapPane(); - mapPane.setDisplayArea(tripArea); - } - - ui.getContentLayout().last(ui.getContent()); - firstRendering = false; - } else { - zoomApply(); - } - } - } - - protected void init(ObserveActionMap actionMap, InputMap inputMap, AbstractButton editor) { - String actionId = (String) editor.getClientProperty(OBSERVE_ACTION); - - // on a trouve une action commune - TripMapActionSupport action = (TripMapActionSupport) actionMap.get(actionId); - Objects.requireNonNull(action, "action [" + actionId + "] not found for ui " + ui.getClass().getName()); - - if (log.isDebugEnabled()) { - log.debug("init common action " + actionId); - } - - action.setUi(ui); - action.initForMainUi(editor, inputMap, actionMap); - - } - -} ===================================== dto/src/main/java/fr/ird/observe/dto/data/TripMapDto.java deleted ===================================== --- a/dto/src/main/java/fr/ird/observe/dto/data/TripMapDto.java +++ /dev/null @@ -1,97 +0,0 @@ -package fr.ird.observe.dto.data; - -/*- - * #%L - * ObServe :: Dto - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -import fr.ird.observe.dto.IdDto; -import java.util.Collection; -import java.util.LinkedHashSet; - -public class TripMapDto extends IdDto { - - public static final String PROPERTY_POINTS = "points"; - - protected LinkedHashSet<TripMapPoint> points; - - public TripMapPoint getPoints(int index) { - TripMapPoint o = getChild(points, index); - return o; - } - - public boolean isPointsEmpty() { - return points == null || points.isEmpty(); - } - - public int sizePoints() { - return points == null ? 0 : points.size(); - } - - public void addPoints(TripMapPoint points) { - getPoints().add(points); - firePropertyChange(PROPERTY_POINTS, null, points); - } - - public void addAllPoints(Collection<TripMapPoint> points) { - getPoints().addAll(points); - firePropertyChange(PROPERTY_POINTS, null, points); - } - - public boolean removePoints(TripMapPoint points) { - boolean removed = getPoints().remove(points); - if (removed) { - firePropertyChange(PROPERTY_POINTS, points, null); - } - return removed; - } - - public boolean removeAllPoints(Collection<TripMapPoint> points) { - boolean removed = getPoints().removeAll(points); - if (removed) { - firePropertyChange(PROPERTY_POINTS, points, null); - } - return removed; - } - - public boolean containsPoints(TripMapPoint points) { - boolean contains = getPoints().contains(points); - return contains; - } - - public boolean containsAllPoints(Collection<TripMapPoint> points) { - boolean contains = getPoints().containsAll(points); - return contains; - } - - public LinkedHashSet<TripMapPoint> getPoints() { - if (points == null) { - points = new LinkedHashSet<>(); - } - return points; - } - - public void setPoints(LinkedHashSet<TripMapPoint> points) { - LinkedHashSet<TripMapPoint> oldValue = getPoints(); - this.points = points; - firePropertyChange(PROPERTY_POINTS, oldValue, points); - } - -} ===================================== pom.xml ===================================== --- a/pom.xml +++ b/pom.xml @@ -151,7 +151,7 @@ <maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format> <buildDate>${maven.build.timestamp}</buildDate> - <observeToolkitVersion>1.6-SNAPSHOT</observeToolkitVersion> + <observeToolkitVersion>1.6</observeToolkitVersion> <eugenePluginVersion>3.0-alpha-16</eugenePluginVersion> <processorPluginVersion>1.3</processorPluginVersion> View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/617ddef49f75a381f84455ae1609... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/617ddef49f75a381f84455ae1609... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT