|
From: <de...@us...> - 2012-07-18 15:21:59
|
Revision: 7508
http://fudaa.svn.sourceforge.net/fudaa/?rev=7508&view=rev
Author: deniger
Date: 2012-07-18 15:21:48 +0000 (Wed, 18 Jul 2012)
Log Message:
-----------
ajout m?\195?\169thode utilitaires
Modified Paths:
--------------
trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGTableGraphePanel.java
Added Paths:
-----------
trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EgCourbeTransfertHandler.java
Modified: trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGTableGraphePanel.java
===================================================================
--- trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGTableGraphePanel.java 2012-07-18 15:20:28 UTC (rev 7507)
+++ trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGTableGraphePanel.java 2012-07-18 15:21:48 UTC (rev 7508)
@@ -42,8 +42,10 @@
import org.fudaa.ctulu.gui.CtuluLibSwing;
import org.fudaa.ctulu.gui.CtuluSelectionListTableModelUpdater;
import org.fudaa.ctulu.table.CtuluTable;
+import org.fudaa.ebli.commun.EbliActionSimple;
import org.fudaa.ebli.commun.EbliLib;
import org.fudaa.ebli.ressource.EbliResource;
+import org.geotools.math.Statistics;
/**
* Un panneau qui affiche une table de la courbe selectionne par le graphe.
@@ -53,11 +55,26 @@
*/
public class EGTableGraphePanel extends BuPanel implements EGSelectionListener, EGGrapheModelListener {
- class SpecTableModel extends EGTableModel {
+ public static class SpecTableModel extends EGTableModel {
+ private EGTableGraphePanel graphePanel;
Double newX_;
Double newY_;
+ protected int xRowIndex = 0;
+ protected int yRowIndex = 1;
+ public SpecTableModel(EGTableGraphePanel graphePanel) {
+ this.graphePanel = graphePanel;
+ }
+
+ @Override
+ public void fireTableRowsDeleted(int firstRow, int lastRow) {
+ newX_ = null;
+ newY_ = null;
+ super.fireTableRowsDeleted(firstRow, lastRow);
+ }
+
+ @Override
protected void selectedCourbeChanged(final EGCourbe _a) {
newX_ = null;
newY_ = null;
@@ -84,10 +101,12 @@
return CtuluLibString.ESPACE;
}
if (_rowIndex == c_.getModel().getNbValues()) {
- if (_columnIndex == 0) {
+ if (_columnIndex == xRowIndex) {
return newX_ == null ? null : getX(newX_.doubleValue());
}
- return newY_ == null ? null : getY(newY_.doubleValue());
+ if (_columnIndex == yRowIndex) {
+ return newY_ == null ? null : getY(newY_.doubleValue());
+ }
}
return super.getValueAt(_rowIndex, _columnIndex);
}
@@ -104,9 +123,9 @@
if (d == null) {
return;
}
- if (_columnIndex == 0) {
+ if (_columnIndex == xRowIndex) {
newX_ = d;
- } else if (_columnIndex == 1) {
+ } else if (_columnIndex == yRowIndex) {
newY_ = d;
}
if (newX_ != null && newY_ != null) {
@@ -115,12 +134,12 @@
if (r) {
fireTableRowsInserted(0, _rowIndex);
}
- if (!r && lbXyInfo_ != null) {
- lbError_.setText(EbliLib.getS("Point non ajout\xE9 !"));
+ if (!r && graphePanel.lbXyInfo_ != null) {
+ graphePanel.lbError_.setText(EbliLib.getS("Point non ajout\xE9 !"));
new Timer().schedule(new TimerTask() {
public void run() {
- lbError_.setText(CtuluLibString.ESPACE);
+ graphePanel.lbError_.setText(CtuluLibString.ESPACE);
}
}, 3 * 1000);
}
@@ -134,8 +153,8 @@
} else {
super.setValueAt(_value, _rowIndex, _columnIndex);
}
- if (t_.getCellEditor() != null) {
- t_.getCellEditor().cancelCellEditing();
+ if (graphePanel.t_.getCellEditor() != null) {
+ graphePanel.t_.getCellEditor().cancelCellEditing();
}
}
}
@@ -145,17 +164,18 @@
public void actionPerformed(final ActionEvent _e) {
final JTable t = (JTable) _e.getSource();
+ SpecTableModel tableModel = (SpecTableModel) t.getModel();
int row = t.getSelectedRow();
int col = t.getSelectedColumn();
if (t.isEditing()) {
t.getCellEditor().stopCellEditing();
}
- if (col == 1) {
- col = 0;
+ if (col == tableModel.yRowIndex) {
+ col = tableModel.xRowIndex;
row++;
} else {
- col = 1;
+ col = tableModel.yRowIndex;
}
if (row >= t.getRowCount()) {
row = t.getRowCount() - 1;
@@ -194,8 +214,11 @@
*/
public static class EvolTable extends CtuluTable {
+ Action deleteAction;
+
public EvolTable() {
super();
+ setTransferHandler(new EgCourbeTransfertHandler());
}
/**
@@ -204,13 +227,39 @@
*/
public EvolTable(final Object[][] _values, final Object[] _names) {
super(_values, _names);
+ setTransferHandler(new EgCourbeTransfertHandler());
}
/**
+ * @param _model
+ */
+ public EvolTable(final TableModel _model) {
+ super(_model);
+ setTransferHandler(new EgCourbeTransfertHandler());
+ }
+
+ void setDeleteAction(Action deleteAction) {
+ this.deleteAction = deleteAction;
+ }
+
+ protected void delete() {
+ deleteAction.actionPerformed(null);
+ }
+
+ @Override
+ public TransferHandler getTransferHandler() {
+ return super.getTransferHandler();
+ }
+
+ public EGTableModel getEGTableModel() {
+ return (EGTableModel) super.getModel();
+ }
+
+ /**
* @param _tab ArrayList
*/
protected void insertTableInTable(final ArrayList _tab) {
- final EGTableModel model = (EGTableModel) getModel();
+ final EGTableModel model = getEGTableModel();
if (!model.isModelModifiable()) {
return;
}
@@ -218,15 +267,14 @@
int selectedRow = getSelectedRow();
final CtuluDoubleParser doubleParser = new CtuluDoubleParser();
- if ((selectedColumm == -1) || (selectedRow == -1)) {
- selectedColumm = 0;
- selectedRow = 0;
- }
final CtuluCommandComposite cmp = new CtuluCommandComposite();
- final int maxUpdate = updateLines(_tab, model, selectedColumm, selectedRow, doubleParser, cmp);
- if (model.isModelXModifiable() && selectedColumm == 0) {
- addValuesInModel(_tab, model, doubleParser, cmp, maxUpdate);
-
+ if (selectedRow >= 0) {
+ int maxUpdate = updateLines(_tab, model, selectedColumm, selectedRow, doubleParser, cmp);
+ if (model.isModelXModifiable()) {
+ addValuesInModel(_tab, model, doubleParser, cmp, maxUpdate);
+ }
+ } else if (model.isModelXModifiable()) {
+ addValuesInModel(_tab, model, doubleParser, cmp, 0);
}
model.a_.getCmd().addCmd(cmp.getSimplify());
}
@@ -331,17 +379,20 @@
}
return maxUpdate;
}
-
- /**
- * @param _model
- */
- public EvolTable(final TableModel _model) {
- super(_model);
- }
private boolean canEdit_;
+ @Override
protected boolean processKeyBinding(final KeyStroke _ks, final KeyEvent _e, final int _condition,
final boolean _pressed) {
+ Object key = getInputMap(_condition).get(_ks);
+ if (key != null) {
+ Action action = getActionMap().get(key);
+ if (action != null) {
+ return SwingUtilities.notifyAction(action, _ks, _e, this,
+ _e.getModifiers());
+
+ }
+ }
final int keyCode = _ks.getKeyCode();
if (!isEditing() && (keyCode >= KeyEvent.VK_A && keyCode <= KeyEvent.VK_Z) && _pressed) {
return false;
@@ -402,6 +453,10 @@
public EGTableGraphePanel() {
this(true);
}
+
+ public EvolTable getTable() {
+ return t_;
+ }
boolean afficheNomCourbe_ = true;
/**
@@ -440,6 +495,7 @@
return renderer_;
}
};
+ t_.setDeleteAction(getActionDelete());
setDefaultEnterAction(t_);
final BuTextField txt = BuTextField.createDoubleField();
txt.setColumns(10);
@@ -453,7 +509,7 @@
}
});
- t_.setModel(new SpecTableModel());
+ t_.setModel(createValuesTableModel());
t_.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
t_.setCellSelectionEnabled(true);
// t_.getSelectionModel().addListSelectionListener(this);
@@ -473,7 +529,14 @@
setPreferredSize(new Dimension(150, 200));
}
+ protected SpecTableModel createValuesTableModel() {
+ return new SpecTableModel(this);
+ }
+
private void eventReceived() {
+ if (t_.getCellEditor() != null) {
+ t_.getCellEditor().cancelCellEditing();
+ }
if (a_.getSelectedComponent() == null) {
lb_.setText(CtuluLibString.ESPACE);
t_.repaint();
@@ -488,6 +551,7 @@
} else {
nbPoint_ = pt;
(getSpecTableModel()).fireTableRowsDeleted(0, nbPoint_);
+ (getSpecTableModel()).fireTableRowsInserted(0, nbPoint_);
}
}
}
@@ -495,11 +559,12 @@
void updateButtons() {
final EGCourbe c = a_.getSelectedComponent();
if (btAdd_ != null) {
- btAdd_.setEnabled(c != null && c.getModel().isModifiable() && c.getModel().isXModifiable()
+ final boolean modifiable = c != null && c.getModel().isModifiable();
+ btAdd_.setEnabled(modifiable && c.getModel().isXModifiable()
&& selection_.getSelection() != null && selection_.getSelection().getNbSelectedIndex() >= 2);
- btRemove_.setEnabled(c != null && c.getModel().isModifiable() && c.getModel().isXModifiable()
+ btRemove_.setEnabled(modifiable && c.getModel().isXModifiable()
&& selection_.getSelection() != null && (!selection_.getSelection().isEmpty()));
- btAlign_.setEnabled(c != null && c.getModel().isModifiable() && selection_.getSelection() != null
+ btAlign_.setEnabled(modifiable && selection_.getSelection() != null
&& selection_.getSelection().getNbSelectedIndex() >= 2);
}
if (lbXyInfo_ != null) {
@@ -562,7 +627,33 @@
protected void tablePaste() {
t_.paste();
}
+ EbliActionSimple actionDelete;
+ public EbliActionSimple getActionDelete() {
+ if (actionDelete == null) {
+ actionDelete = new DeleteAction();
+ }
+ return actionDelete;
+ }
+
+ public class DeleteAction extends EbliActionSimple {
+
+ public DeleteAction() {
+ super(EbliLib.getS("Supprimer des points"), EbliResource.EBLI.getToolIcon("node-delete"), "REMOVE_POINTS");
+ putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control D"));
+ }
+
+ @Override
+ public void updateStateBeforeShow() {
+ setEnabled(btRemove_.isEnabled());
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent _e) {
+ btRemove_.doClick();
+ }
+ }
+
public void addPanelAction(final EGFillePanel _p) {
// si le contenu n'est pas modifiable ou si les boutons ont deja ete
// initialise on oublie ....
@@ -741,4 +832,4 @@
}
updateButtons();
}
-}
\ No newline at end of file
+}
Added: trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EgCourbeTransfertHandler.java
===================================================================
--- trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EgCourbeTransfertHandler.java (rev 0)
+++ trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EgCourbeTransfertHandler.java 2012-07-18 15:21:48 UTC (rev 7508)
@@ -0,0 +1,51 @@
+package org.fudaa.ebli.courbe;
+
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.InputEvent;
+import javax.swing.JComponent;
+import javax.swing.TransferHandler;
+
+/**
+ *
+ * @author Frederic Deniger
+ */
+public class EgCourbeTransfertHandler extends TransferHandler {
+
+ protected void exportDone(final JComponent _source, final Transferable _data, final int _action) {
+ if (_action == MOVE) {
+ EGTableGraphePanel.EvolTable table = (EGTableGraphePanel.EvolTable) _source;
+ table.delete();
+ } else {
+ super.exportDone(_source, _data, _action);
+ }
+ }
+
+ @Override
+ protected Transferable createTransferable(JComponent c) {
+ EGTableGraphePanel.EvolTable table = (EGTableGraphePanel.EvolTable) c;
+ return table.createTransferable();
+ }
+
+ @Override
+ public boolean canImport(final JComponent _comp, final DataFlavor[] _transferFlavors) {
+ return true;
+ }
+
+ public void exportAsDrag(final JComponent _comp, final InputEvent _e, final int _action) {
+ super.exportAsDrag(_comp, _e, _action);
+ }
+
+ public void exportToClipboard(final JComponent _comp, final Clipboard _clip, final int _action) {
+ super.exportToClipboard(_comp, _clip, _action);
+ }
+
+ public int getSourceActions(final JComponent _c) {
+ EGTableGraphePanel.EvolTable table = (EGTableGraphePanel.EvolTable) _c;
+ if (table.getEGTableModel().isModelXModifiable()) {
+ return COPY_OR_MOVE;
+ }
+ return COPY;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|