Author: fdesbois Date: 2012-09-03 17:47:49 +0200 (Mon, 03 Sep 2012) New Revision: 511 Url: http://forge.codelutin.com/repositories/revision/sammoa/511 Log: Clean packages : - rename and move observations to flight.effort - move action to flight.action - rename SammoaAction to BaseFlightAction, old FlightAction is useless - rename flightUIModel in EffortPanel to model Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/CloseAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/AddAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BaseFlightAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BeginAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CenterObservationAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CircleBackAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeleteTransectAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeviceAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/EndAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/LeftObservationAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextTransectAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ObservationAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/RightObservationAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAudioAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAudioAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidObservationAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/DeviceStateLED.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.css trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/ObservationTableModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/SpeciesCodeValidator.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextEditableCellAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextRowEditableAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousEditableCellAction.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousRowEditableAction.java Removed: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.css trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/region/RegionUI.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/transect/TransectUI.jaxx trunk/sammoa-ui-swing/src/main/resources/validators.xml Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/CloseAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/CloseAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/CloseAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/CloseAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,63 @@ +package fr.ulr.sammoa.ui.swing; +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import jaxx.runtime.JAXXObject; + +import javax.swing.AbstractAction; +import javax.swing.JComponent; +import javax.swing.JDialog; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 24/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class CloseAction extends AbstractAction { + + private static final long serialVersionUID = 1L; + + protected JComponent ui; + + public CloseAction(JComponent ui) { + super(_("sammoa.action.close")); + Preconditions.checkArgument(ui instanceof SammoaUI); + this.ui = ui; + } + + @Override + public void actionPerformed(ActionEvent e) { + JDialog container = ((JAXXObject) ui).getParentContainer(JDialog.class); + if (container != null) { + container.dispose(); + } else { + ui.setVisible(false); + } + ((SammoaUI<?>) ui).getHandler().onCloseUI(); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/CloseAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java 2012-09-03 15:47:49 UTC (rev 511) @@ -1,102 +0,0 @@ -/* - * #%L - * SAMMOA :: UI Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ulr.sammoa.ui.swing.flight; - -import fr.ulr.sammoa.application.device.DeviceState; -import fr.ulr.sammoa.application.device.DeviceStateEvent; -import fr.ulr.sammoa.application.device.DeviceStateListener; -import org.nuiton.util.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.swing.ImageIcon; -import javax.swing.JLabel; - -/** - * Panel qui écoute l'état du peripherique pour afficher à l'utilsateur un voyant - * lunineux dépendant de l'état du peripherique. - * <p/> - * Indicateurs pour l'état du peripherique - * <ul> - * <li>voyant gris : pas de peripherique - * <li>voyant bleu : peripherique prêt - * <li>voyant vert : enregistrement en cours - * <li>voyant rouge clignotant : enregistrement mais pas de données - * </ul> - * - * @author chatellier - */ -public class DeviceStateLED extends JLabel implements DeviceStateListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = 1L; - - private static final Logger logger = LoggerFactory.getLogger(DeviceStateLED.class); - - protected DeviceState state; - - protected static final ImageIcon NO_DEVICE_ICON = Resource.getIcon("/icons/device/nodevice.png"); - - protected static final ImageIcon READY_ICON = Resource.getIcon("/icons/device/ready.png"); - - protected static final ImageIcon RECORDING_ICON = Resource.getIcon("/icons/device/recording.png"); - - protected static final ImageIcon NO_DATA_ICON = Resource.getIcon("/icons/device/nodata.gif"); - - @Override - public void stateChanged(DeviceStateEvent event) { - setState(event.getNewValue()); - } - - public void setState(DeviceState state) { - DeviceState oldValue = getState(); - this.state = state; - - if (oldValue != state) { - - logger.debug("[{}] Update LED status: {}", - getClass().getSimpleName(), state); - - switch (state) { - case UNAVAILABLE: - setIcon(NO_DEVICE_ICON); - break; - case READY: - setIcon(READY_ICON); - break; - case RUNNING: - setIcon(RECORDING_ICON); - break; - case ERROR: - setIcon(NO_DATA_ICON); - break; - } - } - } - - public DeviceState getState() { - return state; - } -} Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.css =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.css 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.css 2012-09-03 15:47:49 UTC (rev 511) @@ -1,101 +0,0 @@ -/* - * #%L - * SAMMOA :: UI Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -#stateBar { - background: {model.getEffortPanelColor()}; -} - -#clockTime { - delay: 1000; - pattern: "dd/MM/yyyy HH:mm:ss"; - visible: {!flightUIModel.isValidationMode()}; -} -#audioTime { - visible: {flightUIModel.isValidationMode()}; - text: {dateFormat.format(flightUIModel.getCurrentRoute().getBeginTime())}; -} - -#beginButton { - _actionName: {"begin"}; -} - -#endButton { - _actionName: {"end"}; -} - -#nextButton { - _actionName: {"next"}; -} - -#effortButtonPanel { - background: {model.getEffortPanelColor()}; -} - -#statusPanel { - background: {model.getEffortPanelColor()}; -} - -#lblEffort { - text: {flightUIModel.getFlightState().name()}; -} - -#lblTransect { - text: {flightUIModel.getCurrentRoute().getTransectFlight().getTransect().getName()}; -} - -#lblStatus { - text: {flightUIModel.getCurrentRoute().getRouteType().name() - + (flightUIModel.getCurrentRoute().getEffortNumber() != null - ? " " + flightUIModel.getCurrentRoute().getEffortNumber() - : "")}; -} - -#lblObservation { - text: {flightUIModel.getCurrentRoute().getTransectFlight().getTransect().getName()}; -} - -#cbPanel { - background: {model.getEffortPanelColor()}; -} - -#gpsLED { - text: "sammoa.statusBar.gps"; -} - -#audioLED { - text: "sammoa.statusBar.audio"; -} - -#indicatorPanel { - background: {model.getEffortPanelColor()}; -} - -#lblAlt { - text: {model.getAlt()}; -} - -#lblSpeed { - text: {model.getSpeed()}; -} Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx 2012-09-03 15:47:49 UTC (rev 511) @@ -1,130 +0,0 @@ -<!-- - #%L - SAMMOA :: UI Swing - - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 UMS 3462, Code Lutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program. If not, see - <http://www.gnu.org/licenses/gpl-3.0.html>. - #L% - --> -<JPanel id='statusBar' layout='{new GridLayout(0,1,0,0)}'> - - <import> - java.text.SimpleDateFormat - javax.swing.BoxLayout - javax.swing.SwingConstants - jaxx.runtime.swing.ClockWidget - </import> - - <script><![CDATA[ - - protected void $afterCompleteSetup() { - getHandler().init(); - } - - ]]></script> - - <FlightBarHandler id='handler' constructorParams='this'/> - - <FlightUIModel id='flightUIModel' initializer='getHandler().getParentUI().getModel()'/> - - <FlightBarModel id='model'/> - - <SimpleDateFormat id='dateFormat' constructorParams='"dd/MM/yyyy HH:mm:ss"'/> - - <Table id='validationBar'> - <row> - <cell fill='horizontal' weightx='0.2'> - <JPanel id='audioButtonPanel' - layout='{new BoxLayout(audioButtonPanel, BoxLayout.X_AXIS)}'> - <JButton id='startAudioButton'/> - <JButton id='stopAudioButton'/> - </JPanel> - </cell> - <cell fill='horizontal'> - <JSlider id='audioSlider' enabled='false'/> - </cell> - <cell fill='horizontal' weightx='0.2'> - <JPanel id='validButtonPanel' - layout='{new BoxLayout(validButtonPanel, BoxLayout.X_AXIS)}'> - <JButton id='validRouteButton'/> - <JButton id='validObservationButton'/> - <JButton id='validTransectButton'/> - </JPanel> - </cell> - </row> - </Table> - <Table id='stateBar'> - <row> - <cell fill='horizontal' weightx='0.2'> - <ClockWidget id='clockTime'/> - </cell> - <cell fill='horizontal' weightx='0.2'> - <JLabel id='audioTime'/> - </cell> - <cell fill='vertical'> - <JSeparator constructorParams='SwingConstants.VERTICAL'/> - </cell> - <cell fill='horizontal'> - <JPanel id='effortButtonPanel' - layout='{new BoxLayout(effortButtonPanel, BoxLayout.X_AXIS)}'> - <JButton id='beginButton'/> - <JButton id='endButton'/> - <JButton id='nextButton'/> - </JPanel> - </cell> - <cell fill='vertical'> - <JSeparator constructorParams='SwingConstants.VERTICAL'/> - </cell> - <cell fill='horizontal' weightx='0.2' anchor='center'> - <JLabel id='lblEffort'/> - </cell> - <cell fill='vertical'> - <JSeparator constructorParams='SwingConstants.VERTICAL'/> - </cell> - <cell fill='horizontal' weightx='0.2' anchor='center'> - <JLabel id='lblTransect'/> - </cell> - <cell fill='vertical'> - <JSeparator constructorParams='SwingConstants.VERTICAL'/> - </cell> - <cell fill='horizontal' weightx='0.2' anchor='center'> - <JLabel id='lblStatus'/> - </cell> - <cell fill='vertical'> - <JSeparator constructorParams='SwingConstants.VERTICAL'/> - </cell> - <cell fill='horizontal' weightx='0.2' anchor='center'> - <JPanel id='cbPanel' layout='{new BoxLayout(cbPanel, BoxLayout.Y_AXIS)}'> - <DeviceStateLED id='gpsLED' /> - <DeviceStateLED id='audioLED' /> - </JPanel> - </cell> - <cell fill='vertical'> - <JSeparator constructorParams='SwingConstants.VERTICAL'/> - </cell> - <cell fill='horizontal' weightx='0.2' anchor='center'> - <JPanel id='indicatorPanel' - layout='{new BoxLayout(indicatorPanel, BoxLayout.Y_AXIS)}'> - <JLabel id='lblAlt'/> - <JLabel id='lblSpeed'/> - </JPanel> - </cell> - </row> - </Table> -</JPanel> Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-09-03 15:47:49 UTC (rev 511) @@ -1,129 +0,0 @@ -/* - * #%L - * SAMMOA :: UI Swing - * * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ulr.sammoa.ui.swing.flight; - -import fr.ulr.sammoa.application.device.audio.AudioRecorder; -import fr.ulr.sammoa.application.device.gps.GpsHandler; -import fr.ulr.sammoa.application.flightController.FlightController; -import fr.ulr.sammoa.application.flightController.FlightState; -import fr.ulr.sammoa.persistence.Route; -import fr.ulr.sammoa.ui.swing.SammoaColors; -import jaxx.runtime.JAXXUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -/** @author sletellier <letellier@codelutin.com> */ -public class FlightBarHandler implements PropertyChangeListener { - - private static final Logger logger = - LoggerFactory.getLogger(FlightBarHandler.class); - - protected final FlightBar ui; - - public FlightBarHandler(FlightBar ui) { - this.ui = ui; - } - - public FlightUI getParentUI() { - return ui.getContextValue(FlightUI.class, JAXXUtil.PARENT); - } - - protected FlightBarModel getModel() { - return ui.getModel(); - } - - public void init() { - - FlightUIModel flightUIModel = ui.getFlightUIModel(); - flightUIModel.addPropertyChangeListener(this); - - - FlightController flightController = - ui.getContextValue(FlightUIHandler.class).getFlightController(); - - if (flightUIModel.isValidationMode()) { - - // Put actionName for validation buttons - ui.getStartAudioButton().putClientProperty("actionName", "startAudio"); - ui.getStopAudioButton().putClientProperty("actionName", "stopAudio"); - ui.getValidObservationButton().putClientProperty("actionName", "validObservation"); - ui.getValidRouteButton().putClientProperty("actionName", "validRoute"); - ui.getValidTransectButton().putClientProperty("actionName", "validTransect"); - - } else { - - // Remove the bar used only for validation - ui.remove(ui.getValidationBar()); - - AudioRecorder audioRecorder = flightController.getDeviceManager(AudioRecorder.class); - ui.getAudioLED().setState(audioRecorder.getState()); - audioRecorder.addDeviceStateListener(ui.getAudioLED()); - - GpsHandler gpsHandler = flightController.getDeviceManager(GpsHandler.class); - ui.getGpsLED().setState(gpsHandler.getState()); - gpsHandler.addDeviceStateListener(ui.getGpsLED()); - gpsHandler.addGpsLocationListener(getModel()); - } - - if (FlightState.OFF_EFFORT.equals(ui.getFlightUIModel().getFlightState())) { - getModel().setEffortPanelColor(SammoaColors.ON_EFFORT_BACKGROUND_COLOR); - } - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - String propertyName = evt.getPropertyName(); - - if (FlightUIModel.PROPERTY_FLIGHT_STATE.equals(propertyName)) { - - logger.debug("Modify flight bar background color"); - - // si l'etat du vol passe en off effort - // affiche à l'utilisateur - FlightState newState = (FlightState) evt.getNewValue(); - if (FlightState.OFF_EFFORT.equals(newState)) { - getModel().setEffortPanelColor(SammoaColors.ON_EFFORT_BACKGROUND_COLOR); - - } else { - getModel().setEffortPanelColor(null); - } - - } else if (FlightUIModel.PROPERTY_CURRENT_ROUTE.equals(propertyName)) { - - Route route = (Route) evt.getNewValue(); - - logger.debug("New value received for current route {}", route); - - if (route == null || route.getTransectFlight() == null) { - // set null will hide label - ui.getLblTransect().setText(null); - } - - } - } -} Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java 2012-09-03 15:47:49 UTC (rev 511) @@ -1,91 +0,0 @@ -/* - * #%L - * SAMMOA :: UI Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ulr.sammoa.ui.swing.flight; - -import fr.ulr.sammoa.application.device.gps.GpsLocationEvent; -import fr.ulr.sammoa.application.device.gps.GpsLocationListener; -import fr.ulr.sammoa.persistence.GeoPoint; -import org.jdesktop.beans.AbstractSerializableBean; - -import java.awt.Color; - -import static org.nuiton.i18n.I18n._; - -/** @author sletellier <letellier@codelutin.com> */ -public class FlightBarModel extends AbstractSerializableBean implements GpsLocationListener { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_ALT = "alt"; - - public static final String PROPERTY_SPEED = "speed"; - - public static final String PROPERTY_EFFORT_PANEL_COLOR = "effortPanelColor"; - - protected float alt; - - protected float speed; - - protected Color effortPanelColor; - - public String getAlt() { - return _("sammoa.statusbar.alt", alt); - } - - public void setAlt(float alt) { - float oldValue = this.alt; - this.alt = alt; - firePropertyChange(PROPERTY_ALT, oldValue, alt); - } - - public String getSpeed() { - return _("sammoa.statusbar.speed", speed); - } - - public void setSpeed(float speed) { - float oldValue = this.speed; - this.speed = speed; - firePropertyChange(PROPERTY_SPEED, oldValue, speed); - } - - public Color getEffortPanelColor() { - return effortPanelColor; - } - - public void setEffortPanelColor(Color effortPanelColor) { - Color oldColor = this.effortPanelColor; - this.effortPanelColor = effortPanelColor; - firePropertyChange(PROPERTY_EFFORT_PANEL_COLOR, oldColor, this.effortPanelColor); - } - - @Override - public void locationChanged(GpsLocationEvent event) { - GeoPoint newLocation = event.getNewValue(); - if (newLocation != null) { - setSpeed((float) newLocation.getSpeed()); - setAlt((float) newLocation.getAltitude()); - } - } -} Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx 2012-09-03 15:47:49 UTC (rev 511) @@ -40,7 +40,8 @@ fr.ulr.sammoa.persistence.Observer fr.ulr.sammoa.application.flightController.FlightState fr.ulr.sammoa.ui.swing.SammoaUIContext - fr.ulr.sammoa.ui.swing.observations.EffortPanel + fr.ulr.sammoa.ui.swing.flight.bar.FlightBar + fr.ulr.sammoa.ui.swing.flight.effort.EffortPanel </import> <FlightUIHandler id='handler' Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-03 15:47:49 UTC (rev 511) @@ -88,23 +88,23 @@ import fr.ulr.sammoa.ui.swing.SammoaUIContext; import fr.ulr.sammoa.ui.swing.SammoaUIHandler; import fr.ulr.sammoa.ui.swing.UIDecoratorService; -import fr.ulr.sammoa.ui.swing.action.AddAction; -import fr.ulr.sammoa.ui.swing.action.BeginAction; -import fr.ulr.sammoa.ui.swing.action.CenterObservationAction; -import fr.ulr.sammoa.ui.swing.action.CircleBackAction; -import fr.ulr.sammoa.ui.swing.action.DeleteTransectAction; -import fr.ulr.sammoa.ui.swing.action.EndAction; -import fr.ulr.sammoa.ui.swing.action.LeftObservationAction; -import fr.ulr.sammoa.ui.swing.action.NextAction; -import fr.ulr.sammoa.ui.swing.action.NextTransectAction; -import fr.ulr.sammoa.ui.swing.action.RightObservationAction; -import fr.ulr.sammoa.ui.swing.action.StartAction; -import fr.ulr.sammoa.ui.swing.action.StartAudioAction; -import fr.ulr.sammoa.ui.swing.action.StopAction; -import fr.ulr.sammoa.ui.swing.action.StopAudioAction; -import fr.ulr.sammoa.ui.swing.action.ValidObservationAction; -import fr.ulr.sammoa.ui.swing.action.ValidRouteAction; -import fr.ulr.sammoa.ui.swing.action.ValidTransectAction; +import fr.ulr.sammoa.ui.swing.flight.action.AddAction; +import fr.ulr.sammoa.ui.swing.flight.action.BeginAction; +import fr.ulr.sammoa.ui.swing.flight.action.CenterObservationAction; +import fr.ulr.sammoa.ui.swing.flight.action.CircleBackAction; +import fr.ulr.sammoa.ui.swing.flight.action.DeleteTransectAction; +import fr.ulr.sammoa.ui.swing.flight.action.EndAction; +import fr.ulr.sammoa.ui.swing.flight.action.LeftObservationAction; +import fr.ulr.sammoa.ui.swing.flight.action.NextAction; +import fr.ulr.sammoa.ui.swing.flight.action.NextTransectAction; +import fr.ulr.sammoa.ui.swing.flight.action.RightObservationAction; +import fr.ulr.sammoa.ui.swing.flight.action.StartAction; +import fr.ulr.sammoa.ui.swing.flight.action.StartAudioAction; +import fr.ulr.sammoa.ui.swing.flight.action.StopAction; +import fr.ulr.sammoa.ui.swing.flight.action.StopAudioAction; +import fr.ulr.sammoa.ui.swing.flight.action.ValidObservationAction; +import fr.ulr.sammoa.ui.swing.flight.action.ValidRouteAction; +import fr.ulr.sammoa.ui.swing.flight.action.ValidTransectAction; import fr.ulr.sammoa.ui.swing.flight.layer.BaseGeoPointLayer; import fr.ulr.sammoa.ui.swing.flight.layer.LineGeoPointLayer; import fr.ulr.sammoa.ui.swing.flight.layer.SimpleGeoPointLayer; Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/AddAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/AddAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/AddAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/AddAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,60 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; +import org.nuiton.util.Resource; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class AddAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + public AddAction(JAXXContext context) { + super(Resource.getIcon("/icons/action-add.png"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.add.tip")); + bindModelProperties(FlightUIModel.PROPERTY_FLIGHT_STATE); + } + + @Override + public void actionPerformed(ActionEvent e) { + getFlightController().add(); + } + + @Override + protected boolean checkEnabled() { + return getModel().getFlightState() == FlightState.ON_EFFORT; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/AddAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BaseFlightAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BaseFlightAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BaseFlightAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,92 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.flightController.FlightController; +import fr.ulr.sammoa.ui.swing.SammoaUIContext; +import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public abstract class BaseFlightAction extends AbstractAction { + + protected JAXXContext context; + + public BaseFlightAction(String name, Icon icon, JAXXContext context) { + super(name, icon); + init(context); + } + + public BaseFlightAction(String name, JAXXContext context) { + super(name); + init(context); + } + + public BaseFlightAction(Icon icon, JAXXContext context) { + this("", icon, context); + } + + protected void init(JAXXContext context) { + this.context = context; + setEnabled(checkEnabled()); + } + + protected FlightController getFlightController() { + return context.getContextValue(FlightUIHandler.class).getFlightController(); + } + + protected FlightUIModel getModel() { + return context.getContextValue(FlightUIHandler.class).getModel(); + } + + protected SammoaUIContext getSammoaUIContext() { + return context.getContextValue(SammoaUIContext.class); + } + + protected void bindModelProperties(String... properties) { + for (String property : properties) { + getModel().addPropertyChangeListener(property, enabledListener); + } + } + + protected PropertyChangeListener enabledListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + setEnabled(checkEnabled()); + } + }; + + protected abstract boolean checkEnabled(); +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BaseFlightAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BeginAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/BeginAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BeginAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BeginAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,74 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.RouteType; +import fr.ulr.sammoa.persistence.TransectFlight; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class BeginAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + public BeginAction(JAXXContext context) { + super(_("sammoa.action.begin"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.begin.tip")); + bindModelProperties( + FlightUIModel.PROPERTY_FLIGHT_STATE, + FlightUIModel.PROPERTY_CURRENT_ROUTE, + FlightUIModel.PROPERTY_NEXT_TRANSECT + ); + } + + @Override + public void actionPerformed(ActionEvent e) { + getFlightController().begin(); + } + + @Override + protected boolean checkEnabled() { + Route currentRoute = getModel().getCurrentRoute(); + boolean isCircleBack = currentRoute != null + && RouteType.CIRCLE_BACK == currentRoute.getRouteType(); + + TransectFlight nextTransect = getModel().getNextTransect(); + boolean isReadyForLeg = nextTransect != null + && getModel().getFlightState() == FlightState.OFF_EFFORT; + + return isCircleBack || isReadyForLeg; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BeginAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CenterObservationAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/CenterObservationAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CenterObservationAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CenterObservationAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,46 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.persistence.Position; +import jaxx.runtime.JAXXContext; + +import javax.swing.Action; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class CenterObservationAction extends ObservationAction { + + private static final long serialVersionUID = 1L; + + public CenterObservationAction(JAXXContext context) { + super(_("sammoa.observation.observations.center"), context, Position.NAVIGATOR); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.center.tip")); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CenterObservationAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CircleBackAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/CircleBackAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CircleBackAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CircleBackAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,88 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import com.google.common.collect.Iterables; +import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.RouteType; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; +import org.nuiton.util.Resource; + +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import java.awt.event.ActionEvent; +import java.util.List; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class CircleBackAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + public static final String CLIENT_PROPERTY_OBSERVATION = "observation"; + + protected static final ImageIcon CIRCLE_BACK_ICON = Resource.getIcon("/icons/undo.png"); + + public CircleBackAction(JAXXContext context) { + super(CIRCLE_BACK_ICON, context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.circleBack.tip")); + bindModelProperties(FlightUIModel.PROPERTY_CURRENT_ROUTE); + } + + @Override + public void actionPerformed(ActionEvent e) { + + Observation observation = null; + Object source = e.getSource(); + if (source instanceof JComponent) { + JComponent comp = (JComponent) source; + observation = (Observation) comp.getClientProperty(CLIENT_PROPERTY_OBSERVATION); + } + + if (observation == null) { + List<Observation> obsList = getModel().getObservations(); + observation = Iterables.getLast(obsList); + } + + getFlightController().circleBack(observation); + } + + @Override + protected boolean checkEnabled() { + boolean result = false; + Route route = getModel().getCurrentRoute(); + if (route != null) { + result = route.getRouteType() != RouteType.TRANSIT; + } + return result; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/CircleBackAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeleteTransectAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/DeleteTransectAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeleteTransectAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeleteTransectAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,78 @@ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.FlightService; +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.ui.swing.flight.FlightUI; +import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel; +import fr.ulr.sammoa.ui.swing.util.SammoaUtil; +import jaxx.runtime.JAXXContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.Action; +import javax.swing.JComponent; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/09/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class DeleteTransectAction extends BaseFlightAction { + + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(DeleteTransectAction.class); + + public static final String CLIENT_PROPERTY_TRANSECT_FLIGHT = "transectFlight"; + + public DeleteTransectAction(JAXXContext context) { + super((String) null, context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.deleteTransect.tip")); + } + + @Override + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + if (source instanceof JComponent) { + JComponent comp = (JComponent) source; + + final TransectFlightModel transectFlight = + (TransectFlightModel) comp.getClientProperty(CLIENT_PROPERTY_TRANSECT_FLIGHT); + + if (logger.isDebugEnabled()) { + logger.debug("Change transect {} deleted flag to {}", + transectFlight.getSource().getTransect().getName(), + !transectFlight.isDeleted()); + } + + transectFlight.setDeleted(!transectFlight.isDeleted()); + + // #1372: If flight isn't started, we propose to delete definitely the transect + if (FlightState.WAITING == getModel().getFlightState() && transectFlight.isDeleted()) { + + if (SammoaUtil.askQuestion((FlightUI) context, _("sammoa.confirmDialog.deleteTransect.message"))) { + + FlightService service = + getSammoaUIContext().getService(FlightService.class); + service.deleteTansectFlight(getModel().getFlight(), transectFlight.getSource()); + + if (logger.isDebugEnabled()) { + logger.debug("Delete transect {} ", + transectFlight.getSource().getTransect().getName()); + } + + // Update model + int index = getModel().indexOfTransectFlights(transectFlight); + getModel().removeTransectFlight(index); + } + } + } + } + + @Override + protected boolean checkEnabled() { + return true; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeleteTransectAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeviceAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/DeviceAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeviceAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeviceAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,71 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.device.DeviceManager; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import jaxx.runtime.JAXXContext; + +import javax.swing.Icon; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public abstract class DeviceAction<T extends DeviceManager> extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + protected T device; + + protected DeviceAction(Icon icon, JAXXContext context) { + super(icon, context); + } + + protected DeviceAction(String name, JAXXContext context) { + super(name, context); + } + + protected T getDevice() { + if (device == null) { + device = getFlightController().getDeviceManager(getDeviceClass()); + device.addDeviceStateListener(new DeviceStateListener() { + + @Override + public void stateChanged(DeviceStateEvent event) { + setEnabled(checkEnabled()); + } + }); + } + return device; + } + + protected boolean hasDevice() { + return device != null || getFlightController().getDeviceManager(getDeviceClass()) != null; + } + + protected abstract Class<T> getDeviceClass(); +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/DeviceAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/EndAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/EndAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/EndAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/EndAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,59 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class EndAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + public EndAction(JAXXContext context) { + super(_("sammoa.action.end"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.end.tip")); + bindModelProperties(FlightUIModel.PROPERTY_FLIGHT_STATE); + } + + @Override + public void actionPerformed(ActionEvent e) { + getFlightController().end(); + } + + @Override + protected boolean checkEnabled() { + return getModel().getFlightState() == FlightState.ON_EFFORT; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/EndAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/LeftObservationAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/LeftObservationAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/LeftObservationAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/LeftObservationAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,46 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.persistence.Position; +import jaxx.runtime.JAXXContext; + +import javax.swing.Action; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class LeftObservationAction extends ObservationAction { + + private static final long serialVersionUID = 1L; + + public LeftObservationAction(JAXXContext context) { + super(_("sammoa.observation.observations.left"), context, Position.FRONT_LEFT); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.left.tip")); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/LeftObservationAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,60 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class NextAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + public NextAction(JAXXContext context) { + super(_("sammoa.action.next"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.next.tip")); + bindModelProperties(FlightUIModel.PROPERTY_FLIGHT_STATE); + } + + @Override + public void actionPerformed(ActionEvent e) { + getFlightController().next(); + } + + @Override + protected boolean checkEnabled() { + return getModel().getFlightState() == FlightState.ON_EFFORT + && getModel().getNextTransect() != null; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextTransectAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextTransectAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextTransectAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextTransectAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,68 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel; +import jaxx.runtime.JAXXContext; +import org.nuiton.util.Resource; + +import javax.swing.Action; +import javax.swing.JComponent; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class NextTransectAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + public static final String CLIENT_PROPERTY_TRANSECT_FLIGHT = "transectFlight"; + + public NextTransectAction(JAXXContext context) { + super(Resource.getIcon("/icons/action-next-transect.png"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.nextTransect.tip")); + } + + @Override + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + if (source instanceof JComponent) { + JComponent component = (JComponent) e.getSource(); + TransectFlightModel transectFlight = + (TransectFlightModel) component.getClientProperty(CLIENT_PROPERTY_TRANSECT_FLIGHT); + + getFlightController().setNextTransect(transectFlight.getSource()); + } + } + + @Override + protected boolean checkEnabled() { + return true; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/NextTransectAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ObservationAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ObservationAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ObservationAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ObservationAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,61 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.persistence.Position; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; + +import java.awt.event.ActionEvent; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public abstract class ObservationAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + protected Position position; + + public ObservationAction(String name, JAXXContext context, Position position) { + super(name, context); + this.position = position; + bindModelProperties(FlightUIModel.PROPERTY_FLIGHT_STATE); + } + + @Override + public void actionPerformed(ActionEvent e) { + getFlightController().observation(position); + } + + @Override + protected boolean checkEnabled() { + FlightState state = getModel().getFlightState(); + return state == FlightState.ON_EFFORT + || state == FlightState.OFF_EFFORT; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ObservationAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/RightObservationAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/RightObservationAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/RightObservationAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/RightObservationAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,46 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.persistence.Position; +import jaxx.runtime.JAXXContext; + +import javax.swing.Action; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 03/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class RightObservationAction extends ObservationAction { + + private static final long serialVersionUID = 1L; + + public RightObservationAction(JAXXContext context) { + super(_("sammoa.observation.observations.right"), context, Position.FRONT_RIGHT); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.right.tip")); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/RightObservationAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StartAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,60 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; +import org.nuiton.util.Resource; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 05/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class StartAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + public StartAction(JAXXContext context) { + super(Resource.getIcon("/icons/playback_play.png"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.start.tip")); + bindModelProperties(FlightUIModel.PROPERTY_FLIGHT_STATE); + } + + @Override + public void actionPerformed(ActionEvent e) { + getFlightController().start(); + } + + @Override + protected boolean checkEnabled() { + return getModel().getFlightState() == FlightState.WAITING; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAudioAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StartAudioAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAudioAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAudioAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,64 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.audio.AudioReader; +import jaxx.runtime.JAXXContext; +import org.nuiton.util.Resource; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 05/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class StartAudioAction extends DeviceAction<AudioReader> { + + private static final long serialVersionUID = 1L; + + public StartAudioAction(JAXXContext context) { + super(Resource.getIcon("/icons/playback_play.png"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.startAudio.tip")); + } + + @Override + public void actionPerformed(ActionEvent e) { + getDevice().start(); + } + + @Override + protected boolean checkEnabled() { + return hasDevice() && getDevice().getState() == DeviceState.READY; + } + + @Override + protected Class<AudioReader> getDeviceClass() { + return AudioReader.class; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StartAudioAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StopAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,61 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; +import org.nuiton.util.Resource; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 05/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class StopAction extends BaseFlightAction { + + private static final long serialVersionUID = 1L; + + public StopAction(JAXXContext context) { + super(Resource.getIcon("/icons/playback_stop.png"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.stop.tip")); + bindModelProperties(FlightUIModel.PROPERTY_FLIGHT_STATE); + } + + @Override + public void actionPerformed(ActionEvent e) { + getFlightController().stop(); + } + + @Override + protected boolean checkEnabled() { + return getModel().getFlight().getEndDate() == null + && getModel().getFlightState() == FlightState.OFF_EFFORT; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAudioAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StopAudioAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAudioAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAudioAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,64 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.action; + +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.audio.AudioReader; +import jaxx.runtime.JAXXContext; +import org.nuiton.util.Resource; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 05/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public class StopAudioAction extends DeviceAction<AudioReader> { + + private static final long serialVersionUID = 1L; + + public StopAudioAction(JAXXContext context) { + super(Resource.getIcon("/icons/playback_stop.png"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.stopAudio.tip")); + } + + @Override + public void actionPerformed(ActionEvent e) { + getDevice().stop(); + } + + @Override + protected boolean checkEnabled() { + return hasDevice() && getDevice().getState() == DeviceState.RUNNING; + } + + @Override + protected Class<AudioReader> getDeviceClass() { + return AudioReader.class; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/StopAudioAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,155 @@ +package fr.ulr.sammoa.ui.swing.flight.action; +/* + * #%L + * SAMMOA :: UI Swing + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import fr.ulr.sammoa.application.ValidationService; +import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.Validable; +import fr.ulr.sammoa.ui.swing.SammoaUIContext; +import jaxx.runtime.JAXXContext; +import org.jdesktop.beans.AbstractBean; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.Resource; +import org.nuiton.validator.bean.list.BeanListValidator; +import org.nuiton.validator.bean.list.BeanListValidatorEvent; +import org.nuiton.validator.bean.list.BeanListValidatorListener; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Map; + +/** + * Created: 23/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public abstract class ValidAction extends BaseFlightAction { + + protected ValidationService validationService; + + protected Map<Class<?>, BeanListValidator<?>> validators = Maps.newHashMap(); + + public ValidAction(String name, JAXXContext context) { + super(name, Resource.getIcon("/icons/action-tick.png"), context); + } + + protected ValidationService getValidationService() { + if (validationService == null) { + validationService = + SammoaUIContext.getUIContext().getService(ValidationService.class); + } + return validationService; + } + + /** + * Retrieve a validator for the {@code beanClass}. A cache + * is used to keep the validator for this property. A listener is also + * used to call checkEnabled() on each validation change. + * + * @param beanClass Class of the bean + * @param <E> generic type of the bean + * @return the {@link BeanListValidator} found + * @throws NullPointerException if no validator exists in context for the + * given {@code modelPropertyName} + */ + private <E extends Validable> BeanListValidator<E> getValidator(Class<E> beanClass) { + BeanListValidator<E> validator = (BeanListValidator<E>) validators.get(beanClass); + if (validator == null) { + String prefix = beanClass.getSimpleName().toLowerCase(); + String contextValueName = prefix + "Validator"; + validator = context.getContextValue(BeanListValidator.class, + contextValueName); + Preconditions.checkNotNull(validator, + "No validator exists for bean type : " + + beanClass.getName() + + " (property from context = " + + contextValueName + ")" + ); + validator.addBeanListValidatorListener(new BeanListValidatorListener() { + + @Override + public void onFieldChanged(BeanListValidatorEvent event) { + setEnabled(checkEnabled()); + } + }); + validators.put(beanClass, validator); + } + return validator; + } + + protected BeanListValidator<Route> getRouteValidator() { + return getValidator(Route.class); + } + + protected BeanListValidator<Observation> getObservationValidator() { + return getValidator(Observation.class); + } + + protected <E extends TopiaEntity & Validable> void bindValidableEntity(String propertyName, + Class<E> propertyClass) { + + getModel().addPropertyChangeListener(propertyName, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + TopiaEntity oldValue = (TopiaEntity) evt.getOldValue(); + if (oldValue != null) { + oldValue.removePropertyChangeListener( + "deleted", enabledListener); + } + TopiaEntity newValue = (TopiaEntity) evt.getNewValue(); + if (newValue != null) { + newValue.addPropertyChangeListener( + "deleted", enabledListener); + } + enabledListener.propertyChange(evt); + } + }); + } + + protected <E extends AbstractBean & Validable> void bindValidableModel(String propertyName, + Class<E> propertyClass) { + + getModel().addPropertyChangeListener(propertyName, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + AbstractBean oldValue = (AbstractBean) evt.getOldValue(); + if (oldValue != null) { + oldValue.removePropertyChangeListener( + "deleted", enabledListener); + } + AbstractBean newValue = (AbstractBean) evt.getNewValue(); + if (newValue != null) { + newValue.addPropertyChangeListener( + "deleted", enabledListener); + } + enabledListener.propertyChange(evt); + } + }); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidObservationAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidObservationAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidObservationAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidObservationAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,84 @@ +package fr.ulr.sammoa.ui.swing.flight.action; +/* + * #%L + * SAMMOA :: UI Swing + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.Observations; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 23/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class ValidObservationAction extends ValidAction { + + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(ValidObservationAction.class); + + private static final long serialVersionUID = 1L; + + public ValidObservationAction(JAXXContext context) { + super(_("sammoa.action.validObservation"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validObservation.tip")); + bindValidableEntity(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); + } + + @Override + public void actionPerformed(ActionEvent e) { + + Observation observation = getModel().getObservationEditBean(); + + if (observation != null) { + + if (logger.isDebugEnabled()) { + logger.debug("Validation for observation {}", observation.getObservationNumber()); + } + + Observation observationChanged = getValidationService().validateObservation(observation); + + if (observationChanged.isDeleted()) { + getModel().removeObservation(observationChanged); + } else { + getModel().updateObservation(observationChanged); + getModel().setObservationEditBean(observationChanged); + } + } + } + + @Override + protected boolean checkEnabled() { + Observation observation = getModel().getObservationEditBean(); + return observation != null + && Observations.isValid(observation, getObservationValidator()); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidObservationAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidRouteAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,110 @@ +package fr.ulr.sammoa.ui.swing.flight.action; +/* + * #%L + * SAMMOA :: UI Swing + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ulr.sammoa.application.FlightService; +import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.Routes; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 23/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class ValidRouteAction extends ValidAction { + + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(ValidRouteAction.class); + + private static final long serialVersionUID = 1L; + + protected boolean validatorIsAdjusting; + + public ValidRouteAction(JAXXContext context) { + super(_("sammoa.action.validRoute"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validRoute.tip")); + bindValidableEntity(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); + bindValidableEntity(FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, Route.class); + } + + @Override + public void actionPerformed(ActionEvent e) { + + Route route = getModel().getRouteEditBean(); + + if (route != null) { + + if (logger.isDebugEnabled()) { + logger.debug("Validation for route {} : {}", + route.getRouteType(), + route.getEffortNumber() + ); + } + + Route routeChanged = getValidationService().validateRoute(route); + + if (routeChanged.isDeleted()) { + getModel().removeRoute(routeChanged); + } else { + getModel().updateRoute(routeChanged); + + validatorIsAdjusting = true; + + getModel().setCurrentRoute(routeChanged); + getModel().setRouteEditBean(routeChanged); + + getModel().setObservationEditBean(null); + + // Reload all observations + FlightService service = + getSammoaUIContext().getService(FlightService.class); + getModel().clearObservation(); + getModel().addAllObservation(service.getObservations(getModel().getFlight())); + + validatorIsAdjusting = false; + } + } + } + + @Override + protected boolean checkEnabled() { + boolean result = isEnabled(); + if (!validatorIsAdjusting) { + Route bean = getModel().getRouteEditBean(); + result = bean != null + && Routes.isValid(bean, getRouteValidator(), getObservationValidator()); + } + return result; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ValidTransectAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,135 @@ +package fr.ulr.sammoa.ui.swing.flight.action; +/* + * #%L + * SAMMOA :: UI Swing + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ulr.sammoa.application.FlightService; +import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.TransectFlight; +import fr.ulr.sammoa.persistence.TransectFlights; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel; +import jaxx.runtime.JAXXContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.Action; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * Created: 23/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class ValidTransectAction extends ValidAction { + + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(ValidTransectAction.class); + + private static final long serialVersionUID = 1L; + + protected boolean validatorIsAdjusting; + + public ValidTransectAction(JAXXContext context) { + super(_("sammoa.action.validTransect"), context); + putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validTransect.tip")); + bindValidableEntity(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, Observation.class); + bindValidableEntity(FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, Route.class); + bindValidableModel(FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, TransectFlightModel.class); + } + + @Override + public void actionPerformed(ActionEvent e) { + + TransectFlightModel bean = getModel().getTransectFlightEditBean(); + + if (bean != null) { + + TransectFlight transectFlight = bean.getSource(); + + int index = getModel().indexOfTransectFlights(bean); + + if (logger.isDebugEnabled()) { + logger.debug("Validation for transectFlight {} : {}", + index, + transectFlight.getTransect().getName() + ); + } + + TransectFlight transectFlightChanged = + getValidationService().validateTransectFlight(getModel().getFlight(), transectFlight); + + if (transectFlightChanged.isDeleted()) { + getModel().removeTransectFlight(index); + + } else { + getModel().updateTransectFlight(transectFlightChanged); + + validatorIsAdjusting = true; + + Route routeEditBean = getModel().getRouteEditBean(); + + getModel().setRouteEditBean(null); + + // Reload all routes + FlightService service = + getSammoaUIContext().getService(FlightService.class); + getModel().clearRoute(); + getModel().addAllRoute(service.getRoutes(getModel().getFlight())); + + // Keep the route selected + if (routeEditBean != null && !routeEditBean.isDeleted()) { + getModel().setCurrentRoute(routeEditBean); + getModel().setRouteEditBean(routeEditBean); + } + + getModel().setObservationEditBean(null); + + // Reload all observations + getModel().clearObservation(); + getModel().addAllObservation(service.getObservations(getModel().getFlight())); + + validatorIsAdjusting = false; + } + } + } + + @Override + protected boolean checkEnabled() { + boolean result = isEnabled(); + if (!validatorIsAdjusting) { + TransectFlightModel bean = getModel().getTransectFlightEditBean(); + if (bean != null) { + TransectFlight transectflight = bean.getSource(); + result = transectflight != null + && TransectFlights.isValid(transectflight, + getRouteValidator(), + getObservationValidator()); + } + } + return result; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/DeviceStateLED.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/DeviceStateLED.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/DeviceStateLED.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,102 @@ +/* + * #%L + * SAMMOA :: UI Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.bar; + +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import org.nuiton.util.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; + +/** + * Panel qui écoute l'état du peripherique pour afficher à l'utilsateur un voyant + * lunineux dépendant de l'état du peripherique. + * <p/> + * Indicateurs pour l'état du peripherique + * <ul> + * <li>voyant gris : pas de peripherique + * <li>voyant bleu : peripherique prêt + * <li>voyant vert : enregistrement en cours + * <li>voyant rouge clignotant : enregistrement mais pas de données + * </ul> + * + * @author chatellier + */ +public class DeviceStateLED extends JLabel implements DeviceStateListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1L; + + private static final Logger logger = LoggerFactory.getLogger(DeviceStateLED.class); + + protected DeviceState state; + + protected static final ImageIcon NO_DEVICE_ICON = Resource.getIcon("/icons/device/nodevice.png"); + + protected static final ImageIcon READY_ICON = Resource.getIcon("/icons/device/ready.png"); + + protected static final ImageIcon RECORDING_ICON = Resource.getIcon("/icons/device/recording.png"); + + protected static final ImageIcon NO_DATA_ICON = Resource.getIcon("/icons/device/nodata.gif"); + + @Override + public void stateChanged(DeviceStateEvent event) { + setState(event.getNewValue()); + } + + public void setState(DeviceState state) { + DeviceState oldValue = getState(); + this.state = state; + + if (oldValue != state) { + + logger.debug("[{}] Update LED status: {}", + getClass().getSimpleName(), state); + + switch (state) { + case UNAVAILABLE: + setIcon(NO_DEVICE_ICON); + break; + case READY: + setIcon(READY_ICON); + break; + case RUNNING: + setIcon(RECORDING_ICON); + break; + case ERROR: + setIcon(NO_DATA_ICON); + break; + } + } + } + + public DeviceState getState() { + return state; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/DeviceStateLED.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.css) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,101 @@ +/* + * #%L + * SAMMOA :: UI Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +#stateBar { + background: {model.getEffortPanelColor()}; +} + +#clockTime { + delay: 1000; + pattern: "dd/MM/yyyy HH:mm:ss"; + visible: {!flightUIModel.isValidationMode()}; +} +#audioTime { + visible: {flightUIModel.isValidationMode()}; + text: {dateFormat.format(flightUIModel.getCurrentRoute().getBeginTime())}; +} + +#beginButton { + _actionName: {"begin"}; +} + +#endButton { + _actionName: {"end"}; +} + +#nextButton { + _actionName: {"next"}; +} + +#effortButtonPanel { + background: {model.getEffortPanelColor()}; +} + +#statusPanel { + background: {model.getEffortPanelColor()}; +} + +#lblEffort { + text: {flightUIModel.getFlightState().name()}; +} + +#lblTransect { + text: {flightUIModel.getCurrentRoute().getTransectFlight().getTransect().getName()}; +} + +#lblStatus { + text: {flightUIModel.getCurrentRoute().getRouteType().name() + + (flightUIModel.getCurrentRoute().getEffortNumber() != null + ? " " + flightUIModel.getCurrentRoute().getEffortNumber() + : "")}; +} + +#lblObservation { + text: {flightUIModel.getCurrentRoute().getTransectFlight().getTransect().getName()}; +} + +#cbPanel { + background: {model.getEffortPanelColor()}; +} + +#gpsLED { + text: "sammoa.statusBar.gps"; +} + +#audioLED { + text: "sammoa.statusBar.audio"; +} + +#indicatorPanel { + background: {model.getEffortPanelColor()}; +} + +#lblAlt { + text: {model.getAlt()}; +} + +#lblSpeed { + text: {model.getSpeed()}; +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,132 @@ +<!-- + #%L + SAMMOA :: UI Swing + + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 UMS 3462, Code Lutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<JPanel id='statusBar' layout='{new GridLayout(0,1,0,0)}'> + + <import> + java.text.SimpleDateFormat + javax.swing.BoxLayout + javax.swing.SwingConstants + jaxx.runtime.swing.ClockWidget + + fr.ulr.sammoa.ui.swing.flight.FlightUIModel + </import> + + <script><![CDATA[ + + protected void $afterCompleteSetup() { + getHandler().init(); + } + + ]]></script> + + <FlightBarHandler id='handler' constructorParams='this'/> + + <FlightUIModel id='flightUIModel' initializer='getHandler().getParentUI().getModel()'/> + + <FlightBarModel id='model'/> + + <SimpleDateFormat id='dateFormat' constructorParams='"dd/MM/yyyy HH:mm:ss"'/> + + <Table id='validationBar'> + <row> + <cell fill='horizontal' weightx='0.2'> + <JPanel id='audioButtonPanel' + layout='{new BoxLayout(audioButtonPanel, BoxLayout.X_AXIS)}'> + <JButton id='startAudioButton'/> + <JButton id='stopAudioButton'/> + </JPanel> + </cell> + <cell fill='horizontal'> + <JSlider id='audioSlider' enabled='false'/> + </cell> + <cell fill='horizontal' weightx='0.2'> + <JPanel id='validButtonPanel' + layout='{new BoxLayout(validButtonPanel, BoxLayout.X_AXIS)}'> + <JButton id='validRouteButton'/> + <JButton id='validObservationButton'/> + <JButton id='validTransectButton'/> + </JPanel> + </cell> + </row> + </Table> + <Table id='stateBar'> + <row> + <cell fill='horizontal' weightx='0.2'> + <ClockWidget id='clockTime'/> + </cell> + <cell fill='horizontal' weightx='0.2'> + <JLabel id='audioTime'/> + </cell> + <cell fill='vertical'> + <JSeparator constructorParams='SwingConstants.VERTICAL'/> + </cell> + <cell fill='horizontal'> + <JPanel id='effortButtonPanel' + layout='{new BoxLayout(effortButtonPanel, BoxLayout.X_AXIS)}'> + <JButton id='beginButton'/> + <JButton id='endButton'/> + <JButton id='nextButton'/> + </JPanel> + </cell> + <cell fill='vertical'> + <JSeparator constructorParams='SwingConstants.VERTICAL'/> + </cell> + <cell fill='horizontal' weightx='0.2' anchor='center'> + <JLabel id='lblEffort'/> + </cell> + <cell fill='vertical'> + <JSeparator constructorParams='SwingConstants.VERTICAL'/> + </cell> + <cell fill='horizontal' weightx='0.2' anchor='center'> + <JLabel id='lblTransect'/> + </cell> + <cell fill='vertical'> + <JSeparator constructorParams='SwingConstants.VERTICAL'/> + </cell> + <cell fill='horizontal' weightx='0.2' anchor='center'> + <JLabel id='lblStatus'/> + </cell> + <cell fill='vertical'> + <JSeparator constructorParams='SwingConstants.VERTICAL'/> + </cell> + <cell fill='horizontal' weightx='0.2' anchor='center'> + <JPanel id='cbPanel' layout='{new BoxLayout(cbPanel, BoxLayout.Y_AXIS)}'> + <DeviceStateLED id='gpsLED' /> + <DeviceStateLED id='audioLED' /> + </JPanel> + </cell> + <cell fill='vertical'> + <JSeparator constructorParams='SwingConstants.VERTICAL'/> + </cell> + <cell fill='horizontal' weightx='0.2' anchor='center'> + <JPanel id='indicatorPanel' + layout='{new BoxLayout(indicatorPanel, BoxLayout.Y_AXIS)}'> + <JLabel id='lblAlt'/> + <JLabel id='lblSpeed'/> + </JPanel> + </cell> + </row> + </Table> +</JPanel> Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,132 @@ +/* + * #%L + * SAMMOA :: UI Swing + * * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.bar; + +import fr.ulr.sammoa.application.device.audio.AudioRecorder; +import fr.ulr.sammoa.application.device.gps.GpsHandler; +import fr.ulr.sammoa.application.flightController.FlightController; +import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.ui.swing.SammoaColors; +import fr.ulr.sammoa.ui.swing.flight.FlightUI; +import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import jaxx.runtime.JAXXUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +/** @author sletellier <letellier@codelutin.com> */ +public class FlightBarHandler implements PropertyChangeListener { + + private static final Logger logger = + LoggerFactory.getLogger(FlightBarHandler.class); + + protected final FlightBar ui; + + public FlightBarHandler(FlightBar ui) { + this.ui = ui; + } + + public FlightUI getParentUI() { + return ui.getContextValue(FlightUI.class, JAXXUtil.PARENT); + } + + protected FlightBarModel getModel() { + return ui.getModel(); + } + + public void init() { + + FlightUIModel flightUIModel = ui.getFlightUIModel(); + flightUIModel.addPropertyChangeListener(this); + + + FlightController flightController = + ui.getContextValue(FlightUIHandler.class).getFlightController(); + + if (flightUIModel.isValidationMode()) { + + // Put actionName for validation buttons + ui.getStartAudioButton().putClientProperty("actionName", "startAudio"); + ui.getStopAudioButton().putClientProperty("actionName", "stopAudio"); + ui.getValidObservationButton().putClientProperty("actionName", "validObservation"); + ui.getValidRouteButton().putClientProperty("actionName", "validRoute"); + ui.getValidTransectButton().putClientProperty("actionName", "validTransect"); + + } else { + + // Remove the bar used only for validation + ui.remove(ui.getValidationBar()); + + AudioRecorder audioRecorder = flightController.getDeviceManager(AudioRecorder.class); + ui.getAudioLED().setState(audioRecorder.getState()); + audioRecorder.addDeviceStateListener(ui.getAudioLED()); + + GpsHandler gpsHandler = flightController.getDeviceManager(GpsHandler.class); + ui.getGpsLED().setState(gpsHandler.getState()); + gpsHandler.addDeviceStateListener(ui.getGpsLED()); + gpsHandler.addGpsLocationListener(getModel()); + } + + if (FlightState.OFF_EFFORT.equals(ui.getFlightUIModel().getFlightState())) { + getModel().setEffortPanelColor(SammoaColors.ON_EFFORT_BACKGROUND_COLOR); + } + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + String propertyName = evt.getPropertyName(); + + if (FlightUIModel.PROPERTY_FLIGHT_STATE.equals(propertyName)) { + + logger.debug("Modify flight bar background color"); + + // si l'etat du vol passe en off effort + // affiche à l'utilisateur + FlightState newState = (FlightState) evt.getNewValue(); + if (FlightState.OFF_EFFORT.equals(newState)) { + getModel().setEffortPanelColor(SammoaColors.ON_EFFORT_BACKGROUND_COLOR); + + } else { + getModel().setEffortPanelColor(null); + } + + } else if (FlightUIModel.PROPERTY_CURRENT_ROUTE.equals(propertyName)) { + + Route route = (Route) evt.getNewValue(); + + logger.debug("New value received for current route {}", route); + + if (route == null || route.getTransectFlight() == null) { + // set null will hide label + ui.getLblTransect().setText(null); + } + + } + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarModel.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarModel.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarModel.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,91 @@ +/* + * #%L + * SAMMOA :: UI Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.bar; + +import fr.ulr.sammoa.application.device.gps.GpsLocationEvent; +import fr.ulr.sammoa.application.device.gps.GpsLocationListener; +import fr.ulr.sammoa.persistence.GeoPoint; +import org.jdesktop.beans.AbstractSerializableBean; + +import java.awt.Color; + +import static org.nuiton.i18n.I18n._; + +/** @author sletellier <letellier@codelutin.com> */ +public class FlightBarModel extends AbstractSerializableBean implements GpsLocationListener { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_ALT = "alt"; + + public static final String PROPERTY_SPEED = "speed"; + + public static final String PROPERTY_EFFORT_PANEL_COLOR = "effortPanelColor"; + + protected float alt; + + protected float speed; + + protected Color effortPanelColor; + + public String getAlt() { + return _("sammoa.statusbar.alt", alt); + } + + public void setAlt(float alt) { + float oldValue = this.alt; + this.alt = alt; + firePropertyChange(PROPERTY_ALT, oldValue, alt); + } + + public String getSpeed() { + return _("sammoa.statusbar.speed", speed); + } + + public void setSpeed(float speed) { + float oldValue = this.speed; + this.speed = speed; + firePropertyChange(PROPERTY_SPEED, oldValue, speed); + } + + public Color getEffortPanelColor() { + return effortPanelColor; + } + + public void setEffortPanelColor(Color effortPanelColor) { + Color oldColor = this.effortPanelColor; + this.effortPanelColor = effortPanelColor; + firePropertyChange(PROPERTY_EFFORT_PANEL_COLOR, oldColor, this.effortPanelColor); + } + + @Override + public void locationChanged(GpsLocationEvent event) { + GeoPoint newLocation = event.getNewValue(); + if (newLocation != null) { + setSpeed((float) newLocation.getSpeed()); + setAlt((float) newLocation.getAltitude()); + } + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.css (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanel.css) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.css (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.css 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,164 @@ +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +#effortPanel { + minimumSize:{new Dimension(0,0)}; + preferredSize:{new Dimension(0,0)}; +} + +#scrollPanel { + columnHeaderView:{errorTable.getTableHeader()}; +} + +#errorTable { + rowSelectionAllowed:true; + autoCreateRowSorter:true; + autoResizeMode:2; + cellSelectionEnabled:false; + selectionMode:0; + model:{errorTableModel}; + sortable:false; +} + +#transecLbl { + text: "sammoa.observation.observationCondition.transec"; +} + +#observersLbl { + text: "sammoa.observation.observationCondition.observers"; +} + +#lblObservation { + text: "sammoa.observationCondition.title"; + horizontalTextPosition: {JLabel.CENTER}; + horizontalAlignment: {JLabel.CENTER}; +} + +#navLabel { + text: "sammoa.flightPanel.table.column.position.navigator"; + enabled: {model.getRouteEditBean() != null}; +} + +#navObserversModel { + elements:{model.getFlightObserverForPositions()}; +} + +#navComboBox { + enabled: {model.getRouteEditBean() != null}; + model: {navObserversModel}; + /*renderer: {new DecoratorProviderListCellRenderer(handler.getDecoratorProvider())};*/ + selectedItem: {getHandler().getObserverByPosition(model.getRouteEditBean(), Position.NAVIGATOR)}; +} + +#leftLabel { + text: "sammoa.flightPanel.table.column.position.left"; + enabled: {model.getRouteEditBean() != null}; +} + +#leftObserversModel { + elements:{model.getFlightObserverForPositions()}; +} + +#leftComboBox { + enabled: {model.getRouteEditBean() != null}; + model: {leftObserversModel}; + /*renderer: {new DecoratorProviderListCellRenderer(handler.getDecoratorProvider())};*/ + selectedItem: {getHandler().getObserverByPosition(model.getRouteEditBean(), Position.FRONT_LEFT)}; + background: {SammoaColors.POSITION_LEFT_COLOR}; +} + +#rightLabel { + text: "sammoa.flightPanel.table.column.position.right"; + enabled: {model.getRouteEditBean() != null}; +} + +#rightObserversModel { + elements:{model.getFlightObserverForPositions()}; +} + +#rightComboBox { + enabled: {model.getRouteEditBean() != null}; + model: {rightObserversModel}; + /*renderer: {new DecoratorProviderListCellRenderer(handler.getDecoratorProvider())};*/ + selectedItem: {getHandler().getObserverByPosition(model.getRouteEditBean(), Position.FRONT_RIGHT)}; + background: {SammoaColors.POSITION_RIGHT_COLOR}; +} + +#conavLabel { + text: "sammoa.flightPanel.table.column.position.co-navigator"; + enabled: {model.getRouteEditBean() != null}; +} + +#coNavObserversModel { + elements:{model.getFlightObserverForPositions()}; +} + +#conavComboBox { + enabled: {model.getRouteEditBean() != null}; + model: {coNavObserversModel}; + /*renderer: {new DecoratorProviderListCellRenderer(handler.getDecoratorProvider())};*/ + selectedItem: {getHandler().getObserverByPosition(model.getRouteEditBean(), Position.CO_NAVIGATOR)}; +} + +#routeTable { + model: {routeTableModel}; + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; + _terminateEditOnFocusLost: {true}; +} + +#addButton { + _actionName: {"add"}; +} + +#lblObservation2 { + text: "sammoa.observation.title"; + horizontalTextPosition: {JLabel.CENTER}; + horizontalAlignment: {JLabel.CENTER}; +} + +#observationTable { + model:{observationTableModel}; + selectionMode: {ListSelectionModel.SINGLE_SELECTION}; + selectionBackground: {null}; + selectionForeground: {Color.BLACK}; + sortable: false; + _terminateEditOnFocusLost: {true}; +} + +#leftButton { + _actionName: {"leftObservation"}; + background: {SammoaColors.POSITION_LEFT_COLOR}; +} + +#centerButton { + _actionName: {"centerObservation"}; +} + +#rightButton { + _actionName: {"rightObservation"}; + background: {SammoaColors.POSITION_RIGHT_COLOR}; +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.jaxx (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanel.jaxx) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.jaxx (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.jaxx 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,184 @@ +<!-- + #%L + SAMMOA :: UI Swing + + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 UMS 3462, Code Lutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<JSplitPane id='effortSplitPane' resizeWeight='0.9'> + + <import> + java.awt.Dimension + java.awt.Color + javax.swing.ListSelectionModel + + fr.ulr.sammoa.persistence.Position + fr.ulr.sammoa.persistence.Route + fr.ulr.sammoa.persistence.Observer + fr.ulr.sammoa.persistence.Observation + + fr.ulr.sammoa.ui.swing.SammoaColors + fr.ulr.sammoa.ui.swing.flight.FlightUIModel + + org.nuiton.validator.bean.list.BeanListValidator + org.jdesktop.swingx.JXTable + + jaxx.runtime.swing.model.GenericListModel + jaxx.runtime.validator.swing.SwingListValidatorMessageTableModel + + static org.nuiton.i18n.I18n._ + + </import> + + <EffortPanelHandler id='handler' constructorParams='this'/> + + <SwingListValidatorMessageTableModel id='errorTableModel'/> + + <FlightUIModel id='model' + initializer='handler.getParentUI().getModel()'/> + + <GenericListModel id='navObserversModel' genericType='Observer'/> + + <GenericListModel id='leftObserversModel' genericType='Observer'/> + + <GenericListModel id='rightObserversModel' genericType='Observer'/> + + <GenericListModel id='coNavObserversModel' genericType='Observer'/> + + <RouteTableModel id='routeTableModel' + initializer='new RouteTableModel(model)'/> + + <!--RouteTableListSelectionListener id='routeSelectionModel' + constructorParams='flightUIModel'/--> + + <ObservationTableModel id='observationTableModel' + constructorParams='model'/> + + <!--ObservationTableListSelectionListener id='observationSelectionModel' + constructorParams='flightUIModel'/--> + + <!-- validator --> + <BeanListValidator id='routeValidator' genericType='Route' + initializer='BeanListValidator.newValidator(Route.class, null)'/> + + <BeanListValidator id='observationValidator' genericType='Observation' + initializer='BeanListValidator.newValidator(Observation.class, null)'/> + + <script><![CDATA[ + + protected void $afterCompleteSetup() { + getHandler().init(); + } + + ]]></script> + + <Table id='effortPanel'> + + <row> + <cell fill='both' weightx='1.0' weighty='1'> + <Table id='routePanel'> + <row> + <cell> + <JButton id='addButton'/> + </cell> + <cell> + <JLabel id='navLabel'/> + </cell> + <cell> + <JComboBox id='navComboBox' + onActionPerformed='handler.setObserverByPosition(navObserversModel.getSelectedItem(), Position.NAVIGATOR)'/> + </cell> + <cell> + <JLabel id='leftLabel'/> + </cell> + <cell> + <JComboBox id='leftComboBox' + onActionPerformed='handler.setObserverByPosition(leftObserversModel.getSelectedItem(), Position.FRONT_LEFT)'/> + </cell> + <cell> + <JLabel id='rightLabel'/> + </cell> + <cell> + <JComboBox id='rightComboBox' + onActionPerformed='handler.setObserverByPosition(rightObserversModel.getSelectedItem(), Position.FRONT_RIGHT)'/> + </cell> + <cell> + <JLabel id='conavLabel'/> + </cell> + <cell> + <JComboBox id='conavComboBox' + onActionPerformed='handler.setObserverByPosition(coNavObserversModel.getSelectedItem(), Position.CO_NAVIGATOR)'/> + </cell> + <cell weightx='1' anchor='east'> + <JLabel id='lblObservation'/> + </cell> + </row> + <row> + <cell fill='both' weightx='1.0' weighty='1.0' columns='10'> + <JScrollPane id='routeTableScroll'> + <JXTable id='routeTable'/> + </JScrollPane> + </cell> + </row> + </Table> + + </cell> + </row> + <row> + <cell fill='both' weightx='1.0' weighty='1.6'> + <Table id='observations'> + + <row> + <cell> + <JButton id='leftButton'/> + </cell> + <cell> + <JButton id='centerButton'/> + </cell> + <cell> + <JButton id='rightButton'/> + </cell> + <cell weightx='1' anchor='east'> + <JLabel id='lblObservation2'/> + </cell> + </row> + <row> + <cell fill='both' weightx='1.0' weighty='1.0' columns='4'> + <JScrollPane id='observationTableScroll'> + <JXTable id='observationTable' /> + </JScrollPane> + </cell> + </row> + + </Table> + </cell> + </row> + </Table> + + <JPanel id='validationTable' layout='{new BorderLayout()}'> + + <JScrollPane id='scrollPanel' constraints='BorderLayout.CENTER'> + + <JXTable id='errorTable'/> + </JScrollPane> + + </JPanel> + +</JSplitPane> \ No newline at end of file Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanel.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,1063 @@ +package fr.ulr.sammoa.ui.swing.flight.effort; +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import fr.ulr.sammoa.application.FlightService; +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import fr.ulr.sammoa.application.device.audio.AudioRecorder; +import fr.ulr.sammoa.application.device.gps.GpsHandler; +import fr.ulr.sammoa.application.flightController.FlightController; +import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.ObservationStatus; +import fr.ulr.sammoa.persistence.Observations; +import fr.ulr.sammoa.persistence.Observer; +import fr.ulr.sammoa.persistence.ObserverPosition; +import fr.ulr.sammoa.persistence.Position; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.Routes; +import fr.ulr.sammoa.ui.swing.SammoaColors; +import fr.ulr.sammoa.ui.swing.SammoaUIContext; +import fr.ulr.sammoa.ui.swing.UIDecoratorService; +import fr.ulr.sammoa.ui.swing.flight.FlightUI; +import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel; +import fr.ulr.sammoa.ui.swing.flight.action.CircleBackAction; +import fr.ulr.sammoa.ui.swing.flight.effort.action.MoveToNextEditableCellAction; +import fr.ulr.sammoa.ui.swing.flight.effort.action.MoveToNextRowEditableAction; +import fr.ulr.sammoa.ui.swing.flight.effort.action.MoveToPreviousEditableCellAction; +import fr.ulr.sammoa.ui.swing.flight.effort.action.MoveToPreviousRowEditableAction; +import fr.ulr.sammoa.ui.swing.util.AbstractRowHighlightPredicate; +import fr.ulr.sammoa.ui.swing.util.ButtonActionTableCellEditorRenderer; +import fr.ulr.sammoa.ui.swing.util.DeletedRowHighlightPredicate; +import fr.ulr.sammoa.ui.swing.util.SammoaUtil; +import fr.ulr.sammoa.ui.swing.util.SelectionModelAdapter; +import fr.ulr.sammoa.ui.swing.util.TableDataChangeListener; +import fr.ulr.sammoa.ui.swing.util.TextCellEditor; +import fr.ulr.sammoa.ui.swing.util.TimeCellEditor; +import fr.ulr.sammoa.ui.swing.util.ValidRowHighlightPredicate; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.JAXXDatePicker; +import jaxx.runtime.swing.JAXXWidgetUtil; +import jaxx.runtime.swing.editor.cell.NumberCellEditor; +import jaxx.runtime.validator.swing.SwingListValidatorDataLocator; +import jaxx.runtime.validator.swing.SwingListValidatorHighlightPredicate; +import jaxx.runtime.validator.swing.SwingListValidatorMessageTableModel; +import jaxx.runtime.validator.swing.SwingListValidatorMessageTableRenderer; +import jaxx.runtime.validator.swing.SwingValidatorUtil; +import org.apache.commons.lang3.tuple.Pair; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.decorator.Highlighter; +import org.jdesktop.swingx.table.TableColumnExt; +import org.nuiton.util.decorator.Decorator; +import org.nuiton.validator.NuitonValidatorScope; +import org.nuiton.validator.bean.list.BeanListValidator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.Action; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.ListCellRenderer; +import javax.swing.border.LineBorder; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableModel; +import java.awt.Color; +import java.awt.Component; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Date; +import java.util.List; + +import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; + +/** + * Handler of {@link EffortPanel} ui. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.4 + */ +public class EffortPanelHandler implements DeviceStateListener { + + private static final Logger logger = + LoggerFactory.getLogger(EffortPanelHandler.class); + + protected static final Color DEVICE_ERROR_BACKGROUND_COLOR = Color.RED; + + public static final String ROUTE_VALIDATOR_CONTEXT_VALUE = + "routeValidator"; + + public static final String OBSERVATION_VALIDATOR_CONTEXT_VALUE = + "observationValidator"; + + protected boolean comboIsAdjusting; + + private final SammoaUIContext context; + + private final EffortPanel ui; + + public EffortPanelHandler(EffortPanel ui) { + this.ui = ui; + context = ui.getContextValue(SammoaUIContext.class); + } + + public FlightUI getParentUI() { + return ui.getContextValue(FlightUI.class, JAXXUtil.PARENT); + } + + public FlightUIModel getModel() { + return ui.getModel(); + } + + public void init() { + + final UIDecoratorService decoratorService = + context.getService(UIDecoratorService.class); + + ListCellRenderer observeCellRenderer = + decoratorService.newListCellRender(Observer.class); + + ui.getNavComboBox().setRenderer(observeCellRenderer); + ui.getLeftComboBox().setRenderer(observeCellRenderer); + ui.getRightComboBox().setRenderer(observeCellRenderer); + ui.getConavComboBox().setRenderer(observeCellRenderer); + + JTable errorTable = ui.getErrorTable(); + + // prepare error table ui + SwingValidatorUtil.installUI( + errorTable, + new SwingListValidatorMessageTableRenderer() { + + private static final long serialVersionUID = 1L; + + @Override + protected String decorateBean(Object bean) { + return decoratorService.getDecorator(bean).toString(bean); + } + + } + ); + + initRouteTable(); + + initObservationTable(); + } + + + /** + * Add hightlighters on the editor of beans. + * + * @param validator the validator where to find bean states + * @param editor the editor of beans + * @param dataLocator the data locator + * @param scopes scopes to hightlight + * @param <O> type of bean to validate + * @since 2.5.3 + */ + public static <O> void addHightLighterOnEditor(BeanListValidator<O> validator, + JXTable editor, + SwingListValidatorDataLocator<O> dataLocator, + NuitonValidatorScope... scopes) { + + for (NuitonValidatorScope scope : scopes) { + + SwingListValidatorHighlightPredicate<O> predicate = SwingListValidatorHighlightPredicate.newPredicate( + scope, + validator, dataLocator + ); + + Highlighter highlighter = SammoaUtil.newBackgroundColorHighlighter( + predicate, SwingValidatorUtil.getColor(scope)); + editor.addHighlighter(highlighter); + } + } + + public Observer getObserverByPosition(Route route, Position position) { + Observer result; + if (route != null) { + ObserverPosition observerPosition = + route.getObserverPositionByPosition(position); + result = observerPosition.getObserver(); + + } else { + result = null; + } + return result; + } + + public void setObserverByPosition(Observer newValue, Position position) { + if (!comboIsAdjusting) { + + Route route = getModel().getRouteEditBean(); + if (route != null) { + + if (logger.isDebugEnabled()) { + logger.debug(String.format("Set observer %s for position %s", newValue, position)); + } + + FlightService flightService = context.getService(FlightService.class); + flightService.setRouteObserverByPosition(route, newValue, position); + + // the method setObserverByPosition could update other positions + // so we need to refresh all comboboxes + comboIsAdjusting = true; + + try { + if (Position.NAVIGATOR != position) { + ObserverPosition navPosition = route.getObserverPositionByPosition(Position.NAVIGATOR); + ui.getNavComboBox().setSelectedItem(navPosition.getObserver()); + } + + if (Position.FRONT_LEFT != position) { + ObserverPosition leftPosition = route.getObserverPositionByPosition(Position.FRONT_LEFT); + ui.getLeftComboBox().setSelectedItem(leftPosition.getObserver()); + } + + if (Position.FRONT_RIGHT != position) { + ObserverPosition rightPosition = route.getObserverPositionByPosition(Position.FRONT_RIGHT); + ui.getRightComboBox().setSelectedItem(rightPosition.getObserver()); + } + + if (Position.CO_NAVIGATOR != position) { + ObserverPosition conavPosition = route.getObserverPositionByPosition(Position.CO_NAVIGATOR); + ui.getConavComboBox().setSelectedItem(conavPosition.getObserver()); + } + } finally { + + comboIsAdjusting = false; + } + + // Fire on TableModel to update the row (highlighting) + // ensureRowIndex in case of new route, otherwise the size is + // not updated yet in tableModel and an IndexOutOfBounds appears + int index = getModel().indexOfRoutes(route); + SwingUtil.ensureRowIndex(ui.getRouteTableModel(), index); + ui.getRouteTableModel().fireTableRowsUpdated(index, index); + + // Update observation table to ensure observer's name during validation + if (getModel().isValidationMode()) { + fireObservationsUpdated(route, false); + } + } + } + } + + @Override + public void stateChanged(DeviceStateEvent event) { + DeviceState state = event.getNewValue(); + if (DeviceState.ERROR == state) { + ui.getObservationTable().setBackground(DEVICE_ERROR_BACKGROUND_COLOR); + + } else { + ui.getObservationTable().setBackground(Color.WHITE); + } + } + + public void initRouteTable() { + + JXTable table = ui.getRouteTable(); + RouteTableModel tableModel = ui.getRouteTableModel(); + + SwingUtil.setI18nTableHeaderRenderer( + table, + n_("sammoa.observations.routeTable.column.effortNumber"), + n_("sammoa.observations.routeTable.column.effortNumber.tip"), + n_("sammoa.observations.routeTable.column.beginTime"), + n_("sammoa.observations.routeTable.column.beginTime.tip"), + n_("sammoa.observations.routeTable.column.routeType"), + n_("sammoa.observations.routeTable.column.routeType.tip"), + n_("sammoa.observations.routeTable.column.transect"), + n_("sammoa.observations.routeTable.column.transect.tip"), + n_("sammoa.observations.routeTable.column.seaState"), + n_("sammoa.observations.routeTable.column.seaState.tip"), + n_("sammoa.observations.routeTable.column.swell"), + n_("sammoa.observations.routeTable.column.swell.tip"), + n_("sammoa.observations.routeTable.column.turbidity"), + n_("sammoa.observations.routeTable.column.turbidity.tip"), + n_("sammoa.observations.routeTable.column.skyGlint"), + n_("sammoa.observations.routeTable.column.skyGlint.tip"), + n_("sammoa.observations.routeTable.column.glareFrom"), + n_("sammoa.observations.routeTable.column.glareFrom.tip"), + n_("sammoa.observations.routeTable.column.glareTo"), + n_("sammoa.observations.routeTable.column.glareTo.tip"), + n_("sammoa.observations.routeTable.column.glareSeverity"), + n_("sammoa.observations.routeTable.column.glareSeverity.tip"), + n_("sammoa.observations.routeTable.column.glareUnder"), + n_("sammoa.observations.routeTable.column.glareUnder.tip"), + n_("sammoa.observations.routeTable.column.cloudCover"), + n_("sammoa.observations.routeTable.column.cloudCover.tip"), + n_("sammoa.observations.routeTable.column.subjectiveConditions"), + n_("sammoa.observations.routeTable.column.subjectiveConditions.tip"), + n_("sammoa.observations.routeTable.column.unexpectedLeft"), + n_("sammoa.observations.routeTable.column.unexpectedLeft.tip"), + n_("sammoa.observations.routeTable.column.unexpectedRight"), + n_("sammoa.observations.routeTable.column.unexpectedRight.tip"), + n_("sammoa.observations.routeTable.column.comment"), + n_("sammoa.observations.routeTable.column.comment.tip"), + n_("sammoa.observations.routeTable.column.deleted"), + n_("sammoa.observations.routeTable.column.deleted.tip") + ); + + init(table, new SelectionModelAdapter<Route>() { + + @Override + public List<Route> getElements() { + return getModel().getRoutes(); + } + + @Override + public void setSelectedElement(Route element) { + getModel().setRouteEditBean(element); + } + }); + + // Listeners + { + int columnToEditOnInsert = RouteTableModel.RouteColumn.SEA_STATE.ordinal(); + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_ROUTES, + new TableDataChangeListener(table, columnToEditOnInsert) + ); + + if (getModel().isValidationMode()) { + + // FlightController # change current route + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, + new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Route route = (Route) evt.getNewValue(); + getParentUI().getHandler().getFlightController().setCurrentRoute(route); + + // no unselect but ensure valid button (a select will cause a loop) + getModel().setObservationEditBean(null); + } + } + ); + + // Refresh matching routes from selected transectFlight + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + TransectFlightModel oldValue = (TransectFlightModel) evt.getOldValue(); + if (oldValue != null) { + fireRoutesUpdated(oldValue, false); + } + TransectFlightModel newValue = (TransectFlightModel) evt.getNewValue(); + if (newValue != null) { + fireRoutesUpdated(newValue, true); + } + } + }); + } + } + + // Validation + { + JTable errorTable = ui.getErrorTable(); + SwingListValidatorMessageTableModel errorTableModel = ui.getErrorTableModel(); + + BeanListValidator<Route> validator = ui.getRouteValidator(); + validator.setContext(getValidatorContext()); + getParentUI().setContextValue(validator, ROUTE_VALIDATOR_CONTEXT_VALUE); + + RouteValidatorDataLocator dataLocator = new RouteValidatorDataLocator(); + + SwingValidatorUtil.registerListValidator( + validator, + errorTableModel, + table, + errorTable, + dataLocator + ); + + addHightLighterOnEditor( + validator, + table, + dataLocator, + NuitonValidatorScope.ERROR, + NuitonValidatorScope.WARNING + ); + + for (Route route : tableModel.getBean()) { + validator.addBean(route); + } + } + + // Highlighters + { + table.addHighlighter(SammoaUtil.newBackgroundColorHighlighter( + new RouteForSelectedTransectFlightHighlightPredicate(getModel()), + SammoaColors.OBSERVATION_FOR_ROUTE_ROW_COLOR) + ); + table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( + new RouteNoModificationHighlightPredicate(tableModel), + SammoaColors.ROUTE_NO_MODIFICATION_ROW_COLOR) + ); + table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( + new DeletedRowHighlightPredicate(getModel().getRoutes()), + SammoaColors.DELETED_ROW_COLOR) + ); + table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( + new ValidRowHighlightPredicate(getModel().getRoutes()), + SammoaColors.VALID_ROW_COLOR) + ); + } + } + + public void initObservationTable() { + + JXTable table = ui.getObservationTable(); + ObservationTableModel tableModel = ui.getObservationTableModel(); + + SwingUtil.setI18nTableHeaderRenderer( + table, + n_("sammoa.observations.observationTable.column.observationNumber"), + n_("sammoa.observations.observationTable.column.observationNumber.tip"), + n_("sammoa.observations.observationTable.column.observationTime"), + n_("sammoa.observations.observationTable.column.observationTime.tip"), + n_("sammoa.observations.observationTable.column.position"), + n_("sammoa.observations.observationTable.column.position.tip"), + n_("sammoa.observations.observationTable.column.podSize"), + n_("sammoa.observations.observationTable.column.podSize.tip"), + n_("sammoa.observations.observationTable.column.species"), + n_("sammoa.observations.observationTable.column.species.tip"), + n_("sammoa.observations.observationTable.column.age"), + n_("sammoa.observations.observationTable.column.age.tip"), + n_("sammoa.observations.observationTable.column.decAngle"), + n_("sammoa.observations.observationTable.column.decAngle.tip"), + n_("sammoa.observations.observationTable.column.cue"), + n_("sammoa.observations.observationTable.column.cue.tip"), + n_("sammoa.observations.observationTable.column.behaviour"), + n_("sammoa.observations.observationTable.column.behaviour.tip"), + n_("sammoa.observations.observationTable.column.swimDir"), + n_("sammoa.observations.observationTable.column.swimDir.tip"), + n_("sammoa.observations.observationTable.column.calves"), + n_("sammoa.observations.observationTable.column.calves.tip"), + n_("sammoa.observations.observationTable.column.photo"), + n_("sammoa.observations.observationTable.column.photo.tip"), + n_("sammoa.observations.observationTable.column.comment"), + n_("sammoa.observations.observationTable.column.comment.tip"), + n_("sammoa.observations.observationTable.column.observationStatus"), + n_("sammoa.observations.observationTable.column.observationStatus.tip"), + n_("sammoa.observations.observationTable.column.deleted"), + n_("sammoa.observations.observationTable.column.deleted.tip"), + n_("sammoa.observations.observationTable.column.circleback"), + n_("sammoa.observations.observationTable.column.circleback.tip") + ); + + init(table, new SelectionModelAdapter<Observation>() { + + @Override + public List<Observation> getElements() { + return getModel().getObservations(); + } + + @Override + public void setSelectedElement(Observation element) { + getModel().setObservationEditBean(element); + } + }); + + // Listeners + { + FlightController flightController = + getParentUI().getHandler().getFlightController(); + + int columnToEditOnInsert = ObservationTableModel.ObservationColumn.POD_SIZE.ordinal(); + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_OBSERVATIONS, + new TableDataChangeListener(table, columnToEditOnInsert) + ); + + // For CircleBack buttons + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_FLIGHT_STATE, + new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + FlightUIModel model = (FlightUIModel) evt.getSource(); + + if (model.sizeObservations() > 0) { + + ui.getObservationTableModel().fireTableRowsUpdated( + 0, model.sizeObservations() - 1); + } + } + }); + + // Refresh matching observations from selected route + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, + new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + Route oldValue = (Route) evt.getOldValue(); + if (oldValue != null) { + fireObservationsUpdated(oldValue, false); + } + Route newValue = (Route) evt.getNewValue(); + if (newValue != null) { + fireObservationsUpdated(newValue, true); + } + } + }); + + if (getModel().isValidationMode()) { + + // For validation, time change is listening to properly select the route + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, + new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + Observation oldValue = (Observation) evt.getNewValue(); + if (oldValue != null) { + oldValue.removePropertyChangeListener( + Observation.PROPERTY_OBSERVATION_TIME, + observationTimeChangeListener); + } + Observation newValue = (Observation) evt.getNewValue(); + if (newValue != null) { + newValue.addPropertyChangeListener( + Observation.PROPERTY_OBSERVATION_TIME, + observationTimeChangeListener); + + selectRouteByObservation(newValue); + } +// else { +// SammoaUtil.unselectAll(ui.getObservationTable()); +// } + } + }); + + } else { + flightController.getDeviceManager(GpsHandler.class).addDeviceStateListener(this); + flightController.getDeviceManager(AudioRecorder.class).addDeviceStateListener(this); + } + } + + table.addHighlighter( + SammoaUtil.newBackgroundColorHighlighter( + new ObservationForSelectedRouteHighlightPredicate(getModel()), + SammoaColors.OBSERVATION_FOR_ROUTE_ROW_COLOR) + ); + + // Validation + { + JTable errorTable = ui.getErrorTable(); + SwingListValidatorMessageTableModel errorTableModel = ui.getErrorTableModel(); + + BeanListValidator<Observation> validator = ui.getObservationValidator(); + validator.setContext(getValidatorContext()); + getParentUI().setContextValue(validator, OBSERVATION_VALIDATOR_CONTEXT_VALUE); + + ObservationValidatorDataLocator dataLocator = + new ObservationValidatorDataLocator(); + + SwingValidatorUtil.registerListValidator( + validator, + errorTableModel, + table, + errorTable, + dataLocator + ); + + addHightLighterOnEditor( + validator, + table, + dataLocator, + NuitonValidatorScope.ERROR, + NuitonValidatorScope.WARNING + ); + + for (Observation observation : tableModel.getBean()) { + validator.addBean(observation); + } + } + + // Renderers/Editors/Highlighters + { + UIDecoratorService decoratorService = + context.getService(UIDecoratorService.class); + + TableCellRenderer stringRenderer = table.getDefaultRenderer(String.class); + + // ObservationStatus + { + JComboBox comboBox = new JComboBox(ObservationStatus.values()); + table.setDefaultEditor( + ObservationStatus.class, new DefaultCellEditor(comboBox)); + } + + // Position + { + TableCellRenderer renderer; + if (getModel().isValidationMode()) { + renderer = new ObservationPositionCellRenderer( + stringRenderer, decoratorService, ui.getObservationTableModel()); + + } else { + renderer = decoratorService.newTableCellRender(Position.class); + } + + JComboBox comboBox = new JComboBox(); + comboBox.setRenderer(decoratorService.newListCellRender(Position.class)); + SwingUtil.fillComboBox(comboBox, ImmutableList.of( + Position.FRONT_LEFT, Position.NAVIGATOR, Position.FRONT_RIGHT + ), null); + + table.setDefaultRenderer(Position.class, renderer); + table.setDefaultEditor( + Position.class, new DefaultCellEditor(comboBox)); + } + + // CircleBack action + { + int circleBack = ObservationTableModel.ObservationColumn.CIRCLE_BACK.ordinal(); + ButtonActionTableCellEditorRenderer editorRenderer = new ButtonActionTableCellEditorRenderer( + CircleBackAction.CLIENT_PROPERTY_OBSERVATION, + JButton.class, + new Supplier<Action>() { + + @Override + public Action get() { + FlightUIHandler flightUIHandler = getParentUI().getHandler(); + return flightUIHandler.getActionMap().get("circleBack"); + } + }, + null + ); + TableColumnExt column = table.getColumnExt(circleBack); + + column.setSortable(false); + column.setCellEditor(editorRenderer); + column.setCellRenderer(editorRenderer); + } + + table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( + new DeletedRowHighlightPredicate(getModel().getObservations()), + SammoaColors.DELETED_ROW_COLOR) + ); + table.addHighlighter(SammoaUtil.newForegroundColorHighlighter( + new ValidRowHighlightPredicate(getModel().getObservations()), + SammoaColors.VALID_ROW_COLOR) + ); + } + } + + public <T> void init(final JXTable table, + SelectionModelAdapter<T> selectionModelAdapter) { + + final Action moveToNextEditableCell = new MoveToNextEditableCellAction(table); + final Action moveToPreviousEditableCell = new MoveToPreviousEditableCellAction(table); + final Action moveToPreviousRowEditableCell = new MoveToPreviousRowEditableAction(table); + final Action moveToNextRowEditableCell = new MoveToNextRowEditableAction(table); + + // redéfini les comportements par defaut de la table par les notres + table.getActionMap().put("selectNextRowCell", moveToNextEditableCell); + table.getActionMap().put("selectNextColumnCell", moveToNextEditableCell); + table.getActionMap().put("selectNextColumn", moveToNextEditableCell); + table.getActionMap().put("selectPreviousColumn", moveToPreviousEditableCell); + + // Key adapter à ajouter sur les éditeurs où l'on souhaite gérer les + // touches "entrer", "gauche", "doite" de facon personnalisée. + KeyListener goNextCellAdapter = new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER || + e.getKeyCode() == KeyEvent.VK_RIGHT) { + e.consume(); + moveToNextEditableCell.actionPerformed(null); + } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { + e.consume(); + moveToPreviousEditableCell.actionPerformed(null); + } else if (e.getKeyCode() == KeyEvent.VK_UP) { + e.consume(); + moveToPreviousRowEditableCell.actionPerformed(null); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + e.consume(); + moveToNextRowEditableCell.actionPerformed(null); + } + } + }; + + // Text + { + TextCellEditor editor = new TextCellEditor(); + JTextField textField = editor.getComponent(); + textField.addKeyListener(goNextCellAdapter); + textField.setBorder(new LineBorder(Color.GRAY, 2)); +// textField.setBorder(BasicBorders.getTextFieldBorder()); + table.setDefaultEditor(String.class, editor); + } + + // Number + { + NumberCellEditor<Integer> editor = + JAXXWidgetUtil.newNumberTableCellEditor(Integer.class, false); + editor.getNumberEditor().setSelectAllTextOnError(true); + JTextField textField = editor.getNumberEditor().getTextField(); + textField.addKeyListener(goNextCellAdapter); + textField.setBorder(new LineBorder(Color.GRAY, 2)); +// textField.setBorder(BasicBorders.getTextFieldBorder()); + table.setDefaultEditor(int.class, editor); + table.setDefaultEditor(Integer.class, editor); + } + + // Boolean + { + TableCellRenderer renderer = table.getDefaultRenderer(Boolean.class); + table.setDefaultRenderer(boolean.class, renderer); + + TableCellEditor editor = table.getDefaultEditor(Boolean.class); + table.setDefaultEditor(boolean.class, editor); + } + + // Date + { + TableCellRenderer defaultDateCellRenderer = table.getDefaultRenderer(Date.class); + TableCellRenderer renderer = JAXXWidgetUtil.newDateTableCellRenderer( + defaultDateCellRenderer, _("sammoa.timePattern")); + table.setDefaultRenderer(Date.class, renderer); + + JAXXDatePicker datePicker = new JAXXDatePicker(); + datePicker.setShowPopupButton(false); + datePicker.setPatternLayout(_("sammoa.timePattern")); + JTextField textField = datePicker.getEditor(); +// textField.addKeyListener(goNextCellAdapter); + textField.setBorder(new LineBorder(Color.GRAY, 2)); + table.setDefaultEditor(Date.class, new TimeCellEditor(datePicker)); + } + + SammoaUtil.addTableSelectionListener(table, selectionModelAdapter); + + SwingUtil.scrollToTableSelection(table); + } + + protected String getValidatorContext() { + return getModel().isValidationMode() ? "validation" : "onBoard"; + } + + protected void fireObservationsUpdated(Route route, boolean scrollToFirst) { + + FlightUIModel model = getModel(); + + Iterable<Observation> observations = Observations.filterInRoute( + model.getObservations(), route, model.getRoutes(), true); + + SammoaUtil.fireTableRowsUpdated(ui.getObservationTable(), + model.getObservations(), + observations, + scrollToFirst); + } + + protected void fireRoutesUpdated(TransectFlightModel transectFlight, boolean scrollToFirst) { + + Iterable<Route> routes = Iterables.filter( + getModel().getRoutes(), Routes.withTransectFlight(transectFlight.getSource())); + + SammoaUtil.fireTableRowsUpdated(ui.getRouteTable(), + getModel().getRoutes(), + routes, + scrollToFirst); + } + + protected void selectRouteByObservation(Observation observation) { + + Route route = Routes.findWithObservation( + getModel().getRoutes(), observation, true); + + int routeIndex = getModel().indexOfRoutes(route); + ui.getRouteTable().getSelectionModel().setSelectionInterval(routeIndex, routeIndex); + } + + private PropertyChangeListener observationTimeChangeListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + selectRouteByObservation((Observation) evt.getSource()); + } + }; + + private static class ObservationPositionCellRenderer implements TableCellRenderer { + + protected TableCellRenderer delegate; + + protected Decorator<Position> decorator; + + protected ObservationTableModel model; + + public ObservationPositionCellRenderer(TableCellRenderer delegate, + UIDecoratorService decoratorService, + ObservationTableModel model) { + this.delegate = delegate; + this.decorator = decoratorService.getDecoratorByType(Position.class); + this.model = model; + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + + Observation observation = model.getBean(row); + + Route route = Routes.findWithObservation(model.getFlightUIModel().getRoutes(), observation, true); + + ObserverPosition observerPosition = route.getObserverPositionByPosition(observation.getPosition()); + + String newValue = decorator.toString(observation.getPosition()); + if (observerPosition != null && observerPosition.getObserver() != null) { + newValue += " (" + observerPosition.getObserver().getInitials() + ")"; + } + + return delegate.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column); + } + } + + private static class RouteValidatorDataLocator implements SwingListValidatorDataLocator<Route> { + + @Override + public boolean acceptType(Class<?> beanType) { + return Route.class.isAssignableFrom(beanType); + } + + @Override + public Pair<Integer, Integer> locateDataCell(TableModel tableModel, + Route bean, + String fieldName) { + RouteTableModel model = (RouteTableModel) tableModel; + + Pair<Integer, Integer> cell = + model.getCell(bean, fieldName); + return cell; + } + + @Override + public int locateBeanRowIndex(TableModel tableModel, Route bean) { + RouteTableModel model = (RouteTableModel) tableModel; + return model.getBeanIndex(bean); + } + + @Override + public Route locateBean(TableModel tableModel, int rowIndex) { + RouteTableModel model = + (RouteTableModel) tableModel; + return model.getBean(rowIndex); + } + } + + private static class ObservationValidatorDataLocator implements SwingListValidatorDataLocator<Observation> { + + @Override + public boolean acceptType(Class<?> beanType) { + return Observation.class.isAssignableFrom(beanType); + } + + @Override + public Pair<Integer, Integer> locateDataCell(TableModel tableModel, + Observation bean, + String fieldName) { + ObservationTableModel model = (ObservationTableModel) tableModel; + + Pair<Integer, Integer> cell = + model.getCell(bean, fieldName); + return cell; + } + + @Override + public int locateBeanRowIndex(TableModel tableModel, Observation bean) { + ObservationTableModel model = (ObservationTableModel) tableModel; + return model.getBeanIndex(bean); + } + + @Override + public Observation locateBean(TableModel tableModel, int rowIndex) { + ObservationTableModel model = + (ObservationTableModel) tableModel; + return model.getBean(rowIndex); + } + } + +// public static class DeletedRowHighlightPredicate<T extends Deletable> extends AbstractRowHighlightPredicate { +// +// protected FlightUIModel UIModel; +// +// protected Class<T> referenceClass; +// +// public DeletedRowHighlightPredicate(FlightUIModel UIModel, +// Class<T> referenceClass) { +// this.UIModel = UIModel; +// this.referenceClass = referenceClass; +// } +// +// @Override +// protected boolean isHighlighted(int rowIndex) { +// boolean result = getValueAt(rowIndex).isDeleted(); +// return result; +// } +// +// @Override +// protected T getValueAt(int rowIndex) { +// List<T> list; +// if (Route.class.isAssignableFrom(referenceClass)) { +// list = (List<T>) UIModel.getRoutes(); +// +// } else if (Observation.class.isAssignableFrom(referenceClass)) { +// list = (List<T>) UIModel.getObservations(); +// +// } else { +// throw new IllegalStateException("Not supported type " + referenceClass.getName()); +// } +// return list.get(rowIndex); +// } +// } + + public static class RouteForSelectedTransectFlightHighlightPredicate extends AbstractRowHighlightPredicate { + + protected FlightUIModel UIModel; + + public RouteForSelectedTransectFlightHighlightPredicate(FlightUIModel UIModel) { + this.UIModel = UIModel; + } + + @Override + protected boolean isHighlighted(int rowIndex) { + + TransectFlightModel selectedTransectFlight = UIModel.getTransectFlightEditBean(); + + boolean result; + if (selectedTransectFlight != null) { + + Route route = getValueAt(rowIndex); + + result = selectedTransectFlight.getSource().equals(route.getTransectFlight()); + + } else { + result = false; + } + return result; + } + + @Override + protected Route getValueAt(int rowIndex) { + return UIModel.getRoutes().get(rowIndex); + } + } + + public static class ObservationForSelectedRouteHighlightPredicate extends AbstractRowHighlightPredicate { + + protected FlightUIModel UIModel; + + public ObservationForSelectedRouteHighlightPredicate(FlightUIModel UIModel) { + this.UIModel = UIModel; + } + + @Override + protected boolean isHighlighted(int rowIndex) { + + Route selectedRoute = UIModel.getRouteEditBean(); + + boolean result; + if (selectedRoute != null) { + + Observation observation = getValueAt(rowIndex); + + result = Observations.inRoute(observation, selectedRoute, UIModel.getRoutes(), true); + + } else { + result = false; + } + return result; + } + + @Override + protected Observation getValueAt(int rowIndex) { + return UIModel.getObservations().get(rowIndex); + } + } + + public class RouteNoModificationHighlightPredicate extends AbstractRowHighlightPredicate { + + protected RouteTableModel model; + + public RouteNoModificationHighlightPredicate(RouteTableModel model) { + this.model = model; + } + + @Override + protected boolean isHighlighted(int rowIndex) { + + Route route = getValueAt(rowIndex); + + boolean result = false; + + if (route.isDeleted()) { + // do nothing + + } else { + + int previousRouteIndex = rowIndex - 1; + if (previousRouteIndex >= 0) { + + Route previousRoute = getValueAt(previousRouteIndex); + + result = Routes.equal(route, previousRoute); + } + } + return result; + } + + @Override + protected Route getValueAt(int rowIndex) { + return model.getRow(rowIndex); + } + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/ObservationTableModel.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/ObservationTableModel.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/ObservationTableModel.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,266 @@ +/* + * #%L + * SAMMOA :: UI Swing + * * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.effort; + +import com.google.common.base.Strings; +import fr.ulr.sammoa.persistence.Campaign; +import fr.ulr.sammoa.persistence.Flight; +import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.ObservationStatus; +import fr.ulr.sammoa.persistence.Position; +import fr.ulr.sammoa.persistence.Region; +import fr.ulr.sammoa.persistence.Species; +import fr.ulr.sammoa.persistence.SpeciesImpl; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import fr.ulr.sammoa.ui.swing.util.SammoaUtil; +import jaxx.runtime.SwingUtil; +import org.apache.commons.lang3.tuple.Pair; + +import javax.swing.table.AbstractTableModel; +import java.util.Date; +import java.util.List; + +/** @author sletellier <letellier@codelutin.com> */ +public class ObservationTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 1L; + + protected FlightUIModel flightUIModel; + + public ObservationTableModel(FlightUIModel flightUIModel) { + this.flightUIModel = flightUIModel; + } + + @Override + public int getRowCount() { + return getBean().size(); + } + + @Override + public int getColumnCount() { + return ObservationColumn.values().length; + } + + @Override + public String getColumnName(int column) { + ObservationColumn observationColumn = ObservationColumn.valueOf(column); + return observationColumn.getColumnName(); + } + + @Override + public Class<?> getColumnClass(int column) { + ObservationColumn observationColumn = ObservationColumn.valueOf(column); + return observationColumn.getType(); + } + + @Override + public boolean isCellEditable(int row, int column) { + Observation observation = getBean(row); + ObservationColumn observationColumn = ObservationColumn.valueOf(column); + boolean result = observationColumn.isEditable(observation, flightUIModel.isValidationMode()); + return result; + } + + @Override + public Object getValueAt(int row, int column) { + Observation observation = getBean(row); + ObservationColumn observationColumn = ObservationColumn.valueOf(column); + Object result = observationColumn.getValue(observation); + return result; + } + + @Override + public void setValueAt(Object aValue, int row, int column) { + Observation observation = getBean(row); + ObservationColumn observationColumn = ObservationColumn.valueOf(column); + Flight flight = observation.getFlight(); + Campaign campaign = flight.getCampaign(); + Region region = campaign.getRegion(); + observationColumn.setValue(observation, aValue, region); + fireTableRowsUpdated(row, row); + } + + public int getBeanIndex(Observation bean) { + int row = getBean().indexOf(bean); + return row; + } + + public List<Observation> getBean() { + return flightUIModel.getObservations(); + } + + public Observation getBean(int row) { + SwingUtil.ensureRowIndex(this, row); + Observation bean = getBean().get(row); + return bean; + } + + public Pair<Integer, Integer> getCell(Observation bean, String fieldName) { + + int row = getBeanIndex(bean); + int col = ObservationColumn.getValueFromFieldName(fieldName).ordinal(); + + Pair<Integer, Integer> cell = Pair.of(row, col); + return cell; + } + + public FlightUIModel getFlightUIModel() { + return flightUIModel; + } + + public enum ObservationColumn { + + OBSERVATION_NUMBER(false, int.class, Observation.PROPERTY_OBSERVATION_NUMBER), + OBSERVATION_TIME(true, Date.class, Observation.PROPERTY_OBSERVATION_TIME) { + + @Override + public boolean isEditable(Observation bean, boolean validationMode) { + return super.isEditable(bean, validationMode) && validationMode; + } + }, + POSITION(true, Position.class, Observation.PROPERTY_POSITION), + POD_SIZE(true, int.class, Observation.PROPERTY_POD_SIZE), + SPECIES(true, String.class, Observation.PROPERTY_SPECIES, Species.PROPERTY_CODE) { + @Override + public void setValue(Observation bean, Object value, Region region) { + String newValue = (String) value; + + if (!Strings.isNullOrEmpty(newValue)) { + + String oldValue = bean.getSpecies() == null + ? null : bean.getSpecies().getCode(); + + if (!newValue.equals(oldValue)) { + + // Always use a new instance for different value to + // fire change on Observation and not on Species + Species species = new SpeciesImpl((String) value, region); + bean.setSpecies(species); + } + + } else { + bean.setSpecies(null); + } + } + }, + AGE(true, String.class, Observation.PROPERTY_AGE), + DEC_ANGLE(true, int.class, Observation.PROPERTY_DEC_ANGLE), + CUE(true, String.class, Observation.PROPERTY_CUE), + BEHAVIOUR(true, String.class, Observation.PROPERTY_BEHAVIOUR) { + @Override + public void setValue(Observation bean, Object value, Region region) { + String newValue = (String) value; + if (Strings.isNullOrEmpty(newValue)) { + newValue = null; + } + bean.setBehaviour(newValue); + } + }, + SWIM_DIR(true, int.class, Observation.PROPERTY_SWIM_DIR), + CALVES(true, String.class, Observation.PROPERTY_CALVES), + PHOTO(true, boolean.class, Observation.PROPERTY_PHOTO), + COMMENT(true, String.class, Observation.PROPERTY_COMMENT), + OBSERVATION_STATUS(true, ObservationStatus.class, Observation.PROPERTY_OBSERVATION_STATUS), + DELETED(true, boolean.class, Observation.PROPERTY_DELETED), + CIRCLE_BACK(true, Observation.class, "circleBack") { + @Override + public Object getValue(Observation bean) { + return bean; + } + + @Override + public void setValue(Observation bean, Object value, Region region) { + } + }; + + private boolean editable; + + private String[] beanProperties; + + private Class<?> type; + + private final String columnName; + + private ObservationColumn(boolean editable, + Class<?> type, + String... beanProperties) { + this.editable = editable; + this.type = type; + this.beanProperties = beanProperties; + this.columnName = beanProperties[0]; + } + + public Class<?> getType() { + return type; + } + + public String getColumnName() { + return columnName; + } + + public int getColumnIndex() { + return ordinal(); + } + + public Object getValue(Observation bean) { + Object result = SammoaUtil.getPropertyValue(bean, beanProperties); + return result; + } + + public void setValue(Observation bean, Object value, Region region) { + if (type.isPrimitive() && value == null) { + // can not set a null value to a primitive field + } else { + SammoaUtil.setPropertyValue(bean, value, beanProperties); + } + } + + public boolean isEditable(Observation bean, boolean validationMode) { + boolean result = !bean.isValid() && editable; + return result; + } + + public static ObservationColumn valueOf(int ordinal) { + for (ObservationColumn value : values()) { + if (ordinal == value.ordinal()) { + return value; + } + } + throw new EnumConstantNotPresentException(ObservationColumn.class, + "ordinal=" + ordinal); + } + + public static ObservationColumn getValueFromFieldName(String fieldName) { + ObservationColumn result = null; + for (ObservationColumn value : values()) { + if (fieldName.equals(value.columnName)) { + result = value; + break; + } + } + return result; + } + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/ObservationTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,244 @@ +/* + * #%L + * SAMMOA :: UI Swing + * * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ulr.sammoa.ui.swing.flight.effort; + +import fr.ulr.sammoa.persistence.Flight; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.RouteType; +import fr.ulr.sammoa.persistence.Transect; +import fr.ulr.sammoa.persistence.TransectFlight; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import fr.ulr.sammoa.ui.swing.util.SammoaUtil; +import jaxx.runtime.SwingUtil; +import org.apache.commons.lang3.tuple.Pair; + +import javax.swing.table.AbstractTableModel; +import java.util.Date; +import java.util.List; + +/** @author sletellier <letellier@codelutin.com> */ +public class RouteTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 1L; + + protected FlightUIModel flightUIModel; + + public RouteTableModel(FlightUIModel flightUIModel) { + this.flightUIModel = flightUIModel; + } + + @Override + public Class<?> getColumnClass(int column) { + RouteColumn routeColumn = RouteColumn.valueOf(column); + return routeColumn.getType(); + } + + @Override + public int getRowCount() { + return getBean().size(); + } + + public Route getRow(int index) { + return getBean().get(index); + } + + public List<Route> getBean() { + return flightUIModel.getRoutes(); + } + + @Override + public int getColumnCount() { + return RouteColumn.values().length; + } + + @Override + public String getColumnName(int column) { + return RouteColumn.valueOf(column).getColumnName(); + } + + @Override + public boolean isCellEditable(int row, int column) { + Route route = getRow(row); + RouteColumn routeColumn = RouteColumn.valueOf(column); + boolean result = routeColumn.isEditable(route, flightUIModel.isValidationMode()); + return result; + } + + @Override + public Object getValueAt(int row, int column) { + Route route = getRow(row); + RouteColumn routeColumn = RouteColumn.valueOf(column); + Object result = routeColumn.getValue(route, this); + return result; + } + + @Override + public void setValueAt(Object aValue, int row, int column) { + Route route = getRow(row); + RouteColumn routeColumn = RouteColumn.valueOf(column); + routeColumn.setValue(route, aValue); + fireTableRowsUpdated(row, row); + } + + public int getBeanIndex(Route bean) { + int row = getBean().indexOf(bean); + return row; + } + + public Route getBean(int row) { + SwingUtil.ensureRowIndex(this, row); + Route bean = getBean().get(row); + return bean; + } + + public Pair<Integer, Integer> getCell(Route bean, String fieldName) { + + int row = getBeanIndex(bean); + int col = RouteColumn.getValueFromFieldName(fieldName).ordinal(); + + Pair<Integer, Integer> cell = Pair.of(row, col); + return cell; + } + + protected Flight getFlight() { + return flightUIModel.getFlight(); + } + + protected enum RouteColumn { + + EFFORT_NUMBER(false, Integer.class, Route.PROPERTY_EFFORT_NUMBER), + BEGIN_TIME(true, Date.class, Route.PROPERTY_BEGIN_TIME) { + + @Override + public boolean isEditable(Route bean, boolean validationMode) { + return super.isEditable(bean, validationMode) && validationMode; + } + }, + ROUTE_TYPE(false, RouteType.class, Route.PROPERTY_ROUTE_TYPE), + TRANSECT(false, String.class, + Route.PROPERTY_TRANSECT_FLIGHT, + TransectFlight.PROPERTY_TRANSECT, + Transect.PROPERTY_NAME + ) { + @Override + public Object getValue(Route bean, RouteTableModel model) { + Object result; + TransectFlight transectFlight = bean.getTransectFlight(); + if (transectFlight != null) { + + Transect transect = transectFlight.getTransect(); + +// int index = model.getFlight().getTransectFlightIndex(transectFlight); +// result = transect.getName() + " (" + index + ")"; + + int crossingNumber = transectFlight.getCrossingNumber(); + result = transect.getName() + " (" + crossingNumber + ")"; + + } else { + result = null; + } + return result; + } + }, + SEA_STATE(true, int.class, Route.PROPERTY_SEA_STATE), + SWELL(true, int.class, Route.PROPERTY_SWELL), + TURBIDITY(true, int.class, Route.PROPERTY_TURBIDITY), + SKY_GLINT(true, int.class, Route.PROPERTY_SKY_GLINT), + GLARE_FROM(true, Integer.class, Route.PROPERTY_GLARE_FROM), + GLARE_TO(true, Integer.class, Route.PROPERTY_GLARE_TO), + GLARE_SEVERITY(true, int.class, Route.PROPERTY_GLARE_SEVERITY), + GLARE_UNDER(true, boolean.class, Route.PROPERTY_GLARE_UNDER), + CLOUD_COVER(true, int.class, Route.PROPERTY_CLOUD_COVER), + SUBJECTIVE_CONDITIONS(true, String.class, Route.PROPERTY_SUBJECTIVE_CONDITIONS), + UNEXPECTED_LEFT(true, String.class, Route.PROPERTY_UNEXPECTED_LEFT), + UNEXEPECTED_RIGHT(true, String.class, Route.PROPERTY_UNEXPECTED_RIGHT), + COMMENT(true, String.class, Route.PROPERTY_COMMENT), + DELETED(true, boolean.class, Route.PROPERTY_DELETED); + + private final boolean editable; + + private final String[] beanProperties; + + private final Class<?> type; + + private final String columnName; + + private RouteColumn(boolean editable, + Class<?> type, + String... beanProperties) { + this.editable = editable; + this.type = type; + this.beanProperties = beanProperties; + this.columnName = beanProperties[0]; + } + + public Class<?> getType() { + return type; + } + + public String getColumnName() { + return columnName; + } + + public Object getValue(Route bean, RouteTableModel model) { + Object result = SammoaUtil.getPropertyValue(bean, beanProperties); + return result; + } + + public void setValue(Route bean, Object value) { + if (type.isPrimitive() && value == null) { + // can not set a null value to a primitive field + } else { + SammoaUtil.setPropertyValue(bean, value, beanProperties); + } + } + + public boolean isEditable(Route bean, boolean validationMode) { + boolean result = !bean.isValid() && editable; + return result; + } + + public static RouteColumn valueOf(int ordinal) { + for (RouteColumn value : values()) { + if (ordinal == value.ordinal()) { + return value; + } + } + throw new EnumConstantNotPresentException(RouteColumn.class, + "ordinal=" + ordinal); + } + + public static RouteColumn getValueFromFieldName(String fieldName) { + RouteColumn result = null; + for (RouteColumn value : values()) { + if (fieldName.equals(value.columnName)) { + result = value; + break; + } + } + return result; + } + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/SpeciesCodeValidator.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/SpeciesCodeValidator.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/SpeciesCodeValidator.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/SpeciesCodeValidator.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,59 @@ +package fr.ulr.sammoa.ui.swing.flight.effort; +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.opensymphony.xwork2.validator.ValidationException; +import fr.ulr.sammoa.application.ReferentialService; +import fr.ulr.sammoa.application.SammoaContext; +import fr.ulr.sammoa.persistence.Species; +import fr.ulr.sammoa.ui.swing.SammoaUIContext; +import org.nuiton.validator.xwork2.field.CollectionFieldExpressionValidator; + +import java.util.Collection; + +/** + * To validate that a given species use a known {@link Species#getCode()}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.5 + */ +public class SpeciesCodeValidator extends CollectionFieldExpressionValidator { + + protected Collection<Species> species; + + @Override + protected Collection<?> getCollection(Object object) throws ValidationException { + if (species == null) { + SammoaContext appContext = SammoaUIContext.getUIContext().getAppContext(); + species = appContext.getService(ReferentialService.class).getAllValidSpecies(); + } + return species; + } + + @Override + public String getValidatorType() { + return "speciesCode"; + } + +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/SpeciesCodeValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextEditableCellAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextEditableCellAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextEditableCellAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextEditableCellAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,90 @@ +package fr.ulr.sammoa.ui.swing.flight.effort.action; +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.AbstractAction; +import javax.swing.JTable; +import java.awt.event.ActionEvent; + +/** + * Action to edit next editable cell from selected cell. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.5 + */ +public class MoveToNextEditableCellAction extends AbstractAction { + private static final long serialVersionUID = 1L; + + private static final Logger logger = + LoggerFactory.getLogger(MoveToNextEditableCellAction.class); + + protected final JTable table; + + public MoveToNextEditableCellAction(JTable table) { + this.table = table; + } + + + @Override + public void actionPerformed(ActionEvent e) { + int currentRow = table.getSelectedRow(); + int currentColumn = table.getSelectedColumn(); + + logger.debug("Move to next editable cell, {}, {}", currentRow, currentColumn); + + while (currentRow <= table.getRowCount() || currentColumn <= table.getColumnCount()) { + + // go to next cell + currentColumn++; + + // select next cell + if (currentColumn >= table.getColumnCount()) { + currentColumn = 0; + currentRow++; + } + + if (table.isCellEditable(currentRow, currentColumn)) { + doSelectCell(currentRow, currentColumn); +// // select cell +// setColumnSelectionInterval(currentColumn, currentColumn); +// setRowSelectionInterval(currentRow, currentRow); +// editCellAt(currentRow, currentColumn); +// logger.debug("While select cell at {}, {}", currentRow, currentColumn); + break; + } else { + logger.debug("Cell at {}, {} not editable", currentRow, currentColumn); + } + } + } + + protected void doSelectCell(int currentRow, int currentColumn) { + table.setColumnSelectionInterval(currentColumn, currentColumn); + table.setRowSelectionInterval(currentRow, currentRow); + logger.debug("While select cell at {}, {}", currentRow, currentColumn); + table.editCellAt(currentRow, currentColumn); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextEditableCellAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextRowEditableAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextRowEditableAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextRowEditableAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextRowEditableAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,76 @@ +package fr.ulr.sammoa.ui.swing.flight.effort.action; +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.AbstractAction; +import javax.swing.JTable; +import java.awt.event.ActionEvent; + +/** + * Action to edit next row only if selected cell is editable. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.5 + */ +public class MoveToNextRowEditableAction extends AbstractAction { + + private static final long serialVersionUID = 1L; + + private static final Logger logger = LoggerFactory.getLogger(MoveToNextRowEditableAction.class); + + protected final JTable table; + + public MoveToNextRowEditableAction(JTable table) { + this.table = table; + } + + @Override + public void actionPerformed(ActionEvent e) { + int currentRow = table.getSelectedRow(); + int currentColumn = table.getSelectedColumn(); + + if (table.isCellEditable(currentRow, currentColumn)) { + logger.debug("Move to next row editable cell, {}, {}", currentRow, currentColumn); + currentRow++; + + if (currentRow >= table.getRowCount()) { + logger.debug("No next row"); + } else { + doSelectCell(currentRow, currentColumn); + } + } else { + logger.debug("Cell at {}, {} not editable", currentRow, currentColumn); + } + } + + protected void doSelectCell(int currentRow, int currentColumn) { + table.setColumnSelectionInterval(currentColumn, currentColumn); + table.setRowSelectionInterval(currentRow, currentRow); + logger.debug("While select cell at {}, {}", currentRow, currentColumn); + table.editCellAt(currentRow, currentColumn); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToNextRowEditableAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousEditableCellAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousEditableCellAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousEditableCellAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousEditableCellAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,89 @@ +package fr.ulr.sammoa.ui.swing.flight.effort.action; +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.AbstractAction; +import javax.swing.JTable; +import java.awt.event.ActionEvent; + +/** + * Action to edit previous editable cell from selected cell. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.5 + */ +public class MoveToPreviousEditableCellAction extends AbstractAction { + private static final long serialVersionUID = 1L; + + private static final Logger logger = + LoggerFactory.getLogger(MoveToPreviousEditableCellAction.class); + + protected final JTable table; + + public MoveToPreviousEditableCellAction(JTable table) { + this.table = table; + } + + @Override + public void actionPerformed(ActionEvent e) { + int currentRow = table.getSelectedRow(); + int currentColumn = table.getSelectedColumn(); + + logger.debug("Move to previous editable cell, {}, {}", currentRow, currentColumn); + + while (currentRow > 0 || currentColumn > 0) { + + // go to next cell + currentColumn--; + + // select next cell + if (currentColumn < 0) { + currentColumn = table.getColumnCount() - 1; + currentRow--; + } + + if (table.isCellEditable(currentRow, currentColumn)) { + doSelectCell(currentRow, currentColumn); +// // select cell +// setColumnSelectionInterval(currentColumn, currentColumn); +// setRowSelectionInterval(currentRow, currentRow); +// logger.debug("While select cell at {}, {}", currentRow, currentColumn); +// editCellAt(currentRow, currentColumn); + break; + } else { + logger.debug("Cell at {}, {} not editable", currentRow, currentColumn); + } + } + } + + protected void doSelectCell(int currentRow, int currentColumn) { + table.setColumnSelectionInterval(currentColumn, currentColumn); + table.setRowSelectionInterval(currentRow, currentRow); + logger.debug("While select cell at {}, {}", currentRow, currentColumn); + table.editCellAt(currentRow, currentColumn); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousEditableCellAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousRowEditableAction.java (from rev 510, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousRowEditableAction.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousRowEditableAction.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousRowEditableAction.java 2012-09-03 15:47:49 UTC (rev 511) @@ -0,0 +1,76 @@ +package fr.ulr.sammoa.ui.swing.flight.effort.action; +/* + * #%L + * SAMMOA :: UI Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.AbstractAction; +import javax.swing.JTable; +import java.awt.event.ActionEvent; + +/** + * Action to edit previous row only if selected cell is editable. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.5 + */ +public class MoveToPreviousRowEditableAction extends AbstractAction { + private static final long serialVersionUID = 1L; + + private static final Logger logger = LoggerFactory.getLogger(MoveToPreviousRowEditableAction.class); + + protected final JTable table; + + public MoveToPreviousRowEditableAction(JTable table) { + this.table = table; + } + + @Override + public void actionPerformed(ActionEvent e) { + + int currentRow = table.getSelectedRow(); + int currentColumn = table.getSelectedColumn(); + + if (table.isCellEditable(currentRow, currentColumn)) { + logger.debug("Move to previous row editable cell, {}, {}", currentRow, currentColumn); + currentRow--; + + if (currentRow < 0) { + logger.debug("No previous row"); + } else { + doSelectCell(currentRow, currentColumn); + } + } else { + logger.debug("Cell at {}, {} not editable", currentRow, currentColumn); + } + } + + protected void doSelectCell(int currentRow, int currentColumn) { + table.setColumnSelectionInterval(currentColumn, currentColumn); + table.setRowSelectionInterval(currentRow, currentRow); + logger.debug("While select cell at {}, {}", currentRow, currentColumn); + table.editCellAt(currentRow, currentColumn); + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/action/MoveToPreviousRowEditableAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/region/RegionUI.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/region/RegionUI.jaxx 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/region/RegionUI.jaxx 2012-09-03 15:47:49 UTC (rev 511) @@ -27,7 +27,7 @@ implements='fr.ulr.sammoa.ui.swing.SammoaUI<RegionUIHandler>'> <import> - fr.ulr.sammoa.ui.swing.action.CloseAction + fr.ulr.sammoa.ui.swing.CloseAction fr.ulr.sammoa.ui.swing.SammoaUIContext jaxx.runtime.swing.editor.FileEditor Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/transect/TransectUI.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/transect/TransectUI.jaxx 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/transect/TransectUI.jaxx 2012-09-03 15:47:49 UTC (rev 511) @@ -28,7 +28,7 @@ <import> fr.ulr.sammoa.ui.swing.flight.StrateModel - fr.ulr.sammoa.ui.swing.action.CloseAction + fr.ulr.sammoa.ui.swing.CloseAction fr.ulr.sammoa.ui.swing.SammoaUIContext jaxx.runtime.validator.swing.SwingValidatorUtil Modified: trunk/sammoa-ui-swing/src/main/resources/validators.xml =================================================================== --- trunk/sammoa-ui-swing/src/main/resources/validators.xml 2012-09-03 14:57:07 UTC (rev 510) +++ trunk/sammoa-ui-swing/src/main/resources/validators.xml 2012-09-03 15:47:49 UTC (rev 511) @@ -41,7 +41,7 @@ <validator name="fieldexpression" class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/> <validator name="email" class="com.opensymphony.xwork2.validator.validators.EmailValidator"/> - <validator name="speciesCode" class="fr.ulr.sammoa.ui.swing.observations.SpeciesCodeValidator"/> + <validator name="speciesCode" class="fr.ulr.sammoa.ui.swing.flight.effort.SpeciesCodeValidator"/> <validator name="collectionUniqueKey" class="org.nuiton.validator.xwork2.field.CollectionUniqueKeyValidator"/> <!--<validator name="url" class="com.opensymphony.xwork2.validator.validators.URLValidator"/>