From mallon@users.chorem.org Mon Jul 16 19:09:58 2012
From: mallon@users.chorem.org
To: lima-commits@list.chorem.org
Subject: [Lima-commits] r3531 - in
	trunk/lima-swing/src/main/java/org/chorem/lima/ui: celleditor
	financialtransaction
Date: Mon, 16 Jul 2012 19:09:58 +0200
Message-ID: <20120716170958.0AB765A83B@nuiton.codelutin.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============0787298408664993813=="

--===============0787298408664993813==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Author: mallon
Date: 2012-07-16 19:09:57 +0200 (Mon, 16 Jul 2012)
New Revision: 3531

Url: http://chorem.org/repositories/revision/lima/3531

Log:
fixes #647 Correction sur les editeurs de cellules (Panneau de saisie des ?\1=
95?\169critures), afin de permettre que la valeur affichee ne soit pas suppri=
mee des l edition de la cellule.

Modified:
   trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTab=
leCellEditor.java
   trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCell=
Editor.java
   trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTabl=
eCellEditor.java
   trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/Fin=
ancialTransactionTable.java

Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDec=
imalTableCellEditor.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTa=
bleCellEditor.java	2012-07-16 10:41:16 UTC (rev 3530)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTa=
bleCellEditor.java	2012-07-16 17:09:57 UTC (rev 3531)
@@ -23,11 +23,13 @@
  * #L%
  */
=20
-import java.awt.Component;
-import java.math.BigDecimal;
-import javax.swing.JTable;
 import jaxx.runtime.swing.editor.cell.NumberCellEditor;
=20
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.FocusEvent;
+import java.math.BigDecimal;
+
 /**
  * @author sletellier <letellier@codelutin.com>
  */
@@ -51,4 +53,16 @@
         this.row =3D row;
         return super.getTableCellEditorComponent(table, value, isSelected, r=
ow, column);
     }
+
+    //To stay with old value and just complete it
+    @Override
+    public void focusGained(FocusEvent e) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                numberEditor.getTextField().requestFocus();
+                int length =3D numberEditor.getTextField().getText().length(=
);
+                numberEditor.getTextField().select(length, length);
+            }
+        });
+    }
 }

Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTa=
bleCellEditor.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCel=
lEditor.java	2012-07-16 10:41:16 UTC (rev 3530)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCel=
lEditor.java	2012-07-16 17:09:57 UTC (rev 3531)
@@ -29,13 +29,11 @@
 import org.chorem.lima.LimaContext;
 import org.jdesktop.swingx.JXDatePicker;
=20
-import javax.swing.AbstractCellEditor;
-import javax.swing.JTable;
-import javax.swing.SwingUtilities;
+import javax.swing.*;
 import javax.swing.event.AncestorEvent;
 import javax.swing.event.AncestorListener;
 import javax.swing.table.TableCellEditor;
-import java.awt.Component;
+import java.awt.*;
 import java.awt.event.FocusEvent;
 import java.awt.event.FocusListener;
 import java.awt.event.MouseEvent;
@@ -101,18 +99,14 @@
         return !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCo=
unt() =3D=3D 2;
     }
=20
-//    public static DateTableCellEditor getInstance() {
-//        if (editor =3D=3D null) {
-//            editor =3D new DateTableCellEditor();
-//        }
-//        return editor;
-//    }
-
     /** Listeners */
+    //To stay with old value and just complete it
+    @Override
     public void focusGained(FocusEvent e) {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
-                datePicker.getEditor().selectAll();
+                int length =3D datePicker.getEditor().getText().length();
+                datePicker.getEditor().select(length, length);
             }
         });
     }

Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryB=
ookTableCellEditor.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTab=
leCellEditor.java	2012-07-16 10:41:16 UTC (rev 3530)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTab=
leCellEditor.java	2012-07-16 17:09:57 UTC (rev 3531)
@@ -34,13 +34,10 @@
 import org.chorem.lima.widgets.JWideComboBox;
 import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
=20
-import javax.swing.AbstractCellEditor;
-import javax.swing.JTable;
-import javax.swing.ListCellRenderer;
-import javax.swing.SwingUtilities;
+import javax.swing.*;
 import javax.swing.table.TableCellEditor;
 import javax.swing.text.JTextComponent;
-import java.awt.Component;
+import java.awt.*;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
@@ -141,10 +138,4 @@
         return !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCo=
unt() =3D=3D 2;
     }
=20
-//    public static EntryBookTableCellEditor getInstance() {
-//        if (editor =3D=3D null) {
-//            editor =3D new EntryBookTableCellEditor();
-//        }
-//        return editor;
-//    }
 }

Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransact=
ion/FinancialTransactionTable.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/Fi=
nancialTransactionTable.java	2012-07-16 10:41:16 UTC (rev 3530)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/Fi=
nancialTransactionTable.java	2012-07-16 17:09:57 UTC (rev 3531)
@@ -38,6 +38,7 @@
 import org.chorem.lima.ui.celleditor.DateTableCellEditor;
 import org.chorem.lima.ui.celleditor.EmptyCellRenderer;
 import org.chorem.lima.ui.celleditor.EntryBookTableCellEditor;
+import org.jdesktop.swingx.JXDatePicker;
 import org.jdesktop.swingx.JXTable;
 import org.jdesktop.swingx.decorator.ColorHighlighter;
 import org.jdesktop.swingx.decorator.ComponentAdapter;
@@ -47,6 +48,7 @@
 import javax.swing.*;
 import javax.swing.border.LineBorder;
 import javax.swing.plaf.BorderUIResource;
+import javax.swing.text.JTextComponent;
 import java.awt.*;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
@@ -54,6 +56,7 @@
 import java.awt.event.MouseEvent;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.EventObject;
=20
 /**
  * Table des transaction qui ajoute des comportement (keys).
@@ -80,7 +83,6 @@
     private int y_tab;
=20
     public FinancialTransactionTable(FinancialTransactionViewHandler handler=
) {
-
         this.handler =3D handler;
=20
         //Change border of cell focus for a better visibility
@@ -147,6 +149,7 @@
         colorTransaction =3D
                 new ColorHighlighter(predicate, new Color(255, 198, 209), nu=
ll);
         addHighlighter(colorTransaction);
+
     }
=20
     public FinancialTransactionViewHandler getHandler() {
@@ -311,10 +314,18 @@
=20
                 }
             }
+           =20
+            //focusEdition();
         }
     }
=20
     private class MyMouseAdapter extends MouseAdapter {
+
+        /*@Override
+        public void mouseClicked(MouseEvent e){
+            focusEdition();
+        }*/
+
         @Override
         public void mousePressed(MouseEvent e) {
             if (rowAtPoint(e.getPoint()) =3D=3D -1) {
@@ -322,4 +333,113 @@
             }
         }
     }
+
+    //TEST
+    /*boolean selectAllForActionEvent;
+    boolean selectAllForMouseEvent;
+    boolean selectAllForKeyEvent;
+
+    @Override
+    public boolean editCellAt(int row, int column, EventObject e) {
+        boolean result =3D super.editCellAt(row, column, e);
+
+        if (selectAllForMouseEvent || selectAllForActionEvent || selectAllFo=
rKeyEvent){
+            selectAll(e);
+        }
+
+        return result;
+    }
+
+    private void selectAll(EventObject e) {
+        final Component editor =3D getEditorComponent();
+
+        if (editor =3D=3D null || ! (editor instanceof JTextComponent)){
+            return;
+        }
+
+        if (e =3D=3D null) {
+            ((JTextComponent)editor).selectAll();
+            return;
+        }
+
+        //  Typing in the cell was used to activate the editor
+        if (e instanceof KeyEvent && selectAllForKeyEvent) {
+            ((JTextComponent)editor).selectAll();
+            return;
+        }
+
+        //  F2 was used to activate the editor
+        if (e instanceof ActionEvent && selectAllForActionEvent){
+            ((JTextComponent)editor).selectAll();
+            return;
+        }
+
+        //  A mouse click was used to activate the editor.
+        //  Generally this is a double click and the second mouse click is
+        //  passed to the editor which would remove the text selection unless
+        //  we use the invokeLater()
+        if (e instanceof MouseEvent && selectAllForMouseEvent) {
+            SwingUtilities.invokeLater(new Runnable() {
+                public void run() {
+                    ((JTextComponent)editor).selectAll();
+                }
+            });
+        }
+    }*/
+
+    /*public void setSelectAllForEdit(boolean selectAllForEdit){
+        setSelectAllForMouseEvent( selectAllForEdit );
+        setSelectAllForActionEvent( selectAllForEdit );
+        setSelectAllForKeyEvent( selectAllForEdit );
+    }*/
+
+    /*
+      *  Set the Select All property when editing is invoked by the mouse
+      */
+    /*public void setSelectAllForMouseEvent(boolean isSelectAllForMouseEvent=
){
+        selectAllForMouseEvent =3D isSelectAllForMouseEvent;
+    }*/
+
+    /*
+      *  Set the Select All property when editing is invoked by the "F2" key
+      */
+    /*public void setSelectAllForActionEvent(boolean isSelectAllForActionEve=
nt) {
+        selectAllForActionEvent =3D isSelectAllForActionEvent;
+    }*/
+
+    /*
+      *  Set the Select All property when editing is invoked by
+      *  typing directly into the cell
+      */
+    /*public void setSelectAllForKeyEvent(boolean isSelectAllForKeyEvent){
+        selectAllForKeyEvent =3D isSelectAllForKeyEvent;
+    }*/
+
+    //FIN TEST
+
+    @Override
+    public boolean editCellAt(int row, int column, EventObject e) {
+        boolean result =3D super.editCellAt(row, column, e);
+        int lengthCellValue;
+        if (getEditorComponent() !=3D null)
+        if (getEditorComponent() instanceof JXDatePicker) {
+            if (log.isInfoEnabled()) {
+                log.info("Test sur JXDatePicker");
+            }
+            lengthCellValue =3D ((JXDatePicker)getEditorComponent()).getEdit=
or().getText().length();
+            if (lengthCellValue !=3D -1) {
+                ((JXDatePicker)getEditorComponent()).getEditor().select(leng=
thCellValue, lengthCellValue);
+            }
+        } else if ( (getEditorComponent() instanceof JTextComponent)) {
+                    if (log.isInfoEnabled()) {
+                        log.info("Test sur JTextComponent / Number editor");
+                    }
+                    lengthCellValue =3D ((JTextComponent)getEditorComponent(=
)).getText().length();
+                    if (lengthCellValue !=3D -1) {
+                        ((JTextComponent)getEditorComponent()).select(length=
CellValue, lengthCellValue);
+                    }
+                }
+        return result;
+    }
+
 }


--===============0787298408664993813==--


