r1387 - in application/trunk: application/src/main/java/fr/ifremer/shared/application application/src/main/java/fr/ifremer/shared/application/listener application-swing/src/main/java/fr/ifremer/shared/application/swing application-swing/src/main/java/fr/ifremer/shared/application/swing/computable application-swing/src/main/java/fr/ifremer/shared/application/swing/tab application-swing/src/main/java/fr/ifremer/shared/application/swing/util
Author: tchemit Date: 2013-11-25 17:03:00 +0100 (Mon, 25 Nov 2013) New Revision: 1387 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1387 Log: continue adding some stuff Added: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableData.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataEditor.jaxx application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataEditorHandler.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataTableCell.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/CustomTab.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/DelegateTabContainerHandler.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContainerHandler.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContentModel.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabHandler.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/util/ActionListCellRenderer.java application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/util/Cancelable.java application/trunk/application/src/main/java/fr/ifremer/shared/application/listener/ application/trunk/application/src/main/java/fr/ifremer/shared/application/listener/PropagatePropertyChangeListener.java Modified: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/AbstractApplicationUIHandler.java application/trunk/application/src/main/java/fr/ifremer/shared/application/ApplicationConfiguration.java Modified: application/trunk/application/src/main/java/fr/ifremer/shared/application/ApplicationConfiguration.java =================================================================== --- application/trunk/application/src/main/java/fr/ifremer/shared/application/ApplicationConfiguration.java 2013-11-24 23:48:14 UTC (rev 1386) +++ application/trunk/application/src/main/java/fr/ifremer/shared/application/ApplicationConfiguration.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -27,6 +27,8 @@ import org.nuiton.config.ApplicationConfig; import org.nuiton.util.Version; +import javax.swing.KeyStroke; + /** * Created on 11/24/13. * @@ -44,6 +46,8 @@ public abstract Version getVersion(); + public abstract KeyStroke getShortcutClosePopup(); + public ApplicationConfiguration(ApplicationConfig applicationConfig) { this.applicationConfig = applicationConfig; } Copied: application/trunk/application/src/main/java/fr/ifremer/shared/application/listener/PropagatePropertyChangeListener.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-persistence/src/main/java/fr/ifremer/tutti/PropagatePropertyChangeListener.java) =================================================================== --- application/trunk/application/src/main/java/fr/ifremer/shared/application/listener/PropagatePropertyChangeListener.java (rev 0) +++ application/trunk/application/src/main/java/fr/ifremer/shared/application/listener/PropagatePropertyChangeListener.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,80 @@ +package fr.ifremer.shared.application.listener; + +/* + * #%L + * Ifremer shared :: Application + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.jdesktop.beans.AbstractBean; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +/** + * To listen a bean and propagate some of properties. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class PropagatePropertyChangeListener implements PropertyChangeListener { + + public static interface PropagatePropertyChange { + void firePropertyChanged(String propertyName, + Object oldValue, + Object newValue); + } + + public static void listenAndPropagate(AbstractBean producer, + PropagatePropertyChange consumer, + String propertyNameToListen, + String propertyNameToForward) { + PropagatePropertyChangeListener listener = + new PropagatePropertyChangeListener(propertyNameToForward, + consumer); + producer.addPropertyChangeListener(propertyNameToListen, listener); + } + + public static void listenAndPropagateAll(AbstractBean producer, + PropagatePropertyChange consumer) { + PropagatePropertyChangeListener listener = + new PropagatePropertyChangeListener(null, consumer); + producer.addPropertyChangeListener(listener); + } + + private String propertyName; + + private PropagatePropertyChange editor; + + public PropagatePropertyChangeListener(String propertyName, + PropagatePropertyChange editor) { + this.propertyName = propertyName; + this.editor = editor; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + String name = propertyName == null ? evt.getPropertyName() : propertyName; + editor.firePropertyChanged(name, + evt.getOldValue(), + evt.getNewValue()); + } +} \ No newline at end of file Modified: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/AbstractApplicationUIHandler.java =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/AbstractApplicationUIHandler.java 2013-11-24 23:48:14 UTC (rev 1386) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/AbstractApplicationUIHandler.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -27,8 +27,13 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.shared.application.ApplicationDataUtil; +import fr.ifremer.shared.application.swing.action.ApplicationActionUI; +import fr.ifremer.shared.application.swing.computable.ComputableDataEditor; import fr.ifremer.shared.application.swing.table.ColumnIdentifier; +import fr.ifremer.shared.application.swing.util.Cancelable; +import fr.ifremer.shared.application.type.ApplicationProgressionModel; import fr.ifremer.shared.application.type.WeightUnit; +import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.JAXXWidgetUtil; import jaxx.runtime.swing.editor.FileEditor; @@ -54,6 +59,7 @@ import org.nuiton.decorator.Decorator; import org.nuiton.decorator.JXPathDecorator; +import javax.swing.AbstractAction; import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.DefaultComboBoxModel; @@ -64,11 +70,13 @@ import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; +import javax.swing.JRootPane; import javax.swing.JScrollPane; import javax.swing.JSpinner; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.JViewport; +import javax.swing.KeyStroke; import javax.swing.ListCellRenderer; import javax.swing.ListSelectionModel; import javax.swing.ScrollPaneConstants; @@ -85,8 +93,9 @@ import javax.swing.text.JTextComponent; import java.awt.Color; import java.awt.Component; +import java.awt.Dialog; import java.awt.Dimension; -import java.awt.Font; +import java.awt.Frame; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; @@ -97,6 +106,8 @@ import java.awt.event.ItemEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.io.File; import java.io.Serializable; import java.text.ParseException; @@ -211,7 +222,7 @@ selectionModel.setValueIsAdjusting(true); try { - List selectedList = Lists.newLinkedList(); + List<Object> selectedList = Lists.newLinkedList(); for (int index : list.getSelectedIndices()) { Object o = list.getModel().getElementAt(index); @@ -224,62 +235,62 @@ } } -// public void openDialog(TuttiUI dialogContent, -// String title, Dimension dim) { -// Component topestUI = getTopestUI(); -// -// JDialog result; -// if (topestUI instanceof Frame) { -// result = new JDialog((Frame) topestUI, title, true); -// } else { -// result = new JDialog((Dialog) topestUI, title, true); -// } -// -// result.add((Component) dialogContent); -// result.setResizable(true); -// -// result.setSize(dim); -// -// final AbstractTuttiUIHandler handler = dialogContent.getHandler(); -// -// if (handler instanceof Cancelable) { -// -// // add a auto-close action -// JRootPane rootPane = result.getRootPane(); -// -// KeyStroke shortcutClosePopup = getConfig().getShortcutClosePopup(); -// -// rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( -// shortcutClosePopup, "close"); -// rootPane.getActionMap().put("close", new AbstractAction() { -// private static final long serialVersionUID = 1L; -// -// @Override -// public void actionPerformed(ActionEvent e) { -// ((Cancelable) handler).cancel(); -// } -// }); -// } -// -// result.addWindowListener(new WindowAdapter() { -// -// @Override -// public void windowClosed(WindowEvent e) { -// Component ui = (Component) e.getSource(); -// if (log.isDebugEnabled()) { -// log.debug("Destroy ui " + ui); -// } -// JAXXUtil.destroy(ui); -// } -// }); -// SwingUtil.center(getContext().getMainUI(), result); -// result.setVisible(true); -// } -// -// public void closeDialog(ApplicationUI ui) { -// SwingUtil.getParentContainer(ui, JDialog.class).setVisible(false); -// } + public void openDialog(ApplicationUI dialogContent, + String title, Dimension dim) { + Component topestUI = getTopestUI(); + JDialog result; + if (topestUI instanceof Frame) { + result = new JDialog((Frame) topestUI, title, true); + } else { + result = new JDialog((Dialog) topestUI, title, true); + } + + result.add((Component) dialogContent); + result.setResizable(true); + + result.setSize(dim); + + final AbstractApplicationUIHandler handler = dialogContent.getHandler(); + + if (handler instanceof Cancelable) { + + // add a auto-close action + JRootPane rootPane = result.getRootPane(); + + KeyStroke shortcutClosePopup = getContext().getConfiguration().getShortcutClosePopup(); + + rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + shortcutClosePopup, "close"); + rootPane.getActionMap().put("close", new AbstractAction() { + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + ((Cancelable) handler).cancel(); + } + }); + } + + result.addWindowListener(new WindowAdapter() { + + @Override + public void windowClosed(WindowEvent e) { + Component ui = (Component) e.getSource(); + if (log.isDebugEnabled()) { + log.debug("Destroy ui " + ui); + } + JAXXUtil.destroy(ui); + } + }); + SwingUtil.center(getContext().getMainUI(), result); + result.setVisible(true); + } + + public void closeDialog(ApplicationUI ui) { + SwingUtil.getParentContainer(ui, JDialog.class).setVisible(false); + } + public static final String CONFIRMATION_FORMAT = "<html>%s<hr/><br/>%s</html>"; public int askSaveBeforeLeaving(String message) { @@ -349,6 +360,10 @@ // handler.clearValidators(); // } + protected void addHighlighters(final JXTable table) { + + } + public void autoSelectRowInTable(MouseEvent e, JPopupMenu popup) { boolean rightClick = SwingUtilities.isRightMouseButton(e); @@ -545,40 +560,29 @@ } protected void initLabel(JLabel jLabel) { - Boolean strongStyle = (Boolean) jLabel.getClientProperty("strongStyle"); - Boolean italicStyle = (Boolean) jLabel.getClientProperty("italicStyle"); - Font font = jLabel.getFont(); - int style = font.getStyle(); - if (strongStyle != null && strongStyle) { - style |= Font.BOLD; + + WeightUnit weightUnit = (WeightUnit) jLabel.getClientProperty("addWeightUnit"); + if (weightUnit != null) { + String text = weightUnit.decorateLabel(jLabel.getText()); + jLabel.setText(text); + + String tip = weightUnit.decorateTip(jLabel.getToolTipText()); + jLabel.setToolTipText(tip); + + Component labelFor = jLabel.getLabelFor(); + if (labelFor instanceof ComputableDataEditor) { + + // set also the number of digits (4 for kg, 1 for g) + ComputableDataEditor editor = (ComputableDataEditor) labelFor; + editor.setNumberPattern(weightUnit.getNumberEditorPattern()); + editor.setDecimalNumber(weightUnit.getNumberDigits()); + } else if (labelFor instanceof NumberEditor) { + + // set also the number of digits (4 for kg, 1 for g) + NumberEditor editor = (NumberEditor) labelFor; + editor.setNumberPattern(weightUnit.getNumberEditorPattern()); + } } - if (italicStyle != null && italicStyle) { - style |= Font.ITALIC; - } - jLabel.setFont(font.deriveFont(style)); - -// WeightUnit weightUnit = (WeightUnit) jLabel.getClientProperty("addWeightUnit"); -// if (weightUnit != null) { -// String text = weightUnit.decorateLabel(jLabel.getText()); -// jLabel.setText(text); -// -// String tip = weightUnit.decorateTip(jLabel.getToolTipText()); -// jLabel.setToolTipText(tip); -// -// Component labelFor = jLabel.getLabelFor(); -// if (labelFor instanceof TuttiComputedOrNotDataEditor) { -// -// // set also the number of digits (4 for kg, 1 for g) -// TuttiComputedOrNotDataEditor editor = (TuttiComputedOrNotDataEditor) labelFor; -// editor.setNumberPattern(weightUnit.getNumberEditorPattern()); -// editor.setDecimalNumber(weightUnit.getNumberDigits()); -// } else if (labelFor instanceof NumberEditor) { -// -// // set also the number of digits (4 for kg, 1 for g) -// NumberEditor editor = (NumberEditor) labelFor; -// editor.setNumberPattern(weightUnit.getNumberEditorPattern()); -// } -// } } // protected void initButtonAttachment(ButtonAttachment component) { @@ -1067,4 +1071,15 @@ DecoratorTableCellRenderer result = new DecoratorTableCellRenderer(decorator, true); return result; } + + protected void incrementsMessage(String message) { + + ApplicationActionUI actionUI = getContext().getActionUI(); + if (actionUI != null) { + ApplicationProgressionModel progressionModel = actionUI.getModel().getProgressionModel(); + if (progressionModel != null) + + progressionModel.increments(message); + } + } } Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableData.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableData.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableData.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,127 @@ +package fr.ifremer.shared.application.swing.computable; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.shared.application.listener.PropagatePropertyChangeListener; +import org.jdesktop.beans.AbstractSerializableBean; + + +/** + * A number data plus a possible computed value. + * + * @author kmorin <kmorin@codelutin.com> + * @since 1.0 + */ +public class ComputableData<N extends Number> extends AbstractSerializableBean { + + public static final String PROPERTY_DATA = "data"; + + public static final String PROPERTY_COMPUTED_DATA = "computedData"; + + private static final long serialVersionUID = 1L; + + protected N data; + + protected N computedData; + + public ComputableData() { + data = null; + computedData = null; + } + + public ComputableData(N data, N computedData) { + this.data = data; + this.computedData = computedData; + } + + public N getData() { + return data; + } + + public void setData(N data) { + Object oldValue = getData(); + this.data = data; + firePropertyChange(PROPERTY_DATA, oldValue, data); + } + + public N getComputedData() { + return computedData; + } + + public void setComputedData(N computedData) { + Object oldValue = getComputedData(); + this.computedData = computedData; + firePropertyChange(PROPERTY_COMPUTED_DATA, oldValue, computedData); + } + + @Override + public String toString() { + String result = null; + if (data != null) { + result = data.toString(); + } else if (computedData != null) { + result = computedData.toString(); + } + return result; + } + + /** + * Add a listener to propagate the modification of the + * {@link #PROPERTY_DATA} property to a given {@code propertyName}. + * + * @param propertyName name of the property to fire on given bean + * @param otherBean bean that will fires + * @since 1.2 + */ + public void addPropagateListener(String propertyName, + PropagatePropertyChangeListener.PropagatePropertyChange otherBean) { + + PropagatePropertyChangeListener.listenAndPropagate(this, + otherBean, + PROPERTY_DATA, + propertyName); + +// PropagatePropertyChangeListener listener = new PropagatePropertyChangeListener(propertyName, otherBean); +// addPropertyChangeListener(PROPERTY_DATA, listener); + } + +// private static class PropagateProperyChangeListener implements PropertyChangeListener { +// +// private String propertyName; +// +// private AbstractTuttiBeanUIModel otherBean; +// +// public PropagatePropertyChangeLstener(String propertyName, +// AbstractTuttiBeanUIModel otherBean) { +// this.propertyName = propertyName; +// this.otherBean = otherBean; +// } +// +// @Override +// public void propertyChange(PropertyChangeEvent evt) { +// otherBean.firePropertyChanged(propertyName, evt.getOldValue(), evt.getNewValue()); +// } +// } +} Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataEditor.jaxx (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataEditor.jaxx (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataEditor.jaxx 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,54 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 - 2013 Ifremer, CodeLutin, Tony CHEMIT + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<jaxx.runtime.swing.editor.NumberEditor genericType='E extends Number'> + + <import> + fr.ifremer.shared.application.swing.computable.ComputableData + java.awt.Color + </import> + + <String id='property' javaBean='ComputableData.PROPERTY_DATA'/> + + <ComputableData id='bean' genericType='E' javaBean='null'/> + + <Color id='computedDataColor' javaBean='null'/> + + <!-- ui handler --> + <ComputableDataEditorHandler id='handler' constructorParams='this'/> + + <Integer id='decimalNumber' javaBean='null'/> + + <script><![CDATA[ + + public void setBean(ComputableData<E> bean) { + super.setBean(bean); + } + + public void setProperty(String property) { + // cannot change the property + } +]]> + </script> + +</jaxx.runtime.swing.editor.NumberEditor> \ No newline at end of file Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataEditorHandler.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataEditorHandler.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataEditorHandler.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,138 @@ + +package fr.ifremer.shared.application.swing.computable; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.shared.application.ApplicationDataUtil; +import fr.ifremer.shared.application.swing.ApplicationUI; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.swing.editor.NumberEditorHandler; + +import javax.swing.JTextField; +import java.awt.Color; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.text.DecimalFormat; + +/** + * @author kmorin <kmorin@codelutin.com> + * @since 1.0 + */ +public class ComputableDataEditorHandler extends NumberEditorHandler { + + protected Integer decimalNumber; + + public ComputableDataEditorHandler(ComputableDataEditor ui) { + super(ui); + } + + @Override + public void init() { + final PropertyChangeListener l = new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + setComputedTextIfNullModel(); + } + }; + + ComputableData bean = (ComputableData) editor.getBean(); + if (bean != null) { + bean.addPropertyChangeListener(l); + } + editor.addPropertyChangeListener(ComputableDataEditor.PROPERTY_BEAN, new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + + ComputableData bean = (ComputableData) evt.getOldValue(); + if (bean != null) { + bean.removePropertyChangeListener(ComputableData.PROPERTY_COMPUTED_DATA, l); + } + + bean = (ComputableData) evt.getNewValue(); + if (bean != null) { + bean.addPropertyChangeListener(ComputableData.PROPERTY_COMPUTED_DATA, l); + } + } + }); + + editor.addPropertyChangeListener(ComputableDataEditor.PROPERTY_MODEL, l); + + editor.getTextField().addFocusListener(new FocusListener() { + + public void focusGained(FocusEvent e) { + JTextField tf = editor.getTextField(); + tf.setFont(ApplicationUI.TEXTFIELD_NORMAL_FONT); + tf.setForeground(Color.BLACK); + if (editor.getModel() == null) { + tf.setText(""); + } + } + + public void focusLost(FocusEvent e) { + setComputedTextIfNullModel(); + } + }); + + editor.addPropertyChangeListener(ComputableDataEditor.PROPERTY_DECIMAL_NUMBER, + new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + decimalNumber = (Integer) evt.getNewValue(); + } + }); + + decimalNumber = ((ComputableDataEditor) editor).getDecimalNumber(); + + super.init(); + + } + + protected void setComputedTextIfNullModel() { + ComputableData bean = (ComputableData) editor.getBean(); + JTextField tf = editor.getTextField(); + if (bean != null && editor.getModel() == null) { + tf.setFont(ApplicationUI.TEXTFIELD_COMPUTED_FONT); + tf.setForeground(((ComputableDataEditor) editor).getComputedDataColor()); + + String modelText; + Number computedData = bean.getComputedData(); + if (editor.isUseFloat() + && decimalNumber != null && computedData != null) { + DecimalFormat decimalFormat = ApplicationDataUtil.getDecimalFormat(1, decimalNumber); + modelText = decimalFormat.format(computedData); + } else { + modelText = JAXXUtil.getStringValue(computedData); + } + tf.setText(modelText); + + } else { + tf.setFont(ApplicationUI.TEXTFIELD_NORMAL_FONT); + tf.setForeground(Color.BLACK); + } + } + +} Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataTableCell.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataTableCell.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/computable/ComputableDataTableCell.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,259 @@ +package fr.ifremer.shared.application.swing.computable; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.shared.application.ApplicationDataUtil; +import fr.ifremer.shared.application.swing.ApplicationUI; +import fr.ifremer.shared.application.type.WeightUnit; +import jaxx.runtime.JAXXUtil; + +import javax.swing.AbstractCellEditor; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.border.LineBorder; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.text.DecimalFormat; + +/** + * Editor for TuttiComputedOrNotData + * + * @author kmorin <kmorin@codelutin.com> + * @since 1.0 + */ +public class ComputableDataTableCell extends DefaultTableCellRenderer { + private static final long serialVersionUID = 1L; + + public static TableCellRenderer newRender(TableCellRenderer renderer, + WeightUnit weightUnit, + Color computedDataColor) { + + return new TuttiComputedOrNotDataTableCellRenderer(renderer, + true, + weightUnit.getNumberDigits(), + computedDataColor); + } + + public static TableCellEditor newEditor(Class type, + WeightUnit weightUnit, + Color computedDataColor) { + + return new TuttiComputedOrNotDataTableCellEditor(type, + false, + true, + weightUnit.getNumberDigits(), + weightUnit.getNumberEditorPattern(), + computedDataColor); + } + + public static class TuttiComputedOrNotDataTableCellEditor + extends AbstractCellEditor + implements TableCellEditor, FocusListener, AncestorListener { + + private static final long serialVersionUID = 1L; + + protected final ComputableDataEditor numberEditor; + + protected ComputableData data; + + /** constructor */ + public TuttiComputedOrNotDataTableCellEditor(Class type, + boolean useSign, + boolean useFloat, + Integer decimalNumber, + String numberPattern, + Color computedDataColor) { + + numberEditor = new ComputableDataEditor(); + numberEditor.setComputedDataColor(computedDataColor); + numberEditor.getTextField().setHorizontalAlignment(SwingConstants.RIGHT); + numberEditor.getTextField().addFocusListener(this); + numberEditor.getTextField().addAncestorListener(this); + numberEditor.getTextField().setBorder(new LineBorder(Color.GRAY, 2)); + numberEditor.setSelectAllTextOnError(true); + + numberEditor.setNumberPattern(numberPattern); + numberEditor.setModelType(type); + numberEditor.setUseSign(useSign); + numberEditor.setUseFloat(useFloat); + numberEditor.setDecimalNumber(decimalNumber); + numberEditor.init(); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int row, int column) { + + data = (ComputableData) value; + numberEditor.setModel(data.getData()); + + // Check nullity and set the text that will be selected with the current value + if (data.getData() != null) { + numberEditor.setModelText(String.valueOf(data.getData())); + } + return numberEditor; + } + + public ComputableDataEditor getNumberEditor() { + return numberEditor; + } + + @Override + public ComputableData getCellEditorValue() { + return data; + } + + @Override + public void focusGained(FocusEvent e) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + numberEditor.getTextField().requestFocus(); + numberEditor.getTextField().selectAll(); + } + }); + } + + @Override + public void focusLost(FocusEvent e) { + } + + @Override + public void ancestorAdded(AncestorEvent event) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + numberEditor.getTextField().requestFocus(); + numberEditor.getTextField().selectAll(); + } + }); + } + + @Override + public void ancestorRemoved(AncestorEvent event) { + } + + @Override + public void ancestorMoved(AncestorEvent event) { + } + + @Override + public boolean stopCellEditing() { + boolean result = super.stopCellEditing(); + // Reset previous data to avoid keeping it on other cell edition + if (result) { + data.setData(numberEditor.getModel()); + + numberEditor.setBean(null); + + data = null; + } + return result; + } + } + + public static class TuttiComputedOrNotDataTableCellRenderer + implements TableCellRenderer { + + protected final TableCellRenderer delegate; + + protected Integer decimalNumber; + + protected Color computedDataColor; + + protected boolean useFloat; + + public TuttiComputedOrNotDataTableCellRenderer( + TableCellRenderer delegate, + boolean useFloat, + Integer decimalNumber, + Color computedDataColor) { + + this.delegate = delegate; + this.useFloat = useFloat; + this.decimalNumber = decimalNumber; + this.computedDataColor = computedDataColor; + } + + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + + ComputableData data = (ComputableData) value; + Number dataValue = data.getData(); + Font font; + Color foreground; + String text; + if (dataValue == null) { + dataValue = data.getComputedData(); + font = ApplicationUI.TEXTFIELD_COMPUTED_FONT; + foreground = computedDataColor; + + if (useFloat && decimalNumber != null && dataValue != null) { + DecimalFormat decimalFormat = ApplicationDataUtil.getDecimalFormat(1, decimalNumber); + text = JAXXUtil.getStringValue(decimalFormat.format(dataValue)); + } else { + text = JAXXUtil.getStringValue(dataValue); + } + + } else { + font = ApplicationUI.TEXTFIELD_NORMAL_FONT; + foreground = Color.BLACK; + text = JAXXUtil.getStringValue(dataValue); + } + + Component component = delegate.getTableCellRendererComponent(table, + text, + isSelected, + hasFocus, + row, + column); + + if (isSelected) { + font = font.deriveFont(Font.BOLD); + } + component.setFont(font); + component.setForeground(foreground); + if (component instanceof JLabel) { + JLabel jLabel = (JLabel) component; + jLabel.setHorizontalAlignment(RIGHT); + } + + return component; + } + + } +} Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/CustomTab.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/CustomTab.java) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/CustomTab.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/CustomTab.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,126 @@ +package fr.ifremer.shared.application.swing.tab; + +/* + * #%L + * Ifremer shared :: Application Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import jaxx.runtime.SwingUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.beans.BeanUtil; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.UIManager; +import java.awt.Color; +import java.awt.Font; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import static org.nuiton.i18n.I18n._; + +/** + * Custom tab component which adds a * in the end of the title + * when the content is modified. + * + * @author kmorin <kmorin@codelutin.com> + * @since 1.0 + */ +public class CustomTab extends JPanel { + + private static final long serialVersionUID = 1L; + + private static final Log log = LogFactory.getLog(CustomTab.class); + + protected TabContentModel model; + + protected JLabel title = new JLabel(); + + public TabContentModel getModel() { + return model; + } + + public CustomTab(TabContentModel model) { + this.model = model; + try { + BeanUtil.addPropertyChangeListener( + new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + updateTitle(); + } + }, this.model); + + } catch (Exception ex) { + log.error("Error while adding the listener to the model modifications", ex); + } + + setBackground(null); + + updateTitle(); + String actionIcon = model.getIcon(); + if (actionIcon != null) { + title.setIcon(SwingUtil.createActionIcon(actionIcon)); + } + add(title); + } + + @Override + public void setBackground(Color bg) { + if (bg == null) { + bg = new Color(0, 0, 0, 0); + } + super.setBackground(bg); + revalidate(); + } + + @Override + public void setForeground(Color fg) { + super.setForeground(fg); + if (title != null) { + title.setForeground(fg); + } + } + + protected void updateTitle() { + Font f = UIManager.getDefaults().getFont("Label.font"); + String titleValue = _(model.getTitle()); + + int style; + if (model.isModify()) { + style = Font.BOLD; + titleValue += "*"; + + } else if (model.isEmpty()) { + style = Font.ITALIC; + + } else { + style = Font.PLAIN; + } + + title.setText(titleValue); + title.setFont(f.deriveFont(style)); + } + +} Added: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/DelegateTabContainerHandler.java =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/DelegateTabContainerHandler.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/DelegateTabContainerHandler.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,112 @@ +package fr.ifremer.shared.application.swing.tab; + +/* + * #%L + * Ifremer shared :: Application Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.shared.application.swing.AbstractApplicationUIHandler; +import fr.ifremer.shared.application.swing.ApplicationUI; + +import javax.swing.DefaultSingleSelectionModel; +import javax.swing.JTabbedPane; +import java.awt.Component; + +/** + * Created on 11/25/13. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.0 + */ +public class DelegateTabContainerHandler implements TabContainerHandler { + + final JTabbedPane tabbedPane; + + public DelegateTabContainerHandler(JTabbedPane tabbedPane) { + this.tabbedPane = tabbedPane; + } + + @Override + public JTabbedPane getTabPanel() { + return tabbedPane; + } + + @Override + public void init() { + + getTabPanel().setModel(new DefaultSingleSelectionModel() { + + private static final long serialVersionUID = 1L; + + @Override + public void setSelectedIndex(int index) { + int currentIndex = getTabPanel().getSelectedIndex(); + boolean mustChangeTab = onTabChanged(currentIndex, index); + + if (mustChangeTab) { + super.setSelectedIndex(index); + } + } + + }); + } + + + @Override + public boolean onTabChanged(int currentIndex, int newIndex) { + boolean result = true; + if (currentIndex != newIndex) { + TabHandler handler = getTabHandler(currentIndex); + if (handler != null) { + result = handler.onHideTab(currentIndex, newIndex); + } + + handler = getTabHandler(newIndex); + if (handler != null) { + handler.onShowTab(currentIndex, newIndex); + } + } + return result; + } + + @Override + public TabHandler getTabHandler(int index) { + TabHandler tabHandler = null; + JTabbedPane tabPanel = getTabPanel(); + if (index >= 0 && index < tabPanel.getTabCount()) { + Component tab = tabPanel.getComponentAt(index); + if (ApplicationUI.class.isInstance(tab)) { + ApplicationUI tuttiTab = (ApplicationUI) tabPanel.getComponentAt(index); + AbstractApplicationUIHandler handler = tuttiTab.getHandler(); + if (TabHandler.class.isInstance(handler)) { + tabHandler = (TabHandler) handler; + } + } + } + return tabHandler; + } + + @Override + public void setCustomTab(int index, TabContentModel model) { + getTabPanel().setTabComponentAt(index, new CustomTab(model)); + } +} Property changes on: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/DelegateTabContainerHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContainerHandler.java =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContainerHandler.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContainerHandler.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,68 @@ +package fr.ifremer.shared.application.swing.tab; + +/* + * #%L + * Ifremer shared :: Application Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import javax.swing.JTabbedPane; + +/** + * Created on 11/25/13. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.0 + */ +public interface TabContainerHandler { + + JTabbedPane getTabPanel(); + + void init(); + + /** + * Method called when the user selects a tab. + * + * @param currentIndex + * @param newIndex + * @return <code>false</code> if you want to prevent the tab change, + * <code>true</code> otherwise + */ + boolean onTabChanged(int currentIndex, int newIndex); + + /** + * Returns the tab handler of the tab i. + * + * @param index the index of the tab + * @return the tab handler of the index i if the handler implements + * the {@link TabHandler} interface, + * <code>null</code> otherwise + */ + TabHandler getTabHandler(int index); + + /** + * Sets a {@link CustomTab} as tab component. + * + * @param index + * @param model + */ + void setCustomTab(int index, TabContentModel model); +} Property changes on: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContainerHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContentModel.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TabContentModel.java) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContentModel.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabContentModel.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,44 @@ +package fr.ifremer.shared.application.swing.tab; + +/* + * #%L + * Ifremer shared :: Application Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * Interface defining the models of the tab content UIs. + * + * @author kmorin <kmorin@codelutin.com> + * @since 1.0 + */ +public interface TabContentModel { + + boolean isEmpty(); + + boolean isValid(); + + boolean isModify(); + + String getTitle(); + + String getIcon(); +} Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabHandler.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TabHandler.java) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabHandler.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/tab/TabHandler.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,52 @@ +package fr.ifremer.shared.application.swing.tab; + +/* + * #%L + * Ifremer shared :: Application Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * Interface describing UI contained in a tab. + * + * @author kmorin <kmorin@codelutin.com> + * @since 1.0 + */ +public interface TabHandler { + + /** + * Method called when the tab is hidden + * + * @param currentIndex + * @param newIndex + * @return <code>false</code> to prevent the tab to be hidden, + * <code>true</code> otherwise. + */ + boolean onHideTab(int currentIndex, int newIndex); + + /** + * Method called when the tab is shown + * + * @param currentIndex + * @param newIndex + */ + void onShowTab(int currentIndex, int newIndex); +} Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/util/ActionListCellRenderer.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/ActionListCellRenderer.java) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/util/ActionListCellRenderer.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/util/ActionListCellRenderer.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,61 @@ +package fr.ifremer.shared.application.swing.util; + +/* + * #%L + * Ifremer shared :: Application Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import javax.swing.Action; +import javax.swing.DefaultListCellRenderer; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JList; +import javax.swing.border.EmptyBorder; +import java.awt.Component; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class ActionListCellRenderer extends DefaultListCellRenderer { + + private static final long serialVersionUID = 1L; + + protected final EmptyBorder border = new EmptyBorder(4, 8, 4, 8); + + @Override + public Component getListCellRendererComponent(JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + + Component result = super.getListCellRendererComponent( + list, value, index, isSelected, cellHasFocus); + Action action = ((JButton) value).getAction(); + setIcon((Icon) action.getValue(Action.LARGE_ICON_KEY)); + setText((String) action.getValue(Action.NAME)); + setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); + setBorder(border); + return result; + } +} Copied: application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/util/Cancelable.java (from rev 1385, branches/tutti-with-ifremer-shared/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/Cancelable.java) =================================================================== --- application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/util/Cancelable.java (rev 0) +++ application/trunk/application-swing/src/main/java/fr/ifremer/shared/application/swing/util/Cancelable.java 2013-11-25 16:03:00 UTC (rev 1387) @@ -0,0 +1,36 @@ +package fr.ifremer.shared.application.swing.util; + +/* + * #%L + * Ifremer shared :: Application Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, CodeLutin, Tony CHEMIT + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * To cancel contract. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public interface Cancelable { + + void cancel(); +}
participants (1)
-
tchemit@users.forge.codelutin.com