Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 4f3e50ee by Tony CHEMIT at 2017-08-25T02:20:56+02:00 Ajout du zoom +/- sur les cartes (See #859) - - - - - 21 changed files: - client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java - + client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ExportPngUIAction.java - + client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/TripMapActionSupport.java - + client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomItUIAction.java - + client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomMoinsUIAction.java - + client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomPlusUIAction.java - + client/src/main/java/fr/ird/observe/client/ui/content/open/TripUI.java - client/src/main/java/fr/ird/observe/client/ui/content/open/longline/TripLonglineUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/open/longline/TripLonglineUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/content/open/seine/TripSeineUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/open/seine/TripSeineUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUI.jcss - client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUIHandler.java - client/src/main/resources/i18n/client_en_GB.properties - client/src/main/resources/i18n/client_es_ES.properties - client/src/main/resources/i18n/client_fr_FR.properties - + client/src/main/resources/icons/action-zoomMoins.png - + client/src/main/resources/icons/action-zoomPlus.png - client/src/main/resources/observe-ui.properties - services/src/main/java/fr/ird/observe/services/decoration/ObserveI18nLabelsBuilder.java Changes: ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java @@ -32,6 +32,7 @@ import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import javax.swing.AbstractAction; import javax.swing.AbstractButton; +import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.Icon; import javax.swing.InputMap; @@ -131,8 +132,14 @@ public abstract class UIActionSupport extends AbstractAction { KeyStroke keyStroke = getAcceleratorKey(); if (keyStroke != null) { String actionCommandKey = getActionCommandKey(); + register(this, inputMap, actionMap,keyStroke, actionCommandKey); + } + } + + public static void register(Action action, InputMap inputMap, ActionMap actionMap, KeyStroke keyStroke , String actionCommandKey ) { + if (keyStroke != null) { inputMap.put(keyStroke, actionCommandKey); - actionMap.put(actionCommandKey, this); + actionMap.put(actionCommandKey, action); } } ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ExportPngUIAction.java ===================================== --- /dev/null +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ExportPngUIAction.java @@ -0,0 +1,80 @@ +package fr.ird.observe.client.ui.actions.tripMap; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ObserveSwingTechnicalException; +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.util.UIHelper; +import fr.ird.observe.client.ui.util.tripMap.TripMapUI; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; +import javax.swing.KeyStroke; + + +import static org.nuiton.i18n.I18n.t; + +/** + * Created by tchemit on 25/08/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ExportPngUIAction extends TripMapActionSupport { + + public static final String ACTION_NAME = ExportPngUIAction.class.getName(); + + public ExportPngUIAction(ObserveMainUI mainUI) { + super(mainUI, + ACTION_NAME, + t("observe.content.map.action.exportPng"), + t("observe.content.map.action.exportPng.tip"), + "save", + KeyStroke.getKeyStroke("ctrl pressed S")); + } + + @Override + protected void actionPerformed(TripMapUI view) { + + File file = UIHelper.chooseFile( + view, + t("observe.content.map.export.chooseFile.title"), + t("observe.content.map.export.chooseFile.ok"), + null, + "^.+\\.png|.+\\.PNG$", + t("observe.content.map.export.chooseFile.png")); + + if (file != null && UIHelper.confirmOverwriteFileIfExist(view, file)) { + + BufferedImage im = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_ARGB); + view.paint(im.getGraphics()); + try { + ImageIO.write(im, "PNG", file); + } catch (IOException e) { + throw new ObserveSwingTechnicalException("unable to export map ", e); + } + + UIHelper.displayInfo(t("observe.content.map.export.success", file)); + } + } +} ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/TripMapActionSupport.java ===================================== --- /dev/null +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/TripMapActionSupport.java @@ -0,0 +1,83 @@ +package fr.ird.observe.client.ui.actions.tripMap; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.actions.UIActionSupport; +import fr.ird.observe.client.ui.content.open.TripUI; +import fr.ird.observe.client.ui.util.tripMap.TripMapUI; +import java.awt.event.ActionEvent; +import javax.swing.JComponent; +import javax.swing.KeyStroke; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Created by tchemit on 25/08/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public abstract class TripMapActionSupport extends UIActionSupport { + + /** Logger. */ + private static final Log log = LogFactory.getLog(TripMapActionSupport.class); + + private TripMapUI ui; + protected ActionEvent e; + + protected abstract void actionPerformed(TripMapUI ui); + + TripMapActionSupport(ObserveMainUI mainUI, String actionCommandKey, String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) { + super(mainUI, actionCommandKey, label, shortDescription, actionIcon, acceleratorKey); + } + + public void setUi(TripMapUI ui) { + this.ui = ui; + } + + @Override + public final void actionPerformed(ActionEvent e) { + if (!canExecuteAction()) { + return; + } + this.e = e; + + if (ui != null) { + actionPerformed(ui); + return; + } + TripUI source = (TripUI) e.getSource(); + actionPerformed(source.getTripMap()); + } + + private boolean canExecuteAction() { + JComponent editor = getEditor(); + if ((editor == null || (editor.isVisible() && editor.isEnabled() && editor.isShowing()))) { + return true; + } + if (log.isInfoEnabled()) { + log.info("Disabled action: " + getActionCommandKey() + " :: " + this); + } + return false; + } +} ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomItUIAction.java ===================================== --- /dev/null +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomItUIAction.java @@ -0,0 +1,61 @@ +package fr.ird.observe.client.ui.actions.tripMap; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.util.tripMap.TripMapUI; +import javax.swing.KeyStroke; +import org.geotools.geometry.jts.ReferencedEnvelope; +import org.geotools.swing.JMapPane; + + +import static org.nuiton.i18n.I18n.t; + +/** + * Created by tchemit on 25/08/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ZoomItUIAction extends TripMapActionSupport { + + public static final String ACTION_NAME = ZoomItUIAction.class.getName(); + + public ZoomItUIAction(ObserveMainUI mainUI) { + super(mainUI, + ACTION_NAME, + t("observe.content.map.action.zoomIt"), + t("observe.content.map.action.zoomIt.tip"), + "center", + KeyStroke.getKeyStroke("ctrl pressed I")); + } + + @Override + protected void actionPerformed(TripMapUI view) { + + ReferencedEnvelope tripArea = view.getHandler().getTripArea(); + if (!tripArea.isEmpty()) { + JMapPane mapPane = view.getObserveMapPane(); + mapPane.setDisplayArea(tripArea); + } + } +} ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomMoinsUIAction.java ===================================== --- /dev/null +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomMoinsUIAction.java @@ -0,0 +1,72 @@ +package fr.ird.observe.client.ui.actions.tripMap; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.util.tripMap.TripMapUI; +import fr.ird.observe.client.ui.util.tripMap.TripMapUIHandler; +import java.awt.Point; +import javax.swing.KeyStroke; +import org.geotools.geometry.jts.ReferencedEnvelope; + + +import static fr.ird.observe.client.ui.util.tripMap.TripMapUIHandler.ZOOM_STEP_RATIO; +import static org.nuiton.i18n.I18n.t; + +/** + * Created by tchemit on 25/08/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ZoomMoinsUIAction extends TripMapActionSupport { + + public static final String ACTION_NAME = ZoomMoinsUIAction.class.getName(); + + public ZoomMoinsUIAction(ObserveMainUI mainUI) { + super(mainUI, + ACTION_NAME, + t("observe.content.map.action.zoomMoins"), + t("observe.content.map.action.zoomMoins.tip"), + "center", + KeyStroke.getKeyStroke("ctrl pressed L")); + } + + @Override + protected void actionPerformed(TripMapUI view) { + + TripMapUIHandler handler = view.getHandler(); + ReferencedEnvelope tripArea = handler.getTripArea(); + + if (!tripArea.isEmpty()) { + int notches = 1; + ReferencedEnvelope displayArea = view.getObserveMapPane().getDisplayArea(); + double w = displayArea.getMedian(0); + double h = displayArea.getMedian(1); + Point zoomCenter = new Point((int) w, (int) h); + handler.setZoomCenter(zoomCenter); + handler.setZoomRatio(handler.getZoomRatio() * (1 + (ZOOM_STEP_RATIO * notches * -1))); + handler.zoomApply(); + } + + } +} ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomPlusUIAction.java ===================================== --- /dev/null +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/tripMap/ZoomPlusUIAction.java @@ -0,0 +1,72 @@ +package fr.ird.observe.client.ui.actions.tripMap; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.util.tripMap.TripMapUI; +import fr.ird.observe.client.ui.util.tripMap.TripMapUIHandler; +import java.awt.Point; +import javax.swing.KeyStroke; +import org.geotools.geometry.jts.ReferencedEnvelope; + + +import static fr.ird.observe.client.ui.util.tripMap.TripMapUIHandler.ZOOM_STEP_RATIO; +import static org.nuiton.i18n.I18n.t; + +/** + * Created by tchemit on 25/08/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ZoomPlusUIAction extends TripMapActionSupport { + + public static final String ACTION_NAME = ZoomPlusUIAction.class.getName(); + + public ZoomPlusUIAction(ObserveMainUI mainUI) { + super(mainUI, + ACTION_NAME, + t("observe.content.map.action.zoomPlus"), + t("observe.content.map.action.zoomPlus.tip"), + "zoomPlus", + KeyStroke.getKeyStroke("ctrl pressed P")); + } + + @Override + protected void actionPerformed(TripMapUI view) { + + TripMapUIHandler handler = view.getHandler(); + ReferencedEnvelope tripArea = handler.getTripArea(); + + if (!tripArea.isEmpty()) { + int notches = 1; + ReferencedEnvelope displayArea = view.getObserveMapPane().getDisplayArea(); + double w = displayArea.getMedian(0); + double h = displayArea.getMedian(1); + Point zoomCenter = new Point((int) w, (int) h); + handler.setZoomCenter(zoomCenter); + handler.setZoomRatio(handler.getZoomRatio() * (1 - (ZOOM_STEP_RATIO * notches * -1))); + handler.zoomApply(); + } + + } +} ===================================== client/src/main/java/fr/ird/observe/client/ui/content/open/TripUI.java ===================================== --- /dev/null +++ b/client/src/main/java/fr/ird/observe/client/ui/content/open/TripUI.java @@ -0,0 +1,36 @@ +package fr.ird.observe.client.ui.content.open; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ui.util.tripMap.TripMapUI; + +/** + * Created by tchemit on 25/08/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public interface TripUI { + + TripMapUI getTripMap(); + +} ===================================== client/src/main/java/fr/ird/observe/client/ui/content/open/longline/TripLonglineUI.jaxx ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/open/longline/TripLonglineUI.jaxx +++ b/client/src/main/java/fr/ird/observe/client/ui/content/open/longline/TripLonglineUI.jaxx @@ -23,7 +23,8 @@ <fr.ird.observe.client.ui.content.open.ContentOpenableUI i18nFormat="observe.common.TripLonglineDto.%s" superGenericType='TripLonglineDto, TripLonglineUI' - contentTitle='{n("observe.common.TripLonglineDto.title")}'> + contentTitle='{n("observe.common.TripLonglineDto.title")}' + implements="fr.ird.observe.client.ui.content.open.TripUI"> <style source="../../Common.jcss"/> ===================================== client/src/main/java/fr/ird/observe/client/ui/content/open/longline/TripLonglineUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/open/longline/TripLonglineUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/open/longline/TripLonglineUIHandler.java @@ -43,6 +43,7 @@ import fr.ird.observe.services.dto.referential.VesselHelper; import fr.ird.observe.services.dto.result.SaveResultDto; import java.util.Date; import java.util.List; +import javax.swing.JComponent; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; import org.apache.commons.logging.Log; @@ -104,6 +105,7 @@ class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLonglineDto, Tr ClientConfig config = ObserveSwingApplicationContext.get().getConfig(); tripMap.getHandler().setConfig(config); + tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); getUi().getMainTabbedPane().addChangeListener(e -> { JTabbedPane tripLonglineTabPane = (JTabbedPane) e.getSource(); ===================================== client/src/main/java/fr/ird/observe/client/ui/content/open/seine/TripSeineUI.jaxx ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/open/seine/TripSeineUI.jaxx +++ b/client/src/main/java/fr/ird/observe/client/ui/content/open/seine/TripSeineUI.jaxx @@ -23,7 +23,8 @@ <fr.ird.observe.client.ui.content.open.ContentOpenableUI i18nFormat="observe.common.TripSeineDto.%s" superGenericType='TripSeineDto, TripSeineUI' - contentTitle='{n("observe.common.TripSeineDto.title")}'> + contentTitle='{n("observe.common.TripSeineDto.title")}' + implements="fr.ird.observe.client.ui.content.open.TripUI"> <style source="../../Common.jcss"/> ===================================== client/src/main/java/fr/ird/observe/client/ui/content/open/seine/TripSeineUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/open/seine/TripSeineUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/open/seine/TripSeineUIHandler.java @@ -42,6 +42,7 @@ import fr.ird.observe.services.dto.seine.TripSeineDto; import fr.ird.observe.services.dto.seine.TripSeineHelper; import java.util.Date; import java.util.List; +import javax.swing.JComponent; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; import org.apache.commons.logging.Log; @@ -102,6 +103,7 @@ class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeineDto, TripSein ClientConfig config = ObserveSwingApplicationContext.get().getConfig(); tripMap.getHandler().setConfig(config); + tripMap.getHandler().init(ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); ui.getMainTabbedPane().addChangeListener(e -> { JTabbedPane tripSeineTabPane = (JTabbedPane) e.getSource(); ===================================== client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUI.jaxx ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUI.jaxx +++ b/client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUI.jaxx @@ -19,20 +19,27 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<JPanel id="tripMap" layout="{new CardLayout()}"> +<JPanel id="tripMap" layout="{new BorderLayout()}"> <import> + fr.ird.observe.client.ui.actions.tripMap.ExportPngUIAction + fr.ird.observe.client.ui.actions.tripMap.ZoomItUIAction + fr.ird.observe.client.ui.actions.tripMap.ZoomMoinsUIAction + fr.ird.observe.client.ui.actions.tripMap.ZoomPlusUIAction java.awt.CardLayout - static org.nuiton.i18n.I18n.n </import> - <JPopupMenu id='mapPopupMenu'> - <JMenuItem id='zoomIt' onActionPerformed='getHandler().zoomIt()'/> - <JMenuItem id='exportPng' onActionPerformed='getHandler().exportPng()'/> - </JPopupMenu> + <CardLayout id="contentLayout"/> + <JToolBar constraints="BorderLayout.NORTH"> + <JButton id='zoomIt'/> + <JButton id='zoomPlus'/> + <JButton id='zoomMoins'/> + <JButton id='exportPng'/> + </JToolBar> - <JLabel id="waitLoadingLabel"/> - - <ObserveMapPane id='observeMapPane' constraints="BorderLayout.CENTER"/> + <JPanel id="content" layout="{contentLayout}" constraints="BorderLayout.CENTER"> + <JLabel id="waitLoadingLabel"/> + <ObserveMapPane id='observeMapPane'/> + </JPanel> </JPanel> ===================================== client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUI.jcss ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUI.jcss +++ b/client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUI.jcss @@ -28,13 +28,17 @@ } #zoomIt { - text: "observe.content.map.action.zoomIt"; - toolTipText: "observe.content.map.action.zoomIt.tip"; - actionIcon: center; + _observeAction:{ZoomItUIAction.ACTION_NAME}; +} + +#zoomMoins { + _observeAction:{ZoomMoinsUIAction.ACTION_NAME}; +} + +#zoomPlus { + _observeAction:{ZoomPlusUIAction.ACTION_NAME}; } #exportPng { - text: "observe.content.map.action.exportPng"; - toolTipText: "observe.content.map.action.exportPng.tip"; - actionIcon: save; + _observeAction:{ExportPngUIAction.ACTION_NAME}; } ===================================== client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/ui/util/tripMap/TripMapUIHandler.java @@ -26,12 +26,13 @@ import com.google.common.collect.Lists; import fr.ird.observe.client.ObserveSwingApplicationContext; import fr.ird.observe.client.ObserveSwingTechnicalException; import fr.ird.observe.client.configuration.ClientConfig; -import fr.ird.observe.client.ui.util.UIHelper; +import fr.ird.observe.client.ui.actions.tripMap.TripMapActionSupport; +import fr.ird.observe.client.ui.content.ObserveActionMap; import fr.ird.observe.common.TripMapPoint; import fr.ird.observe.services.dto.IdHelper; import fr.ird.observe.services.dto.TripMapDto; -import java.awt.CardLayout; import java.awt.Point; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; @@ -39,11 +40,13 @@ import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; -import java.awt.image.BufferedImage; import java.io.File; -import java.io.IOException; import java.util.List; -import javax.imageio.ImageIO; +import java.util.Objects; +import javax.swing.AbstractButton; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.KeyStroke; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.geotools.geometry.DirectPosition2D; @@ -54,7 +57,7 @@ import org.geotools.swing.event.MapPaneListener; import org.nuiton.jaxx.runtime.spi.UIHandler; -import static org.nuiton.i18n.I18n.t; +import static fr.ird.observe.client.ui.content.ContentUIInitializer.OBSERVE_ACTION; /** * @author Tony Chemit - dev@tchemit.fr @@ -65,12 +68,12 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { private static final Log log = LogFactory.getLog(TripMapUIHandler.class); - protected TripMapUI view; - + private TripMapUI ui; private ClientConfig config; - protected ReferencedEnvelope tripArea; - - protected boolean rendererRunning; + private ReferencedEnvelope tripArea; + private boolean rendererRunning; + private double zoomRatio = 1; + private Point zoomCenter; public void setConfig(ClientConfig config) { this.config = config; @@ -79,14 +82,14 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { mapPane.setBackground(config.getMapBackgroundColor()); } - protected ObserveMapPane getObserveMapPane() { - return view.getObserveMapPane(); + private ObserveMapPane getObserveMapPane() { + return ui.getObserveMapPane(); } public void doOpenMap(TripMapDto tripMapDto) { try { - ((CardLayout) view.getLayout()).first(view); + flipContent(); ObserveSwingApplicationContext.get().getMainUI().getModel().setBusy(true); ObserveMapPane mapPane = getObserveMapPane(); @@ -137,45 +140,15 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { } - public void doCloseMap() { - ((CardLayout) view.getLayout()).first(view); - } - - public void zoomIt() { - if (!tripArea.isEmpty()) { - JMapPane mapPane = getObserveMapPane(); - mapPane.setDisplayArea(tripArea); - } + private void flipContent() { + ui.getContentLayout().first(ui.getContent()); } - public void exportPng() { - - File file = UIHelper.chooseFile( - view, - t("observe.content.map.export.chooseFile.title"), - t("observe.content.map.export.chooseFile.ok"), - null, - "^.+\\.png|.+\\.PNG$", - t("observe.content.map.export.chooseFile.png")); - - if (file != null && UIHelper.confirmOverwriteFileIfExist(view, file)) { - - BufferedImage im = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_ARGB); - view.paint(im.getGraphics()); - try { - ImageIO.write(im, "PNG", file); - } catch (IOException e) { - throw new ObserveSwingTechnicalException("unable to export map ", e); - } - - UIHelper.displayInfo(t("observe.content.map.export.success", file)); - } + public void doCloseMap() { + flipContent(); } - protected double zoomRatio = 1; - protected Point zoomCenter; - - protected void zoomApply() { + public void zoomApply() { if (zoomRatio != 1 && !rendererRunning) { JMapPane mapPane = getObserveMapPane(); @@ -221,7 +194,7 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { @Override public void beforeInit(TripMapUI ui) { - this.view = ui; + this.ui = ui; } @Override @@ -235,12 +208,36 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { mapPane.addMouseListener(mouseMapListener); mapPane.addMapPaneListener(new TripMapListener()); - mapPane.setComponentPopupMenu(view.getMapPopupMenu()); - rendererRunning = false; } + public void init(InputMap inputMap) { + ObserveActionMap actionMap = ObserveSwingApplicationContext.get().getActionMap(); + + init(actionMap, inputMap, ui.zoomIt); + init(actionMap, inputMap, ui.zoomMoins); + init(actionMap, inputMap, ui.zoomPlus); + init(actionMap, inputMap, ui.exportPng); + + } + + public ReferencedEnvelope getTripArea() { + return tripArea; + } + + public double getZoomRatio() { + return zoomRatio; + } + + public void setZoomRatio(double zoomRatio) { + this.zoomRatio = zoomRatio; + } + + public void setZoomCenter(Point zoomCenter) { + this.zoomCenter = zoomCenter; + } + private class MouseMapListener implements MouseWheelListener, MouseListener, MouseMotionListener { @Override @@ -256,9 +253,9 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { } - protected Point2D startPointInWorld; - protected AffineTransform startScreenToWorldTransform; - protected ReferencedEnvelope startDisplayArea; + Point2D startPointInWorld; + AffineTransform startScreenToWorldTransform; + ReferencedEnvelope startDisplayArea; @Override public void mousePressed(MouseEvent e) { @@ -294,7 +291,7 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { } - protected void startMove(Point2D startPointInScreen) { + void startMove(Point2D startPointInScreen) { JMapPane mapPane = getObserveMapPane(); startDisplayArea = mapPane.getDisplayArea(); @@ -307,7 +304,7 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { } - protected void endMove(Point2D endPointInScreen) { + void endMove(Point2D endPointInScreen) { Point2D endPointInWorld = new Point2D.Double(); @@ -332,7 +329,7 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { protected class TripMapListener implements MapPaneListener { - protected boolean firstRendering; + boolean firstRendering; @Override public void onNewMapContent(MapPaneEvent ev) { @@ -352,8 +349,13 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { public void onRenderingStopped(MapPaneEvent ev) { rendererRunning = false; if (firstRendering) { - zoomIt(); - ((CardLayout) view.getLayout()).last(view); + + if (!tripArea.isEmpty()) { + JMapPane mapPane = getObserveMapPane(); + mapPane.setDisplayArea(tripArea); + } + + ui.getContentLayout().last(ui.getContent()); firstRendering = false; } else { zoomApply(); @@ -361,4 +363,20 @@ public class TripMapUIHandler implements UIHandler<TripMapUI> { } } + protected void init(ObserveActionMap actionMap, InputMap inputMap, AbstractButton editor) { + String actionId = (String) editor.getClientProperty(OBSERVE_ACTION); + + // on a trouve une action commune + TripMapActionSupport action = (TripMapActionSupport) actionMap.get(actionId); + Objects.requireNonNull(action, "action [" + actionId + "] not found for ui " + ui.getClass().getName()); + + if (log.isDebugEnabled()) { + log.debug("init common action " + actionId); + } + + action.setUi(ui); + action.initForMainUi(editor, inputMap, actionMap); + + } + } ===================================== client/src/main/resources/i18n/client_en_GB.properties ===================================== --- a/client/src/main/resources/i18n/client_en_GB.properties +++ b/client/src/main/resources/i18n/client_en_GB.properties @@ -1204,6 +1204,10 @@ observe.content.map.action.exportPng=Export observe.content.map.action.exportPng.tip=Export map in PNG format observe.content.map.action.zoomIt=Center observe.content.map.action.zoomIt.tip=Center map on the trip +observe.content.map.action.zoomMoins=Zoom out +observe.content.map.action.zoomMoins.tip=Zoom out +observe.content.map.action.zoomPlus=Zoom in +observe.content.map.action.zoomPlus.tip=Zoom in observe.content.map.east=East observe.content.map.export.chooseFile.ok=Exporter observe.content.map.export.chooseFile.png=PNG image ===================================== client/src/main/resources/i18n/client_es_ES.properties ===================================== --- a/client/src/main/resources/i18n/client_es_ES.properties +++ b/client/src/main/resources/i18n/client_es_ES.properties @@ -1204,6 +1204,10 @@ observe.content.map.action.exportPng=Exportar observe.content.map.action.exportPng.tip=Exportar el mapa en el formato PNG observe.content.map.action.zoomIt=Centrar observe.content.map.action.zoomIt.tip=Centrar el mapa sobre la marea +observe.content.map.action.zoomMoins=Zoom out \#TODO +observe.content.map.action.zoomMoins.tip=Zoom out \#TODO +observe.content.map.action.zoomPlus=Zoom in \#TODO +observe.content.map.action.zoomPlus.tip=Zoom in \#TODO observe.content.map.east=Este observe.content.map.export.chooseFile.ok=Exportar observe.content.map.export.chooseFile.png=imagen PNG ===================================== client/src/main/resources/i18n/client_fr_FR.properties ===================================== --- a/client/src/main/resources/i18n/client_fr_FR.properties +++ b/client/src/main/resources/i18n/client_fr_FR.properties @@ -1204,6 +1204,10 @@ observe.content.map.action.exportPng=Exporter observe.content.map.action.exportPng.tip=Exporter la carte au format PNG observe.content.map.action.zoomIt=Centrer observe.content.map.action.zoomIt.tip=Centrer la carte sur la marée +observe.content.map.action.zoomMoins=Réduire +observe.content.map.action.zoomMoins.tip=Réduire +observe.content.map.action.zoomPlus=Agrandir +observe.content.map.action.zoomPlus.tip=Agrandir observe.content.map.east=Est observe.content.map.export.chooseFile.ok=Exporter observe.content.map.export.chooseFile.png=image PNG ===================================== client/src/main/resources/icons/action-zoomMoins.png ===================================== Binary files /dev/null and b/client/src/main/resources/icons/action-zoomMoins.png differ ===================================== client/src/main/resources/icons/action-zoomPlus.png ===================================== Binary files /dev/null and b/client/src/main/resources/icons/action-zoomPlus.png differ ===================================== client/src/main/resources/observe-ui.properties ===================================== --- a/client/src/main/resources/observe-ui.properties +++ b/client/src/main/resources/observe-ui.properties @@ -105,6 +105,8 @@ icon.action.data-calcule=action-data-calcule.png icon.action.numbereditor-reset=action-numbereditor-reset.png icon.action.numbereditor-calculator=action-numbereditor-calculator.png icon.action.center=action-center.png +icon.action.zoomPlus=action-zoomPlus.png +icon.action.zoomMoins=action-zoomMoins.png icon.action.config=action-config.png icon.action.consolidate=action-data-calcule.png icon.action.connected=action-connected.png ===================================== services/src/main/java/fr/ird/observe/services/decoration/ObserveI18nLabelsBuilder.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/decoration/ObserveI18nLabelsBuilder.java +++ b/services/src/main/java/fr/ird/observe/services/decoration/ObserveI18nLabelsBuilder.java @@ -1,5 +1,27 @@ package fr.ird.observe.services.decoration; +/*- + * #%L + * ObServe :: Services + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import com.google.common.collect.ImmutableMap; import fr.ird.observe.services.ObserveDtoInitializer; import fr.ird.observe.services.dto.referential.I18nReferentialDto; View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/4f3e50eef7940fce6e25e95cc7c0... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/4f3e50eef7940fce6e25e95cc7c0... You're receiving this email because of your account on gitlab.com.