Skip to content
Snippets Groups Projects
Commit 50505b6e authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

new 'Follow ordinates instead of abscissa' checkboxes for matrix scale data cases (EXPDATA-667)

parent cb1dc808
No related branches found
No related tags found
No related merge requests found
......@@ -119,11 +119,9 @@ public class SettingsManager {
}
if (configFilename != null) {
// if we don't remove preferences, it is persisted in the system
// memory
// this allow temporary preferences to be used from one launch to
// another
// without specifying a config file
// If we don't remove preferences, it is persisted in the system memory.
// This allows temporary preferences to be used from one launch to another without specifying a config
// file.
InputStream in = null;
try {
in = new FileInputStream(configFilename);
......
package org.cdma.gui.databrowser.model;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.LinkedList;
import java.util.List;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
......@@ -30,15 +33,18 @@ import org.jdesktop.swingx.action.AbstractActionExt;
import org.jdesktop.swingx.action.ActionManager;
import fr.soleil.comete.box.matrixbox.AbstractMatrixBox;
import fr.soleil.comete.definition.event.ValueConvertorEvent;
import fr.soleil.comete.definition.listener.IValueConvertorListener;
import fr.soleil.comete.definition.util.ArrayPositionConvertor;
import fr.soleil.comete.swing.ImageViewer;
import fr.soleil.comete.swing.NumberMatrixArea;
import fr.soleil.comete.swing.util.EDTManager;
import fr.soleil.data.target.matrix.IMatrixTarget;
import fr.soleil.lib.project.ObjectUtils;
import fr.soleil.lib.project.swing.ConstrainedCheckBox;
public abstract class ImageMatrixItem<T extends IMatrixTarget, B extends AbstractMatrixBox<T>>
extends MatrixItem<ImageViewer> implements ScaleConstants {
extends MatrixItem<ImageViewer> implements ScaleConstants, ItemListener, IValueConvertorListener {
private static final String DATABROWSER = "DATABROWSER";
private static final String WRITE_DATA = "Write data";
......@@ -50,12 +56,10 @@ public abstract class ImageMatrixItem<T extends IMatrixTarget, B extends Abstrac
private final List<Item> scaleItemsList;
protected JPanel topPanel;
protected ArrayPositionConvertor xValueConvertor;
protected ArrayPositionConvertor yValueConvertor;
protected JComboBox<Object> xScaleCombo;
protected JComboBox<Object> yScaleCombo;
protected DefaultComboBoxModel<Object> xScaleModel;
protected DefaultComboBoxModel<Object> yScaleModel;
protected ArrayPositionConvertor xValueConvertor, yValueConvertor;
protected JComboBox<Object> xScaleCombo, yScaleCombo;
protected DefaultComboBoxModel<Object> xScaleModel, yScaleModel;
protected ConstrainedCheckBox xOrdinateBox, yOrdinateBox;
public ImageMatrixItem(MatrixViewer matrixViewer, Item item, DataBrowserController controller) {
super(matrixViewer, item, controller);
......@@ -72,8 +76,12 @@ public abstract class ImageMatrixItem<T extends IMatrixTarget, B extends Abstrac
theViewer.setApplicationId(DATABROWSER);
theViewer.setCleanOnDataSetting(false);
theViewer.setAlwaysFitMaxSize(true);
xValueConvertor = new ArrayPositionConvertor();
yValueConvertor = new ArrayPositionConvertor();
xValueConvertor = generateConvertor();
yValueConvertor = generateConvertor();
xOrdinateBox = generateCheckBox("MatrixViewer.Scale.Concertor.Ordinate.Text",
"MatrixViewer.Scale.Concertor.Ordinate.Tooltip.X", xValueConvertor);
yOrdinateBox = generateCheckBox("MatrixViewer.Scale.Concertor.Ordinate.Text",
"MatrixViewer.Scale.Concertor.Ordinate.Tooltip.Y", yValueConvertor);
theViewer.setXAxisConvertor(xValueConvertor);
theViewer.setYAxisConvertor(yValueConvertor);
MatrixViewer matrixViewer = ObjectUtils.recoverObject(matrixViewerRef);
......@@ -146,24 +154,61 @@ public abstract class ImageMatrixItem<T extends IMatrixTarget, B extends Abstrac
@Override
protected JPanel getTopPanel() {
if (topPanel == null) {
topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
topPanel.add(Box.createHorizontalStrut(5));
topPanel.add(Box.createHorizontalGlue());
topPanel.add(new JLabel(DataBrowser.MESSAGES.getString("MatrixViewer.XScale")));
topPanel.add(Box.createHorizontalStrut(5));
topPanel.add(xScaleCombo);
topPanel.add(Box.createHorizontalStrut(10));
topPanel.add(Box.createHorizontalGlue());
topPanel.add(new JLabel(DataBrowser.MESSAGES.getString("MatrixViewer.YScale")));
topPanel.add(Box.createHorizontalStrut(5));
topPanel.add(yScaleCombo);
topPanel.add(Box.createHorizontalStrut(5));
topPanel.add(Box.createHorizontalGlue());
topPanel = new JPanel(new GridBagLayout());
int x = 0, y = 0, gap = 10;
x = addComponents(topPanel, x, y, gap, new JLabel(DataBrowser.MESSAGES.getString("MatrixViewer.XScale")),
xScaleCombo);
addComponents(topPanel, x, y++, 0, new JLabel(DataBrowser.MESSAGES.getString("MatrixViewer.YScale")),
yScaleCombo);
x = 0;
x = addComponents(topPanel, x, y, gap, null, xOrdinateBox);
addComponents(topPanel, ++x, y++, 0, null, yOrdinateBox);
}
return topPanel;
}
protected int addComponents(JPanel panel, int x, int y, int gap, JComponent comp1, JComponent comp2) {
if (comp1 != null) {
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = x++;
constraints.gridy = y;
constraints.weightx = 0;
constraints.weighty = 0;
constraints.insets = new Insets(0, 0, 0, 5);
panel.add(comp1, constraints);
}
if (comp2 != null) {
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = x++;
constraints.gridy = y;
constraints.weightx = 0.5;
constraints.weighty = 0;
if (comp1 == null) {
constraints.gridwidth = 2;
}
constraints.insets = new Insets(0, 0, 0, gap);
panel.add(comp2, constraints);
}
return x;
}
protected ArrayPositionConvertor generateConvertor() {
ArrayPositionConvertor convertor = new ArrayPositionConvertor();
convertor.addValueConvertorListener(this);
return convertor;
}
protected ConstrainedCheckBox generateCheckBox(String textKey, String tooltipKey,
ArrayPositionConvertor convertor) {
ConstrainedCheckBox checkBox = new ConstrainedCheckBox(DataBrowser.MESSAGES.getString(textKey));
checkBox.setToolTipText(DataBrowser.MESSAGES.getString(tooltipKey));
checkBox.setSelected(convertor.isFollowOrdinate());
checkBox.addItemListener(this);
return checkBox;
}
protected T getReadTarget() {
@SuppressWarnings("unchecked")
T target = (T) viewer;
......@@ -247,6 +292,44 @@ public abstract class ImageMatrixItem<T extends IMatrixTarget, B extends Abstrac
}
}
@Override
public void itemStateChanged(ItemEvent e) {
if ((e != null) && (e.getItemSelectable() != null)) {
if (e.getItemSelectable() == xOrdinateBox) {
xValueConvertor.removeValueConvertorListener(this);
xValueConvertor.setFollowOrdinate(xOrdinateBox.isSelected());
xValueConvertor.addValueConvertorListener(this);
} else if (e.getItemSelectable() == yOrdinateBox) {
yValueConvertor.removeValueConvertorListener(this);
yValueConvertor.setFollowOrdinate(yOrdinateBox.isSelected());
yValueConvertor.addValueConvertorListener(this);
}
}
}
@Override
public void convertorChanged(ValueConvertorEvent event) {
if ((event != null) && (event.getSource() != null)) {
if (event.getSource() == xValueConvertor) {
EDTManager.INSTANCE.runInDrawingThread(() -> {
if (xValueConvertor.isFollowOrdinate() != xOrdinateBox.isSelected()) {
xOrdinateBox.removeItemListener(this);
xOrdinateBox.setSelected(xValueConvertor.isFollowOrdinate());
xOrdinateBox.addItemListener(this);
}
});
} else if (event.getSource() == yValueConvertor) {
EDTManager.INSTANCE.runInDrawingThread(() -> {
if (yValueConvertor.isFollowOrdinate() != yOrdinateBox.isSelected()) {
yOrdinateBox.removeItemListener(this);
yOrdinateBox.setSelected(yValueConvertor.isFollowOrdinate());
yOrdinateBox.addItemListener(this);
}
});
}
}
}
public String getXAxisFormat() {
return theViewer == null ? null : theViewer.getXAxisFormat();
}
......
......@@ -87,6 +87,39 @@ DisplayManager.Column.Alias = Alias
MatrixViewer.XScale = X Scale
MatrixViewer.YScale = Y Scale
MatrixViewer.Scale.Concertor.Ordinate.Text = Follow ordinates instead of abscissa
MatrixViewer.Scale.Concertor.Ordinate.Tooltip.X = <html><body>\
<ul>\
<li>\
If checked\
<ul>\
<li>\
If data in X scale represents a matrix, X scale will be read by columns (column 1, then columns 2, etc.)\
</li>\
<li>If data in X scale does not represent a matrix, X scale will be classic dimensions (from 0 to width).</li>\
</ul>\
</li>\
<li>\
Otherwise, X scale will be the usual one (row by row for matrix, natural order for arrays).\
</li>\
</ul>\
</body></html>
MatrixViewer.Scale.Concertor.Ordinate.Tooltip.Y = <html><body>\
<ul>\
<li>\
If checked\
<ul>\
<li>\
If data in Y scale represents a matrix, Y scale will be read by columns (column 1, then columns 2, etc.)\
</li>\
<li>If data in Y scale does not represent a matrix, Y scale will be classic dimensions (from 0 to height).</li>\
</ul>\
</li>\
<li>\
Otherwise, Y scale will be the usual one (row by row for matrix, natural order for arrays).\
</li>\
</ul>\
</body></html>
Player.ChangeScaled = Change scale of player
Player.ToolTip = Get the scale to the player index
......
......@@ -86,6 +86,39 @@ DisplayManager.Column.Alias = Alias
MatrixViewer.XScale = Echelle X
MatrixViewer.YScale = Echelle Y
MatrixViewer.Scale.Concertor.Ordinate.Text = Suivre les ordonn\u00e9es au lieu des abscisses
MatrixViewer.Scale.Concertor.Ordinate.Tooltip.X = <html><body>\
<ul>\
<li>\
Si coch\u00e9\
<ul>\
<li>\
Si la donn\u00e9e sur l'\u00e9chelle des X repr\u00e9sente une matrice, l'\u00e9chelle des X sera lue colonne par colonne (colonne 1, puis colonne 2, etc.)\
</li>\
<li>Si la donn\u00e9e sur l'\u00e9chelle des X ne repr\u00e9sente pas une matrice, l'\u00e9chelle des X sera la dimension classique (de 0 à largeur).</li>\
</ul>\
</li>\
<li>\
Sinon, l'\u00e9chelle des X sera l'\u00e9chelle habituelle (ligne par ligne pour les matrices, ordre naturel pour les tableaux).\
</li>\
</ul>\
</body></html>
MatrixViewer.Scale.Concertor.Ordinate.Tooltip.Y = <html><body>\
<ul>\
<li>\
Si coch\u00e9\
<ul>\
<li>\
Si la donn\u00e9e sur l'\u00e9chelle des Y repr\u00e9sente une matrice, l'\u00e9chelle des Y sera lue colonne par colonne (colonne 1, puis colonne 2, etc.)\
</li>\
<li>Si la donn\u00e9e sur l'\u00e9chelle des Y ne repr\u00e9sente pas une matrice, l'\u00e9chelle des Y sera la dimension classique (de 0 à hauteur).</li>\
</ul>\
</li>\
<li>\
Sinon, l'\u00e9chelle des Y sera l'\u00e9chelle habituelle (ligne par ligne pour les matrices, ordre naturel pour les tableaux).\
</li>\
</ul>\
</body></html>
Player.ChangeScaled = Changer l'\u00e9chelle du player
Player.ToolTip = Get the scale to the player index
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment