|
From: <de...@us...> - 2003-10-29 11:41:29
|
Update of /cvsroot/fudaa/fudaa_devel/dodico/src/org/fudaa/dodico/commun
In directory sc8-pr-cvs1:/tmp/cvs-serv13994/commun
Modified Files:
DodicoLib.java ProgressionBuAdapter.java
ProgressionInterface.java
Added Files:
DodicoCmdMngListener.java DodicoCommand.java
DodicoCommandComposite.java DodicoCommandManager.java
Log Message:
Ajout du pattern command pour annuler des operations
--- NEW FILE: DodicoCmdMngListener.java ---
/*
* @file DodicoCmdMngListener.java
* @creation 21 oct. 2003
* @modification $Date: 2003/10/29 11:41:26 $
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.commun;
/**
* @author deniger
* @version $Id: DodicoCmdMngListener.java,v 1.1 2003/10/29 11:41:26 deniger Exp $
*/
public interface DodicoCmdMngListener {
public void undoredoStateChange(DodicoCommandManager _source);
}
--- NEW FILE: DodicoCommand.java ---
/*
* @file DodicoCommand.java
* @creation 20 oct. 2003
* @modification $Date: 2003/10/29 11:41:26 $
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.commun;
/**
* @author deniger
* @version $Id: DodicoCommand.java,v 1.1 2003/10/29 11:41:26 deniger Exp $
*/
public interface DodicoCommand {
public void undo();
public void redo();
}
--- NEW FILE: DodicoCommandComposite.java ---
/*
* @file DodicoCommandComposite.java
* @creation 21 oct. 2003
* @modification $Date: 2003/10/29 11:41:26 $
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.commun;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author deniger
* @version $Id: DodicoCommandComposite.java,v 1.1 2003/10/29 11:41:26 deniger Exp $
*/
public class DodicoCommandComposite implements DodicoCommand {
private List command_;
/**
*
*/
public DodicoCommandComposite() {
super();
}
public boolean isEmpty(){
return ((command_==null) || (command_.size()==0));
}
public void addCmd(DodicoCommand _cmd) {
if (_cmd != null) {
if (command_ == null)
command_= new ArrayList(10);
command_.add(_cmd);
}
}
public void removeCmd(DodicoCommand _cmd) {
if ((command_ != null) && (_cmd != null)) {
command_.remove(_cmd);
}
}
public int getNbCmd() {
return command_ == null ? 0 : command_.size();
}
/**
*
*/
public void undo() {
if (command_ != null) {
int n=command_.size()-1;
for (int i=n-1;i>=0;i--) {
((DodicoCommand)command_.get(i)).undo();
}
}
}
/**
*
*/
public void redo() {
if (command_ != null) {
for (Iterator it= command_.iterator(); it.hasNext();) {
((DodicoCommand)it.next()).redo();
}
}
}
}
--- NEW FILE: DodicoCommandManager.java ---
/*
* @file DodicoCommandManager.java
* @creation 21 oct. 2003
* @modification $Date: 2003/10/29 11:41:26 $
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.commun;
import java.util.LinkedList;
/**
* @author deniger
* @version $Id: DodicoCommandManager.java,v 1.1 2003/10/29 11:41:26 deniger Exp $
*/
public class DodicoCommandManager {
private LinkedList cmd_;
private int nbMaxCommand_=
DodicoPreferences.DODICO.getIntegerProperty("dodico.undo.cmd.nb", 10);
private int indexLastUndoCmd_;
private DodicoCmdMngListener listener_;
private boolean canUndo_;
private boolean canRedo_;
/**
*
*/
public DodicoCommandManager() {}
public DodicoCommandManager(int _maxNb) {
if (_maxNb > 0)
nbMaxCommand_= _maxNb;
}
public void setListener(DodicoCmdMngListener _l) {
if ((_l != null) && (_l != listener_)) {
listener_= _l;
}
}
public void removeListener() {
listener_= null;
}
public void clean(){
if(cmd_!=null) {
cmd_.clear();
indexLastUndoCmd_= 0;
update();
if(listener_!=null) listener_.undoredoStateChange(this);
}
}
public boolean containsCmd(DodicoCommand _c) {
return cmd_.contains(_c);
}
public synchronized void addCmd(DodicoCommand _c) {
if(_c==null) return;
if (cmd_ == null) {
cmd_= new LinkedList();
cmd_.add(_c);
indexLastUndoCmd_= 1;
} else {
//reset undo command
if (indexLastUndoCmd_ != cmd_.size()) {
int nbToRemove= cmd_.size() - indexLastUndoCmd_;
for (int i= nbToRemove; i > 0; i--) {
cmd_.removeLast();
}
}
//add the new command
cmd_.add(_c);
if (indexLastUndoCmd_ > nbMaxCommand_) {
cmd_.removeFirst();
}
indexLastUndoCmd_= cmd_.size();
}
update();
}
public int getNbMaxCmd() {
return nbMaxCommand_;
}
public int getNbCmd() {
return cmd_.size();
}
public boolean isUndo(DodicoCommand _c) {
return isUndo(cmd_.indexOf(_c));
}
public boolean isUndo(int _idx) {
return _idx >= indexLastUndoCmd_;
}
public boolean isACommandUndo() {
return indexLastUndoCmd_ != cmd_.size();
}
private void update() {
boolean change= false;
boolean newValue=
((cmd_ != null) && (cmd_.size() > 0) && (indexLastUndoCmd_ > 0));
if (newValue != canUndo_) {
canUndo_= newValue;
change= true;
}
newValue=
((cmd_ != null)
&& (cmd_.size() > 0)
&& (indexLastUndoCmd_ != cmd_.size()));
if (newValue != canRedo_) {
canRedo_= newValue;
change= true;
}
if (change && (listener_ != null)) {
listener_.undoredoStateChange(this);
}
}
public boolean canUndo() {
return canUndo_;
}
public boolean canRedo() {
return canRedo_;
}
public void undo() {
if (canUndo()) {
((DodicoCommand)cmd_.get(--indexLastUndoCmd_)).undo();
update();
}
}
public void redo() {
if (canRedo()) {
((DodicoCommand)cmd_.get(indexLastUndoCmd_++)).redo();
update();
}
}
}
Index: DodicoLib.java
===================================================================
RCS file: /cvsroot/fudaa/fudaa_devel/dodico/src/org/fudaa/dodico/commun/DodicoLib.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** DodicoLib.java 26 Sep 2003 10:42:08 -0000 1.14
--- DodicoLib.java 29 Oct 2003 11:41:26 -0000 1.15
***************
*** 449,452 ****
--- 449,461 ----
return new File(_baseDir, _path);
}
+
+ public static File getAbsolutePath(File _baseDir, String _path) {
+ File f= new File(_path);
+ if (f.isAbsolute())
+ return f;
+ else
+ return new File(_baseDir, _path);
+ }
+
public static boolean copyFile(File _fileFrom, File _fileTo) {
Index: ProgressionBuAdapter.java
===================================================================
RCS file: /cvsroot/fudaa/fudaa_devel/dodico/src/org/fudaa/dodico/commun/ProgressionBuAdapter.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ProgressionBuAdapter.java 22 Sep 2003 20:47:47 -0000 1.7
--- ProgressionBuAdapter.java 29 Oct 2003 11:41:26 -0000 1.8
***************
*** 1,50 ****
! /*
! * @file ProgressionBuAdapter.java
! * @creation 2002-11-21
! * @modification $Date$
! * @license GNU General Public License 2
! * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
! * @mail de...@fu...
! */
! package org.fudaa.dodico.commun;
!
! import com.memoire.bu.BuTask;
! /**
! * une interface pour mettre a jour la progression.
! *
! * @version $Id$
! * @author Fred Deniger
! */
! public class ProgressionBuAdapter
! implements ProgressionInterface
! {
! private BuTask t_;
!
! public ProgressionBuAdapter()
! {
! this(null);
! }
!
! public ProgressionBuAdapter(BuTask _t)
! {
! t_=_t;
! }
!
! public void setTask(BuTask _t)
! {
! t_=_t;
! }
!
!
! public void setProgression(int _v)
! {
! if(t_!=null) t_.setProgression(_v);
! }
!
! public void setDesc(String _s)
! {
! if(t_!=null) t_.setName(_s);
! }
! }
!
!
--- 1 ----
! /*
* @file ProgressionBuAdapter.java
* @creation 2002-11-21
* @modification $Date$
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.commun;
import com.memoire.bu.BuTask;
/**
* une interface pour mettre a jour la progression.
*
* @version $Id$
* @author Fred Deniger
*/
public class ProgressionBuAdapter implements ProgressionInterface {
private BuTask t_;
public ProgressionBuAdapter() {
this(null);
}
public ProgressionBuAdapter(BuTask _t) {
t_= _t;
}
public void setTask(BuTask _t) {
t_= _t;
}
public void setProgression(int _v) {
if (t_ != null)
t_.setProgression(_v);
}
public void setDesc(String _s) {
if (t_ != null)
t_.setName(_s);
}
}
\ No newline at end of file
Index: ProgressionInterface.java
===================================================================
RCS file: /cvsroot/fudaa/fudaa_devel/dodico/src/org/fudaa/dodico/commun/ProgressionInterface.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ProgressionInterface.java 22 Sep 2003 20:47:47 -0000 1.5
--- ProgressionInterface.java 29 Oct 2003 11:41:26 -0000 1.6
***************
*** 1,23 ****
! /*
! * @file ProgressionInterface.java
! * @creation 2002-11-21
! * @modification $Date$
! * @license GNU General Public License 2
! * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
! * @mail de...@fu...
! */
! package org.fudaa.dodico.commun;
!
! /**
! * une interface pour mettre a jour la progression.
! *
! * @version $Id$
! * @author Fred Deniger
! */
! public interface ProgressionInterface
! {
! void setProgression(int _v);
! void setDesc(String _s);
! }
!
!
--- 1 ----
! /*
* @file ProgressionInterface.java
* @creation 2002-11-21
* @modification $Date$
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.dodico.commun;
/**
* une interface pour mettre a jour la progression.
*
* @version $Id$
* @author Fred Deniger
*/
public interface ProgressionInterface {
void setProgression(int _v);
void setDesc(String _s);
}
\ No newline at end of file
|