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
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:
| ... | ... | @@ -28,6 +28,7 @@ import com.google.gson.Gson; |
| 28 | 28 |
import fr.ird.observe.client.constants.CreationMode;
|
| 29 | 29 |
import fr.ird.observe.client.constants.DbMode;
|
| 30 | 30 |
import fr.ird.observe.dto.FloatingObjectPreset;
|
| 31 |
+import fr.ird.observe.dto.data.TripMapConfig;
|
|
| 31 | 32 |
import fr.ird.observe.dto.presets.RemoteDataSourceConfiguration;
|
| 32 | 33 |
import fr.ird.observe.dto.presets.ServerDataSourceConfiguration;
|
| 33 | 34 |
import java.beans.PropertyChangeListener;
|
| ... | ... | @@ -62,7 +63,7 @@ import static org.nuiton.i18n.I18n.t; |
| 62 | 63 |
* @author Tony Chemit - dev@tchemit.fr
|
| 63 | 64 |
* @since 1.0
|
| 64 | 65 |
*/
|
| 65 |
-public class ClientConfig extends GeneratedClientConfig {
|
|
| 66 |
+public class ClientConfig extends GeneratedClientConfig implements TripMapConfig {
|
|
| 66 | 67 |
|
| 67 | 68 |
/** le pattern du fichier de sauvegarde d'une base locale */
|
| 68 | 69 |
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 { |
| 455 | 456 |
public void setRemoteDataSourceConfigurations(RemoteDataSourceConfiguration[] configurations) {
|
| 456 | 457 |
String option = new Gson().toJson(configurations);
|
| 457 | 458 |
get().setOption(ClientConfigOption.REMOTE_DATA_SOURCE_CONFIGURATIONS.getKey(), option);
|
| 458 |
- remoteDataSourceConfigurationList=null;
|
|
| 459 |
+ remoteDataSourceConfigurationList = null;
|
|
| 459 | 460 |
}
|
| 460 | 461 |
|
| 461 | 462 |
ImmutableList<ServerDataSourceConfiguration> serverDataSourceConfigurationList;
|
| ... | ... | @@ -511,7 +512,7 @@ public class ClientConfig extends GeneratedClientConfig { |
| 511 | 512 |
public void setServerDataSourceConfigurations(ServerDataSourceConfiguration[] configurations) {
|
| 512 | 513 |
String option = new Gson().toJson(configurations);
|
| 513 | 514 |
get().setOption(ClientConfigOption.SERVER_DATA_SOURCE_CONFIGURATIONS.getKey(), option);
|
| 514 |
- serverDataSourceConfigurationList=null;
|
|
| 515 |
+ serverDataSourceConfigurationList = null;
|
|
| 515 | 516 |
}
|
| 516 | 517 |
|
| 517 | 518 |
private final SimpleDateFormat dateFormat = new SimpleDateFormat();
|
| ... | ... | @@ -79,6 +79,16 @@ |
| 79 | 79 |
</releases>
|
| 80 | 80 |
</repository>
|
| 81 | 81 |
</repositories>
|
| 82 |
+ <pluginRepositories>
|
|
| 83 |
+ <pluginRepository>
|
|
| 84 |
+ <id>geotools-repository</id>
|
|
| 85 |
+ <url>http://download.osgeo.org/webdav/geotools</url>
|
|
| 86 |
+ <releases>
|
|
| 87 |
+ <enabled>true</enabled>
|
|
| 88 |
+ <checksumPolicy>fail</checksumPolicy>
|
|
| 89 |
+ </releases>
|
|
| 90 |
+ </pluginRepository>
|
|
| 91 |
+ </pluginRepositories>
|
|
| 82 | 92 |
|
| 83 | 93 |
<dependencyManagement>
|
| 84 | 94 |
<dependencies>
|
| ... | ... | @@ -402,10 +412,10 @@ |
| 402 | 412 |
<groupId>io.ultreia.java4all.jaxx</groupId>
|
| 403 | 413 |
<artifactId>jaxx-runtime-swing-application</artifactId>
|
| 404 | 414 |
</dependency>
|
| 405 |
- <dependency>
|
|
| 415 |
+ <!--dependency>
|
|
| 406 | 416 |
<groupId>io.ultreia.java4all.jaxx</groupId>
|
| 407 | 417 |
<artifactId>jaxx-runtime-swing-session</artifactId>
|
| 408 |
- </dependency>
|
|
| 418 |
+ </dependency-->
|
|
| 409 | 419 |
<dependency>
|
| 410 | 420 |
<groupId>io.ultreia.java4all.jaxx</groupId>
|
| 411 | 421 |
<artifactId>jaxx-runtime-swing-wizard</artifactId>
|
| ... | ... | @@ -418,10 +428,10 @@ |
| 418 | 428 |
<groupId>io.ultreia.java4all.jaxx</groupId>
|
| 419 | 429 |
<artifactId>jaxx-widgets-error</artifactId>
|
| 420 | 430 |
</dependency>
|
| 421 |
- <dependency>
|
|
| 431 |
+ <!--dependency>
|
|
| 422 | 432 |
<groupId>io.ultreia.java4all.jaxx</groupId>
|
| 423 | 433 |
<artifactId>jaxx-widgets-hidor</artifactId>
|
| 424 |
- </dependency>
|
|
| 434 |
+ </dependency-->
|
|
| 425 | 435 |
<dependency>
|
| 426 | 436 |
<groupId>io.ultreia.java4all.jaxx</groupId>
|
| 427 | 437 |
<artifactId>jaxx-widgets-gis</artifactId>
|
| ... | ... | @@ -529,10 +539,10 @@ |
| 529 | 539 |
<groupId>org.swinglabs.swingx</groupId>
|
| 530 | 540 |
<artifactId>swingx-core</artifactId>
|
| 531 | 541 |
</dependency>
|
| 532 |
- <dependency>
|
|
| 542 |
+ <!--dependency>
|
|
| 533 | 543 |
<groupId>org.swinglabs.swingx</groupId>
|
| 534 | 544 |
<artifactId>swingx-painters</artifactId>
|
| 535 |
- </dependency>
|
|
| 545 |
+ </dependency-->
|
|
| 536 | 546 |
<dependency>
|
| 537 | 547 |
<groupId>org.swinglabs.swingx</groupId>
|
| 538 | 548 |
<artifactId>swingx-common</artifactId>
|
| ... | ... | @@ -552,10 +562,10 @@ |
| 552 | 562 |
<artifactId>h2</artifactId>
|
| 553 | 563 |
</dependency>
|
| 554 | 564 |
|
| 555 |
- <dependency>
|
|
| 565 |
+ <!--dependency>
|
|
| 556 | 566 |
<groupId>org.reflections</groupId>
|
| 557 | 567 |
<artifactId>reflections</artifactId>
|
| 558 |
- </dependency>
|
|
| 568 |
+ </dependency-->
|
|
| 559 | 569 |
|
| 560 | 570 |
<!-- FreeMarker -->
|
| 561 | 571 |
<dependency>
|
| ... | ... | @@ -567,26 +577,32 @@ |
| 567 | 577 |
<dependency>
|
| 568 | 578 |
<groupId>org.geotools</groupId>
|
| 569 | 579 |
<artifactId>gt-swing</artifactId>
|
| 580 |
+ <scope>runtime</scope>
|
|
| 570 | 581 |
</dependency>
|
| 571 | 582 |
<dependency>
|
| 572 | 583 |
<groupId>org.geotools</groupId>
|
| 573 | 584 |
<artifactId>gt-api</artifactId>
|
| 585 |
+ <scope>runtime</scope>
|
|
| 574 | 586 |
</dependency>
|
| 575 | 587 |
<dependency>
|
| 576 | 588 |
<groupId>org.geotools</groupId>
|
| 577 | 589 |
<artifactId>gt-main</artifactId>
|
| 590 |
+ <scope>runtime</scope>
|
|
| 578 | 591 |
</dependency>
|
| 579 | 592 |
<dependency>
|
| 580 | 593 |
<groupId>org.geotools</groupId>
|
| 581 | 594 |
<artifactId>gt-render</artifactId>
|
| 595 |
+ <scope>runtime</scope>
|
|
| 582 | 596 |
</dependency>
|
| 583 | 597 |
<dependency>
|
| 584 | 598 |
<groupId>org.geotools</groupId>
|
| 585 | 599 |
<artifactId>gt-referencing</artifactId>
|
| 600 |
+ <scope>runtime</scope>
|
|
| 586 | 601 |
</dependency>
|
| 587 | 602 |
<dependency>
|
| 588 | 603 |
<groupId>org.geotools</groupId>
|
| 589 | 604 |
<artifactId>gt-opengis</artifactId>
|
| 605 |
+ <scope>runtime</scope>
|
|
| 590 | 606 |
</dependency>
|
| 591 | 607 |
<dependency>
|
| 592 | 608 |
<groupId>org.geotools</groupId>
|
| ... | ... | @@ -601,6 +617,7 @@ |
| 601 | 617 |
<dependency>
|
| 602 | 618 |
<groupId>com.vividsolutions</groupId>
|
| 603 | 619 |
<artifactId>jts</artifactId>
|
| 620 |
+ <scope>runtime</scope>
|
|
| 604 | 621 |
</dependency>
|
| 605 | 622 |
|
| 606 | 623 |
<dependency>
|
| ... | ... | @@ -688,6 +705,13 @@ |
| 688 | 705 |
</goals>
|
| 689 | 706 |
</execution>
|
| 690 | 707 |
</executions>
|
| 708 |
+ <dependencies>
|
|
| 709 |
+ <dependency>
|
|
| 710 |
+ <groupId>org.geotools</groupId>
|
|
| 711 |
+ <artifactId>gt-swing</artifactId>
|
|
| 712 |
+ <version>${geoToolsVersion}</version>
|
|
| 713 |
+ </dependency>
|
|
| 714 |
+ </dependencies>
|
|
| 691 | 715 |
</plugin>
|
| 692 | 716 |
|
| 693 | 717 |
<plugin>
|
| ... | ... | @@ -169,30 +169,40 @@ public void registerAction(AbstractButton editor) { |
| 169 | 169 |
actionMap.registerAction(editor);
|
| 170 | 170 |
}
|
| 171 | 171 |
|
| 172 |
+@Override
|
|
| 172 | 173 |
public void displayInfo(String text) {
|
| 173 | 174 |
status.setStatus(text);
|
| 174 | 175 |
}
|
| 175 | 176 |
|
| 177 |
+@Override
|
|
| 176 | 178 |
public void displayInfo(String title, String text) {
|
| 177 | 179 |
JOptionPanes.displayInfo(this, title, text);
|
| 178 | 180 |
}
|
| 179 | 181 |
|
| 182 |
+@Override
|
|
| 180 | 183 |
public void displayWarning(String title, String text) {
|
| 181 | 184 |
JOptionPanes.displayWarning(this, title, text);
|
| 182 | 185 |
}
|
| 183 | 186 |
|
| 187 |
+@Override
|
|
| 184 | 188 |
public int askUser(String title, String message, int typeMessage, Object[] options, int defaultOption) {
|
| 185 | 189 |
return JOptionPanes.askUser(this, title, message, typeMessage, options, defaultOption);
|
| 186 | 190 |
}
|
| 187 | 191 |
|
| 192 |
+@Override
|
|
| 188 | 193 |
public int askUser(String title, Object message, int typeMessage, Object[] options, int defaultOption) {
|
| 189 | 194 |
return JOptionPanes.askUser(this, title, message, typeMessage, options, defaultOption);
|
| 190 | 195 |
}
|
| 191 | 196 |
|
| 197 |
+@Override
|
|
| 192 | 198 |
public int askUser(JOptionPane pane, String title, Object[] options) {
|
| 193 | 199 |
return JOptionPanes.askUser(this, pane, title, options);
|
| 194 | 200 |
}
|
| 195 | 201 |
|
| 202 |
+@Override
|
|
| 203 |
+public void setBusy(boolean busy) {
|
|
| 204 |
+ model.setBusy(busy);
|
|
| 205 |
+}
|
|
| 196 | 206 |
]]>
|
| 197 | 207 |
</script>
|
| 198 | 208 |
|
| 1 |
-package fr.ird.observe.client.action.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.client.ObserveClientTechnicalException;
|
|
| 26 |
-import fr.ird.observe.client.ObserveMainUI;
|
|
| 27 |
-import fr.ird.observe.client.util.tripMap.TripMapUI;
|
|
| 28 |
-import java.awt.image.BufferedImage;
|
|
| 29 |
-import java.io.File;
|
|
| 30 |
-import java.io.IOException;
|
|
| 31 |
-import javax.imageio.ImageIO;
|
|
| 32 |
-import javax.swing.KeyStroke;
|
|
| 33 |
-import org.nuiton.jaxx.widgets.file.JaxxFileChoosers;
|
|
| 34 |
- |
|
| 35 |
- |
|
| 36 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 37 |
- |
|
| 38 |
-/**
|
|
| 39 |
- * Created by tchemit on 25/08/17.
|
|
| 40 |
- *
|
|
| 41 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 42 |
- */
|
|
| 43 |
-public class ExportPngUIAction extends TripMapActionSupport {
|
|
| 44 |
- |
|
| 45 |
- public static final String ACTION_NAME = ExportPngUIAction.class.getName();
|
|
| 46 |
- |
|
| 47 |
- public ExportPngUIAction(ObserveMainUI mainUI) {
|
|
| 48 |
- super(mainUI,
|
|
| 49 |
- ACTION_NAME,
|
|
| 50 |
- t("observe.content.map.action.exportPng"),
|
|
| 51 |
- t("observe.content.map.action.exportPng.tip"),
|
|
| 52 |
- "save",
|
|
| 53 |
- KeyStroke.getKeyStroke("ctrl pressed S"));
|
|
| 54 |
- }
|
|
| 55 |
- |
|
| 56 |
- @Override
|
|
| 57 |
- protected void actionPerformed(TripMapUI view) {
|
|
| 58 |
- |
|
| 59 |
- File file = JaxxFileChoosers.chooseFile(
|
|
| 60 |
- view,
|
|
| 61 |
- t("observe.content.map.export.chooseFile.title"),
|
|
| 62 |
- t("observe.content.map.export.chooseFile.ok"),
|
|
| 63 |
- null,
|
|
| 64 |
- "^.+\\.png|.+\\.PNG$",
|
|
| 65 |
- t("observe.content.map.export.chooseFile.png"));
|
|
| 66 |
- |
|
| 67 |
- if (file != null && JaxxFileChoosers.confirmOverwriteFileIfExist(view, file)) {
|
|
| 68 |
- |
|
| 69 |
- BufferedImage im = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
|
| 70 |
- view.paint(im.getGraphics());
|
|
| 71 |
- try {
|
|
| 72 |
- ImageIO.write(im, "PNG", file);
|
|
| 73 |
- } catch (IOException e) {
|
|
| 74 |
- throw new ObserveClientTechnicalException("unable to export map ", e);
|
|
| 75 |
- }
|
|
| 76 |
- |
|
| 77 |
- displayInfo(t("observe.content.map.export.success", file));
|
|
| 78 |
- }
|
|
| 79 |
- }
|
|
| 80 |
-}
|
| 1 |
-package fr.ird.observe.client.action.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.client.action.UIActionSupport;
|
|
| 26 |
-import fr.ird.observe.client.ObserveMainUI;
|
|
| 27 |
-import fr.ird.observe.client.form.TripUI;
|
|
| 28 |
-import fr.ird.observe.client.util.tripMap.TripMapUI;
|
|
| 29 |
-import java.awt.event.ActionEvent;
|
|
| 30 |
-import javax.swing.JComponent;
|
|
| 31 |
-import javax.swing.KeyStroke;
|
|
| 32 |
-import org.apache.commons.logging.Log;
|
|
| 33 |
-import org.apache.commons.logging.LogFactory;
|
|
| 34 |
- |
|
| 35 |
-/**
|
|
| 36 |
- * Created by tchemit on 25/08/17.
|
|
| 37 |
- *
|
|
| 38 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 39 |
- */
|
|
| 40 |
-public abstract class TripMapActionSupport extends UIActionSupport {
|
|
| 41 |
- |
|
| 42 |
- /** Logger. */
|
|
| 43 |
- private static final Log log = LogFactory.getLog(TripMapActionSupport.class);
|
|
| 44 |
- |
|
| 45 |
- private TripMapUI ui;
|
|
| 46 |
- protected ActionEvent e;
|
|
| 47 |
- |
|
| 48 |
- protected abstract void actionPerformed(TripMapUI ui);
|
|
| 49 |
- |
|
| 50 |
- TripMapActionSupport(ObserveMainUI mainUI, String actionCommandKey, String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) {
|
|
| 51 |
- super(mainUI, actionCommandKey, label, shortDescription, actionIcon, acceleratorKey);
|
|
| 52 |
- }
|
|
| 53 |
- |
|
| 54 |
- public void setUi(TripMapUI ui) {
|
|
| 55 |
- this.ui = ui;
|
|
| 56 |
- }
|
|
| 57 |
- |
|
| 58 |
- @Override
|
|
| 59 |
- public final void actionPerformed(ActionEvent e) {
|
|
| 60 |
- if (!canExecuteAction()) {
|
|
| 61 |
- return;
|
|
| 62 |
- }
|
|
| 63 |
- this.e = e;
|
|
| 64 |
- |
|
| 65 |
- if (ui != null) {
|
|
| 66 |
- actionPerformed(ui);
|
|
| 67 |
- return;
|
|
| 68 |
- }
|
|
| 69 |
- TripUI source = (TripUI) e.getSource();
|
|
| 70 |
- actionPerformed(source.getTripMap());
|
|
| 71 |
- }
|
|
| 72 |
- |
|
| 73 |
- private boolean canExecuteAction() {
|
|
| 74 |
- JComponent editor = getEditor();
|
|
| 75 |
- if ((editor == null || (editor.isVisible() && editor.isEnabled() && editor.isShowing()))) {
|
|
| 76 |
- return true;
|
|
| 77 |
- }
|
|
| 78 |
- if (log.isInfoEnabled()) {
|
|
| 79 |
- log.info("Disabled action: " + getActionCommandKey() + " :: " + this);
|
|
| 80 |
- }
|
|
| 81 |
- return false;
|
|
| 82 |
- }
|
|
| 83 |
-}
|
| 1 |
-package fr.ird.observe.client.action.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.client.ObserveMainUI;
|
|
| 26 |
-import fr.ird.observe.client.util.tripMap.TripMapUI;
|
|
| 27 |
-import javax.swing.KeyStroke;
|
|
| 28 |
-import org.geotools.geometry.jts.ReferencedEnvelope;
|
|
| 29 |
-import org.geotools.swing.JMapPane;
|
|
| 30 |
- |
|
| 31 |
- |
|
| 32 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 33 |
- |
|
| 34 |
-/**
|
|
| 35 |
- * Created by tchemit on 25/08/17.
|
|
| 36 |
- *
|
|
| 37 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 38 |
- */
|
|
| 39 |
-public class ZoomItUIAction extends TripMapActionSupport {
|
|
| 40 |
- |
|
| 41 |
- public static final String ACTION_NAME = ZoomItUIAction.class.getName();
|
|
| 42 |
- |
|
| 43 |
- public ZoomItUIAction(ObserveMainUI mainUI) {
|
|
| 44 |
- super(mainUI,
|
|
| 45 |
- ACTION_NAME,
|
|
| 46 |
- t("observe.content.map.action.zoomIt"),
|
|
| 47 |
- t("observe.content.map.action.zoomIt.tip"),
|
|
| 48 |
- "center",
|
|
| 49 |
- KeyStroke.getKeyStroke("ctrl pressed I"));
|
|
| 50 |
- }
|
|
| 51 |
- |
|
| 52 |
- @Override
|
|
| 53 |
- protected void actionPerformed(TripMapUI view) {
|
|
| 54 |
- |
|
| 55 |
- ReferencedEnvelope tripArea = view.getHandler().getTripArea();
|
|
| 56 |
- if (!tripArea.isEmpty()) {
|
|
| 57 |
- JMapPane mapPane = view.getObserveMapPane();
|
|
| 58 |
- mapPane.setDisplayArea(tripArea);
|
|
| 59 |
- }
|
|
| 60 |
- }
|
|
| 61 |
-}
|
| 1 |
-package fr.ird.observe.client.action.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.client.ObserveMainUI;
|
|
| 26 |
-import fr.ird.observe.client.util.tripMap.TripMapUI;
|
|
| 27 |
-import fr.ird.observe.client.util.tripMap.TripMapUIHandler;
|
|
| 28 |
-import java.awt.Point;
|
|
| 29 |
-import javax.swing.KeyStroke;
|
|
| 30 |
-import org.geotools.geometry.jts.ReferencedEnvelope;
|
|
| 31 |
- |
|
| 32 |
- |
|
| 33 |
-import static fr.ird.observe.client.util.tripMap.TripMapUIHandler.ZOOM_STEP_RATIO;
|
|
| 34 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 35 |
- |
|
| 36 |
-/**
|
|
| 37 |
- * Created by tchemit on 25/08/17.
|
|
| 38 |
- *
|
|
| 39 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 40 |
- */
|
|
| 41 |
-public class ZoomMoinsUIAction extends TripMapActionSupport {
|
|
| 42 |
- |
|
| 43 |
- public static final String ACTION_NAME = ZoomMoinsUIAction.class.getName();
|
|
| 44 |
- |
|
| 45 |
- public ZoomMoinsUIAction(ObserveMainUI mainUI) {
|
|
| 46 |
- super(mainUI,
|
|
| 47 |
- ACTION_NAME,
|
|
| 48 |
- t("observe.content.map.action.zoomMoins"),
|
|
| 49 |
- t("observe.content.map.action.zoomMoins.tip"),
|
|
| 50 |
- "center",
|
|
| 51 |
- KeyStroke.getKeyStroke("ctrl pressed L"));
|
|
| 52 |
- }
|
|
| 53 |
- |
|
| 54 |
- @Override
|
|
| 55 |
- protected void actionPerformed(TripMapUI view) {
|
|
| 56 |
- |
|
| 57 |
- TripMapUIHandler handler = view.getHandler();
|
|
| 58 |
- ReferencedEnvelope tripArea = handler.getTripArea();
|
|
| 59 |
- |
|
| 60 |
- if (!tripArea.isEmpty()) {
|
|
| 61 |
- int notches = 1;
|
|
| 62 |
- ReferencedEnvelope displayArea = view.getObserveMapPane().getDisplayArea();
|
|
| 63 |
- double w = displayArea.getMedian(0);
|
|
| 64 |
- double h = displayArea.getMedian(1);
|
|
| 65 |
- Point zoomCenter = new Point((int) w, (int) h);
|
|
| 66 |
- handler.setZoomCenter(zoomCenter);
|
|
| 67 |
- handler.setZoomRatio(handler.getZoomRatio() * (1 + (ZOOM_STEP_RATIO * notches * -1)));
|
|
| 68 |
- handler.zoomApply();
|
|
| 69 |
- }
|
|
| 70 |
- |
|
| 71 |
- }
|
|
| 72 |
-}
|
| 1 |
-package fr.ird.observe.client.action.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.client.ObserveMainUI;
|
|
| 26 |
-import fr.ird.observe.client.util.tripMap.TripMapUI;
|
|
| 27 |
-import fr.ird.observe.client.util.tripMap.TripMapUIHandler;
|
|
| 28 |
-import java.awt.Point;
|
|
| 29 |
-import javax.swing.KeyStroke;
|
|
| 30 |
-import org.geotools.geometry.jts.ReferencedEnvelope;
|
|
| 31 |
- |
|
| 32 |
- |
|
| 33 |
-import static fr.ird.observe.client.util.tripMap.TripMapUIHandler.ZOOM_STEP_RATIO;
|
|
| 34 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 35 |
- |
|
| 36 |
-/**
|
|
| 37 |
- * Created by tchemit on 25/08/17.
|
|
| 38 |
- *
|
|
| 39 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 40 |
- */
|
|
| 41 |
-public class ZoomPlusUIAction extends TripMapActionSupport {
|
|
| 42 |
- |
|
| 43 |
- public static final String ACTION_NAME = ZoomPlusUIAction.class.getName();
|
|
| 44 |
- |
|
| 45 |
- public ZoomPlusUIAction(ObserveMainUI mainUI) {
|
|
| 46 |
- super(mainUI,
|
|
| 47 |
- ACTION_NAME,
|
|
| 48 |
- t("observe.content.map.action.zoomPlus"),
|
|
| 49 |
- t("observe.content.map.action.zoomPlus.tip"),
|
|
| 50 |
- "zoomPlus",
|
|
| 51 |
- KeyStroke.getKeyStroke("ctrl pressed P"));
|
|
| 52 |
- }
|
|
| 53 |
- |
|
| 54 |
- @Override
|
|
| 55 |
- protected void actionPerformed(TripMapUI view) {
|
|
| 56 |
- |
|
| 57 |
- TripMapUIHandler handler = view.getHandler();
|
|
| 58 |
- ReferencedEnvelope tripArea = handler.getTripArea();
|
|
| 59 |
- |
|
| 60 |
- if (!tripArea.isEmpty()) {
|
|
| 61 |
- int notches = 1;
|
|
| 62 |
- ReferencedEnvelope displayArea = view.getObserveMapPane().getDisplayArea();
|
|
| 63 |
- double w = displayArea.getMedian(0);
|
|
| 64 |
- double h = displayArea.getMedian(1);
|
|
| 65 |
- Point zoomCenter = new Point((int) w, (int) h);
|
|
| 66 |
- handler.setZoomCenter(zoomCenter);
|
|
| 67 |
- handler.setZoomRatio(handler.getZoomRatio() * (1 - (ZOOM_STEP_RATIO * notches * -1)));
|
|
| 68 |
- handler.zoomApply();
|
|
| 69 |
- }
|
|
| 70 |
- |
|
| 71 |
- }
|
|
| 72 |
-}
|
| 1 |
-package fr.ird.observe.client.form;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.client.util.tripMap.TripMapUI;
|
|
| 26 |
- |
|
| 27 |
-/**
|
|
| 28 |
- * Created by tchemit on 25/08/17.
|
|
| 29 |
- *
|
|
| 30 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 31 |
- */
|
|
| 32 |
-public interface TripUI {
|
|
| 33 |
- |
|
| 34 |
- TripMapUI getTripMap();
|
|
| 35 |
- |
|
| 36 |
- Boolean getBuildTripMap();
|
|
| 37 |
- |
|
| 38 |
- void setBuildTripMap(Boolean buildTripMap);
|
|
| 39 |
-}
|
| ... | ... | @@ -87,7 +87,7 @@ class TripLonglineUIHandler extends ObserveOpenDataFormUIHandler<TripLonglineDto |
| 87 | 87 |
ClientConfig config = ObserveClientApplicationContext.get().getConfig();
|
| 88 | 88 |
|
| 89 | 89 |
tripMap.getHandler().setConfig(config);
|
| 90 |
- tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW));
|
|
| 90 |
+ tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), mainUI.getActionMap());
|
|
| 91 | 91 |
|
| 92 | 92 |
//FIXME!!! Use a action (shared with TripSeineHandler)
|
| 93 | 93 |
getUi().getMainTabbedPane().addChangeListener(e -> {
|
| ... | ... | @@ -102,7 +102,7 @@ class TripLonglineUIHandler extends ObserveOpenDataFormUIHandler<TripLonglineDto |
| 102 | 102 |
try {
|
| 103 | 103 |
TripMapUI tripMap11 = ui.getTripMap();
|
| 104 | 104 |
TripMapDto tripLonglineMap = model.getService().getTripLonglineMap(getModel().getSelectedId());
|
| 105 |
- tripMap11.getHandler().doOpenMap(tripLonglineMap);
|
|
| 105 |
+ tripMap11.getHandler().doOpenMap(mainUI, tripLonglineMap);
|
|
| 106 | 106 |
} finally {
|
| 107 | 107 |
ObserveClientApplicationContext.get().getMainUI().getModel().setBusy(false);
|
| 108 | 108 |
}
|
| ... | ... | @@ -84,7 +84,7 @@ class TripSeineUIHandler extends ObserveOpenDataFormUIHandler<TripSeineDto, Trip |
| 84 | 84 |
ClientConfig config = ObserveClientApplicationContext.get().getConfig();
|
| 85 | 85 |
|
| 86 | 86 |
tripMap.getHandler().setConfig(config);
|
| 87 |
- tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW));
|
|
| 87 |
+ tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), mainUI.getActionMap());
|
|
| 88 | 88 |
|
| 89 | 89 |
ui.getMainTabbedPane().addChangeListener(e -> {
|
| 90 | 90 |
JTabbedPane tripSeineTabPane = (JTabbedPane) e.getSource();
|
| ... | ... | @@ -99,7 +99,7 @@ class TripSeineUIHandler extends ObserveOpenDataFormUIHandler<TripSeineDto, Trip |
| 99 | 99 |
try {
|
| 100 | 100 |
TripMapUI tripMap11 = ui.getTripMap();
|
| 101 | 101 |
TripMapDto tripSeineMap = model.getService().getTripSeineMap(getModel().getSelectedId());
|
| 102 |
- tripMap11.getHandler().doOpenMap(tripSeineMap);
|
|
| 102 |
+ tripMap11.getHandler().doOpenMap(mainUI, tripSeineMap);
|
|
| 103 | 103 |
} finally {
|
| 104 | 104 |
ObserveClientApplicationContext.get().getMainUI().getModel().setBusy(false);
|
| 105 | 105 |
}
|
| 1 |
-package fr.ird.observe.client.util.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import com.google.common.collect.Lists;
|
|
| 26 |
-import java.awt.Color;
|
|
| 27 |
-import java.awt.Font;
|
|
| 28 |
-import java.awt.FontMetrics;
|
|
| 29 |
-import java.awt.Graphics;
|
|
| 30 |
-import java.awt.Point;
|
|
| 31 |
-import java.awt.Polygon;
|
|
| 32 |
-import java.awt.geom.Point2D;
|
|
| 33 |
-import java.awt.geom.Rectangle2D;
|
|
| 34 |
-import java.awt.image.BufferedImage;
|
|
| 35 |
-import java.util.List;
|
|
| 36 |
-import org.apache.commons.logging.Log;
|
|
| 37 |
-import org.apache.commons.logging.LogFactory;
|
|
| 38 |
-import org.geotools.geometry.jts.ReferencedEnvelope;
|
|
| 39 |
-import org.geotools.renderer.lite.RendererUtilities;
|
|
| 40 |
-import org.geotools.styling.FeatureTypeStyle;
|
|
| 41 |
-import org.geotools.styling.Rule;
|
|
| 42 |
-import org.geotools.styling.Style;
|
|
| 43 |
-import org.geotools.swing.JMapPane;
|
|
| 44 |
-import org.geotools.swing.event.MapPaneAdapter;
|
|
| 45 |
-import org.geotools.swing.event.MapPaneEvent;
|
|
| 46 |
- |
|
| 47 |
- |
|
| 48 |
-import static org.nuiton.i18n.I18n.n;
|
|
| 49 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 50 |
- |
|
| 51 |
-/**
|
|
| 52 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 53 |
- */
|
|
| 54 |
-public class ObserveMapPane extends JMapPane {
|
|
| 55 |
- |
|
| 56 |
- private static final long serialVersionUID = 1L;
|
|
| 57 |
- private static final Log log = LogFactory.getLog(ObserveMapPane.class);
|
|
| 58 |
- |
|
| 59 |
- protected static final int MARGIN = 10;
|
|
| 60 |
- |
|
| 61 |
- protected static final int SCALE_HEIGHT = 15;
|
|
| 62 |
- protected static final int SCALE_WIDTH_MAX = 200;
|
|
| 63 |
- |
|
| 64 |
- protected static final int METERS_BY_MILES = 1852;
|
|
| 65 |
- |
|
| 66 |
- protected int scaleWidth;
|
|
| 67 |
- |
|
| 68 |
- protected String labelScaleUp;
|
|
| 69 |
- |
|
| 70 |
- protected double rotation;
|
|
| 71 |
- |
|
| 72 |
- public ObserveMapPane() {
|
|
| 73 |
- labelScaleUp = "0 m";
|
|
| 74 |
- scaleWidth = 100;
|
|
| 75 |
- rotation = 0;
|
|
| 76 |
- addMapPaneListener(new MapPaneAdapter() {
|
|
| 77 |
- @Override
|
|
| 78 |
- public void onDisplayAreaChanged(MapPaneEvent ev) {
|
|
| 79 |
- updateScale();
|
|
| 80 |
- }
|
|
| 81 |
- });
|
|
| 82 |
- legendItems = Lists.newArrayList();
|
|
| 83 |
- |
|
| 84 |
- }
|
|
| 85 |
- |
|
| 86 |
- |
|
| 87 |
- protected void updateScale() {
|
|
| 88 |
- ReferencedEnvelope displayArea = getDisplayArea();
|
|
| 89 |
- double dpi = 2.54 / 100; // pour avoir l'echélle en metre/pixel
|
|
| 90 |
- |
|
| 91 |
- try {
|
|
| 92 |
- double meterPerPixel = RendererUtilities.calculateScale(displayArea, getWidth(), getHeight(), dpi);
|
|
| 93 |
- |
|
| 94 |
- double maxWidthMeter = SCALE_WIDTH_MAX * meterPerPixel;
|
|
| 95 |
- |
|
| 96 |
- double maxWidthMiles = maxWidthMeter / METERS_BY_MILES;
|
|
| 97 |
- |
|
| 98 |
- int nbDigit = (int) Math.floor(Math.log10(maxWidthMiles));
|
|
| 99 |
- |
|
| 100 |
- int firstDigit = (int) Math.floor(maxWidthMiles / Math.pow(10, nbDigit)); // le premier chiffre significatif
|
|
| 101 |
- |
|
| 102 |
- int useFirstDigit;
|
|
| 103 |
- |
|
| 104 |
- if (firstDigit >= 5) {
|
|
| 105 |
- useFirstDigit = 5;
|
|
| 106 |
- } else if (firstDigit >= 2) {
|
|
| 107 |
- useFirstDigit = 2;
|
|
| 108 |
- } else {
|
|
| 109 |
- useFirstDigit = 1;
|
|
| 110 |
- }
|
|
| 111 |
- |
|
| 112 |
- long scaleInMiles = useFirstDigit * (long) Math.pow(10, nbDigit);
|
|
| 113 |
- |
|
| 114 |
- scaleWidth = (int) Math.round(scaleInMiles * METERS_BY_MILES / meterPerPixel);
|
|
| 115 |
- |
|
| 116 |
- labelScaleUp = String.format("%,d " + t("observe.content.map.miles"), scaleInMiles);
|
|
| 117 |
- |
|
| 118 |
- } catch (Exception e) {
|
|
| 119 |
- if (log.isErrorEnabled()) {
|
|
| 120 |
- log.error("error", e);
|
|
| 121 |
- }
|
|
| 122 |
- }
|
|
| 123 |
- }
|
|
| 124 |
- |
|
| 125 |
- protected void paintScale(Graphics graphics) {
|
|
| 126 |
- graphics.setColor(Color.BLACK);
|
|
| 127 |
- |
|
| 128 |
- FontMetrics fm = graphics.getFontMetrics();
|
|
| 129 |
- |
|
| 130 |
- Rectangle2D textArea = fm.getStringBounds(labelScaleUp, graphics);
|
|
| 131 |
- |
|
| 132 |
- int labelLeft = getWidth() - MARGIN * 2 - scaleWidth - (int) textArea.getWidth();
|
|
| 133 |
- |
|
| 134 |
- graphics.drawString(labelScaleUp, labelLeft, getHeight() - MARGIN);
|
|
| 135 |
- |
|
| 136 |
- int scalesEndX = getWidth() - MARGIN;
|
|
| 137 |
- |
|
| 138 |
- int scaleStartX = scalesEndX - scaleWidth;
|
|
| 139 |
- |
|
| 140 |
- int scalesEndY = getHeight() - MARGIN;
|
|
| 141 |
- |
|
| 142 |
- int scaleStartY = scalesEndY - SCALE_HEIGHT;
|
|
| 143 |
- |
|
| 144 |
- graphics.drawLine(scaleStartX, scaleStartY, scaleStartX, scalesEndY);
|
|
| 145 |
- graphics.drawLine(scaleStartX, scalesEndY, scalesEndX, scalesEndY);
|
|
| 146 |
- graphics.drawLine(scalesEndX, scalesEndY, scalesEndX, scaleStartY);
|
|
| 147 |
- |
|
| 148 |
- }
|
|
| 149 |
- |
|
| 150 |
- protected static int AXIS_LENGTH = 30;
|
|
| 151 |
- |
|
| 152 |
- protected static int SUB_AXIS_LENGTH = 5;
|
|
| 153 |
- |
|
| 154 |
- protected static int CENTER_MARGIN = 50;
|
|
| 155 |
- |
|
| 156 |
- protected static int INTER_AXIS_TEXT = 3;
|
|
| 157 |
- |
|
| 158 |
- protected static double FONT_SIZE = 12;
|
|
| 159 |
- |
|
| 160 |
- |
|
| 161 |
- protected void paintCompass(Graphics graphics) {
|
|
| 162 |
- |
|
| 163 |
- Point center = new Point(getWidth() - CENTER_MARGIN, CENTER_MARGIN);
|
|
| 164 |
- |
|
| 165 |
- Font font = graphics.getFont();
|
|
| 166 |
- Font fontRatio = font.deriveFont((float) (FONT_SIZE));
|
|
| 167 |
- graphics.setFont(fontRatio);
|
|
| 168 |
- |
|
| 169 |
- FontMetrics fm = graphics.getFontMetrics();
|
|
| 170 |
- |
|
| 171 |
- for (CardinalPoint cardinalPoint : CardinalPoint.values()) {
|
|
| 172 |
- |
|
| 173 |
- Point2D direction = cardinalPoint.getDirection(rotation, AXIS_LENGTH, center);
|
|
| 174 |
- |
|
| 175 |
- Point2D sommet1 = cardinalPoint.getDirection(rotation - Math.PI / 4, SUB_AXIS_LENGTH, center);
|
|
| 176 |
- |
|
| 177 |
- Point2D sommet2 = cardinalPoint.getDirection(rotation + Math.PI / 4, SUB_AXIS_LENGTH, center);
|
|
| 178 |
- |
|
| 179 |
- |
|
| 180 |
- Polygon polygon = new Polygon();
|
|
| 181 |
- polygon.addPoint((int) center.getX(), (int) center.getY());
|
|
| 182 |
- polygon.addPoint((int) direction.getX(), (int) direction.getY());
|
|
| 183 |
- polygon.addPoint((int) sommet2.getX(), (int) sommet2.getY());
|
|
| 184 |
- graphics.fillPolygon(polygon);
|
|
| 185 |
- |
|
| 186 |
- graphics.drawLine((int) sommet1.getX(), (int) sommet1.getY(), (int) direction.getX(), (int) direction.getY());
|
|
| 187 |
- |
|
| 188 |
- Rectangle2D textArea = fm.getStringBounds(cardinalPoint.getLabel(), graphics);
|
|
| 189 |
- |
|
| 190 |
- // on cherche la ditance entre le centre du text et sa bordure dans le direction donné
|
|
| 191 |
- double l = cardinalPoint.distanceCenterBorder(rotation, textArea);
|
|
| 192 |
- |
|
| 193 |
- Point2D textCenter = cardinalPoint.getDirection(rotation, AXIS_LENGTH + INTER_AXIS_TEXT + l, center);
|
|
| 194 |
- |
|
| 195 |
- graphics.drawString(
|
|
| 196 |
- cardinalPoint.getLabel(),
|
|
| 197 |
- (int) (textCenter.getX() - textArea.getWidth() / 2),
|
|
| 198 |
- (int) (textCenter.getY() + textArea.getHeight() / 2));
|
|
| 199 |
- }
|
|
| 200 |
- |
|
| 201 |
- }
|
|
| 202 |
- |
|
| 203 |
- |
|
| 204 |
- protected static int LEGEND_MARGIN = 3;
|
|
| 205 |
- |
|
| 206 |
- protected List<ObserveMapPaneLegendItem> legendItems;
|
|
| 207 |
- |
|
| 208 |
- public List<ObserveMapPaneLegendItem> getLegendItems() {
|
|
| 209 |
- return legendItems;
|
|
| 210 |
- }
|
|
| 211 |
- |
|
| 212 |
- public void setLegendItems(List<ObserveMapPaneLegendItem> legendItems) {
|
|
| 213 |
- this.legendItems = legendItems;
|
|
| 214 |
- }
|
|
| 215 |
- |
|
| 216 |
- protected void paintLegend(Graphics graphics) {
|
|
| 217 |
- |
|
| 218 |
- if (legendItems != null) {
|
|
| 219 |
- |
|
| 220 |
- int x = 0;
|
|
| 221 |
- int y = getHeight() - ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT * legendItems.size() - 2 * LEGEND_MARGIN;
|
|
| 222 |
- |
|
| 223 |
- ObserverMapPanLegendDrawer drawer = new ObserverMapPanLegendDrawer();
|
|
| 224 |
- |
|
| 225 |
- FontMetrics fm = graphics.getFontMetrics();
|
|
| 226 |
- |
|
| 227 |
- int maxLabelWidth = 0;
|
|
| 228 |
- |
|
| 229 |
- for (ObserveMapPaneLegendItem item : legendItems) {
|
|
| 230 |
- Rectangle2D labelArea = fm.getStringBounds(item.getLabel(), graphics);
|
|
| 231 |
- |
|
| 232 |
- maxLabelWidth = Math.max((int) labelArea.getWidth(), maxLabelWidth);
|
|
| 233 |
- |
|
| 234 |
- }
|
|
| 235 |
- |
|
| 236 |
- int legendWidth = ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH + maxLabelWidth + ObserveMapPaneLegendItem.LEGEND_MARGIN * 2;
|
|
| 237 |
- |
|
| 238 |
- graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND);
|
|
| 239 |
- graphics.fillRect(
|
|
| 240 |
- x,
|
|
| 241 |
- y,
|
|
| 242 |
- legendWidth,
|
|
| 243 |
- LEGEND_MARGIN);
|
|
| 244 |
- |
|
| 245 |
- y += LEGEND_MARGIN;
|
|
| 246 |
- |
|
| 247 |
- for (ObserveMapPaneLegendItem item : legendItems) {
|
|
| 248 |
- |
|
| 249 |
- graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND);
|
|
| 250 |
- graphics.fillRect(
|
|
| 251 |
- x,
|
|
| 252 |
- y,
|
|
| 253 |
- legendWidth,
|
|
| 254 |
- ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT);
|
|
| 255 |
- |
|
| 256 |
- BufferedImage symbole = new BufferedImage(
|
|
| 257 |
- ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH,
|
|
| 258 |
- ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT,
|
|
| 259 |
- BufferedImage.TYPE_INT_ARGB);
|
|
| 260 |
- |
|
| 261 |
- Style style = item.getStyle();
|
|
| 262 |
- |
|
| 263 |
- for (FeatureTypeStyle featureTypeStyle : style.featureTypeStyles()) {
|
|
| 264 |
- |
|
| 265 |
- for (Rule rule : featureTypeStyle.rules()) {
|
|
| 266 |
- |
|
| 267 |
- if (rule.getFilter().evaluate(item.getSimpleFeature())) {
|
|
| 268 |
- |
|
| 269 |
- drawer.drawDirect(symbole, item.getSimpleFeature(), rule);
|
|
| 270 |
- |
|
| 271 |
- }
|
|
| 272 |
- }
|
|
| 273 |
- }
|
|
| 274 |
- |
|
| 275 |
- graphics.drawImage(symbole, x + LEGEND_MARGIN, y, null);
|
|
| 276 |
- |
|
| 277 |
- graphics.setColor(Color.BLACK);
|
|
| 278 |
- |
|
| 279 |
- int labelMarginBottom = ((ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT - fm.getHeight()) / 2) + fm.getDescent();
|
|
| 280 |
- |
|
| 281 |
- graphics.drawString(item.getLabel(),
|
|
| 282 |
- x + LEGEND_MARGIN + ObserveMapPaneLegendItem.LEGEND_SYMBOL_WIDTH,
|
|
| 283 |
- y + ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT - labelMarginBottom);
|
|
| 284 |
- |
|
| 285 |
- y += ObserveMapPaneLegendItem.LEGEND_ITEM_HEIGHT;
|
|
| 286 |
- |
|
| 287 |
- }
|
|
| 288 |
- |
|
| 289 |
- graphics.setColor(ObserveMapPaneLegendItem.LEGEND_BACKGROUND);
|
|
| 290 |
- graphics.fillRect(
|
|
| 291 |
- x,
|
|
| 292 |
- y,
|
|
| 293 |
- legendWidth,
|
|
| 294 |
- LEGEND_MARGIN);
|
|
| 295 |
- |
|
| 296 |
- }
|
|
| 297 |
- |
|
| 298 |
- }
|
|
| 299 |
- |
|
| 300 |
- |
|
| 301 |
- @Override
|
|
| 302 |
- public void paint(Graphics graphics) {
|
|
| 303 |
- |
|
| 304 |
- super.paint(graphics);
|
|
| 305 |
- |
|
| 306 |
- paintScale(graphics);
|
|
| 307 |
- |
|
| 308 |
- paintCompass(graphics);
|
|
| 309 |
- |
|
| 310 |
- paintLegend(graphics);
|
|
| 311 |
- |
|
| 312 |
- }
|
|
| 313 |
- |
|
| 314 |
- protected enum CardinalPoint {
|
|
| 315 |
- NORTH(-1, 0, 0, -1, n("observe.content.map.north")),
|
|
| 316 |
- SOUTH(1, 0, 0, 1, n("observe.content.map.south")),
|
|
| 317 |
- WEST(0, -1, 1, 0, n("observe.content.map.west")),
|
|
| 318 |
- EST(0, 1, -1, 0, n("observe.content.map.east"));
|
|
| 319 |
- |
|
| 320 |
- protected int matrix00;
|
|
| 321 |
- protected int matrix01;
|
|
| 322 |
- protected int matrix10;
|
|
| 323 |
- protected int matrix11;
|
|
| 324 |
- protected String label;
|
|
| 325 |
- |
|
| 326 |
- CardinalPoint(int matrix00, int matrix01, int matrix10, int matrix11, String label) {
|
|
| 327 |
- this.matrix00 = matrix00;
|
|
| 328 |
- this.matrix01 = matrix01;
|
|
| 329 |
- this.matrix10 = matrix10;
|
|
| 330 |
- this.matrix11 = matrix11;
|
|
| 331 |
- this.label = label;
|
|
| 332 |
- }
|
|
| 333 |
- |
|
| 334 |
- public Point2D.Double getDirection(double angle, double length, Point center) {
|
|
| 335 |
- |
|
| 336 |
- double x = Math.sin(angle) * length;
|
|
| 337 |
- double y = Math.cos(angle) * length;
|
|
| 338 |
- |
|
| 339 |
- double deltaX = matrix00 * x + matrix01 * y;
|
|
| 340 |
- double deltaY = matrix10 * x + matrix11 * y;
|
|
| 341 |
- |
|
| 342 |
- return new Point2D.Double(center.getX() + deltaX, center.getY() + deltaY);
|
|
| 343 |
- }
|
|
| 344 |
- |
|
| 345 |
- // on cherche la ditance entre le centre du text et sa bordure dans le direction donné
|
|
| 346 |
- public double distanceCenterBorder(double angle, Rectangle2D textArea) {
|
|
| 347 |
- |
|
| 348 |
- double x = Math.sin(angle);
|
|
| 349 |
- double y = Math.cos(angle);
|
|
| 350 |
- |
|
| 351 |
- double deltaW = Math.abs(textArea.getWidth() / 2 / (matrix00 * x + matrix01 * y));
|
|
| 352 |
- double deltaH = Math.abs(textArea.getHeight() / 2 / (matrix10 * x + matrix11 * y));
|
|
| 353 |
- |
|
| 354 |
- return Math.min(deltaH, deltaW);
|
|
| 355 |
- }
|
|
| 356 |
- |
|
| 357 |
- public String getLabel() {
|
|
| 358 |
- return t(label);
|
|
| 359 |
- }
|
|
| 360 |
- }
|
|
| 361 |
- |
|
| 362 |
-}
|
| 1 |
-package fr.ird.observe.client.util.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import com.vividsolutions.jts.geom.Coordinate;
|
|
| 26 |
-import java.awt.Color;
|
|
| 27 |
-import org.geotools.styling.Style;
|
|
| 28 |
-import org.opengis.feature.simple.SimpleFeature;
|
|
| 29 |
- |
|
| 30 |
-/**
|
|
| 31 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 32 |
- */
|
|
| 33 |
-public class ObserveMapPaneLegendItem {
|
|
| 34 |
- |
|
| 35 |
- protected static final int LEGEND_ITEM_HEIGHT = 20;
|
|
| 36 |
- protected static final int LEGEND_SYMBOL_WIDTH = 50;
|
|
| 37 |
- protected static final int LEGEND_MARGIN = 5;
|
|
| 38 |
- protected static final Color LEGEND_BACKGROUND = new Color(1f, 1f, 1f, 0.8f);
|
|
| 39 |
- |
|
| 40 |
- |
|
| 41 |
- public static Coordinate[] lineCoordinates() {
|
|
| 42 |
- Coordinate[] coordinates = new Coordinate[2];
|
|
| 43 |
- coordinates[0] = new Coordinate(LEGEND_MARGIN, LEGEND_ITEM_HEIGHT / 2);
|
|
| 44 |
- coordinates[1] = new Coordinate(LEGEND_SYMBOL_WIDTH - LEGEND_MARGIN, LEGEND_ITEM_HEIGHT / 2);
|
|
| 45 |
- return coordinates;
|
|
| 46 |
- }
|
|
| 47 |
- |
|
| 48 |
- public static Coordinate pointCoordinates() {
|
|
| 49 |
- return new Coordinate(LEGEND_SYMBOL_WIDTH / 2, LEGEND_ITEM_HEIGHT / 2);
|
|
| 50 |
- }
|
|
| 51 |
- |
|
| 52 |
- |
|
| 53 |
- protected SimpleFeature simpleFeature;
|
|
| 54 |
- |
|
| 55 |
- protected Style style;
|
|
| 56 |
- |
|
| 57 |
- protected String label;
|
|
| 58 |
- |
|
| 59 |
- public ObserveMapPaneLegendItem(SimpleFeature simpleFeature, Style style, String label) {
|
|
| 60 |
- this.simpleFeature = simpleFeature;
|
|
| 61 |
- this.style = style;
|
|
| 62 |
- this.label = label;
|
|
| 63 |
- }
|
|
| 64 |
- |
|
| 65 |
- public SimpleFeature getSimpleFeature() {
|
|
| 66 |
- return simpleFeature;
|
|
| 67 |
- }
|
|
| 68 |
- |
|
| 69 |
- public void setSimpleFeature(SimpleFeature simpleFeature) {
|
|
| 70 |
- this.simpleFeature = simpleFeature;
|
|
| 71 |
- }
|
|
| 72 |
- |
|
| 73 |
- public Style getStyle() {
|
|
| 74 |
- return style;
|
|
| 75 |
- }
|
|
| 76 |
- |
|
| 77 |
- public void setStyle(Style style) {
|
|
| 78 |
- this.style = style;
|
|
| 79 |
- }
|
|
| 80 |
- |
|
| 81 |
- public String getLabel() {
|
|
| 82 |
- return label;
|
|
| 83 |
- }
|
|
| 84 |
- |
|
| 85 |
- public void setLabel(String label) {
|
|
| 86 |
- this.label = label;
|
|
| 87 |
- }
|
|
| 88 |
-}
|
| 1 |
-package fr.ird.observe.client.util.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import com.vividsolutions.jts.geom.Geometry;
|
|
| 26 |
-import java.awt.BasicStroke;
|
|
| 27 |
-import java.awt.Color;
|
|
| 28 |
-import java.awt.Graphics;
|
|
| 29 |
-import java.awt.Graphics2D;
|
|
| 30 |
-import java.awt.Stroke;
|
|
| 31 |
-import java.awt.geom.AffineTransform;
|
|
| 32 |
-import java.awt.image.BufferedImage;
|
|
| 33 |
-import org.geotools.geometry.jts.LiteShape;
|
|
| 34 |
-import org.geotools.legend.Drawer;
|
|
| 35 |
-import org.geotools.styling.LineSymbolizer;
|
|
| 36 |
-import org.geotools.styling.Rule;
|
|
| 37 |
-import org.geotools.styling.SLD;
|
|
| 38 |
-import org.geotools.styling.Symbolizer;
|
|
| 39 |
-import org.opengis.feature.simple.SimpleFeature;
|
|
| 40 |
- |
|
| 41 |
-/**
|
|
| 42 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 43 |
- */
|
|
| 44 |
-public class ObserverMapPanLegendDrawer {
|
|
| 45 |
- |
|
| 46 |
- protected final Drawer drawer;
|
|
| 47 |
- |
|
| 48 |
- |
|
| 49 |
- public ObserverMapPanLegendDrawer() {
|
|
| 50 |
- drawer = Drawer.create();
|
|
| 51 |
- |
|
| 52 |
- }
|
|
| 53 |
- |
|
| 54 |
- public void drawDirect(BufferedImage bi, SimpleFeature feature, Rule rule) {
|
|
| 55 |
- AffineTransform affineTransform = new AffineTransform();
|
|
| 56 |
- |
|
| 57 |
- LiteShape shape = new LiteShape(null, affineTransform, false);
|
|
| 58 |
- for (Symbolizer symbolizer : rule.getSymbolizers()) {
|
|
| 59 |
- if (symbolizer instanceof LineSymbolizer) {
|
|
| 60 |
- LineSymbolizer lineSymbolizer = (LineSymbolizer) symbolizer;
|
|
| 61 |
- |
|
| 62 |
- Geometry geometry = findGeometry(feature, lineSymbolizer);
|
|
| 63 |
- if (geometry != null) {
|
|
| 64 |
- |
|
| 65 |
- Graphics graphics = bi.getGraphics();
|
|
| 66 |
- Graphics2D g = (Graphics2D) graphics;
|
|
| 67 |
- |
|
| 68 |
- shape.setGeometry(geometry);
|
|
| 69 |
- |
|
| 70 |
- |
|
| 71 |
- Color c = SLD.color(lineSymbolizer);
|
|
| 72 |
- int w = SLD.width(lineSymbolizer);
|
|
| 73 |
- float[] lineDash = SLD.lineDash(lineSymbolizer);
|
|
| 74 |
- if (c != null && w > 0) {
|
|
| 75 |
- g.setColor(c);
|
|
| 76 |
- |
|
| 77 |
- Stroke str = new BasicStroke(
|
|
| 78 |
- w,
|
|
| 79 |
- BasicStroke.CAP_SQUARE,
|
|
| 80 |
- BasicStroke.JOIN_MITER,
|
|
| 81 |
- 10.0f, lineDash, 0.0f
|
|
| 82 |
- );
|
|
| 83 |
- g.setStroke(str);
|
|
| 84 |
- |
|
| 85 |
- g.draw(shape);
|
|
| 86 |
- }
|
|
| 87 |
- }
|
|
| 88 |
- } else {
|
|
| 89 |
- drawer.drawFeature(bi, feature, affineTransform, false, symbolizer, null, shape);
|
|
| 90 |
- }
|
|
| 91 |
- |
|
| 92 |
- }
|
|
| 93 |
- |
|
| 94 |
- |
|
| 95 |
- }
|
|
| 96 |
- |
|
| 97 |
- protected Geometry findGeometry(SimpleFeature feature, LineSymbolizer lineSymbolizer) {
|
|
| 98 |
- String geomName = lineSymbolizer.getGeometryPropertyName();
|
|
| 99 |
- |
|
| 100 |
- Geometry geom;
|
|
| 101 |
- if (geomName == null) {
|
|
| 102 |
- geom = (Geometry) feature.getDefaultGeometry();
|
|
| 103 |
- } else {
|
|
| 104 |
- geom = (Geometry) feature.getAttribute(geomName);
|
|
| 105 |
- }
|
|
| 106 |
- return geom;
|
|
| 107 |
- }
|
|
| 108 |
- |
|
| 109 |
- |
|
| 110 |
-}
|
| 1 |
-package fr.ird.observe.client.util.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import com.google.common.collect.ImmutableSet;
|
|
| 26 |
-import com.google.common.collect.Lists;
|
|
| 27 |
-import com.google.common.collect.Sets;
|
|
| 28 |
-import com.vividsolutions.jts.geom.Coordinate;
|
|
| 29 |
-import com.vividsolutions.jts.geom.GeometryFactory;
|
|
| 30 |
-import com.vividsolutions.jts.geom.LineString;
|
|
| 31 |
-import com.vividsolutions.jts.geom.Point;
|
|
| 32 |
-import com.vividsolutions.jts.geom.Polygon;
|
|
| 33 |
-import fr.ird.observe.client.I18nEnumHelper;
|
|
| 34 |
-import fr.ird.observe.client.ObserveClientTechnicalException;
|
|
| 35 |
-import fr.ird.observe.dto.data.TripMapPoint;
|
|
| 36 |
-import fr.ird.observe.dto.data.TripMapPointType;
|
|
| 37 |
-import java.io.File;
|
|
| 38 |
-import java.io.FileNotFoundException;
|
|
| 39 |
-import java.io.IOException;
|
|
| 40 |
-import java.text.DateFormat;
|
|
| 41 |
-import java.text.SimpleDateFormat;
|
|
| 42 |
-import java.util.List;
|
|
| 43 |
-import java.util.Optional;
|
|
| 44 |
-import java.util.Set;
|
|
| 45 |
-import org.apache.commons.lang3.StringUtils;
|
|
| 46 |
-import org.apache.commons.lang3.time.DateUtils;
|
|
| 47 |
-import org.geotools.data.FileDataStore;
|
|
| 48 |
-import org.geotools.data.FileDataStoreFinder;
|
|
| 49 |
-import org.geotools.data.simple.SimpleFeatureSource;
|
|
| 50 |
-import org.geotools.factory.CommonFactoryFinder;
|
|
| 51 |
-import org.geotools.feature.DefaultFeatureCollection;
|
|
| 52 |
-import org.geotools.feature.simple.SimpleFeatureBuilder;
|
|
| 53 |
-import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
|
| 54 |
-import org.geotools.geometry.jts.JTSFactoryFinder;
|
|
| 55 |
-import org.geotools.map.FeatureLayer;
|
|
| 56 |
-import org.geotools.map.Layer;
|
|
| 57 |
-import org.geotools.map.MapContent;
|
|
| 58 |
-import org.geotools.referencing.CRS;
|
|
| 59 |
-import org.geotools.styling.NamedLayer;
|
|
| 60 |
-import org.geotools.styling.SLD;
|
|
| 61 |
-import org.geotools.styling.SLDParser;
|
|
| 62 |
-import org.geotools.styling.Style;
|
|
| 63 |
-import org.geotools.styling.StyleFactory;
|
|
| 64 |
-import org.geotools.styling.StyledLayer;
|
|
| 65 |
-import org.geotools.styling.StyledLayerDescriptor;
|
|
| 66 |
-import org.geotools.styling.UserLayer;
|
|
| 67 |
-import org.opengis.feature.simple.SimpleFeature;
|
|
| 68 |
-import org.opengis.feature.simple.SimpleFeatureType;
|
|
| 69 |
-import org.opengis.referencing.FactoryException;
|
|
| 70 |
- |
|
| 71 |
- |
|
| 72 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 73 |
- |
|
| 74 |
-/**
|
|
| 75 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 76 |
- */
|
|
| 77 |
-public class TripMapContentBuilder {
|
|
| 78 |
- |
|
| 79 |
- public static final String TRIP_LINES_LAYER_NAME = "Trip lines";
|
|
| 80 |
- public static final String TRIP_LONGLINE_FISHING_ZONE_LAYER_NAME = "Trip longline zone";
|
|
| 81 |
- public static final String TRIP_LONGLINE_LINE_LAYER_NAME = "Trip longline line";
|
|
| 82 |
- public static final String TRIP_POINTS_LAYER_NAME = "Trip points";
|
|
| 83 |
- |
|
| 84 |
- protected static final Set<TripMapPointType> TRIP_MAP_POINT_TYPES_IN_LEGEND = ImmutableSet.of(
|
|
| 85 |
- TripMapPointType.seineActivityInHarbour,
|
|
| 86 |
- TripMapPointType.seineActivityWithFreeSchoolType,
|
|
| 87 |
- TripMapPointType.seineActivityWithObjectSchoolType,
|
|
| 88 |
- TripMapPointType.longlineActivityInHarbour,
|
|
| 89 |
- TripMapPointType.longlineActivityWithSettingStart,
|
|
| 90 |
- TripMapPointType.longlineActivityWithSettingEnd,
|
|
| 91 |
- TripMapPointType.longlineActivityWithHaulingStart,
|
|
| 92 |
- TripMapPointType.longlineActivityWithHaulingEnd,
|
|
| 93 |
- TripMapPointType.longlineActivityWithStation,
|
|
| 94 |
- TripMapPointType.longlineActivityWithInteraction);
|
|
| 95 |
- |
|
| 96 |
- public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM");
|
|
| 97 |
- |
|
| 98 |
- protected StyledLayerDescriptor styledLayerDescriptor;
|
|
| 99 |
- protected final MapContent mapContent;
|
|
| 100 |
- protected final List<ObserveMapPaneLegendItem> legendItems;
|
|
| 101 |
- |
|
| 102 |
- public TripMapContentBuilder() {
|
|
| 103 |
- mapContent = new MapContent();
|
|
| 104 |
- legendItems = Lists.newArrayList();
|
|
| 105 |
- }
|
|
| 106 |
- |
|
| 107 |
- public MapContent getMapContent() {
|
|
| 108 |
- return mapContent;
|
|
| 109 |
- }
|
|
| 110 |
- |
|
| 111 |
- public List<ObserveMapPaneLegendItem> getLegendItems() {
|
|
| 112 |
- return legendItems;
|
|
| 113 |
- }
|
|
| 114 |
- |
|
| 115 |
- public void setStyledLayerDescriptor(File styleFile) throws FileNotFoundException {
|
|
| 116 |
- |
|
| 117 |
- StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
|
|
| 118 |
- |
|
| 119 |
- SLDParser stylereader = new SLDParser(styleFactory, styleFile);
|
|
| 120 |
- |
|
| 121 |
- styledLayerDescriptor = stylereader.parseSLD();
|
|
| 122 |
- }
|
|
| 123 |
- |
|
| 124 |
- public void addLayer(File layerFile) throws IOException {
|
|
| 125 |
- FileDataStore store = FileDataStoreFinder.getDataStore(layerFile);
|
|
| 126 |
- SimpleFeatureSource featureSource = store.getFeatureSource();
|
|
| 127 |
- Style style = SLD.createSimpleStyle(featureSource.getSchema());
|
|
| 128 |
- style = findStyle(styledLayerDescriptor, store.getNames().get(0).getLocalPart(), null, style);
|
|
| 129 |
- Layer layer = new FeatureLayer(featureSource, style, layerFile.getName());
|
|
| 130 |
- mapContent.addLayer(layer);
|
|
| 131 |
- }
|
|
| 132 |
- |
|
| 133 |
- public void addTripLine(List<TripMapPoint> tripMapPoints) throws FactoryException {
|
|
| 134 |
- |
|
| 135 |
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
|
|
| 136 |
- |
|
| 137 |
- SimpleFeatureTypeBuilder lineFeatureTypeBuilder = new SimpleFeatureTypeBuilder();
|
|
| 138 |
- lineFeatureTypeBuilder.setName("lineBuilder");
|
|
| 139 |
- lineFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true));
|
|
| 140 |
- lineFeatureTypeBuilder.add("line", LineString.class);
|
|
| 141 |
- lineFeatureTypeBuilder.add("label", String.class);
|
|
| 142 |
- lineFeatureTypeBuilder.add("type", String.class);
|
|
| 143 |
- |
|
| 144 |
- SimpleFeatureType lineFeatureType = lineFeatureTypeBuilder.buildFeatureType();
|
|
| 145 |
- SimpleFeatureBuilder lineBuilder = new SimpleFeatureBuilder(lineFeatureType);
|
|
| 146 |
- |
|
| 147 |
- DefaultFeatureCollection linesFeatures = new DefaultFeatureCollection();
|
|
| 148 |
- |
|
| 149 |
- List<Coordinate> coordinatesByDay = null;
|
|
| 150 |
- |
|
| 151 |
- TripMapPoint previousPoint = null;
|
|
| 152 |
- |
|
| 153 |
- for (TripMapPoint point : tripMapPoints) {
|
|
| 154 |
- if (previousPoint == null) {
|
|
| 155 |
- coordinatesByDay = Lists.newLinkedList();
|
|
| 156 |
- } else if (!DateUtils.isSameDay(previousPoint.getTime(), point.getTime())) {
|
|
| 157 |
- |
|
| 158 |
- if (coordinatesByDay.size() > 1) {
|
|
| 159 |
- LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0]));
|
|
| 160 |
- lineBuilder.add(line);
|
|
| 161 |
- lineBuilder.add(DATE_FORMAT.format(previousPoint.getTime()));
|
|
| 162 |
- lineBuilder.add("tripDay");
|
|
| 163 |
- SimpleFeature feature = lineBuilder.buildFeature(null);
|
|
| 164 |
- |
|
| 165 |
- linesFeatures.add(feature);
|
|
| 166 |
- }
|
|
| 167 |
- |
|
| 168 |
- |
|
| 169 |
- Coordinate[] coordinates = {
|
|
| 170 |
- new Coordinate(previousPoint.getLongitude(), previousPoint.getLatitude()),
|
|
| 171 |
- new Coordinate(point.getLongitude(), point.getLatitude()),
|
|
| 172 |
- };
|
|
| 173 |
- LineString lineBetweenTwoDays = geometryFactory.createLineString(coordinates);
|
|
| 174 |
- lineBuilder.add(lineBetweenTwoDays);
|
|
| 175 |
- lineBuilder.add(DateFormat.getDateInstance().format(previousPoint.getTime()));
|
|
| 176 |
- lineBuilder.add("tripBetweenTwoDays");
|
|
| 177 |
- linesFeatures.add(lineBuilder.buildFeature(null));
|
|
| 178 |
- |
|
| 179 |
- coordinatesByDay = Lists.newLinkedList();
|
|
| 180 |
- }
|
|
| 181 |
- |
|
| 182 |
- Coordinate coordinate = new Coordinate(point.getLongitude(), point.getLatitude());
|
|
| 183 |
- coordinatesByDay.add(coordinate);
|
|
| 184 |
- |
|
| 185 |
- previousPoint = point;
|
|
| 186 |
- }
|
|
| 187 |
- |
|
| 188 |
- if (coordinatesByDay != null && coordinatesByDay.size() > 1) {
|
|
| 189 |
- LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0]));
|
|
| 190 |
- lineBuilder.add(line);
|
|
| 191 |
- lineBuilder.add(DATE_FORMAT.format(previousPoint.getTime()));
|
|
| 192 |
- lineBuilder.add("tripDay");
|
|
| 193 |
- linesFeatures.add(lineBuilder.buildFeature(null));
|
|
| 194 |
- }
|
|
| 195 |
- |
|
| 196 |
- Style styleLines = findStyle(styledLayerDescriptor, TRIP_LINES_LAYER_NAME, null);
|
|
| 197 |
- |
|
| 198 |
- if (!linesFeatures.isEmpty()) {
|
|
| 199 |
- Layer layerLines = new FeatureLayer(linesFeatures, styleLines, TRIP_LINES_LAYER_NAME);
|
|
| 200 |
- mapContent.addLayer(layerLines);
|
|
| 201 |
- }
|
|
| 202 |
- |
|
| 203 |
- |
|
| 204 |
- // add line in legend
|
|
| 205 |
- LineString line = geometryFactory.createLineString(ObserveMapPaneLegendItem.lineCoordinates());
|
|
| 206 |
- lineBuilder.add(line);
|
|
| 207 |
- lineBuilder.add("");
|
|
| 208 |
- lineBuilder.add("tripDay");
|
|
| 209 |
- |
|
| 210 |
- ObserveMapPaneLegendItem legendTripDay = new ObserveMapPaneLegendItem(
|
|
| 211 |
- lineBuilder.buildFeature(null),
|
|
| 212 |
- styleLines,
|
|
| 213 |
- t("observe.content.map.legend.tripDay"));
|
|
| 214 |
- legendItems.add(legendTripDay);
|
|
| 215 |
- |
|
| 216 |
- lineBuilder.add(line);
|
|
| 217 |
- lineBuilder.add("");
|
|
| 218 |
- lineBuilder.add("tripBetweenTwoDays");
|
|
| 219 |
- ObserveMapPaneLegendItem legendTripBetweenTwoDays = new ObserveMapPaneLegendItem(
|
|
| 220 |
- lineBuilder.buildFeature(null),
|
|
| 221 |
- styleLines,
|
|
| 222 |
- t("observe.content.map.legend.tripBetweenTwoDays"));
|
|
| 223 |
- legendItems.add(legendTripBetweenTwoDays);
|
|
| 224 |
- |
|
| 225 |
- }
|
|
| 226 |
- |
|
| 227 |
- public void addLonglineFishingZone(List<TripMapPoint> tripMapPoints) throws FactoryException {
|
|
| 228 |
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
|
|
| 229 |
- |
|
| 230 |
- SimpleFeatureTypeBuilder polygonFeatureTypeBuilder = new SimpleFeatureTypeBuilder();
|
|
| 231 |
- polygonFeatureTypeBuilder.setName("longlineFishingZoneBuilder");
|
|
| 232 |
- polygonFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true));
|
|
| 233 |
- polygonFeatureTypeBuilder.add("zone", Polygon.class);
|
|
| 234 |
- polygonFeatureTypeBuilder.add("label", String.class);
|
|
| 235 |
- polygonFeatureTypeBuilder.add("type", String.class);
|
|
| 236 |
- |
|
| 237 |
- SimpleFeatureType polygonFeatureType = polygonFeatureTypeBuilder.buildFeatureType();
|
|
| 238 |
- SimpleFeatureBuilder polygonBuilder = new SimpleFeatureBuilder(polygonFeatureType);
|
|
| 239 |
- |
|
| 240 |
- DefaultFeatureCollection polygonsFeatures = new DefaultFeatureCollection();
|
|
| 241 |
- |
|
| 242 |
- for (int indexPoint = 3; indexPoint < tripMapPoints.size(); indexPoint++) {
|
|
| 243 |
- if (tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithHaulingEnd)
|
|
| 244 |
- && tripMapPoints.get(indexPoint - 1).getType().equals(TripMapPointType.longlineActivityWithHaulingStart)
|
|
| 245 |
- && tripMapPoints.get(indexPoint - 2).getType().equals(TripMapPointType.longlineActivityWithSettingEnd)
|
|
| 246 |
- && tripMapPoints.get(indexPoint - 3).getType().equals(TripMapPointType.longlineActivityWithSettingStart)) {
|
|
| 247 |
- |
|
| 248 |
- Coordinate[] coordinates = {
|
|
| 249 |
- new Coordinate(tripMapPoints.get(indexPoint - 3).getLongitude(), tripMapPoints.get(indexPoint - 3).getLatitude()),
|
|
| 250 |
- new Coordinate(tripMapPoints.get(indexPoint - 2).getLongitude(), tripMapPoints.get(indexPoint - 2).getLatitude()),
|
|
| 251 |
- new Coordinate(tripMapPoints.get(indexPoint - 1).getLongitude(), tripMapPoints.get(indexPoint - 1).getLatitude()),
|
|
| 252 |
- new Coordinate(tripMapPoints.get(indexPoint).getLongitude(), tripMapPoints.get(indexPoint).getLatitude()),
|
|
| 253 |
- new Coordinate(tripMapPoints.get(indexPoint - 3).getLongitude(), tripMapPoints.get(indexPoint - 3).getLatitude())
|
|
| 254 |
- };
|
|
| 255 |
- |
|
| 256 |
- |
|
| 257 |
- Polygon polygon = geometryFactory.createPolygon(coordinates);
|
|
| 258 |
- //polygon = (Polygon) polygon.convexHull(); // permet de transformer un poliqgone croisé en polygon convex
|
|
| 259 |
- polygonBuilder.add(polygon);
|
|
| 260 |
- polygonBuilder.add(DATE_FORMAT.format(tripMapPoints.get(indexPoint - 3).getTime()));
|
|
| 261 |
- polygonBuilder.add("longlineFishingZone");
|
|
| 262 |
- SimpleFeature feature = polygonBuilder.buildFeature(null);
|
|
| 263 |
- polygonsFeatures.add(feature);
|
|
| 264 |
- |
|
| 265 |
- }
|
|
| 266 |
- }
|
|
| 267 |
- |
|
| 268 |
- if (!polygonsFeatures.isEmpty()) {
|
|
| 269 |
- Style styleLines = findStyle(styledLayerDescriptor, TRIP_LONGLINE_FISHING_ZONE_LAYER_NAME, null);
|
|
| 270 |
- Layer layerLines = new FeatureLayer(polygonsFeatures, styleLines, TRIP_LONGLINE_FISHING_ZONE_LAYER_NAME);
|
|
| 271 |
- mapContent.addLayer(layerLines);
|
|
| 272 |
- }
|
|
| 273 |
- }
|
|
| 274 |
- |
|
| 275 |
- public void addLonglineLine(List<TripMapPoint> tripMapPoints) throws FactoryException {
|
|
| 276 |
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
|
|
| 277 |
- |
|
| 278 |
- SimpleFeatureTypeBuilder lineFeatureTypeBuilder = new SimpleFeatureTypeBuilder();
|
|
| 279 |
- lineFeatureTypeBuilder.setName("longlineSettingBuilder");
|
|
| 280 |
- lineFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true));
|
|
| 281 |
- lineFeatureTypeBuilder.add("line", LineString.class);
|
|
| 282 |
- lineFeatureTypeBuilder.add("type", String.class);
|
|
| 283 |
- |
|
| 284 |
- SimpleFeatureType lineFeatureType = lineFeatureTypeBuilder.buildFeatureType();
|
|
| 285 |
- SimpleFeatureBuilder lineBuilder = new SimpleFeatureBuilder(lineFeatureType);
|
|
| 286 |
- |
|
| 287 |
- DefaultFeatureCollection linesFeatures = new DefaultFeatureCollection();
|
|
| 288 |
- |
|
| 289 |
- List<Coordinate> defaultLineCoordinates = Lists.newLinkedList();
|
|
| 290 |
- |
|
| 291 |
- for (int indexPoint = 0; indexPoint < tripMapPoints.size(); indexPoint++) {
|
|
| 292 |
- if (indexPoint > 1 && tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithSettingEnd)
|
|
| 293 |
- && tripMapPoints.get(indexPoint - 1).getType().equals(TripMapPointType.longlineActivityWithSettingStart)
|
|
| 294 |
- || tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithHaulingEnd)
|
|
| 295 |
- && tripMapPoints.get(indexPoint - 1).getType().equals(TripMapPointType.longlineActivityWithHaulingStart)) {
|
|
| 296 |
- |
|
| 297 |
- Coordinate[] coordinates = {
|
|
| 298 |
- new Coordinate(tripMapPoints.get(indexPoint - 1).getLongitude(), tripMapPoints.get(indexPoint - 1).getLatitude()),
|
|
| 299 |
- new Coordinate(tripMapPoints.get(indexPoint).getLongitude(), tripMapPoints.get(indexPoint).getLatitude()),
|
|
| 300 |
- };
|
|
| 301 |
- |
|
| 302 |
- boolean setting = tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithSettingEnd);
|
|
| 303 |
- LineString lineString = geometryFactory.createLineString(coordinates);
|
|
| 304 |
- lineBuilder.add(lineString);
|
|
| 305 |
- lineBuilder.add(setting ? "setting" : "hauling");
|
|
| 306 |
- SimpleFeature feature = lineBuilder.buildFeature(null);
|
|
| 307 |
- linesFeatures.add(feature);
|
|
| 308 |
- |
|
| 309 |
- defaultLineCoordinates.clear();
|
|
| 310 |
- }
|
|
| 311 |
- |
|
| 312 |
- if (!(tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithSettingEnd)
|
|
| 313 |
- || tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithHaulingStart))) {
|
|
| 314 |
- |
|
| 315 |
- defaultLineCoordinates.add(new Coordinate(tripMapPoints.get(indexPoint).getLongitude(), tripMapPoints.get(indexPoint).getLatitude()));
|
|
| 316 |
- |
|
| 317 |
- }
|
|
| 318 |
- |
|
| 319 |
- if ((tripMapPoints.get(indexPoint).getType().equals(TripMapPointType.longlineActivityWithSettingStart)
|
|
| 320 |
- || indexPoint == tripMapPoints.size() - 1) && defaultLineCoordinates.size() > 1) {
|
|
| 321 |
- |
|
| 322 |
- LineString lineString = geometryFactory.createLineString(defaultLineCoordinates.toArray(new Coordinate[0]));
|
|
| 323 |
- lineBuilder.add(lineString);
|
|
| 324 |
- lineBuilder.add("trip");
|
|
| 325 |
- SimpleFeature feature = lineBuilder.buildFeature(null);
|
|
| 326 |
- linesFeatures.add(feature);
|
|
| 327 |
- |
|
| 328 |
- defaultLineCoordinates.clear();
|
|
| 329 |
- |
|
| 330 |
- }
|
|
| 331 |
- |
|
| 332 |
- |
|
| 333 |
- }
|
|
| 334 |
- |
|
| 335 |
- Style styleLines = findStyle(styledLayerDescriptor, TRIP_LONGLINE_LINE_LAYER_NAME, null);
|
|
| 336 |
- if (!linesFeatures.isEmpty()) {
|
|
| 337 |
- Layer layerLines = new FeatureLayer(linesFeatures, styleLines, TRIP_LONGLINE_LINE_LAYER_NAME);
|
|
| 338 |
- mapContent.addLayer(layerLines);
|
|
| 339 |
- }
|
|
| 340 |
- |
|
| 341 |
- // add line in legend
|
|
| 342 |
- LineString line = geometryFactory.createLineString(ObserveMapPaneLegendItem.lineCoordinates());
|
|
| 343 |
- lineBuilder.add(line);
|
|
| 344 |
- lineBuilder.add("setting");
|
|
| 345 |
- |
|
| 346 |
- ObserveMapPaneLegendItem legendTripDay = new ObserveMapPaneLegendItem(
|
|
| 347 |
- lineBuilder.buildFeature(null),
|
|
| 348 |
- styleLines,
|
|
| 349 |
- t("observe.content.map.legend.setting"));
|
|
| 350 |
- legendItems.add(legendTripDay);
|
|
| 351 |
- |
|
| 352 |
- line = geometryFactory.createLineString(ObserveMapPaneLegendItem.lineCoordinates());
|
|
| 353 |
- lineBuilder.add(line);
|
|
| 354 |
- lineBuilder.add("hauling");
|
|
| 355 |
- |
|
| 356 |
- legendTripDay = new ObserveMapPaneLegendItem(
|
|
| 357 |
- lineBuilder.buildFeature(null),
|
|
| 358 |
- styleLines,
|
|
| 359 |
- t("observe.content.map.legend.hauling"));
|
|
| 360 |
- legendItems.add(legendTripDay);
|
|
| 361 |
- |
|
| 362 |
- |
|
| 363 |
- }
|
|
| 364 |
- |
|
| 365 |
- |
|
| 366 |
- public void addPoints(List<TripMapPoint> tripMapPoints) throws FactoryException {
|
|
| 367 |
- |
|
| 368 |
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
|
|
| 369 |
- |
|
| 370 |
- SimpleFeatureTypeBuilder pointFeatureTypeBuilder = new SimpleFeatureTypeBuilder();
|
|
| 371 |
- pointFeatureTypeBuilder.setName("point Builder");
|
|
| 372 |
- pointFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true));
|
|
| 373 |
- pointFeatureTypeBuilder.add("point", Point.class);
|
|
| 374 |
- pointFeatureTypeBuilder.add("label", String.class);
|
|
| 375 |
- pointFeatureTypeBuilder.add("pointType", String.class);
|
|
| 376 |
- |
|
| 377 |
- SimpleFeatureType pointFeatureType = pointFeatureTypeBuilder.buildFeatureType();
|
|
| 378 |
- SimpleFeatureBuilder pointBuilder = new SimpleFeatureBuilder(pointFeatureType);
|
|
| 379 |
- |
|
| 380 |
- DefaultFeatureCollection pointsFeatures = new DefaultFeatureCollection();
|
|
| 381 |
- |
|
| 382 |
- Style stylePoints = findStyle(styledLayerDescriptor, TRIP_POINTS_LAYER_NAME, null);
|
|
| 383 |
- |
|
| 384 |
- Set<TripMapPointType> pointTypeInLegend = Sets.newHashSet();
|
|
| 385 |
- |
|
| 386 |
- for (TripMapPoint tripMapPoint : tripMapPoints) {
|
|
| 387 |
- Coordinate coordinate = new Coordinate(tripMapPoint.getLongitude(), tripMapPoint.getLatitude());
|
|
| 388 |
- |
|
| 389 |
- TripMapPointType type = tripMapPoint.getType();
|
|
| 390 |
- |
|
| 391 |
- Point point = geometryFactory.createPoint(coordinate);
|
|
| 392 |
- pointBuilder.add(point);
|
|
| 393 |
- pointBuilder.add(DATE_FORMAT.format(tripMapPoint.getTime()));
|
|
| 394 |
- pointBuilder.add(type.name());
|
|
| 395 |
- pointsFeatures.add(pointBuilder.buildFeature(null));
|
|
| 396 |
- |
|
| 397 |
- // add point in legend
|
|
| 398 |
- if (TRIP_MAP_POINT_TYPES_IN_LEGEND.contains(type) && !pointTypeInLegend.contains(type)) {
|
|
| 399 |
- point = geometryFactory.createPoint(ObserveMapPaneLegendItem.pointCoordinates());
|
|
| 400 |
- pointBuilder.add(point);
|
|
| 401 |
- pointBuilder.add("");
|
|
| 402 |
- pointBuilder.add(type.name());
|
|
| 403 |
- |
|
| 404 |
- ObserveMapPaneLegendItem legendPoint = new ObserveMapPaneLegendItem(
|
|
| 405 |
- pointBuilder.buildFeature(null),
|
|
| 406 |
- stylePoints,
|
|
| 407 |
- I18nEnumHelper.getLabel(type));
|
|
| 408 |
- legendItems.add(legendPoint);
|
|
| 409 |
- pointTypeInLegend.add(type);
|
|
| 410 |
- }
|
|
| 411 |
- |
|
| 412 |
- }
|
|
| 413 |
- |
|
| 414 |
- if (!pointsFeatures.isEmpty()) {
|
|
| 415 |
- Layer pointsLayer = new FeatureLayer(pointsFeatures, stylePoints, TRIP_POINTS_LAYER_NAME);
|
|
| 416 |
- mapContent.addLayer(pointsLayer);
|
|
| 417 |
- }
|
|
| 418 |
- |
|
| 419 |
- }
|
|
| 420 |
- |
|
| 421 |
- |
|
| 422 |
- protected Style findStyle(StyledLayerDescriptor styledLayerDescriptor, final String layerName, String styleName, Style defaultStyle) {
|
|
| 423 |
- |
|
| 424 |
- Optional<StyledLayer> styledLayerOptional = styledLayerDescriptor.layers().stream().filter(input -> input.getName().equals(layerName)).findFirst();
|
|
| 425 |
- |
|
| 426 |
- Style style = defaultStyle;
|
|
| 427 |
- |
|
| 428 |
- if (styledLayerOptional.isPresent()) {
|
|
| 429 |
- |
|
| 430 |
- StyledLayer styledLayer = styledLayerOptional.get();
|
|
| 431 |
- |
|
| 432 |
- Style[] styles = new Style[0];
|
|
| 433 |
- |
|
| 434 |
- if (styledLayer instanceof UserLayer) {
|
|
| 435 |
- |
|
| 436 |
- styles = ((UserLayer) styledLayer).getUserStyles();
|
|
| 437 |
- |
|
| 438 |
- } else if (styledLayer instanceof NamedLayer) {
|
|
| 439 |
- |
|
| 440 |
- styles = ((NamedLayer) styledLayer).getStyles();
|
|
| 441 |
- |
|
| 442 |
- }
|
|
| 443 |
- |
|
| 444 |
- if (styles.length == 1) {
|
|
| 445 |
- |
|
| 446 |
- style = styles[0];
|
|
| 447 |
- |
|
| 448 |
- } else {
|
|
| 449 |
- |
|
| 450 |
- for (Style styleTmp : styles) {
|
|
| 451 |
- |
|
| 452 |
- if (StringUtils.isBlank(styleName) && styleTmp.isDefault()
|
|
| 453 |
- || styleTmp.getName().equals(styleName)) {
|
|
| 454 |
- |
|
| 455 |
- style = styleTmp;
|
|
| 456 |
- }
|
|
| 457 |
- }
|
|
| 458 |
- }
|
|
| 459 |
- }
|
|
| 460 |
- |
|
| 461 |
- return style;
|
|
| 462 |
- |
|
| 463 |
- }
|
|
| 464 |
- |
|
| 465 |
- protected Style findStyle(StyledLayerDescriptor styledLayerDescriptor, final String layerName, String styleName) {
|
|
| 466 |
- |
|
| 467 |
- Style style = findStyle(styledLayerDescriptor, layerName, styleName, null);
|
|
| 468 |
- |
|
| 469 |
- if (style == null) {
|
|
| 470 |
- throw new ObserveClientTechnicalException(String.format("No style found for layer name '%s' and style name '%s'", layerName, styleName));
|
|
| 471 |
- }
|
|
| 472 |
- return style;
|
|
| 473 |
- |
|
| 474 |
- }
|
|
| 475 |
- |
|
| 476 |
-}
|
| 1 |
-<!--
|
|
| 2 |
- #%L
|
|
| 3 |
- ObServe :: Client
|
|
| 4 |
- %%
|
|
| 5 |
- Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 6 |
- %%
|
|
| 7 |
- This program is free software: you can redistribute it and/or modify
|
|
| 8 |
- it under the terms of the GNU General Public License as
|
|
| 9 |
- published by the Free Software Foundation, either version 3 of the
|
|
| 10 |
- License, or (at your option) any later version.
|
|
| 11 |
-
|
|
| 12 |
- This program is distributed in the hope that it will be useful,
|
|
| 13 |
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 14 |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 15 |
- GNU General Public License for more details.
|
|
| 16 |
-
|
|
| 17 |
- You should have received a copy of the GNU General Public
|
|
| 18 |
- License along with this program. If not, see
|
|
| 19 |
- <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 20 |
- #L%
|
|
| 21 |
- -->
|
|
| 22 |
-<JPanel id="tripMap" layout="{new BorderLayout()}">
|
|
| 23 |
- |
|
| 24 |
- <import>
|
|
| 25 |
- fr.ird.observe.client.action.tripMap.ExportPngUIAction
|
|
| 26 |
- fr.ird.observe.client.action.tripMap.ZoomItUIAction
|
|
| 27 |
- fr.ird.observe.client.action.tripMap.ZoomMoinsUIAction
|
|
| 28 |
- fr.ird.observe.client.action.tripMap.ZoomPlusUIAction
|
|
| 29 |
- java.awt.CardLayout
|
|
| 30 |
- </import>
|
|
| 31 |
- |
|
| 32 |
- <CardLayout id="contentLayout"/>
|
|
| 33 |
- <JToolBar constraints="BorderLayout.NORTH">
|
|
| 34 |
- <JButton id='zoomIt'/>
|
|
| 35 |
- <JButton id='zoomPlus'/>
|
|
| 36 |
- <JButton id='zoomMoins'/>
|
|
| 37 |
- <JButton id='exportPng'/>
|
|
| 38 |
- </JToolBar>
|
|
| 39 |
- |
|
| 40 |
- <JPanel id="content" layout="{contentLayout}" constraints="BorderLayout.CENTER">
|
|
| 41 |
- <JLabel id="waitLoadingLabel"/>
|
|
| 42 |
- <ObserveMapPane id='observeMapPane'/>
|
|
| 43 |
- </JPanel>
|
|
| 44 |
- |
|
| 45 |
-</JPanel>
|
| 1 |
-/*
|
|
| 2 |
- * #%L
|
|
| 3 |
- * ObServe :: Client
|
|
| 4 |
- * %%
|
|
| 5 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 6 |
- * %%
|
|
| 7 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 8 |
- * it under the terms of the GNU General Public License as
|
|
| 9 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 10 |
- * License, or (at your option) any later version.
|
|
| 11 |
- *
|
|
| 12 |
- * This program is distributed in the hope that it will be useful,
|
|
| 13 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 14 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 15 |
- * GNU General Public License for more details.
|
|
| 16 |
- *
|
|
| 17 |
- * You should have received a copy of the GNU General Public
|
|
| 18 |
- * License along with this program. If not, see
|
|
| 19 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 20 |
- * #L%
|
|
| 21 |
- */
|
|
| 22 |
- |
|
| 23 |
-#waitLoadingLabel {
|
|
| 24 |
- text: "observe.content.map.waitLoading";
|
|
| 25 |
- horizontalAlignment : {JLabel.CENTER};
|
|
| 26 |
- verticalAlignment : {JLabel.CENTER};
|
|
| 27 |
- enabled: false;
|
|
| 28 |
-}
|
|
| 29 |
- |
|
| 30 |
-#zoomIt {
|
|
| 31 |
- _observeAction:{ZoomItUIAction.ACTION_NAME};
|
|
| 32 |
-}
|
|
| 33 |
- |
|
| 34 |
-#zoomMoins {
|
|
| 35 |
- _observeAction:{ZoomMoinsUIAction.ACTION_NAME};
|
|
| 36 |
-}
|
|
| 37 |
- |
|
| 38 |
-#zoomPlus {
|
|
| 39 |
- _observeAction:{ZoomPlusUIAction.ACTION_NAME};
|
|
| 40 |
-}
|
|
| 41 |
- |
|
| 42 |
-#exportPng {
|
|
| 43 |
- _observeAction:{ExportPngUIAction.ACTION_NAME};
|
|
| 44 |
-}
|
| 1 |
-package fr.ird.observe.client.util.tripMap;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import com.google.common.collect.Lists;
|
|
| 26 |
-import fr.ird.observe.client.ObserveClientApplicationContext;
|
|
| 27 |
-import fr.ird.observe.client.ObserveClientTechnicalException;
|
|
| 28 |
-import fr.ird.observe.client.configuration.ClientConfig;
|
|
| 29 |
-import fr.ird.observe.client.action.ObserveActionMap;
|
|
| 30 |
-import fr.ird.observe.client.action.tripMap.TripMapActionSupport;
|
|
| 31 |
-import fr.ird.observe.dto.IdHelper;
|
|
| 32 |
-import fr.ird.observe.dto.data.TripMapDto;
|
|
| 33 |
-import fr.ird.observe.dto.data.TripMapPoint;
|
|
| 34 |
-import java.awt.Point;
|
|
| 35 |
-import java.awt.event.MouseEvent;
|
|
| 36 |
-import java.awt.event.MouseListener;
|
|
| 37 |
-import java.awt.event.MouseMotionListener;
|
|
| 38 |
-import java.awt.event.MouseWheelEvent;
|
|
| 39 |
-import java.awt.event.MouseWheelListener;
|
|
| 40 |
-import java.awt.geom.AffineTransform;
|
|
| 41 |
-import java.awt.geom.Point2D;
|
|
| 42 |
-import java.io.File;
|
|
| 43 |
-import java.util.List;
|
|
| 44 |
-import java.util.Objects;
|
|
| 45 |
-import javax.swing.AbstractButton;
|
|
| 46 |
-import javax.swing.InputMap;
|
|
| 47 |
-import org.apache.commons.logging.Log;
|
|
| 48 |
-import org.apache.commons.logging.LogFactory;
|
|
| 49 |
-import org.geotools.geometry.DirectPosition2D;
|
|
| 50 |
-import org.geotools.geometry.jts.ReferencedEnvelope;
|
|
| 51 |
-import org.geotools.swing.JMapPane;
|
|
| 52 |
-import org.geotools.swing.event.MapPaneEvent;
|
|
| 53 |
-import org.geotools.swing.event.MapPaneListener;
|
|
| 54 |
-import org.nuiton.jaxx.runtime.spi.UIHandler;
|
|
| 55 |
- |
|
| 56 |
- |
|
| 57 |
-import static fr.ird.observe.client.form.FormUIHandler.OBSERVE_ACTION;
|
|
| 58 |
- |
|
| 59 |
-/**
|
|
| 60 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 61 |
- */
|
|
| 62 |
-public class TripMapUIHandler implements UIHandler<TripMapUI> {
|
|
| 63 |
- |
|
| 64 |
- public static final double ZOOM_STEP_RATIO = 0.1;
|
|
| 65 |
- |
|
| 66 |
- private static final Log log = LogFactory.getLog(TripMapUIHandler.class);
|
|
| 67 |
- |
|
| 68 |
- private TripMapUI ui;
|
|
| 69 |
- private ClientConfig config;
|
|
| 70 |
- private ReferencedEnvelope tripArea;
|
|
| 71 |
- private boolean rendererRunning;
|
|
| 72 |
- private double zoomRatio = 1;
|
|
| 73 |
- private Point zoomCenter;
|
|
| 74 |
- |
|
| 75 |
- public void setConfig(ClientConfig config) {
|
|
| 76 |
- this.config = config;
|
|
| 77 |
- |
|
| 78 |
- JMapPane mapPane = getObserveMapPane();
|
|
| 79 |
- mapPane.setBackground(config.getMapBackgroundColor());
|
|
| 80 |
- }
|
|
| 81 |
- |
|
| 82 |
- private ObserveMapPane getObserveMapPane() {
|
|
| 83 |
- return ui.getObserveMapPane();
|
|
| 84 |
- }
|
|
| 85 |
- |
|
| 86 |
- public void doOpenMap(TripMapDto tripMapDto) {
|
|
| 87 |
- |
|
| 88 |
- try {
|
|
| 89 |
- flipContent();
|
|
| 90 |
- ObserveClientApplicationContext.get().getMainUI().getModel().setBusy(true);
|
|
| 91 |
- |
|
| 92 |
- ObserveMapPane mapPane = getObserveMapPane();
|
|
| 93 |
- |
|
| 94 |
- if (mapPane.getMapContent() != null) {
|
|
| 95 |
- // appeler pour libéré les listeners
|
|
| 96 |
- mapPane.getMapContent().dispose();
|
|
| 97 |
- }
|
|
| 98 |
- |
|
| 99 |
- List<TripMapPoint> tripMapPoints = Lists.newArrayList(tripMapDto.getPoints());
|
|
| 100 |
- |
|
| 101 |
- |
|
| 102 |
- TripMapContentBuilder mapContentBuilder = new TripMapContentBuilder();
|
|
| 103 |
- mapContentBuilder.setStyledLayerDescriptor(config.getMapStyleFile());
|
|
| 104 |
- |
|
| 105 |
- for (File layerFile : config.getMapLayerFiles()) {
|
|
| 106 |
- mapContentBuilder.addLayer(layerFile);
|
|
| 107 |
- }
|
|
| 108 |
- |
|
| 109 |
- if (IdHelper.isSeineId(tripMapDto.getId())) {
|
|
| 110 |
- |
|
| 111 |
- mapContentBuilder.addTripLine(tripMapPoints);
|
|
| 112 |
- |
|
| 113 |
- } else if (IdHelper.isLonglineId(tripMapDto.getId())) {
|
|
| 114 |
- |
|
| 115 |
- mapContentBuilder.addLonglineFishingZone(tripMapPoints);
|
|
| 116 |
- mapContentBuilder.addLonglineLine(tripMapPoints);
|
|
| 117 |
- |
|
| 118 |
- }
|
|
| 119 |
- |
|
| 120 |
- mapContentBuilder.addPoints(tripMapPoints);
|
|
| 121 |
- |
|
| 122 |
- // set zoom
|
|
| 123 |
- tripArea = new ReferencedEnvelope();
|
|
| 124 |
- for (TripMapPoint point : tripMapPoints) {
|
|
| 125 |
- tripArea.expandToInclude(new DirectPosition2D(point.getLongitude(), point.getLatitude()));
|
|
| 126 |
- }
|
|
| 127 |
- tripArea.expandBy(1.1);
|
|
| 128 |
- |
|
| 129 |
- mapPane.setMapContent(mapContentBuilder.getMapContent());
|
|
| 130 |
- mapPane.setLegendItems(mapContentBuilder.getLegendItems());
|
|
| 131 |
- |
|
| 132 |
- } catch (Exception e) {
|
|
| 133 |
- throw new ObserveClientTechnicalException("Unable to load trip map activity points", e);
|
|
| 134 |
- } finally {
|
|
| 135 |
- ObserveClientApplicationContext.get().getMainUI().getModel().setBusy(false);
|
|
| 136 |
- }
|
|
| 137 |
- |
|
| 138 |
- }
|
|
| 139 |
- |
|
| 140 |
- private void flipContent() {
|
|
| 141 |
- ui.getContentLayout().first(ui.getContent());
|
|
| 142 |
- }
|
|
| 143 |
- |
|
| 144 |
- public void doCloseMap() {
|
|
| 145 |
- flipContent();
|
|
| 146 |
- }
|
|
| 147 |
- |
|
| 148 |
- public void zoomApply() {
|
|
| 149 |
- if (zoomRatio != 1 && !rendererRunning) {
|
|
| 150 |
- |
|
| 151 |
- JMapPane mapPane = getObserveMapPane();
|
|
| 152 |
- |
|
| 153 |
- ReferencedEnvelope displayArea = mapPane.getDisplayArea();
|
|
| 154 |
- |
|
| 155 |
- double deltaWidth = displayArea.getWidth() * (zoomRatio - 1);
|
|
| 156 |
- double deltaHeight = displayArea.getHeight() * (zoomRatio - 1);
|
|
| 157 |
- |
|
| 158 |
- double ratioLeft = zoomCenter.getX() * 1d / mapPane.getWidth();
|
|
| 159 |
- |
|
| 160 |
- // l'axe de Y est inversé entre le référentiel du composant swing et le référentiel géographique
|
|
| 161 |
- double ratioTop = 1 - (zoomCenter.getY() * 1d / mapPane.getHeight());
|
|
| 162 |
- |
|
| 163 |
- double deltaLeft = deltaWidth * ratioLeft;
|
|
| 164 |
- double deltaRight = deltaLeft - deltaWidth;
|
|
| 165 |
- |
|
| 166 |
- double deltaTop = deltaHeight * ratioTop;
|
|
| 167 |
- double deltaBottom = deltaTop - deltaHeight;
|
|
| 168 |
- |
|
| 169 |
- if (log.isDebugEnabled()) {
|
|
| 170 |
- log.debug(String.format("Map mouse zoom (zoom ratio : %s, deltaLeft : %s, deltaRight : %s, deltaTop : %s, deltaBottom : %s)",
|
|
| 171 |
- zoomRatio, deltaLeft, deltaRight, deltaRight, deltaBottom));
|
|
| 172 |
- }
|
|
| 173 |
- |
|
| 174 |
- ReferencedEnvelope newDisplayArea = new ReferencedEnvelope(
|
|
| 175 |
- displayArea.getMinX() + deltaLeft,
|
|
| 176 |
- displayArea.getMaxX() + deltaRight,
|
|
| 177 |
- displayArea.getMinY() + deltaTop,
|
|
| 178 |
- displayArea.getMaxY() + deltaBottom,
|
|
| 179 |
- displayArea.getCoordinateReferenceSystem()
|
|
| 180 |
- );
|
|
| 181 |
- // -230 is the good value (don't ask me why ?)
|
|
| 182 |
- if (newDisplayArea.getLowerCorner().getOrdinate(0) > -230) {
|
|
| 183 |
- mapPane.setDisplayArea(newDisplayArea);
|
|
| 184 |
- }
|
|
| 185 |
- |
|
| 186 |
- zoomRatio = 1;
|
|
| 187 |
- |
|
| 188 |
- }
|
|
| 189 |
- |
|
| 190 |
- }
|
|
| 191 |
- |
|
| 192 |
- @Override
|
|
| 193 |
- public void beforeInit(TripMapUI ui) {
|
|
| 194 |
- this.ui = ui;
|
|
| 195 |
- }
|
|
| 196 |
- |
|
| 197 |
- @Override
|
|
| 198 |
- public void afterInit(TripMapUI ui) {
|
|
| 199 |
- |
|
| 200 |
- ObserveMapPane mapPane = getObserveMapPane();
|
|
| 201 |
- |
|
| 202 |
- MouseMapListener mouseMapListener = new MouseMapListener();
|
|
| 203 |
- mapPane.addMouseWheelListener(mouseMapListener);
|
|
| 204 |
- mapPane.addMouseMotionListener(mouseMapListener);
|
|
| 205 |
- mapPane.addMouseListener(mouseMapListener);
|
|
| 206 |
- mapPane.addMapPaneListener(new TripMapListener());
|
|
| 207 |
- |
|
| 208 |
- rendererRunning = false;
|
|
| 209 |
- |
|
| 210 |
- }
|
|
| 211 |
- |
|
| 212 |
- public void init(InputMap inputMap) {
|
|
| 213 |
- ObserveActionMap actionMap = ObserveClientApplicationContext.get().getActionMap();
|
|
| 214 |
- |
|
| 215 |
- init(actionMap, inputMap, ui.zoomIt);
|
|
| 216 |
- init(actionMap, inputMap, ui.zoomMoins);
|
|
| 217 |
- init(actionMap, inputMap, ui.zoomPlus);
|
|
| 218 |
- init(actionMap, inputMap, ui.exportPng);
|
|
| 219 |
- |
|
| 220 |
- }
|
|
| 221 |
- |
|
| 222 |
- public ReferencedEnvelope getTripArea() {
|
|
| 223 |
- return tripArea;
|
|
| 224 |
- }
|
|
| 225 |
- |
|
| 226 |
- public double getZoomRatio() {
|
|
| 227 |
- return zoomRatio;
|
|
| 228 |
- }
|
|
| 229 |
- |
|
| 230 |
- public void setZoomRatio(double zoomRatio) {
|
|
| 231 |
- this.zoomRatio = zoomRatio;
|
|
| 232 |
- }
|
|
| 233 |
- |
|
| 234 |
- public void setZoomCenter(Point zoomCenter) {
|
|
| 235 |
- this.zoomCenter = zoomCenter;
|
|
| 236 |
- }
|
|
| 237 |
- |
|
| 238 |
- private class MouseMapListener implements MouseWheelListener, MouseListener, MouseMotionListener {
|
|
| 239 |
- |
|
| 240 |
- @Override
|
|
| 241 |
- public void mouseWheelMoved(MouseWheelEvent e) {
|
|
| 242 |
- int notches = e.getWheelRotation();
|
|
| 243 |
- zoomRatio = zoomRatio * (1 + (ZOOM_STEP_RATIO * notches * -1));
|
|
| 244 |
- zoomCenter = e.getPoint();
|
|
| 245 |
- zoomApply();
|
|
| 246 |
- }
|
|
| 247 |
- |
|
| 248 |
- @Override
|
|
| 249 |
- public void mouseClicked(MouseEvent e) {
|
|
| 250 |
- |
|
| 251 |
- }
|
|
| 252 |
- |
|
| 253 |
- Point2D startPointInWorld;
|
|
| 254 |
- AffineTransform startScreenToWorldTransform;
|
|
| 255 |
- ReferencedEnvelope startDisplayArea;
|
|
| 256 |
- |
|
| 257 |
- @Override
|
|
| 258 |
- public void mousePressed(MouseEvent e) {
|
|
| 259 |
- if (e.getButton() == MouseEvent.BUTTON1) {
|
|
| 260 |
- startMove(e.getPoint());
|
|
| 261 |
- }
|
|
| 262 |
- }
|
|
| 263 |
- |
|
| 264 |
- @Override
|
|
| 265 |
- public void mouseReleased(MouseEvent e) {
|
|
| 266 |
- if (e.getButton() == MouseEvent.BUTTON1) {
|
|
| 267 |
- endMove(e.getPoint());
|
|
| 268 |
- }
|
|
| 269 |
- }
|
|
| 270 |
- |
|
| 271 |
- @Override
|
|
| 272 |
- public void mouseEntered(MouseEvent e) {
|
|
| 273 |
- |
|
| 274 |
- }
|
|
| 275 |
- |
|
| 276 |
- @Override
|
|
| 277 |
- public void mouseExited(MouseEvent e) {
|
|
| 278 |
- |
|
| 279 |
- }
|
|
| 280 |
- |
|
| 281 |
- @Override
|
|
| 282 |
- public void mouseDragged(MouseEvent e) {
|
|
| 283 |
-// endMove(e.getPoint());
|
|
| 284 |
- }
|
|
| 285 |
- |
|
| 286 |
- @Override
|
|
| 287 |
- public void mouseMoved(MouseEvent e) {
|
|
| 288 |
- |
|
| 289 |
- }
|
|
| 290 |
- |
|
| 291 |
- void startMove(Point2D startPointInScreen) {
|
|
| 292 |
- JMapPane mapPane = getObserveMapPane();
|
|
| 293 |
- |
|
| 294 |
- startDisplayArea = mapPane.getDisplayArea();
|
|
| 295 |
- |
|
| 296 |
- startScreenToWorldTransform = mapPane.getScreenToWorldTransform();
|
|
| 297 |
- |
|
| 298 |
- startPointInWorld = new Point2D.Double();
|
|
| 299 |
- |
|
| 300 |
- startScreenToWorldTransform.transform(startPointInScreen, startPointInWorld);
|
|
| 301 |
- |
|
| 302 |
- }
|
|
| 303 |
- |
|
| 304 |
- void endMove(Point2D endPointInScreen) {
|
|
| 305 |
- |
|
| 306 |
- Point2D endPointInWorld = new Point2D.Double();
|
|
| 307 |
- |
|
| 308 |
- startScreenToWorldTransform.transform(endPointInScreen, endPointInWorld);
|
|
| 309 |
- |
|
| 310 |
- double transX = startPointInWorld.getX() - endPointInWorld.getX();
|
|
| 311 |
- double transY = startPointInWorld.getY() - endPointInWorld.getY();
|
|
| 312 |
- |
|
| 313 |
- ReferencedEnvelope endDisplayArea = new ReferencedEnvelope(startDisplayArea);
|
|
| 314 |
- |
|
| 315 |
- endDisplayArea.translate(transX, transY);
|
|
| 316 |
- |
|
| 317 |
- JMapPane mapPane = getObserveMapPane();
|
|
| 318 |
- |
|
| 319 |
- mapPane.setDisplayArea(endDisplayArea);
|
|
| 320 |
- |
|
| 321 |
- if (log.isDebugEnabled()) {
|
|
| 322 |
- log.debug(String.format("Translate (x : %s, y : %s)", transX, transY));
|
|
| 323 |
- }
|
|
| 324 |
- }
|
|
| 325 |
- }
|
|
| 326 |
- |
|
| 327 |
- protected class TripMapListener implements MapPaneListener {
|
|
| 328 |
- |
|
| 329 |
- boolean firstRendering;
|
|
| 330 |
- |
|
| 331 |
- @Override
|
|
| 332 |
- public void onNewMapContent(MapPaneEvent ev) {
|
|
| 333 |
- firstRendering = true;
|
|
| 334 |
- }
|
|
| 335 |
- |
|
| 336 |
- @Override
|
|
| 337 |
- public void onDisplayAreaChanged(MapPaneEvent ev) {
|
|
| 338 |
- }
|
|
| 339 |
- |
|
| 340 |
- @Override
|
|
| 341 |
- public void onRenderingStarted(MapPaneEvent ev) {
|
|
| 342 |
- rendererRunning = true;
|
|
| 343 |
- }
|
|
| 344 |
- |
|
| 345 |
- @Override
|
|
| 346 |
- public void onRenderingStopped(MapPaneEvent ev) {
|
|
| 347 |
- rendererRunning = false;
|
|
| 348 |
- if (firstRendering) {
|
|
| 349 |
- |
|
| 350 |
- if (!tripArea.isEmpty()) {
|
|
| 351 |
- JMapPane mapPane = getObserveMapPane();
|
|
| 352 |
- mapPane.setDisplayArea(tripArea);
|
|
| 353 |
- }
|
|
| 354 |
- |
|
| 355 |
- ui.getContentLayout().last(ui.getContent());
|
|
| 356 |
- firstRendering = false;
|
|
| 357 |
- } else {
|
|
| 358 |
- zoomApply();
|
|
| 359 |
- }
|
|
| 360 |
- }
|
|
| 361 |
- }
|
|
| 362 |
- |
|
| 363 |
- protected void init(ObserveActionMap actionMap, InputMap inputMap, AbstractButton editor) {
|
|
| 364 |
- String actionId = (String) editor.getClientProperty(OBSERVE_ACTION);
|
|
| 365 |
- |
|
| 366 |
- // on a trouve une action commune
|
|
| 367 |
- TripMapActionSupport action = (TripMapActionSupport) actionMap.get(actionId);
|
|
| 368 |
- Objects.requireNonNull(action, "action [" + actionId + "] not found for ui " + ui.getClass().getName());
|
|
| 369 |
- |
|
| 370 |
- if (log.isDebugEnabled()) {
|
|
| 371 |
- log.debug("init common action " + actionId);
|
|
| 372 |
- }
|
|
| 373 |
- |
|
| 374 |
- action.setUi(ui);
|
|
| 375 |
- action.initForMainUi(editor, inputMap, actionMap);
|
|
| 376 |
- |
|
| 377 |
- }
|
|
| 378 |
- |
|
| 379 |
-}
|
| 1 |
-package fr.ird.observe.dto.data;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Dto
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.dto.IdDto;
|
|
| 26 |
-import java.util.Collection;
|
|
| 27 |
-import java.util.LinkedHashSet;
|
|
| 28 |
- |
|
| 29 |
-public class TripMapDto extends IdDto {
|
|
| 30 |
- |
|
| 31 |
- public static final String PROPERTY_POINTS = "points";
|
|
| 32 |
- |
|
| 33 |
- protected LinkedHashSet<TripMapPoint> points;
|
|
| 34 |
- |
|
| 35 |
- public TripMapPoint getPoints(int index) {
|
|
| 36 |
- TripMapPoint o = getChild(points, index);
|
|
| 37 |
- return o;
|
|
| 38 |
- }
|
|
| 39 |
- |
|
| 40 |
- public boolean isPointsEmpty() {
|
|
| 41 |
- return points == null || points.isEmpty();
|
|
| 42 |
- }
|
|
| 43 |
- |
|
| 44 |
- public int sizePoints() {
|
|
| 45 |
- return points == null ? 0 : points.size();
|
|
| 46 |
- }
|
|
| 47 |
- |
|
| 48 |
- public void addPoints(TripMapPoint points) {
|
|
| 49 |
- getPoints().add(points);
|
|
| 50 |
- firePropertyChange(PROPERTY_POINTS, null, points);
|
|
| 51 |
- }
|
|
| 52 |
- |
|
| 53 |
- public void addAllPoints(Collection<TripMapPoint> points) {
|
|
| 54 |
- getPoints().addAll(points);
|
|
| 55 |
- firePropertyChange(PROPERTY_POINTS, null, points);
|
|
| 56 |
- }
|
|
| 57 |
- |
|
| 58 |
- public boolean removePoints(TripMapPoint points) {
|
|
| 59 |
- boolean removed = getPoints().remove(points);
|
|
| 60 |
- if (removed) {
|
|
| 61 |
- firePropertyChange(PROPERTY_POINTS, points, null);
|
|
| 62 |
- }
|
|
| 63 |
- return removed;
|
|
| 64 |
- }
|
|
| 65 |
- |
|
| 66 |
- public boolean removeAllPoints(Collection<TripMapPoint> points) {
|
|
| 67 |
- boolean removed = getPoints().removeAll(points);
|
|
| 68 |
- if (removed) {
|
|
| 69 |
- firePropertyChange(PROPERTY_POINTS, points, null);
|
|
| 70 |
- }
|
|
| 71 |
- return removed;
|
|
| 72 |
- }
|
|
| 73 |
- |
|
| 74 |
- public boolean containsPoints(TripMapPoint points) {
|
|
| 75 |
- boolean contains = getPoints().contains(points);
|
|
| 76 |
- return contains;
|
|
| 77 |
- }
|
|
| 78 |
- |
|
| 79 |
- public boolean containsAllPoints(Collection<TripMapPoint> points) {
|
|
| 80 |
- boolean contains = getPoints().containsAll(points);
|
|
| 81 |
- return contains;
|
|
| 82 |
- }
|
|
| 83 |
- |
|
| 84 |
- public LinkedHashSet<TripMapPoint> getPoints() {
|
|
| 85 |
- if (points == null) {
|
|
| 86 |
- points = new LinkedHashSet<>();
|
|
| 87 |
- }
|
|
| 88 |
- return points;
|
|
| 89 |
- }
|
|
| 90 |
- |
|
| 91 |
- public void setPoints(LinkedHashSet<TripMapPoint> points) {
|
|
| 92 |
- LinkedHashSet<TripMapPoint> oldValue = getPoints();
|
|
| 93 |
- this.points = points;
|
|
| 94 |
- firePropertyChange(PROPERTY_POINTS, oldValue, points);
|
|
| 95 |
- }
|
|
| 96 |
- |
|
| 97 |
-}
|
| ... | ... | @@ -151,7 +151,7 @@ |
| 151 | 151 |
<maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format>
|
| 152 | 152 |
<buildDate>${maven.build.timestamp}</buildDate>
|
| 153 | 153 |
|
| 154 |
- <observeToolkitVersion>1.6-SNAPSHOT</observeToolkitVersion>
|
|
| 154 |
+ <observeToolkitVersion>1.6</observeToolkitVersion>
|
|
| 155 | 155 |
<eugenePluginVersion>3.0-alpha-16</eugenePluginVersion>
|
| 156 | 156 |
<processorPluginVersion>1.3</processorPluginVersion>
|
| 157 | 157 |
|