This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jaxx. See http://git.nuiton.org/jaxx.git commit 0c75922def8a8f43b1438cb0fc76b229870e1ca0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Nov 23 12:55:49 2014 +0100 fixes #3504: Be able to select default value of options fixes #3505: Add an action to reset to default value --- .../jaxx/runtime/swing/config/ConfigCategoryUI.css | 23 +++ .../runtime/swing/config/ConfigCategoryUI.jaxx | 8 +- .../swing/config/ConfigCategoryUIHandler.java | 154 ++++++++++++++++++++- .../resources/i18n/jaxx-config_en_GB.properties | 4 + .../resources/i18n/jaxx-config_es_ES.properties | 4 + .../resources/i18n/jaxx-config_fr_FR.properties | 5 + .../main/resources/icons/action-config-copy.png | Bin 0 -> 309 bytes .../resources/icons/action-config-reset-option.png | Bin 0 -> 396 bytes .../src/main/java/jaxx/runtime/JAXXUtil.java | 18 +++ 9 files changed, 213 insertions(+), 3 deletions(-) diff --git a/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUI.css b/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUI.css index 01fa45d..c2d9493 100644 --- a/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUI.css +++ b/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUI.css @@ -48,6 +48,7 @@ autoCreateRowSorter:true; autoResizeMode:{JXTable.AUTO_RESIZE_ALL_COLUMNS}; rowHeight:25; + selectionModel:{selectionModel}; } #reset{ @@ -63,3 +64,25 @@ actionIcon:"config-save"; enabled:{getCategoryModel().isModified() && getCategoryModel().isValid()}; } + +#tableToolBar { + floatable: false; + opaque: false; + borderPainted: false; +} + +#tablePopup { + label: "config.table.actions"; +} + +#copyCellValue{ + text:"config.action.copyCellValue"; + toolTipText:"config.action.copyCellValue.tip"; + actionIcon:"config-copy"; +} + +#resetOptionValue{ + text:"config.action.resetOptionValue"; + toolTipText:"config.action.resetOptionValue.tip"; + actionIcon:"config-reset-option"; +} diff --git a/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUI.jaxx b/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUI.jaxx index ffc61d9..4a75bed 100644 --- a/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUI.jaxx +++ b/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUI.jaxx @@ -62,8 +62,7 @@ void $afterCompleteSetup() { <!-- table of options --> <JScrollPane id='tablePane' constraints='BorderLayout.CENTER'> - <JXTable id="table" constructorParams='tableModel' - selectionModel='{selectionModel}'/> + <JXTable id="table" constructorParams='tableModel' onMousePressed='handler.openTablePopupMenu(event, tablePopup)'/> </JScrollPane> <JPanel layout='{new BorderLayout()}' constraints='BorderLayout.SOUTH'> @@ -80,4 +79,9 @@ void $afterCompleteSetup() { <JButton id='save' onActionPerformed='model.saveModified()'/> </JPanel> </JPanel> + + <JPopupMenu id='tablePopup'> + <JMenuItem id='copyCellValue' onActionPerformed='handler.copyCellValue()'/> + <JMenuItem id='resetOptionValue' onActionPerformed='handler.resetOptionValue()'/> + </JPopupMenu> </JPanel> diff --git a/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUIHandler.java b/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUIHandler.java index c4fadfc..ee4b318 100644 --- a/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUIHandler.java +++ b/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigCategoryUIHandler.java @@ -22,22 +22,32 @@ package jaxx.runtime.swing.config; * #L% */ +import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.config.model.ConfigTableModel; import jaxx.runtime.swing.config.model.OptionModel; import jaxx.runtime.swing.renderer.ClassTableCellRenderer; import jaxx.runtime.swing.renderer.ColorCellRenderer; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import javax.swing.JLabel; +import javax.swing.JPopupMenu; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; +import javax.swing.table.TableCellRenderer; import java.awt.Color; +import java.awt.Component; import java.awt.Font; +import java.awt.Point; +import java.awt.event.MouseEvent; -import static org.nuiton.i18n.I18n.t; import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; /** * Handler of {@link ConfigCategoryUI}. @@ -116,4 +126,146 @@ public class ConfigCategoryUIHandler { description.setText(buffer.toString()); } + public void copyCellValue() { + + JXTable table = ui.getTable(); + + int[] selectedRows = table.getSelectedRows(); + + int selectedRow = selectedRows[0]; + + Integer selectedColumn = (Integer) ui.getCopyCellValue().getClientProperty("selectedColumn"); + + ConfigTableModel tableModel = ui.getTableModel(); + OptionModel optionModel = tableModel.getEntry(selectedRow); + + Object value = null; + switch (selectedColumn) { + case 1: + if (log.isInfoEnabled()) { + log.info("Will copy option value from " + optionModel.getKey()); + } + value = optionModel.getValue(); + break; + case 2: + if (log.isInfoEnabled()) { + log.info("Will copy option default value from " + optionModel.getKey()); + } + value = optionModel.getOriginalValue(); + break; + } + + String text = ""; + if (value != null) { + TableCellRenderer cellRenderer = table.getCellRenderer(selectedRow, selectedColumn); + Component tableCellRendererComponent = cellRenderer.getTableCellRendererComponent(table, value, false, false, selectedRow, selectedColumn); + + text = ((JLabel) tableCellRendererComponent).getText(); + } + + if (log.isInfoEnabled()) { + log.info("Copy to clipboard cell (" + selectedRow + "-" + selectedColumn + ") value: \"" + text + "\""); + } + + JAXXUtil.copyToClipBoard(text); + + } + + public void resetOptionValue() { + + JXTable table = ui.getTable(); + + int[] selectedRows = table.getSelectedRows(); + + int selectedRow = selectedRows[0]; + + ConfigTableModel tableModel = ui.getTableModel(); + OptionModel optionModel = tableModel.getEntry(selectedRow); + + if (log.isInfoEnabled()) { + log.info("Will reset option: " + optionModel.getKey()); + } + tableModel.setValueAt(optionModel.getDefaultValue(), selectedRow, 1); + + } + + public void openTablePopupMenu(MouseEvent e, JPopupMenu popup) { + + boolean rightClick = SwingUtilities.isRightMouseButton(e); + + if (rightClick) { + + JXTable source = (JXTable) e.getSource(); + + int[] selectedRows = source.getSelectedRows(); + int[] selectedColumns = source.getSelectedColumns(); + + // get the coordinates of the mouse click + Point p = e.getPoint(); + + // get the row index at this point + int rowIndex = source.rowAtPoint(p); + + // get the column index at this point + int columnIndex = source.columnAtPoint(p); + + // select row (could empty selection) + if (rowIndex == -1) { + source.clearSelection(); + } else if (!ArrayUtils.contains(selectedRows, rowIndex)) { + + // set selection + source.setRowSelectionInterval(rowIndex, rowIndex); + } + + // select column (could empty selection) + if (columnIndex == -1) { + source.clearSelection(); + } else if (!ArrayUtils.contains(selectedColumns, columnIndex)) { + source.setColumnSelectionInterval(columnIndex, columnIndex); + } + + int selectedRowCount = source.getSelectedRowCount(); + + boolean enableCopyOptionValue = selectedRowCount == 1; + boolean enableResetOptionValue = selectedRowCount > 0; + + OptionModel selectedOption = ui.getTableModel().getEntry(rowIndex); + + enableResetOptionValue &= selectedOption.isModified(); + + + if (log.isDebugEnabled()) { + log.debug("At point [" + p + "] found Row " + rowIndex + ", Column " + columnIndex); + } + + boolean canContinue = true; + + if (source.isEditing()) { + + // stop editing + boolean stopEdit = source.getCellEditor().stopCellEditing(); + if (!stopEdit) { + if (log.isWarnEnabled()) { + log.warn("Could not stop edit cell..."); + } + canContinue = false; + } + } + + int selectedColumn = source.getSelectedColumn(); + ui.getCopyCellValue().putClientProperty("selectedColumn", selectedColumn); + + ui.getCopyCellValue().setEnabled(enableCopyOptionValue); + ui.getResetOptionValue().setEnabled(enableResetOptionValue); + + if (canContinue) { + + // on right click show popup + popup.show(source, e.getX(), e.getY()); + + } + } + } + } diff --git a/jaxx-config/src/main/resources/i18n/jaxx-config_en_GB.properties b/jaxx-config/src/main/resources/i18n/jaxx-config_en_GB.properties index eaf6ef9..ff7e9d5 100644 --- a/jaxx-config/src/main/resources/i18n/jaxx-config_en_GB.properties +++ b/jaxx-config/src/main/resources/i18n/jaxx-config_en_GB.properties @@ -1,7 +1,11 @@ +config.action.copyCellValue=Copy Cell to clipboard +config.action.copyCellValue.tip=Copy cell content to clipboard config.action.quit=Quit config.action.quit.tip=Quit the configuration editor config.action.reset=Cancel config.action.reset.tip=Cancel the modifications for the category +config.action.resetOptionValue=Reset option +config.action.resetOptionValue.tip=Reset option to his default value config.action.save=Save config.action.save.tip=Save the modifications for the category config.choice.cancel=Cancel diff --git a/jaxx-config/src/main/resources/i18n/jaxx-config_es_ES.properties b/jaxx-config/src/main/resources/i18n/jaxx-config_es_ES.properties index 3f64969..bb8b593 100644 --- a/jaxx-config/src/main/resources/i18n/jaxx-config_es_ES.properties +++ b/jaxx-config/src/main/resources/i18n/jaxx-config_es_ES.properties @@ -1,7 +1,11 @@ +config.action.copyCellValue= +config.action.copyCellValue.tip= config.action.quit=Salir config.action.quit.tip=Salir del editor de configuración config.action.reset=Cancelar config.action.reset.tip=Cancelar las modificaciones de esta categoría +config.action.resetOptionValue= +config.action.resetOptionValue.tip= config.action.save=Guardar config.action.save.tip=Guardar las modificaciones de esta categoría config.choice.cancel=Cancelar diff --git a/jaxx-config/src/main/resources/i18n/jaxx-config_fr_FR.properties b/jaxx-config/src/main/resources/i18n/jaxx-config_fr_FR.properties index a8f0a3a..5abb0c2 100644 --- a/jaxx-config/src/main/resources/i18n/jaxx-config_fr_FR.properties +++ b/jaxx-config/src/main/resources/i18n/jaxx-config_fr_FR.properties @@ -1,7 +1,11 @@ +config.action.copyCellValue=Copier la valeur +config.action.copyCellValue.tip=Copier la valeur dans le presse-papier config.action.quit=Quitter config.action.quit.tip=Quitter l'éditeur de configuration config.action.reset=Annuler config.action.reset.tip=Annuler les modifications de cette catégorie +config.action.resetOptionValue=Réinitialiser +config.action.resetOptionValue.tip=Réinitialiser la valeur à celle de la valeur par défaut config.action.save=Enregistrer config.action.save.tip=Sauver les modifications de cette catégorie config.choice.cancel=Annuler @@ -26,6 +30,7 @@ config.no.option.selected=< Pas d'option sélectionnée > config.option.final=Option non modifiable config.option.label=Option '%1$s' (%2$s) config.option.modified=Valeur modifiée < ancienne valeur \: '%1$s' - nouvelle valeur \: '%2$s' > +config.table.actions=Actions sur l'option sélectionnée config.title=Préférences config.title.need.confirm=Une confirmation de votre part est requise... config.unmodifiable=Ne peut pas être modifié diff --git a/jaxx-config/src/main/resources/icons/action-config-copy.png b/jaxx-config/src/main/resources/icons/action-config-copy.png new file mode 100644 index 0000000..a9f31a2 Binary files /dev/null and b/jaxx-config/src/main/resources/icons/action-config-copy.png differ diff --git a/jaxx-config/src/main/resources/icons/action-config-reset-option.png b/jaxx-config/src/main/resources/icons/action-config-reset-option.png new file mode 100644 index 0000000..0fb00f9 Binary files /dev/null and b/jaxx-config/src/main/resources/icons/action-config-reset-option.png differ diff --git a/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java b/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java index aad4f56..effb5ec 100644 --- a/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java +++ b/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java @@ -28,6 +28,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.awt.Component; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListenerProxy; import java.beans.PropertyChangeSupport; @@ -648,4 +651,19 @@ public class JAXXUtil { return o; } + /** + * Copy to clipBoard the content of the given text. + * + * @param text text to copy to clipboard + * @since 2.17 + */ + public static void copyToClipBoard(String text) { + + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + if (log.isInfoEnabled()) { + log.info("Put in clipboard :\n" + text); + } + StringSelection selection = new StringSelection(text); + clipboard.setContents(selection, selection); + } } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.