Update of /cvsroot/fudaa/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/tableau
In directory sc8-pr-cvs1:/tmp/cvs-serv15821/commun/tableau
Modified Files:
FudaaCellBooleanEditor.java FudaaCellDialogEditor.java
FudaaPanelListEditorModel.java
Log Message:
boundary condition edition for telemac
Index: FudaaCellBooleanEditor.java
===================================================================
RCS file: /cvsroot/fudaa/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/tableau/FudaaCellBooleanEditor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FudaaCellBooleanEditor.java 23 Sep 2003 21:08:06 -0000 1.2
--- FudaaCellBooleanEditor.java 29 Oct 2003 11:54:32 -0000 1.3
***************
*** 1,173 ****
! /*
! * @file TrCellBooleanEditor.java
! * @creation 13 mai 2003
! * @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.fudaa.commun.tableau;
!
! import java.awt.Component;
! import java.awt.event.ActionEvent;
! import java.awt.event.ActionListener;
! import java.awt.event.MouseEvent;
! import java.util.EventObject;
!
! import javax.swing.JTable;
! import javax.swing.event.CellEditorListener;
! import javax.swing.event.ChangeEvent;
! import javax.swing.table.TableCellEditor;
!
! import com.memoire.bu.BuCheckBox;
!
! /**
! * @author deniger
! * @version $Id$
! */
! public class FudaaCellBooleanEditor extends BuCheckBox implements TableCellEditor, ActionListener
! {
! private String trueValue_;
! private String falseValue_;
! private String oldValue_;
! private boolean oldBooleanValue_;
!
! public FudaaCellBooleanEditor()
! {
!
! this("true", "false");
! }
!
! public FudaaCellBooleanEditor(String _trueValue, String _falseValue)
! {
! trueValue_ = _trueValue;
! falseValue_ = _falseValue;
! addActionListener(this);
! setOpaque(true);
! }
!
! /**
! *
! */
! public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
! {
! setValue(value);
! return this;
! }
!
! /**
! *
! */
! public Object getCellEditorValue()
! {
! if (isSelected() == oldBooleanValue_)
! return oldValue_;
! else
! return isSelected() ? trueValue_ : falseValue_;
! }
!
! /**
! *
! */
! public boolean isCellEditable(EventObject anEvent)
! {
! return true;
! }
!
! /**
! *
! */
! public boolean shouldSelectCell(EventObject anEvent)
! {
! if (anEvent instanceof MouseEvent)
! {
! MouseEvent e = (MouseEvent) anEvent;
! return e.getID() != MouseEvent.MOUSE_DRAGGED;
! }
! return true;
! }
!
! /**
! *
! */
! public boolean stopCellEditing()
! {
! Object[] listeners = listenerList.getListenerList();
! for (int i = listeners.length - 2; i >= 0; i -= 2)
! {
! if (listeners[i] == CellEditorListener.class)
! {
! if (changeEvent == null)
! changeEvent = new ChangeEvent(this);
! ((CellEditorListener) listeners[i + 1]).editingStopped(changeEvent);
! }
! }
! return true;
! }
!
! public void setValue(Object _o)
! {
! oldValue_ = (String) _o;
! if (trueValue_ == oldValue_)
! setValue(true);
! else if (falseValue_ == oldValue_)
! setValue(false);
! else
! setValue(getValue(_o));
! }
!
! public boolean getValue(Object value)
! {
! return Boolean.getBoolean(value.toString());
! }
!
! public void setValue(boolean _b)
! {
! setSelected(_b);
! oldBooleanValue_ = _b;
! }
!
! /**
! *
! */
! public void cancelCellEditing()
! {
! Object[] listeners = listenerList.getListenerList();
! for (int i = listeners.length - 2; i >= 0; i -= 2)
! {
! if (listeners[i] == CellEditorListener.class)
! {
! if (changeEvent == null)
! changeEvent = new ChangeEvent(this);
! ((CellEditorListener) listeners[i + 1]).editingCanceled(changeEvent);
! }
! }
! }
!
! /**
! *
! */
! public void addCellEditorListener(CellEditorListener l)
! {
!
! listenerList.add(CellEditorListener.class, l);
! }
!
! /**
! *
! */
! public void removeCellEditorListener(CellEditorListener l)
! {
! listenerList.remove(CellEditorListener.class, l);
!
! }
!
! /**
! *
! */
! public void actionPerformed(ActionEvent e)
! {
! stopCellEditing();
! }
!
! }
--- 1 ----
! /*
* @file TrCellBooleanEditor.java
* @creation 13 mai 2003
* @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.fudaa.commun.tableau;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.EventObject;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.TableCellEditor;
import com.memoire.bu.BuCheckBox;
/**
* @author deniger
* @version $Id$
*/
public class FudaaCellBooleanEditor extends DefaultCellEditor {
public FudaaCellBooleanEditor() {
super(new BuCheckBox());
final JCheckBox ch= ((JCheckBox)editorComponent);
delegate= new EditorDelegate() {
public void setValue(Object value) {
ch.setSelected(getBooleanValue(value));
}
public Object getCellEditorValue() {
return getObjectValue(ch.isSelected());
}
};
}
public boolean getBooleanValue(Object _o) {
if (_o instanceof Boolean) {
return ((Boolean)_o).booleanValue();
} else if (_o instanceof String) {
return _o.equals("true");
}
return false;
}
public Object getObjectValue(boolean _o) {
return _o?Boolean.TRUE:Boolean.FALSE;
}
}
\ No newline at end of file
Index: FudaaCellDialogEditor.java
===================================================================
RCS file: /cvsroot/fudaa/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/tableau/FudaaCellDialogEditor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FudaaCellDialogEditor.java 23 Sep 2003 21:08:06 -0000 1.2
--- FudaaCellDialogEditor.java 29 Oct 2003 11:54:32 -0000 1.3
***************
*** 1,219 ****
! /*
! * @file TrCellDialogEditor.java
! * @creation 13 mai 2003
! * @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.fudaa.commun.tableau;
!
! import java.awt.Component;
! import java.awt.event.ActionEvent;
! import java.awt.event.ActionListener;
! import java.awt.event.MouseEvent;
! import java.awt.event.MouseListener;
! import java.util.EventObject;
!
! import javax.swing.DefaultCellEditor;
! import javax.swing.JButton;
! import javax.swing.JOptionPane;
! import javax.swing.JTable;
! import javax.swing.SwingUtilities;
! import javax.swing.UIManager;
! import javax.swing.event.CellEditorListener;
! import javax.swing.event.ChangeEvent;
! import javax.swing.table.DefaultTableCellRenderer;
! import javax.swing.table.TableCellEditor;
!
! import com.memoire.bu.BuButton;
!
! import org.fudaa.ebli.dialog.EbliSimpleDialogPanel;
!
! /**
! * @author deniger
! * @version $Id$
! */
! public class FudaaCellDialogEditor extends JButton implements TableCellEditor, ActionListener
! {
! protected EbliSimpleDialogPanel dialog_;
! private transient ChangeEvent changeEvent = null;
! private FudaaCellDecorator decorator_;
! private Object value_;
! private boolean doubleClick_;
!
! public FudaaCellDialogEditor(EbliSimpleDialogPanel _dialog)
! {
! this(_dialog, null);
! }
!
! public FudaaCellDialogEditor(EbliSimpleDialogPanel _dialog, FudaaCellDecorator _deco)
! {
! setOpaque(false);
! setEnabled(true);
! addActionListener(this);
! decorator_ = _deco;
! setBorder(UIManager.getBorder("Label.border"));
! setFont(UIManager.getFont("Table.font"));
! setHorizontalAlignment(0);
! dialog_ = _dialog;
! }
!
! /**
! *
! */
! public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
! {
! value_ = value;
! setValue(value);
! if (decorator_ != null)
! decorator_.decore(this, table, value, row, column);
! return this;
! }
!
! public void setValue(Object _o)
! {
! setText(_o.toString());
! }
!
! /**
! *
! */
! public Object getCellEditorValue()
! {
! return value_;
! }
!
! /**
! *
! */
! public boolean isCellEditable(EventObject anEvent)
! {
! if(!doubleClick_) return true;
! if (anEvent instanceof MouseEvent)
! {
! return ((MouseEvent) anEvent).getClickCount() >= 2;
! }
! return true;
! }
!
! /**
! *
! */
! public boolean shouldSelectCell(EventObject anEvent)
! {
! return true;
! }
!
! /**
! *
! */
! public void cancelCellEditing()
! {
! Object[] listeners = listenerList.getListenerList();
! for (int i = listeners.length - 2; i >= 0; i -= 2)
! {
! if (listeners[i] == CellEditorListener.class)
! {
! if (changeEvent == null)
! changeEvent = new ChangeEvent(this);
! ((CellEditorListener) listeners[i + 1]).editingCanceled(changeEvent);
! }
! }
! }
!
! /**
! *
! */
! public void addCellEditorListener(CellEditorListener l)
! {
!
! listenerList.add(CellEditorListener.class, l);
! }
!
! /**
! *
! */
! public void removeCellEditorListener(CellEditorListener l)
! {
! listenerList.remove(CellEditorListener.class, l);
!
! }
! public boolean stopCellEditing()
! {
! Object[] listeners = listenerList.getListenerList();
! for (int i = listeners.length - 2; i >= 0; i -= 2)
! {
! if (listeners[i] == CellEditorListener.class)
! {
! if (changeEvent == null)
! changeEvent = new ChangeEvent(this);
! ((CellEditorListener) listeners[i + 1]).editingStopped(changeEvent);
! }
! }
! return false;
! }
!
! private void go()
! {
! dialog_.setValue(value_);
! dialog_.doLayout();
! int r = dialog_.afficheModale(this);
! if (EbliSimpleDialogPanel.isOkResponse(r))
! {
! value_=dialog_.getValue();
! setValue(value_);
! stopCellEditing();
! }
! else
! cancelCellEditing();
! if (getParent() != null)
! {
! getParent().requestFocus();
! }
!
! // }
!
! }
!
! /**
! *
! */
! public void actionPerformed(ActionEvent _ae)
! {
! go();
! }
!
! /**
! *
! */
! public FudaaCellDecorator getDecorator()
! {
! return decorator_;
! }
!
! /**
! *
! */
! public void setDecorator(FudaaCellDecorator _decorator)
! {
! decorator_ = _decorator;
! }
!
! /**
! *
! */
! public boolean isDoubleClick()
! {
! return doubleClick_;
! }
!
! /**
! *
! */
! public void setDoubleClick(boolean _b)
! {
! doubleClick_ = _b;
! }
!
! }
--- 1 ----
! /*
* @file TrCellDialogEditor.java
* @creation 13 mai 2003
* @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.fudaa.commun.tableau;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.EventObject;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellEditor;
import com.memoire.bu.BuButton;
import org.fudaa.ebli.dialog.EbliSimpleDialogPanel;
/**
* @author deniger
* @version $Id$
*/
public class FudaaCellDialogEditor
extends JButton
implements TableCellEditor, ActionListener {
protected EbliSimpleDialogPanel dialog_;
private transient ChangeEvent changeEvent= null;
private FudaaCellDecorator decorator_;
private Object value_;
private boolean doubleClick_;
public FudaaCellDialogEditor(EbliSimpleDialogPanel _dialog) {
this(_dialog, null);
}
public FudaaCellDialogEditor(
EbliSimpleDialogPanel _dialog,
FudaaCellDecorator _deco) {
setOpaque(false);
setEnabled(true);
addActionListener(this);
decorator_= _deco;
setBorder(UIManager.getBorder("Label.border"));
setFont(UIManager.getFont("Table.font"));
setHorizontalAlignment(0);
dialog_= _dialog;
}
/**
*
*/
public Component getTableCellEditorComponent(
JTable table,
Object value,
boolean isSelected,
int row,
int column) {
value_= value;
setValue(value);
if (decorator_ != null)
decorator_.decore(this, table, value, row, column);
return this;
}
public void setValue(Object _o) {
setText(_o.toString());
}
/**
*
*/
public Object getCellEditorValue() {
return value_;
}
/**
*
*/
public boolean isCellEditable(EventObject anEvent) {
if (!doubleClick_)
return true;
if (anEvent instanceof MouseEvent) {
return ((MouseEvent)anEvent).getClickCount() >= 2;
}
return true;
}
/**
*
*/
public boolean shouldSelectCell(EventObject anEvent) {
return true;
}
/**
*
*/
public void cancelCellEditing() {
Object[] listeners= listenerList.getListenerList();
for (int i= listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == CellEditorListener.class) {
if (changeEvent == null)
changeEvent= new ChangeEvent(this);
((CellEditorListener)listeners[i + 1]).editingCanceled(changeEvent);
}
}
}
/**
*
*/
public void addCellEditorListener(CellEditorListener l) {
listenerList.add(CellEditorListener.class, l);
}
/**
*
*/
public void removeCellEditorListener(CellEditorListener l) {
listenerList.remove(CellEditorListener.class, l);
}
public boolean stopCellEditing() {
Object[] listeners= listenerList.getListenerList();
for (int i= listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == CellEditorListener.class) {
if (changeEvent == null)
changeEvent= new ChangeEvent(this);
((CellEditorListener)listeners[i + 1]).editingStopped(changeEvent);
}
}
return false;
}
private void go() {
dialog_.setValue(value_);
dialog_.doLayout();
int r= dialog_.afficheModale(this);
if (EbliSimpleDialogPanel.isOkResponse(r)) {
value_= dialog_.getValue();
setValue(value_);
stopCellEditing();
} else
cancelCellEditing();
if (getParent() != null) {
getParent().requestFocus();
}
// }
}
/**
*
*/
public void actionPerformed(ActionEvent _ae) {
go();
}
/**
*
*/
public FudaaCellDecorator getDecorator() {
return decorator_;
}
/**
*
*/
public void setDecorator(FudaaCellDecorator _decorator) {
decorator_= _decorator;
}
/**
*
*/
public boolean isDoubleClick() {
return doubleClick_;
}
/**
*
*/
public void setDoubleClick(boolean _b) {
doubleClick_= _b;
}
}
\ No newline at end of file
Index: FudaaPanelListEditorModel.java
===================================================================
RCS file: /cvsroot/fudaa/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/tableau/FudaaPanelListEditorModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FudaaPanelListEditorModel.java 23 Sep 2003 21:08:07 -0000 1.2
--- FudaaPanelListEditorModel.java 29 Oct 2003 11:54:32 -0000 1.3
***************
*** 1,431 ****
! /*
! * @file FudaaListSelectionModelDefault.java
! * @creation 28 mai 2003
! * @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.fudaa.commun.tableau;
!
! import java.util.Arrays;
! import java.util.Collections;
! import java.util.List;
! import java.util.Vector;
!
! import javax.swing.AbstractListModel;
! import javax.swing.ComboBoxModel;
! import javax.swing.ListSelectionModel;
! import javax.swing.MutableComboBoxModel;
! import javax.swing.table.AbstractTableModel;
!
! import org.fudaa.dodico.commun.DodicoLib;
!
! /**
! * Le model attache au panel FudaaPanelListEditor.
! * @author deniger
! * @version $Id$
! */
! public class FudaaPanelListEditorModel extends AbstractTableModel {
!
! Vector v_;
! private boolean showNumber_;
! private int maxValueNb_;
! Vector proposedValues_;
! Object defaultValue_;
!
! public FudaaPanelListEditorModel() {
! this(-1);
! }
!
! public FudaaPanelListEditorModel(boolean _showNumber) {
! this(Collections.EMPTY_LIST, _showNumber, -1);
! }
!
! public FudaaPanelListEditorModel(int _maxNumber) {
! this(new Vector(_maxNumber > 0 ? _maxNumber : 10), false, _maxNumber);
! }
!
! /**
! * @param _l la liste des elements initiaux
! * @param _showNumber si true la premiere colonne affiche le num de ligne
! */
! public FudaaPanelListEditorModel(List _l, boolean _showNumber) {
! this(_l, _showNumber, -1);
! }
!
! public FudaaPanelListEditorModel(
! List _l,
! boolean _showNumber,
! int _maxNbValue) {
! this(new Vector(_l), _showNumber, _maxNbValue);
! }
!
! /**
! * @param _o tableau des elements initiaux
! * @param _showNumber si true la premiere colonne affiche le num de ligne
! */
! public FudaaPanelListEditorModel(Object[] _o, boolean _showNumber) {
! this(Arrays.asList(_o), _showNumber, -1);
! }
!
! public FudaaPanelListEditorModel(
! Object[] _o,
! boolean _showNumber,
! int _maxNbValue) {
! this(new Vector(Arrays.asList(_o)), _showNumber, _maxNbValue);
! }
!
! private FudaaPanelListEditorModel(
! Vector _v,
! boolean _showNumber,
! int _maxValueNb) {
! v_= _v;
! maxValueNb_= _maxValueNb;
! if ((maxValueNb_ > 0) && (v_.size() > _maxValueNb)) {
! v_.setSize(maxValueNb_);
! }
! showNumber_= _showNumber;
! defaultValue_=DodicoLib.EMPTY_STRING;
! }
!
! public void remove(ListSelectionModel _m) {
! if ((_m.isSelectionEmpty()) || (!canRemove()))
! return;
! int min= _m.getMinSelectionIndex();
! int max= _m.getMaxSelectionIndex();
! max= max >= v_.size() ? v_.size() - 1 : max;
! for (int i= max; i >= min; i--) {
! if (_m.isSelectedIndex(i)) {
! v_.remove(i);
! }
!
! }
! fireTableRowsDeleted(min, max);
! }
!
! public void addElement(Object _o) {
! if (canAdd()) {
! v_.add(_o);
! fireTableRowsInserted(v_.size() - 1, v_.size() - 1);
! }
! }
!
! public void getValues(Object[] _o) {
! v_.toArray(_o);
! }
!
! public Object[] getValues() {
! return v_.toArray();
! }
!
! public boolean canAdd() {
! return ((maxValueNb_ < 0) || (v_.size() < maxValueNb_));
! }
!
! public boolean canRemove() {
! return v_.size() > 0;
! }
!
! public void add(int _i, Object _o) {
! if (canAdd()) {
! v_.add(_i, _o);
! fireTableRowsInserted(_i, _i);
! }
! }
!
! public boolean isEmpty() {
! return v_.isEmpty();
! }
!
! /**
! *
! */
! public int getColumnCount() {
! return showNumber_ ? 2 : 1;
! }
!
! /**
! *
! */
! public int getRowCount() {
! return v_.size();
! }
!
! /**
! *
! */
! public Object getValueAt(int _row, int _col) {
! if (showNumber_) {
! if (_col == 0)
! return DodicoLib.getString(_row + 1);
! else if (_col == 1)
! return v_.get(_row);
! } else if (_col == 0) {
! return v_.get(_row);
! }
! return null;
! }
!
! public int getIndexOf(Object _o) {
! return v_.indexOf(_o);
! }
!
! public Object getValueAt(int _i) {
! if ((_i >= 0) && (_i < v_.size())) {
! return v_.get(_i);
! } else
! return null;
!
! }
!
! /**
! *
! */
! public boolean isCellEditable(int rowIndex, int columnIndex) {
! return showNumber_ ? (columnIndex == 1 ? true : false) : true;
! }
!
! /**
! *
! */
! public Class getColumnClass(int columnIndex) {
! return String.class;
! }
!
! /**
! *
! */
! public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
! v_.set(rowIndex, aValue);
! }
!
! /**
! * @return
! */
! public boolean isShowNumber() {
! return showNumber_;
! }
!
! public void setData(Object[] _o) {
! v_.removeAllElements();
! if (_o != null) {
!
! int n= _o.length;
! if (maxValueNb_ > 0) {
! n= n > maxValueNb_ ? maxValueNb_ : n;
! }
! v_.ensureCapacity(n);
! for (int i= 0; i < n; i++) {
! v_.add(_o[i]);
! }
! }
! fireTableDataChanged();
! }
!
! /**
! *
! */
! public int getMaxValueNb() {
! return maxValueNb_;
! }
!
! /**
! *
! */
! public void setMaxValueNb(int _i) {
! if (_i != maxValueNb_) {
! maxValueNb_= _i;
! int n= v_.size();
! if ((maxValueNb_ > 0) && (v_.size() > maxValueNb_)) {
! v_.setSize(maxValueNb_);
! fireTableRowsDeleted(maxValueNb_, n - 1);
! }
! }
! }
!
! public void setProposedValues(Object[] _o) {
! if (_o == null)
! return;
!
! else {
! if (proposedValues_ == null) {
!
! proposedValues_= new Vector(_o.length);
! } else {
! proposedValues_.clear();
! proposedValues_.ensureCapacity(_o.length);
! }
! int n= _o.length;
! for (int i= 0; i < n; i++) {
! proposedValues_.add(_o[i]);
! }
! }
! }
!
! public void setProposedValue(Object _o) {
! if (_o == null)
! return;
!
! else {
! if (proposedValues_ == null) {
!
! proposedValues_= new Vector(10);
! } else {
! proposedValues_.clear();
! proposedValues_.ensureCapacity(10);
! }
! proposedValues_.add(_o);
! }
! }
!
! public void addProposedValue(Object _o) {
! if (_o == null)
! return;
! if (proposedValues_ == null)
! setProposedValue(_o);
! else
! proposedValues_.add(_o);
! }
!
! public void addProposedValuesIfNotPresent(Object[] _o) {
! if (_o == null)
! return;
! if (proposedValues_ == null)
! setProposedValues(_o);
! else {
! int n= _o.length;
! for (int i= 0; i < n; i++) {
! if ((_o[i] != null) && (!proposedValues_.contains(_o[i])))
! proposedValues_.add(_o[i]);
! }
! }
! }
!
! public void addProposedValues(Object[] _o) {
! if (_o == null)
! return;
! if (proposedValues_ == null)
! setProposedValues(_o);
! else {
! int n= _o.length;
! for (int i= 0; i < n; i++) {
! if (_o[i] != null)
! proposedValues_.add(_o[i]);
! }
! }
! }
!
! public void emptyProposedValue() {
! if (proposedValues_ != null)
! proposedValues_.clear();
! }
!
! public boolean isProposedValueEmpty() {
! return proposedValues_ == null ? true : proposedValues_.isEmpty();
! }
!
! public void setDefaultValue(Object _o){
! defaultValue_=_o;
! }
!
! public Object createNewObject() {
! return defaultValue_;
! }
!
! public boolean actionAdd() {
! int n= v_.size();
! if ((maxValueNb_ > 0) && (n == maxValueNb_)) {
! return false;
! }
! if ((proposedValues_ != null) && (n < proposedValues_.size())) {
! addElement(proposedValues_.get(n));
! } else {
! Object o= createNewObject();
! if (o == null)
! return false;
! else
! addElement(o);
! }
! return true;
! }
!
! public boolean actionInserer(int _r) {
! int n= v_.size();
! if ((maxValueNb_ > 0) && (n == maxValueNb_)) {
! return false;
! }
! if ((proposedValues_ != null) && (_r < proposedValues_.size())) {
! add(_r, proposedValues_.get(_r));
! } else {
! Object o= createNewObject();
! if (o == null)
! return false;
! else
! add(_r, o);
! }
! return true;
! }
!
! public int getValueNb() {
! return v_.size();
! }
!
! public List getValuesInList() {
! return new Vector(v_);
! }
!
! /**
! *
! */
! public String getColumnName(int column) {
! return DodicoLib.EMPTY_STRING;
! }
!
! /**
! * Renvoie une model correspondant Attention ce model n'envoie pas d'evenements si le model
! * englobant est modifie;
! */
! public ComboBoxModel createComboBoxModel() {
! return new ListEditorComboBoxModel();
! }
!
! public class ListEditorComboBoxModel
! extends AbstractListModel
! implements ComboBoxModel {
!
! private Object selected_;
!
! public Object getElementAt(int _i) {
! return v_.get(_i);
! }
!
! public int getSize() {
! return v_.size();
! }
!
! public void update() {
! fireContentsChanged(this, 0, getSize());
! }
!
! /**
! *
! */
! public Object getSelectedItem() {
! return selected_;
! }
!
! /**
! *
! */
! public void setSelectedItem(Object anItem) {
! if ((selected_ == null && anItem != null)
! || (selected_ != null && !selected_.equals(anItem))) {
! selected_= anItem;
! fireContentsChanged(this, -1, -1);
! }
! }
!
! };
!
! }
--- 1 ----
! /*
* @file FudaaListSelectionModelDefault.java
* @creation 28 mai 2003
* @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.fudaa.commun.tableau;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.ListSelectionModel;
import javax.swing.MutableComboBoxModel;
import javax.swing.table.AbstractTableModel;
import org.fudaa.dodico.commun.DodicoLib;
/**
* Le model attache au panel FudaaPanelListEditor.
* @author deniger
* @version $Id$
*/
public class FudaaPanelListEditorModel extends AbstractTableModel {
Vector v_;
private boolean showNumber_;
private int maxValueNb_;
Vector proposedValues_;
Object defaultValue_;
public FudaaPanelListEditorModel() {
this(-1);
}
public FudaaPanelListEditorModel(boolean _showNumber) {
this(Collections.EMPTY_LIST, _showNumber, -1);
}
public FudaaPanelListEditorModel(int _maxNumber) {
this(new Vector(_maxNumber > 0 ? _maxNumber : 10), false, _maxNumber);
}
/**
* @param _l la liste des elements initiaux
* @param _showNumber si true la premiere colonne affiche le num de ligne
*/
public FudaaPanelListEditorModel(List _l, boolean _showNumber) {
this(_l, _showNumber, -1);
}
public FudaaPanelListEditorModel(
List _l,
boolean _showNumber,
int _maxNbValue) {
this(new Vector(_l), _showNumber, _maxNbValue);
}
/**
* @param _o tableau des elements initiaux
* @param _showNumber si true la premiere colonne affiche le num de ligne
*/
public FudaaPanelListEditorModel(Object[] _o, boolean _showNumber) {
this(Arrays.asList(_o), _showNumber, -1);
}
public FudaaPanelListEditorModel(
Object[] _o,
boolean _showNumber,
int _maxNbValue) {
this(new Vector(Arrays.asList(_o)), _showNumber, _maxNbValue);
}
private FudaaPanelListEditorModel(
Vector _v,
boolean _showNumber,
int _maxValueNb) {
v_= _v;
maxValueNb_= _maxValueNb;
if ((maxValueNb_ > 0) && (v_.size() > _maxValueNb)) {
v_.setSize(maxValueNb_);
}
showNumber_= _showNumber;
defaultValue_= DodicoLib.EMPTY_STRING;
}
public void remove(ListSelectionModel _m) {
if ((_m.isSelectionEmpty()) || (!canRemove()))
return;
int min= _m.getMinSelectionIndex();
int max= _m.getMaxSelectionIndex();
max= max >= v_.size() ? v_.size() - 1 : max;
for (int i= max; i >= min; i--) {
if (_m.isSelectedIndex(i)) {
v_.remove(i);
}
}
fireTableRowsDeleted(min, max);
}
public void addElement(Object _o) {
if (canAdd()) {
v_.add(_o);
fireTableRowsInserted(v_.size() - 1, v_.size() - 1);
}
}
public void getValues(Object[] _o) {
v_.toArray(_o);
}
public Object[] getValues() {
return v_.toArray();
}
public boolean canAdd() {
return ((maxValueNb_ < 0) || (v_.size() < maxValueNb_));
}
public boolean canRemove() {
return v_.size() > 0;
}
public void add(int _i, Object _o) {
if (canAdd()) {
v_.add(_i, _o);
fireTableRowsInserted(_i, _i);
}
}
public boolean isEmpty() {
return v_.isEmpty();
}
/**
*
*/
public int getColumnCount() {
return showNumber_ ? 2 : 1;
}
/**
*
*/
public int getRowCount() {
return v_.size();
}
/**
*
*/
public Object getValueAt(int _row, int _col) {
if (showNumber_) {
if (_col == 0)
return DodicoLib.getString(_row + 1);
else if (_col == 1)
return v_.get(_row);
} else if (_col == 0) {
return v_.get(_row);
}
return null;
}
public int getIndexOf(Object _o) {
return v_.indexOf(_o);
}
public Object getValueAt(int _i) {
if ((_i >= 0) && (_i < v_.size())) {
return v_.get(_i);
} else
return null;
}
/**
*
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
return showNumber_ ? (columnIndex == 1 ? true : false) : true;
}
/**
*
*/
public Class getColumnClass(int columnIndex) {
return String.class;
}
/**
*
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
v_.set(rowIndex, aValue);
}
/**
* @return
*/
public boolean isShowNumber() {
return showNumber_;
}
public void setData(Object[] _o) {
v_.removeAllElements();
if (_o != null) {
int n= _o.length;
if (maxValueNb_ > 0) {
n= n > maxValueNb_ ? maxValueNb_ : n;
}
v_.ensureCapacity(n);
for (int i= 0; i < n; i++) {
v_.add(_o[i]);
}
}
fireTableDataChanged();
}
/**
*
*/
public int getMaxValueNb() {
return maxValueNb_;
}
/**
*
*/
public void setMaxValueNb(int _i) {
if (_i != maxValueNb_) {
maxValueNb_= _i;
int n= v_.size();
if ((maxValueNb_ > 0) && (v_.size() > maxValueNb_)) {
v_.setSize(maxValueNb_);
fireTableRowsDeleted(maxValueNb_, n - 1);
}
}
}
public void setProposedValues(Object[] _o) {
if (_o == null)
return;
else {
if (proposedValues_ == null) {
proposedValues_= new Vector(_o.length);
} else {
proposedValues_.clear();
proposedValues_.ensureCapacity(_o.length);
}
int n= _o.length;
for (int i= 0; i < n; i++) {
proposedValues_.add(_o[i]);
}
}
}
public void setProposedValue(Object _o) {
if (_o == null)
return;
else {
if (proposedValues_ == null) {
proposedValues_= new Vector(10);
} else {
proposedValues_.clear();
proposedValues_.ensureCapacity(10);
}
proposedValues_.add(_o);
}
}
public void addProposedValue(Object _o) {
if (_o == null)
return;
if (proposedValues_ == null)
setProposedValue(_o);
else
proposedValues_.add(_o);
}
public void addProposedValuesIfNotPresent(Object[] _o) {
if (_o == null)
return;
if (proposedValues_ == null)
setProposedValues(_o);
else {
int n= _o.length;
for (int i= 0; i < n; i++) {
if ((_o[i] != null) && (!proposedValues_.contains(_o[i])))
proposedValues_.add(_o[i]);
}
}
}
public void addProposedValues(Object[] _o) {
if (_o == null)
return;
if (proposedValues_ == null)
setProposedValues(_o);
else {
int n= _o.length;
for (int i= 0; i < n; i++) {
if (_o[i] != null)
proposedValues_.add(_o[i]);
}
}
}
public void emptyProposedValue() {
if (proposedValues_ != null)
proposedValues_.clear();
}
public boolean isProposedValueEmpty() {
return proposedValues_ == null ? true : proposedValues_.isEmpty();
}
public void setDefaultValue(Object _o) {
defaultValue_= _o;
}
public Object createNewObject() {
return defaultValue_;
}
public boolean actionAdd() {
int n= v_.size();
if ((maxValueNb_ > 0) && (n == maxValueNb_)) {
return false;
}
if ((proposedValues_ != null) && (n < proposedValues_.size())) {
addElement(proposedValues_.get(n));
} else {
Object o= createNewObject();
if (o == null)
return false;
else
addElement(o);
}
return true;
}
public boolean actionInserer(int _r) {
int n= v_.size();
if ((maxValueNb_ > 0) && (n == maxValueNb_)) {
return false;
}
if ((proposedValues_ != null) && (_r < proposedValues_.size())) {
add(_r, proposedValues_.get(_r));
} else {
Object o= createNewObject();
if (o == null)
return false;
else
add(_r, o);
}
return true;
}
public int getValueNb() {
return v_.size();
}
public List getValuesInList() {
return new Vector(v_);
}
/**
*
*/
public String getColumnName(int column) {
return DodicoLib.EMPTY_STRING;
}
/**
* Renvoie une model correspondant Attention ce model n'envoie pas d'evenements si le model
* englobant est modifie;
*/
public ComboBoxModel createComboBoxModel() {
return new ListEditorComboBoxModel();
}
public class ListEditorComboBoxModel
extends AbstractListModel
implements ComboBoxModel {
private Object selected_;
public Object getElementAt(int _i) {
return v_.get(_i);
}
public int getSize() {
return v_.size();
}
public void update() {
fireContentsChanged(this, 0, getSize());
}
/**
*
*/
public Object getSelectedItem() {
return selected_;
}
/**
*
*/
public void setSelectedItem(Object anItem) {
if ((selected_ == null && anItem != null)
|| (selected_ != null && !selected_.equals(anItem))) {
selected_= anItem;
fireContentsChanged(this, -1, -1);
}
}
};
}
\ No newline at end of file
|