r560 - in trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing: . flight flight/action flight/bar flight/bar/onBoard flight/bar/validation flight/effort util
Author: fdesbois Date: 2012-09-07 19:51:00 +0200 (Fri, 07 Sep 2012) New Revision: 560 Url: http://forge.codelutin.com/repositories/revision/sammoa/560 Log: fixes #1466 : remove validationBar from FlightBar, split in two different packages, one for each bar fixes #1468 : set valid buttons labels depends on transect/route/observation in edition Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/DeviceStateLED.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBar.css trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBar.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBarHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBarModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/SoundPlayer.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.css trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/NestedPropertyChangeListener.java Removed: 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/bar/SoundPlayer.java Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java 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/flight/action/BaseFlightAction.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/effort/EffortPanelHandler.java Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java 2012-09-07 17:51:00 UTC (rev 560) @@ -27,25 +27,12 @@ import com.google.common.base.Throwables; import fr.ulr.sammoa.application.device.audio.SammoaAudioReader; import fr.ulr.sammoa.application.device.audio.SammoaAudioRecorder; -import fr.ulr.sammoa.ui.swing.flight.bar.SoundPlayer; +import fr.ulr.sammoa.ui.swing.flight.bar.validation.SoundPlayer; import fr.ulr.sammoa.ui.swing.util.SammoaUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.io.File; -import java.io.IOException; -import java.util.Date; -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.Control; -import javax.sound.sampled.Line; import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.Mixer; -import javax.sound.sampled.Port; -import javax.sound.sampled.UnsupportedAudioFileException; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.ButtonGroup; @@ -56,6 +43,13 @@ import javax.swing.JRadioButton; import javax.swing.JTextArea; import javax.swing.JTextField; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.io.File; +import java.io.IOException; +import java.util.Date; //import javax.media.CannotRealizeException; //import javax.media.NoPlayerException; 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-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx 2012-09-07 17:51:00 UTC (rev 560) @@ -40,7 +40,6 @@ fr.ulr.sammoa.persistence.Observer fr.ulr.sammoa.application.flightController.FlightState fr.ulr.sammoa.ui.swing.SammoaUIContext - fr.ulr.sammoa.ui.swing.flight.bar.FlightBar fr.ulr.sammoa.ui.swing.flight.effort.EffortPanel </import> @@ -189,6 +188,6 @@ </JSplitPane> - <FlightBar id='flightBar' constructorParams='this' constraints='BorderLayout.SOUTH'/> + <JComponent id='flightBar' initializer='getHandler().newFlightBar()' constraints='BorderLayout.SOUTH'/> </JPanel> 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-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-07 17:51:00 UTC (rev 560) @@ -105,6 +105,8 @@ 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.bar.onBoard.OnBoardBar; +import fr.ulr.sammoa.ui.swing.flight.bar.validation.ValidationBar; 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; @@ -680,6 +682,16 @@ } + public JComponent newFlightBar() { + JComponent result; + if (getModel().isValidationMode()) { + result = new ValidationBar(ui); + } else { + result = new OnBoardBar(ui); + } + return result; + } + public ActionMap getActionMap() { return ui.getActionMap(); } Modified: 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/BaseFlightAction.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/BaseFlightAction.java 2012-09-07 17:51:00 UTC (rev 560) @@ -23,15 +23,12 @@ */ package fr.ulr.sammoa.ui.swing.flight.action; -import com.google.common.base.Splitter; 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 fr.ulr.sammoa.ui.swing.util.SammoaUtil; +import fr.ulr.sammoa.ui.swing.util.NestedPropertyChangeListener; import jaxx.runtime.JAXXContext; -import org.jdesktop.beans.AbstractBean; -import org.nuiton.topia.persistence.TopiaEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +36,6 @@ import javax.swing.Icon; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.Iterator; /** * Created: 03/07/12 @@ -86,94 +82,23 @@ protected void bindModelProperties(String... properties) { for (String property : properties) { - EnabledListener enabledListener = new EnabledListener(property); - getModel().addPropertyChangeListener(enabledListener.getProperty(), enabledListener); + bindModelProperty(property, false); } } - protected class EnabledListener implements PropertyChangeListener { + protected void bindModelProperty(String property, boolean all) { + NestedPropertyChangeListener listener = + new NestedPropertyChangeListener(enabledListener, property, all); + listener.init(getModel()); + } - protected String property; + protected PropertyChangeListener enabledListener = new PropertyChangeListener() { - protected EnabledListener embeddedListener; - - public EnabledListener(String property) { - - if (logger.isDebugEnabled()) { - logger.debug("[{}] New EnabledListener for property '{}'", - BaseFlightAction.this.getClass().getSimpleName(), - property); - } - - // Init embeddedListener for nestedProperty - if (property.contains(".")) { - Iterator<String> it = - Splitter.on(".").limit(2).split(property).iterator(); - - // First element is the property - this.property = it.next(); - - // Next property is the nested one - String nestedProperty = it.next(); - if (logger.isDebugEnabled()) { - logger.debug("[{}] Add embedded EnabledListener for " + - "nestedProperty '{}', this EnabledListener " + - "attached to '{}'", - new Object[] { - BaseFlightAction.this.getClass().getSimpleName(), - nestedProperty, - this.property - }); - } - this.embeddedListener = new EnabledListener(nestedProperty); - - // Attach embedded on the current value from model - Object currentValue = - SammoaUtil.getPropertyValue(getModel(), this.property); - attachEmbeddedListener(null, currentValue); - - } else { - this.property = property; - } - } - - public String getProperty() { - return property; - } - @Override public void propertyChange(PropertyChangeEvent evt) { - if (embeddedListener != null) { - attachEmbeddedListener(evt.getOldValue(), evt.getNewValue()); - } setEnabled(checkEnabled()); } + }; - protected void attachEmbeddedListener(Object oldValue, Object newValue) { - - if (oldValue != null) { - if (oldValue instanceof TopiaEntity) { - TopiaEntity entity = (TopiaEntity) oldValue; - entity.removePropertyChangeListener(embeddedListener.getProperty(), embeddedListener); - - } else if (oldValue instanceof AbstractBean) { - AbstractBean entity = (AbstractBean) oldValue; - entity.removePropertyChangeListener(embeddedListener.getProperty(), embeddedListener); - } - } - - if (newValue != null) { - if (newValue instanceof TopiaEntity) { - TopiaEntity entity = (TopiaEntity) newValue; - entity.addPropertyChangeListener(embeddedListener.getProperty(), embeddedListener); - - } else if (newValue instanceof AbstractBean) { - AbstractBean entity = (AbstractBean) newValue; - entity.addPropertyChangeListener(embeddedListener.getProperty(), embeddedListener); - } - } - } - } - protected abstract boolean checkEnabled(); } Modified: 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/ValidAction.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidAction.java 2012-09-07 17:51:00 UTC (rev 560) @@ -33,7 +33,6 @@ import fr.ulr.sammoa.ui.swing.flight.FlightUI; import fr.ulr.sammoa.ui.swing.util.SammoaUtil; import jaxx.runtime.JAXXContext; -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; @@ -54,7 +53,7 @@ protected Map<Class<?>, BeanListValidator<?>> validators = Maps.newHashMap(); public ValidAction(String name, JAXXContext context) { - super(name, Resource.getIcon("/icons/action-tick.png"), context); + super(name, context); } protected ValidationService getValidationService() { Modified: 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/ValidObservationAction.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidObservationAction.java 2012-09-07 17:51:00 UTC (rev 560) @@ -50,7 +50,7 @@ public ValidObservationAction(JAXXContext context) { super(_("sammoa.action.validObservation"), context); putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validObservation.tip")); - bindModelProperties(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN + "." + Observation.PROPERTY_DELETED); + bindModelProperty(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, true); } @Override @@ -82,6 +82,9 @@ @Override protected boolean checkEnabled() { Observation observation = getModel().getObservationEditBean(); + if (observation != null && logger.isDebugEnabled()) { + logger.debug("Check valid observation : {}", Observations.isValid(observation, getObservationValidator())); + } return observation != null && Observations.isValid(observation, getObservationValidator()); } Modified: 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/ValidRouteAction.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java 2012-09-07 17:51:00 UTC (rev 560) @@ -54,8 +54,8 @@ public ValidRouteAction(JAXXContext context) { super(_("sammoa.action.validRoute"), context); putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validRoute.tip")); - bindModelProperties(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN + ".deleted", - FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN + ".deleted"); + bindModelProperty(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, true); + bindModelProperty(FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, true); } @Override Modified: 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/action/ValidTransectAction.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java 2012-09-07 17:51:00 UTC (rev 560) @@ -59,9 +59,9 @@ public ValidTransectAction(JAXXContext context) { super(_("sammoa.action.validTransect"), context); putValue(Action.SHORT_DESCRIPTION, _("sammoa.action.validTransect.tip")); - bindModelProperties(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN + ".deleted", - FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN + ".deleted", - FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN + ".deleted"); + bindModelProperty(FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, true); + bindModelProperty(FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, true); + bindModelProperty(FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, true); } @Override @@ -119,7 +119,6 @@ validatorIsAdjusting = true; Route routeEditBean = getModel().getRouteEditBean(); - getModel().setRouteEditBean(null); // Reload all routes Deleted: 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/DeviceStateLED.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/DeviceStateLED.java 2012-09-07 17:51:00 UTC (rev 560) @@ -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.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; - } -} Deleted: 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.css 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css 2012-09-07 17:51:00 UTC (rev 560) @@ -1,105 +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()}; -} - -#soundPlayer { - enabled: {flightUIModel.getTransectFlightEditBean() != null}; -} Deleted: 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/FlightBar.jaxx 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx 2012-09-07 17:51:00 UTC (rev 560) @@ -1,132 +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 - - 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'> - <SoundPlayer id='soundPlayer'/> - </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/bar/FlightBarHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java 2012-09-07 17:51:00 UTC (rev 560) @@ -1,136 +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.bar; - -import fr.ulr.sammoa.application.device.audio.AudioReader; -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"); - - AudioReader audioReader = flightController.getDeviceManager(AudioReader.class); - ui.getSoundPlayer().setReader(audioReader); - - } 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/bar/FlightBarModel.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarModel.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarModel.java 2012-09-07 17:51:00 UTC (rev 560) @@ -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.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()); - } - } -} Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java 2012-09-07 17:51:00 UTC (rev 560) @@ -1,355 +0,0 @@ -package fr.ulr.sammoa.ui.swing.flight.bar; - -/* - * #%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.device.DeviceState; -import fr.ulr.sammoa.application.device.DeviceStateEvent; -import fr.ulr.sammoa.application.device.DeviceStateListener; -import fr.ulr.sammoa.application.device.audio.AudioPositionListener; -import fr.ulr.sammoa.application.device.audio.AudioReader; -import fr.ulr.sammoa.application.device.audio.SammoaAudioReader; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.FastDateFormat; - -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.UnsupportedAudioFileException; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JSlider; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.Hashtable; - -/** - * Composant qui permet de charge un fichier audio et de le jouer. On peut se - * placer ou l'on veut dans le fichier audio. - * - * usage: - * <li> SoundPlayer sp = new SoundPlayer(); - * <li> panel.add(sp); - * <li> sp.load(myFileWav); - * - * Created: 03 septembre 2012 - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class SoundPlayer extends JComponent implements DeviceStateListener, AudioPositionListener { - protected AudioReader reader; - - // le fichier charge acutellement au niveau de l'ui (config du slider - protected File currentFile; - - // The following fields are for the GUI - protected JButton play; // The Play button - protected JButton stop; // The Stop button - protected JSlider progress; // Shows and sets current position in sound - protected JLabel time; // Displays audioPosition as a number - - protected FastDateFormat dateFormat = FastDateFormat.getInstance("HH:mm"); - protected FastDateFormat longDateFormat = FastDateFormat.getInstance("HH:mm:ss"); - - // Create a SoundPlayer component for the specified file. - public SoundPlayer() { - this(null); - } - - public SoundPlayer(AudioReader reader) { - initUI(); - setReader(reader); - } - - protected void initUI() { - // Now create the basic GUI - play = new JButton("Play"); - play.setEnabled(false); - stop = new JButton("Stop"); - stop.setEnabled(false); - - progress = new JSlider(0, 0, 0); - progress.setMajorTickSpacing(60000); // toutes les 60s - progress.setMinorTickSpacing(10000); // toutes les 10s - progress.setPaintTicks(true); - progress.setPaintLabels(true); - - time = new JLabel("00:00:00"); // Shows position as a # - - // put those controls in a row - Box row = Box.createHorizontalBox(); - - Box buttons = Box.createVerticalBox(); - buttons.add(play); - buttons.add(stop); - - row.add(buttons); - row.add(progress); - - Box timeBox = Box.createVerticalBox(); - timeBox.add(time); - timeBox.add(Box.createVerticalGlue()); - - row.add(timeBox); - - // And add them to this component. - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - this.add(row); - - // ADD LISTENER - - // When clicked, start or stop playing the sound - play.addActionListener(new ActionListener( ) { - public void actionPerformed(ActionEvent e) { - play(); - } - }); - - // When clicked, start or stop playing the sound - stop.addActionListener(new ActionListener( ) { - public void actionPerformed(ActionEvent e) { - stop(); - } - }); - - progress.addMouseListener(new MouseAdapter() { - boolean inPlay = false; - - @Override - public void mousePressed(MouseEvent e) { - inPlay= getAudioReader().getState() == DeviceState.RUNNING; - if (inPlay) { - reader.stop(); - } - } - - @Override - public void mouseReleased(MouseEvent e) { - int value = progress.getValue( ); - // Update the time label -// time.setText(value/1000 + "." + (value%1000)/100); - // If we're not already there, skip there. - if (value >= 0 && value <= reader.getLength()) { - reader.setPosition(value); - } - - if (inPlay) { - reader.start(); - } - } - }); - - // Whenever the slider value changes, update the time label. - progress.addChangeListener(new ChangeListener( ) { - public void stateChanged(ChangeEvent e) { - // changement du text de position - Date date = getAudioReader().getStartDate(); - long start = 0; - if (date != null) { - start = date.getTime(); - } - int value = progress.getValue(); - String timeString = longDateFormat.format(start + value); - time.setText(timeString); - } - }); - } - - @Override - public void stateChanged(DeviceStateEvent event) { - DeviceState state = event.getNewValue(); - switch (state) { - case READY: // on vient de charger un fichier, ou arrete la lecture du fichier - play.setEnabled(true); - stop.setEnabled(false); - progress.setEnabled(true); - changeSliderInfo(); - break; - case RUNNING: // un fichier est en cours de lecture - play.setEnabled(false); - stop.setEnabled(true); - progress.setEnabled(true); - break; - case UNAVAILABLE: // aucun fichier charge - play.setEnabled(false); - stop.setEnabled(false); - progress.setEnabled(false); - changeSliderInfo(); - break; - case ERROR: // erreur sur le lecture audio (erreur I/O) - play.setEnabled(false); - stop.setEnabled(false); - progress.setEnabled(false); - changeSliderInfo(); - break; - } - } - - /** - * On met a la seconde dans le slider - */ - protected void changeSliderInfo() { - Date date = getAudioReader().getStartDate(); - long start = date == null ? 0 : date.getTime(); - - long audioLength = getAudioReader().getLength(); - int max = (int)audioLength; - // si la longueur du morceau change, on change l'info affichee - if (progress.getMaximum() != max) { - progress.setValue((int)getAudioReader().getPosition()); - progress.setMaximum(max); - - // calcul de l'espace entre chaque affichage de l'heure en fonction de la longueur du slider - double width = progress.getSize().getWidth(); - long step = audioLength * 100 / (long)width; // on minimum tous les 100px - step = Math.max(step, 60000); // on prend pas en dessous de la minute - - //Create the label table - Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); - labelTable.put( 0, new JLabel(dateFormat.format(start)) ); - for (int i = (int)step; i+step<max; i+=step) { // on ne met pas l'avant dernier vu qu'on met max ensuite - labelTable.put( i, new JLabel(dateFormat.format(start + i)) ); - } - labelTable.put( max, new JLabel(dateFormat.format(start + audioLength)) ); - progress.setLabelTable( labelTable ); - } - } - - public JButton getPlayButton() { - return play; - } - - public JButton getStopButton() { - return stop; - } - - @Override - public void positionChanged(AudioReader source, long audioPosition) { - // changement de la position du slider - int pos = (int)audioPosition; - progress.setValue(pos); - } - - public void setReader(AudioReader reader) { - if (this.reader != null) { - this.reader.removeAudioPositionListener(this); - this.reader.removeDeviceStateListener(this); - } - this.reader = reader; - if (this.reader != null) { - reader.addDeviceStateListener(this); - reader.addAudioPositionListener(this); - } - - } - - /** - * retourne le lecture utilise par ce composant - * @return - */ - public AudioReader getAudioReader() { - return reader; - } - -// /** -// * Charge un nouveau fichier -// * @param f le fichier a charger -// */ -// public void loadFile(File f) { -// getAudioReader().load(f); -// } -// -// /** -// * Donne la position actuelle de la lecture en milliseconde -// * @return -// */ -// public long getPosition() { -// return getAudioReader().getPosition(); -// } -// -// /** -// * Donne la longueur total du fichier en milliseconde -// * @return -// */ -// public long getLength() { -// return getAudioReader().getLength(); -// } - - /** - * Start playing the sound at the current position - */ - public void play() { - getAudioReader().start(); - } - - /** - * Stop playing the sound, but retain the current position - */ - public void stop() { - getAudioReader().stop(); - } - - // The main method just creates a SoundPlayer in a Frame and displays it - public static void main(String[] args) - throws IOException, UnsupportedAudioFileException, LineUnavailableException { - SoundPlayer player; - - File file; - if (args.length == 0) { - file = new File("/tmp/junkk.wav"); - } else { - file = new File(args[0]); - } - - // Create a SoundPlayer object to play the sound. - player = new SoundPlayer(); - AudioReader reader = new SammoaAudioReader(); - player.setReader(reader); - reader.load(file, new Date()); - - // Put it in a window and play it - JFrame f = new JFrame("SoundPlayer"); - f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - f.getContentPane().add(player, "Center"); - f.pack(); - f.setVisible(true); - } - - public void audioChanged(AudioReader source, long audioLength) { - // A SUPPRIMER - } -} \ No newline at end of file Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/DeviceStateLED.java (from rev 559, 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/onBoard/DeviceStateLED.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/DeviceStateLED.java 2012-09-07 17:51:00 UTC (rev 560) @@ -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.onBoard; + +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/onBoard/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/onBoard/OnBoardBar.css (from rev 559, 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/onBoard/OnBoardBar.css (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBar.css 2012-09-07 17:51:00 UTC (rev 560) @@ -0,0 +1,97 @@ +/* + * #%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()}; +} + +#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/onBoard/OnBoardBar.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBar.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBar.jaxx (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBar.jaxx 2012-09-07 17:51:00 UTC (rev 560) @@ -0,0 +1,104 @@ +<!-- + #%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% + --> +<Table id='stateBar'> + + <import> + javax.swing.BoxLayout + javax.swing.SwingConstants + jaxx.runtime.swing.ClockWidget + + fr.ulr.sammoa.ui.swing.flight.FlightUIModel + </import> + + <script><![CDATA[ + + protected void $afterCompleteSetup() { + getHandler().afterInitUI(); + } + + ]]></script> + + <OnBoardBarHandler id='handler' + constructorParams='this'/> + + <FlightUIModel id='flightUIModel' + initializer='getHandler().getParentUI().getModel()'/> + + <OnBoardBarModel id='model'/> + + <row> + <cell fill='horizontal' weightx='0.2'> + <ClockWidget id='clockTime'/> + </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> Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBar.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/onBoard/OnBoardBarHandler.java (from rev 559, 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/onBoard/OnBoardBarHandler.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBarHandler.java 2012-09-07 17:51:00 UTC (rev 560) @@ -0,0 +1,115 @@ +/* + * #%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.onBoard; + +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.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 OnBoardBarHandler implements PropertyChangeListener { + + private static final Logger logger = + LoggerFactory.getLogger(OnBoardBarHandler.class); + + protected final OnBoardBar ui; + + public OnBoardBarHandler(OnBoardBar ui) { + this.ui = ui; + } + + public FlightUI getParentUI() { + return ui.getContextValue(FlightUI.class, JAXXUtil.PARENT); + } + + protected OnBoardBarModel getModel() { + return ui.getModel(); + } + + public void afterInitUI() { + + FlightUIModel flightUIModel = ui.getFlightUIModel(); + flightUIModel.addPropertyChangeListener(this); + + FlightController flightController = + getParentUI().getHandler().getFlightController(); + + 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/onBoard/OnBoardBarHandler.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/onBoard/OnBoardBarModel.java (from rev 559, 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/bar/onBoard/OnBoardBarModel.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/onBoard/OnBoardBarModel.java 2012-09-07 17:51:00 UTC (rev 560) @@ -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.onBoard; + +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 OnBoardBarModel 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/onBoard/OnBoardBarModel.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/validation/SoundPlayer.java (from rev 559, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/SoundPlayer.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/SoundPlayer.java 2012-09-07 17:51:00 UTC (rev 560) @@ -0,0 +1,354 @@ +package fr.ulr.sammoa.ui.swing.flight.bar.validation; + +/* + * #%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.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import fr.ulr.sammoa.application.device.audio.AudioPositionListener; +import fr.ulr.sammoa.application.device.audio.AudioReader; +import fr.ulr.sammoa.application.device.audio.SammoaAudioReader; +import org.apache.commons.lang3.time.FastDateFormat; + +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JSlider; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.Hashtable; + +/** + * Composant qui permet de charge un fichier audio et de le jouer. On peut se + * placer ou l'on veut dans le fichier audio. + * + * usage: + * <li> SoundPlayer sp = new SoundPlayer(); + * <li> panel.add(sp); + * <li> sp.load(myFileWav); + * + * Created: 03 septembre 2012 + * + * @author Benjamin POUSSIN <poussin@codelutin.com> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class SoundPlayer extends JComponent implements DeviceStateListener, AudioPositionListener { + protected AudioReader reader; + + // le fichier charge acutellement au niveau de l'ui (config du slider + protected File currentFile; + + // The following fields are for the GUI + protected JButton play; // The Play button + protected JButton stop; // The Stop button + protected JSlider progress; // Shows and sets current position in sound + protected JLabel time; // Displays audioPosition as a number + + protected FastDateFormat dateFormat = FastDateFormat.getInstance("HH:mm"); + protected FastDateFormat longDateFormat = FastDateFormat.getInstance("HH:mm:ss"); + + // Create a SoundPlayer component for the specified file. + public SoundPlayer() { + this(null); + } + + public SoundPlayer(AudioReader reader) { + initUI(); + setReader(reader); + } + + protected void initUI() { + // Now create the basic GUI + play = new JButton("Play"); + play.setEnabled(false); + stop = new JButton("Stop"); + stop.setEnabled(false); + + progress = new JSlider(0, 0, 0); + progress.setMajorTickSpacing(60000); // toutes les 60s + progress.setMinorTickSpacing(10000); // toutes les 10s + progress.setPaintTicks(true); + progress.setPaintLabels(true); + + time = new JLabel("00:00:00"); // Shows position as a # + + // put those controls in a row + Box row = Box.createHorizontalBox(); + + Box buttons = Box.createVerticalBox(); + buttons.add(play); + buttons.add(stop); + + row.add(buttons); + row.add(progress); + + Box timeBox = Box.createVerticalBox(); + timeBox.add(time); + timeBox.add(Box.createVerticalGlue()); + + row.add(timeBox); + + // And add them to this component. + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + this.add(row); + + // ADD LISTENER + + // When clicked, start or stop playing the sound + play.addActionListener(new ActionListener( ) { + public void actionPerformed(ActionEvent e) { + play(); + } + }); + + // When clicked, start or stop playing the sound + stop.addActionListener(new ActionListener( ) { + public void actionPerformed(ActionEvent e) { + stop(); + } + }); + + progress.addMouseListener(new MouseAdapter() { + boolean inPlay = false; + + @Override + public void mousePressed(MouseEvent e) { + inPlay= getAudioReader().getState() == DeviceState.RUNNING; + if (inPlay) { + reader.stop(); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + int value = progress.getValue( ); + // Update the time label +// time.setText(value/1000 + "." + (value%1000)/100); + // If we're not already there, skip there. + if (value >= 0 && value <= reader.getLength()) { + reader.setPosition(value); + } + + if (inPlay) { + reader.start(); + } + } + }); + + // Whenever the slider value changes, update the time label. + progress.addChangeListener(new ChangeListener( ) { + public void stateChanged(ChangeEvent e) { + // changement du text de position + Date date = getAudioReader().getStartDate(); + long start = 0; + if (date != null) { + start = date.getTime(); + } + int value = progress.getValue(); + String timeString = longDateFormat.format(start + value); + time.setText(timeString); + } + }); + } + + @Override + public void stateChanged(DeviceStateEvent event) { + DeviceState state = event.getNewValue(); + switch (state) { + case READY: // on vient de charger un fichier, ou arrete la lecture du fichier + play.setEnabled(true); + stop.setEnabled(false); + progress.setEnabled(true); + changeSliderInfo(); + break; + case RUNNING: // un fichier est en cours de lecture + play.setEnabled(false); + stop.setEnabled(true); + progress.setEnabled(true); + break; + case UNAVAILABLE: // aucun fichier charge + play.setEnabled(false); + stop.setEnabled(false); + progress.setEnabled(false); + changeSliderInfo(); + break; + case ERROR: // erreur sur le lecture audio (erreur I/O) + play.setEnabled(false); + stop.setEnabled(false); + progress.setEnabled(false); + changeSliderInfo(); + break; + } + } + + /** + * On met a la seconde dans le slider + */ + protected void changeSliderInfo() { + Date date = getAudioReader().getStartDate(); + long start = date == null ? 0 : date.getTime(); + + long audioLength = getAudioReader().getLength(); + int max = (int)audioLength; + // si la longueur du morceau change, on change l'info affichee + if (progress.getMaximum() != max) { + progress.setValue((int)getAudioReader().getPosition()); + progress.setMaximum(max); + + // calcul de l'espace entre chaque affichage de l'heure en fonction de la longueur du slider + double width = progress.getSize().getWidth(); + long step = audioLength * 100 / (long)width; // on minimum tous les 100px + step = Math.max(step, 60000); // on prend pas en dessous de la minute + + //Create the label table + Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); + labelTable.put( 0, new JLabel(dateFormat.format(start)) ); + for (int i = (int)step; i+step<max; i+=step) { // on ne met pas l'avant dernier vu qu'on met max ensuite + labelTable.put( i, new JLabel(dateFormat.format(start + i)) ); + } + labelTable.put( max, new JLabel(dateFormat.format(start + audioLength)) ); + progress.setLabelTable( labelTable ); + } + } + + public JButton getPlayButton() { + return play; + } + + public JButton getStopButton() { + return stop; + } + + @Override + public void positionChanged(AudioReader source, long audioPosition) { + // changement de la position du slider + int pos = (int)audioPosition; + progress.setValue(pos); + } + + public void setReader(AudioReader reader) { + if (this.reader != null) { + this.reader.removeAudioPositionListener(this); + this.reader.removeDeviceStateListener(this); + } + this.reader = reader; + if (this.reader != null) { + reader.addDeviceStateListener(this); + reader.addAudioPositionListener(this); + } + + } + + /** + * retourne le lecture utilise par ce composant + * @return + */ + public AudioReader getAudioReader() { + return reader; + } + +// /** +// * Charge un nouveau fichier +// * @param f le fichier a charger +// */ +// public void loadFile(File f) { +// getAudioReader().load(f); +// } +// +// /** +// * Donne la position actuelle de la lecture en milliseconde +// * @return +// */ +// public long getPosition() { +// return getAudioReader().getPosition(); +// } +// +// /** +// * Donne la longueur total du fichier en milliseconde +// * @return +// */ +// public long getLength() { +// return getAudioReader().getLength(); +// } + + /** + * Start playing the sound at the current position + */ + public void play() { + getAudioReader().start(); + } + + /** + * Stop playing the sound, but retain the current position + */ + public void stop() { + getAudioReader().stop(); + } + + // The main method just creates a SoundPlayer in a Frame and displays it + public static void main(String[] args) + throws IOException, UnsupportedAudioFileException, LineUnavailableException { + SoundPlayer player; + + File file; + if (args.length == 0) { + file = new File("/tmp/junkk.wav"); + } else { + file = new File(args[0]); + } + + // Create a SoundPlayer object to play the sound. + player = new SoundPlayer(); + AudioReader reader = new SammoaAudioReader(); + player.setReader(reader); + reader.load(file, new Date()); + + // Put it in a window and play it + JFrame f = new JFrame("SoundPlayer"); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.getContentPane().add(player, "Center"); + f.pack(); + f.setVisible(true); + } + + public void audioChanged(AudioReader source, long audioLength) { + // A SUPPRIMER + } +} \ No newline at end of file Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/SoundPlayer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.css =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.css (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.css 2012-09-07 17:51:00 UTC (rev 560) @@ -0,0 +1,39 @@ +/* + * #%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% + */ +#audioTime { + text: {dateFormat.format(model.getCurrentRoute().getBeginTime())}; +} + +#validTransectButton { + _actionName: {"validTransect"}; +} + +#validRouteButton { + _actionName: {"validRoute"}; +} + +#validObservationButton { + _actionName: {"validObservation"}; +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.jaxx (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.jaxx 2012-09-07 17:51:00 UTC (rev 560) @@ -0,0 +1,66 @@ +<!-- + #%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% + --> +<Table id='validationBar'> + + <import> + java.text.SimpleDateFormat + javax.swing.BoxLayout + + fr.ulr.sammoa.ui.swing.flight.FlightUIModel + </import> + + <script><![CDATA[ + + protected void $afterCompleteSetup() { + getHandler().afterInitUI(); + } + + ]]></script> + + <ValidationBarHandler id='handler' + constructorParams='this'/> + + <FlightUIModel id='model' + initializer='getHandler().getParentUI().getModel()'/> + + <SimpleDateFormat id='dateFormat' constructorParams='"dd/MM/yyyy HH:mm:ss"'/> + + <row> + <cell fill='horizontal'> + <JLabel id='audioTime'/> + </cell> + <cell fill='horizontal' weightx='1.5'> + <SoundPlayer id='soundPlayer'/> + </cell> + <cell fill='horizontal' weightx='0.2'> + <JPanel id='validButtonPanel' + layout='{new BoxLayout(validButtonPanel, BoxLayout.X_AXIS)}'> + <JButton id='validTransectButton'/> + <JButton id='validRouteButton'/> + <JButton id='validObservationButton'/> + </JPanel> + </cell> + </row> +</Table> Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBar.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.java 2012-09-07 17:51:00 UTC (rev 560) @@ -0,0 +1,127 @@ +/* + * #%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.validation; + +import fr.ulr.sammoa.application.device.audio.AudioReader; +import fr.ulr.sammoa.application.flightController.FlightController; +import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.ui.swing.flight.FlightUI; +import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; +import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel; +import jaxx.runtime.JAXXUtil; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import static org.nuiton.i18n.I18n._; + +/** @author fdesbois <fdesbois@codelutin.com> */ +public class ValidationBarHandler { + +// private static final Logger logger = +// LoggerFactory.getLogger(ValidationBarHandler.class); + + protected final ValidationBar ui; + + public ValidationBarHandler(ValidationBar ui) { + this.ui = ui; + } + + public FlightUI getParentUI() { + return ui.getContextValue(FlightUI.class, JAXXUtil.PARENT); + } + + protected FlightUIModel getModel() { + return ui.getModel(); + } + + public void afterInitUI() { + + FlightController flightController = + getParentUI().getHandler().getFlightController(); + + AudioReader audioReader = flightController.getDeviceManager(AudioReader.class); + ui.getSoundPlayer().setReader(audioReader); + + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, validTransectListener); + + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, validRouteListener); + + getModel().addPropertyChangeListener( + FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, validObservationListener); + } + + protected PropertyChangeListener validTransectListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + TransectFlightModel newValue = (TransectFlightModel) evt.getNewValue(); + + String text = null; + if (newValue != null) { + text = newValue.getTransect().getSource().getName(); + } + ui.getValidTransectButton().setText(text); + } + }; + + protected PropertyChangeListener validRouteListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + Route newValue = (Route) evt.getNewValue(); + + String text = null; + if (newValue != null) { + text = newValue.getRouteType().name(); + if (newValue.getEffortNumber() != null) { + text += " " + newValue.getEffortNumber(); + } + } + ui.getValidRouteButton().setText(text); + } + }; + + protected PropertyChangeListener validObservationListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + Observation newValue = (Observation) evt.getNewValue(); + + String text = null; + if (newValue != null) { + text = _("sammoa.validable.observation") + + " " + newValue.getObservationNumber(); + } + ui.getValidObservationButton().setText(text); + } + }; +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.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/flight/effort/EffortPanelHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-07 14:42:21 UTC (rev 559) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-07 17:51:00 UTC (rev 560) @@ -368,12 +368,23 @@ 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); + if (route == null) { + // no unselect but ensure valid button (a select will cause a loop) + getModel().setObservationEditBean(null); - // Set audio position - if (route != null) { + } else { + + // Set audio position setAudioReaderPositionDate(route.getBeginTime()); + + // Remove observationEditBean if not in route + Observation previousObservation = getModel().getObservationEditBean(); + if (previousObservation != null + && !Observations.inRoute(previousObservation, route, getModel().getRoutes(), true)) { + + // no unselect but ensure valid button (a select will cause a loop) + getModel().setObservationEditBean(null); + } } } } Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/NestedPropertyChangeListener.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/NestedPropertyChangeListener.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/NestedPropertyChangeListener.java 2012-09-07 17:51:00 UTC (rev 560) @@ -0,0 +1,138 @@ +package fr.ulr.sammoa.ui.swing.util; + +import com.google.common.base.Splitter; +import org.jdesktop.beans.AbstractBean; +import org.nuiton.topia.persistence.TopiaEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Iterator; + +/** + * This listener is used to manage nested properties. (Ex: route.deleted will + * listen on property route and on the property deleted). After instanciation, + * use {@link #init(Object)} method to bind the listener with your own {@code model}. + * Only model {@link TopiaEntity} or {@link AbstractBean} are supported. + * <p/> + * Created: 07/09/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class NestedPropertyChangeListener implements PropertyChangeListener { + + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(NestedPropertyChangeListener.class); + + protected PropertyChangeListener delegate; + + protected String property; + + protected NestedPropertyChangeListener embeddedListener; + + public NestedPropertyChangeListener(PropertyChangeListener delegate, + String property, + boolean all) { + + this.delegate = delegate; + + if (logger.isDebugEnabled()) { + logger.debug("New NestedPropertyChangeListener for property '{}'", + property); + } + + // Init embeddedListener for nestedProperty + if (property != null && property.contains(".")) { + Iterator<String> it = + Splitter.on(".").limit(2).split(property).iterator(); + + // First element is the property + this.property = it.next(); + + // Next property is the nested one + String nestedProperty = it.next(); + this.embeddedListener = new NestedPropertyChangeListener(delegate, nestedProperty, all); + + } else if (all) { + this.property = property; + this.embeddedListener = new NestedPropertyChangeListener(delegate, null, false); + + } else { + this.property = property; + } + } + + public void init(Object model) { + + // Add this NestedPropertyChangeListener on model + addNestedPropertyChangeListener(model, this); + + if (embeddedListener != null) { + + // Init the embedded NestedPropertyChangeListener with + // the propertyValue as model + Object propertyValue = + SammoaUtil.getPropertyValue(model, property); + + embeddedListener.init(propertyValue); + } + } + + public String getProperty() { + return property; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (embeddedListener != null) { + if (evt.getOldValue() != null) { + removeNestedPropertyChangeListener(evt.getOldValue(), embeddedListener); + } + if (evt.getNewValue() != null) { + addNestedPropertyChangeListener(evt.getNewValue(), embeddedListener); + } + } + delegate.propertyChange(evt); + } + + protected void addNestedPropertyChangeListener(Object object, NestedPropertyChangeListener listener) { + String property = listener.getProperty(); + if (object instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) object; + if (property == null) { + entity.addPropertyChangeListener(listener); + } else { + entity.addPropertyChangeListener(property, listener); + } + + } else if (object instanceof AbstractBean) { + AbstractBean entity = (AbstractBean) object; + if (property == null) { + entity.addPropertyChangeListener(listener); + } else { + entity.addPropertyChangeListener(property, listener); + } + } + } + + protected void removeNestedPropertyChangeListener(Object object, NestedPropertyChangeListener listener) { + String property = listener.getProperty(); + if (object instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity) object; + if (property == null) { + entity.removePropertyChangeListener(listener); + } else { + entity.removePropertyChangeListener(property, listener); + } + + } else if (object instanceof AbstractBean) { + AbstractBean entity = (AbstractBean) object; + if (property == null) { + entity.removePropertyChangeListener(listener); + } else { + entity.removePropertyChangeListener(property, listener); + } + } + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/NestedPropertyChangeListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
fdesbois@users.forge.codelutin.com