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 ?\195?\169critures), afin de permettre que la valeur affichee ne soit pas supprimee des l edition de la cellule. Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-07-16 10:41:16 UTC (rev 3530) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-07-16 17:09:57 UTC (rev 3531) @@ -23,11 +23,13 @@ * #L% */ -import java.awt.Component; -import java.math.BigDecimal; -import javax.swing.JTable; import jaxx.runtime.swing.editor.cell.NumberCellEditor; +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 = row; return super.getTableCellEditorComponent(table, value, isSelected, row, 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 = numberEditor.getTextField().getText().length(); + numberEditor.getTextField().select(length, length); + } + }); + } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java 2012-07-16 10:41:16 UTC (rev 3530) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java 2012-07-16 17:09:57 UTC (rev 3531) @@ -29,13 +29,11 @@ import org.chorem.lima.LimaContext; import org.jdesktop.swingx.JXDatePicker; -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).getClickCount() == 2; } -// public static DateTableCellEditor getInstance() { -// if (editor == null) { -// editor = 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 = datePicker.getEditor().getText().length(); + datePicker.getEditor().select(length, length); } }); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java 2012-07-16 10:41:16 UTC (rev 3530) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.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; -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).getClickCount() == 2; } -// public static EntryBookTableCellEditor getInstance() { -// if (editor == null) { -// editor = new EntryBookTableCellEditor(); -// } -// return editor; -// } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2012-07-16 10:41:16 UTC (rev 3530) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.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; /** * Table des transaction qui ajoute des comportement (keys). @@ -80,7 +83,6 @@ private int y_tab; public FinancialTransactionTable(FinancialTransactionViewHandler handler) { - this.handler = handler; //Change border of cell focus for a better visibility @@ -147,6 +149,7 @@ colorTransaction = new ColorHighlighter(predicate, new Color(255, 198, 209), null); addHighlighter(colorTransaction); + } public FinancialTransactionViewHandler getHandler() { @@ -311,10 +314,18 @@ } } + + //focusEdition(); } } private class MyMouseAdapter extends MouseAdapter { + + /*@Override + public void mouseClicked(MouseEvent e){ + focusEdition(); + }*/ + @Override public void mousePressed(MouseEvent e) { if (rowAtPoint(e.getPoint()) == -1) { @@ -322,4 +333,113 @@ } } } + + //TEST + /*boolean selectAllForActionEvent; + boolean selectAllForMouseEvent; + boolean selectAllForKeyEvent; + + @Override + public boolean editCellAt(int row, int column, EventObject e) { + boolean result = super.editCellAt(row, column, e); + + if (selectAllForMouseEvent || selectAllForActionEvent || selectAllForKeyEvent){ + selectAll(e); + } + + return result; + } + + private void selectAll(EventObject e) { + final Component editor = getEditorComponent(); + + if (editor == null || ! (editor instanceof JTextComponent)){ + return; + } + + if (e == 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 = isSelectAllForMouseEvent; + }*/ + + /* + * Set the Select All property when editing is invoked by the "F2" key + */ + /*public void setSelectAllForActionEvent(boolean isSelectAllForActionEvent) { + selectAllForActionEvent = isSelectAllForActionEvent; + }*/ + + /* + * Set the Select All property when editing is invoked by + * typing directly into the cell + */ + /*public void setSelectAllForKeyEvent(boolean isSelectAllForKeyEvent){ + selectAllForKeyEvent = isSelectAllForKeyEvent; + }*/ + + //FIN TEST + + @Override + public boolean editCellAt(int row, int column, EventObject e) { + boolean result = super.editCellAt(row, column, e); + int lengthCellValue; + if (getEditorComponent() != null) + if (getEditorComponent() instanceof JXDatePicker) { + if (log.isInfoEnabled()) { + log.info("Test sur JXDatePicker"); + } + lengthCellValue = ((JXDatePicker)getEditorComponent()).getEditor().getText().length(); + if (lengthCellValue != -1) { + ((JXDatePicker)getEditorComponent()).getEditor().select(lengthCellValue, lengthCellValue); + } + } else if ( (getEditorComponent() instanceof JTextComponent)) { + if (log.isInfoEnabled()) { + log.info("Test sur JTextComponent / Number editor"); + } + lengthCellValue = ((JTextComponent)getEditorComponent()).getText().length(); + if (lengthCellValue != -1) { + ((JTextComponent)getEditorComponent()).select(lengthCellValue, lengthCellValue); + } + } + return result; + } + }
participants (1)
-
mallon@users.chorem.org