r2811 - in isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator: . launcher
Author: chatellier Date: 2009-12-10 14:30:26 +0000 (Thu, 10 Dec 2009) New Revision: 2811 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationControl.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTableModel.java Log: Change progress type from int to long. Update javadoc. Format code. Make xml-rpc only method deprecated. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationControl.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationControl.java 2009-12-10 14:28:48 UTC (rev 2810) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationControl.java 2009-12-10 14:30:26 UTC (rev 2811) @@ -1,6 +1,5 @@ /* *##% - * Copyright (C) 2002 - 2009 Code Lutin, Cédric Pineau, - Benjamin Poussin + * Copyright (C) 2002 - 2009 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -51,18 +50,19 @@ protected PropertyChangeSupport listeners = new PropertyChangeSupport(this); protected boolean inUpdateFromHashtable = false; protected transient SimulationStorage simulation = null; - + protected String id = null; protected boolean started = false; protected boolean running = true; protected boolean stop = false; - protected Date date = new Date(); - protected int progressMax = 0; - protected int progress = 0; + protected Date date; + protected long progressMax = 0; + protected long progress = 0; protected String text = ""; - + + /** @deprecated only used in isis xml-rpc server. */ protected Map<String, Object> update = new Hashtable<String, Object>(); - + /** * * @param id simulation id @@ -79,11 +79,11 @@ started = false; running = true; stop = false; - date = new Date(); + date = null; progressMax = 0; progress = 0; } - + /** * Retourne la simulation associe a ce control * @return retourne null si la simulation n'existe pas encore @@ -94,29 +94,30 @@ } return simulation; } - + public void addPropertyChangeListener(String propName, PropertyChangeListener l) { listeners.addPropertyChangeListener(propName, l); } - + public void addPropertyChangeListener(PropertyChangeListener l) { listeners.addPropertyChangeListener(l); } - - public void removePropertyChangeListener(String propName, PropertyChangeListener l) { + + public void removePropertyChangeListener(String propName, + PropertyChangeListener l) { listeners.removePropertyChangeListener(propName, l); } - + public void removePropertyChangeListener(PropertyChangeListener l) { listeners.removePropertyChangeListener(l); } - + public boolean isStarted() { return started; } - + /** - * appelee juste avant de reellement demarrer le thread de simulation + * Appelee juste avant de reellement demarrer le thread de simulation * indique que cette simulation est en cours et qu'il ne faut plus la lancer * * @param started The running to set. @@ -128,7 +129,7 @@ } /** - * Method running + * Method running. * * @return faux une fois que stopSimulation a ete appele. */ @@ -146,14 +147,14 @@ } /** - * Method startSimulation appele lors du debut de la simulation + * Appele lors du debut de la simulation. */ public void startSimulation() { setRunning(true); } /** - * Method stopSimulation appele lors de la fin reelle de la simulation + * Appele lors de la fin reelle de la simulation. */ public void stopSimulation() { setRunning(false); @@ -165,7 +166,7 @@ public String getText() { return this.text; } - + /** * @param text The text to set. */ @@ -177,53 +178,63 @@ this.text = text; listeners.firePropertyChange("text", oldValue, this.text); } - + /** * @return Returns the progressMax. */ - public int getProgressMax() { + public long getProgressMax() { return this.progressMax; } - + /** - * @param progressMax The progressMax to set. + * Set max progress. + * + * @param progressMax progressMax to set. */ - public void setProgressMax(int progressMax) { - int oldValue = this.progressMax; + public void setProgressMax(long progressMax) { + long oldValue = this.progressMax; this.progressMax = progressMax; listeners.firePropertyChange("progressMax", oldValue, this.progressMax); } - + /** - * @return Returns the progress. + * Get current progress. + * + * @return the progress. */ - public int getProgress() { + public long getProgress() { return this.progress; } - + /** - * @param progress The progress to set. + * Set current progress. + * + * @param progress progress to set. */ - public void setProgress(int progress) { - int oldValue = this.progress; + public void setProgress(long progress) { + long oldValue = this.progress; this.progress = progress; - if(log.isTraceEnabled()) { - log.trace("control fire event 'progress' (" + oldValue + "/" + this.progress); + if (log.isTraceEnabled()) { + log.trace("control fire event 'progress' (" + oldValue + "/" + + this.progress); } listeners.firePropertyChange("progress", oldValue, this.progress); } - + /** - * demande l'arret de la simulation - * @param val + * Demande l'arret de la simulation. + * + * @param val {@code true} to stop */ - public void setStopSimulationRequest(boolean val){ + public void setStopSimulationRequest(boolean val) { boolean oldValue = this.stop; this.stop = val; listeners.firePropertyChange("stop", oldValue, this.stop); } - + /** + * Is stop request been asked. + * * @return retourne vrai si l'arret de la simulation a ete demandee */ public boolean isStopSimulationRequest() { @@ -231,7 +242,7 @@ } /** - * Method getId donne id de la simulation + * Method getId donne id de la simulation. * * @return l'id de la simulation */ @@ -240,39 +251,44 @@ } /** - * Method getDate donne la date utiliser par la simulation + * Method getDate donne la date utiliser par la simulation. * * @return donne la date utiliser par la simulation */ public Date getDate() { return date; } - /** - * Modifie la date de la simulation + * Modifie la date de la simulation. + * * @param d la nouvelle date */ public void setDate(Date d) { - int oldValue = this.date.getDate(); + int oldValue = 0; + if (this.date != null) { + oldValue = this.date.getDate(); + } this.date = d; listeners.firePropertyChange("date", oldValue, this.date.getDate()); } /** * Convert current object in hashtable representation, and clear hashtable - * that contains last modified field + * that contains last modified field. + * * @return object hashtable representation + * @deprecated only used in xml-rpc isis server */ public Hashtable<String, Object> getUpdateHashtable() { Hashtable<String, Object> result = new Hashtable<String, Object>(update); update.clear(); - + result.put("id", getId()); - + return result; } - + /** * Met dans un Properties tous les champs * @return un Properties avec tous les champs @@ -283,14 +299,16 @@ result.setProperty("started", String.valueOf(started)); result.setProperty("running", String.valueOf(running)); result.setProperty("stop", String.valueOf(stop)); - result.setProperty("date", String.valueOf(date.getDate())); + if (date != null) { + result.setProperty("date", String.valueOf(date.getDate())); + } result.setProperty("progressMax", String.valueOf(progressMax)); result.setProperty("progress", String.valueOf(progress)); result.setProperty("text", text); - + return result; } - + /** * update current object from Properties representation * @@ -299,36 +317,41 @@ public void updateFromProperties(Properties props) { inUpdateFromHashtable = true; - if(log.isTraceEnabled()) { + if (log.isTraceEnabled()) { log.trace("updateFromProperties properties = " + props.toString()); } - + // warning : props.contains("started") // seems to not works on properties :( // use containsKey() try { if (props.containsKey("started")) { - boolean started = "true".equalsIgnoreCase(props.getProperty("started")); + boolean started = "true".equalsIgnoreCase(props + .getProperty("started")); setStarted(started); } if (props.containsKey("running")) { - boolean running = "true".equalsIgnoreCase(props.getProperty("running")); + boolean running = "true".equalsIgnoreCase(props + .getProperty("running")); setRunning(running); } if (props.containsKey("stop")) { - boolean stop = "true".equalsIgnoreCase(props.getProperty("stop")); + boolean stop = "true".equalsIgnoreCase(props + .getProperty("stop")); setStopSimulationRequest(stop); } if (props.containsKey("date")) { - Date date = new Date(Integer.parseInt(props.getProperty("date"))); + Date date = new Date(Integer + .parseInt(props.getProperty("date"))); setDate(date); } if (props.containsKey("progressMax")) { - int progressMax = Integer.parseInt(props.getProperty("progressMax")); + long progressMax = Long.parseLong(props + .getProperty("progressMax")); setProgressMax(progressMax); } if (props.containsKey("progress")) { - int progress = Integer.parseInt(props.getProperty("progress")); + long progress = Long.parseLong(props.getProperty("progress")); setProgress(progress); } if (props.containsKey("text")) { @@ -339,41 +362,41 @@ inUpdateFromHashtable = false; } } - - + /** * update current object from hashtable representation - * + * + * @deprecated only used in xml-rpc isis server */ public void updateFromHashtable(Hashtable<String, Object> h) { inUpdateFromHashtable = true; try { if (h.containsKey("started")) { - boolean started = (Boolean)h.get("started"); + boolean started = (Boolean) h.get("started"); setStarted(started); } if (h.containsKey("running")) { - boolean running = (Boolean)h.get("running"); + boolean running = (Boolean) h.get("running"); setRunning(running); } if (h.containsKey("stop")) { - boolean stop = (Boolean)h.get("stop"); + boolean stop = (Boolean) h.get("stop"); setStopSimulationRequest(stop); } if (h.containsKey("date")) { - Date date = new Date((Integer)h.get("date")); + Date date = new Date((Integer) h.get("date")); setDate(date); } if (h.containsKey("progressMax")) { - int progressMax = (Integer)h.get("progressMax"); + long progressMax = (Long) h.get("progressMax"); setProgressMax(progressMax); } if (h.containsKey("progress")) { - int progress = (Integer)h.get("progress"); + long progress = (Long) h.get("progress"); setProgress(progress); } if (h.containsKey("text")) { - String text = (String)h.get("text"); + String text = (String) h.get("text"); setText(text); } } finally { @@ -396,5 +419,5 @@ } } } - + } // SimulationControl Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTableModel.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTableModel.java 2009-12-10 14:28:48 UTC (rev 2810) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTableModel.java 2009-12-10 14:30:26 UTC (rev 2811) @@ -21,19 +21,23 @@ import static org.nuiton.i18n.I18n._; -import fr.ifremer.isisfish.simulator.SimulationControl; -import fr.ifremer.isisfish.simulator.SimulationParameter; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.WeakHashMap; + import javax.swing.JProgressBar; import javax.swing.table.AbstractTableModel; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import fr.ifremer.isisfish.simulator.SimulationControl; +import fr.ifremer.isisfish.simulator.SimulationParameter; +import fr.ifremer.isisfish.types.Date; + /** * Model de table pour suivre l'evolution des differentes simulations en cours. * @@ -248,10 +252,14 @@ break; case 4: JProgressBar pb = getProgressBar(job); - pb.setMaximum(control.getProgressMax()); - pb.setValue(control.getProgress()); - pb.setString(control.getDate().getMonth() + "/" - + control.getDate().getYear()); + pb.setMaximum((int)control.getProgressMax()); + pb.setValue((int)control.getProgress()); + + // progress can be used for other things + Date date = control.getDate(); + if (date != null) { + pb.setString(date.getMonth() + "/" + date.getYear()); + } result = pb; break; }
participants (1)
-
chatellier@users.labs.libre-entreprise.org