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

- Edited preferences are always up-to-date (useful for SCAN-902)

- Added a waiting dialog at preferences frame closing (detected during SCAN-902)
parent 97d9caed
Branches
Tags
No related merge requests found
......@@ -8,6 +8,7 @@ import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import fr.soleil.lib.project.ObjectUtils;
import fr.soleil.salsa.client.preferences.UIPreferences;
import fr.soleil.salsa.preferences.DevicePreferences;
......@@ -18,7 +19,7 @@ import fr.soleil.salsa.preferences.DevicePreferences;
*/
public class BeanPreference extends JPanel implements Preference {
private static final long serialVersionUID = 8247679651671351814L;
private static final long serialVersionUID = -6452680257666171637L;
private DevicePreferences devicePreferences;
private final JTable table;
......@@ -70,11 +71,14 @@ public class BeanPreference extends JPanel implements Preference {
return "Bean Preferences";
}
}
// ///////////// //
// Inner classes //
// ///////////// //
protected static class UiTableModel extends AbstractTableModel {
class UiTableModel extends AbstractTableModel {
private static final long serialVersionUID = -8041638129379208113L;
private static final long serialVersionUID = -3143617959903292641L;
private DevicePreferences devicePreferences;
public final static String[] COLUMN_NAMES = { "Display", "Your choice" };
public static final int YOUR_CHOICE = 1;
......@@ -92,7 +96,8 @@ class UiTableModel extends AbstractTableModel {
{ "Allow display image as spectrums", UIPreferences.getInstance().isShowImageAsSpectrumStack() },
{ "Allow send values to sensors", UIPreferences.getInstance().isSendSensor() },
{ "Control Panel", UIPreferences.getInstance().getControlPanel() },
{ "User LogFile", (devicePreferences == null ? "" : devicePreferences.getUserLogFile()) } };
{ "User LogFile", (devicePreferences == null ? ObjectUtils.EMPTY_STRING
: devicePreferences.getUserLogFile()) } };
fireTableDataChanged();
}
......@@ -118,30 +123,38 @@ class UiTableModel extends AbstractTableModel {
@Override
public void setValueAt(Object aValue, int r, int c) {
values[r][c] = aValue;
// fireTableCellUpdated(r, c);
if (aValue != null && c == 1) {
try {
if ((aValue != null) && (c == 1)) {
String name = (String) getValueAt(r, 0);
if (name.equalsIgnoreCase("Enable confirmation")) {
String stringValue = aValue.toString().toLowerCase();
Boolean value = "true".equals(stringValue) || "yes".equals(stringValue);
UIPreferences.getInstance().setEnableConfirmation(value);
UIPreferences.getInstance()
.setEnableConfirmation("true".equals(stringValue) || "yes".equals(stringValue));
aValue = UIPreferences.getInstance().isEnableConfirmation();
} else if (name.equalsIgnoreCase("Data browser")) {
String value = aValue.toString();
UIPreferences.getInstance().setDataBrowser(value);
aValue = UIPreferences.getInstance().getDataBrowser();
} else if (name.equalsIgnoreCase("Allow display image as spectrums")) {
String value = aValue.toString();
UIPreferences.getInstance().showImageAsSpectrumStack(value);
aValue = UIPreferences.getInstance().isShowImageAsSpectrumStack();
} else if (name.equalsIgnoreCase("Allow send values to sensors")) {
String value = aValue.toString();
UIPreferences.getInstance().sendSensor(value);
aValue = UIPreferences.getInstance().isSendSensor();
} else if (name.equalsIgnoreCase("User LogFile")) {
String value = aValue.toString();
getDevicePreferences().setUserLogFile(value);
aValue = getDevicePreferences().getUserLogFile();
} else if (name.equalsIgnoreCase("Control Panel")) {
UIPreferences.getInstance().setControlPanel(aValue.toString().trim());
aValue = UIPreferences.getInstance().getControlPanel();
}
}
} finally {
values[r][c] = aValue;
}
}
@Override
......@@ -159,3 +172,5 @@ class UiTableModel extends AbstractTableModel {
}
}
}
......@@ -15,8 +15,10 @@ import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import fr.soleil.lib.project.swing.dialog.ProgressDialog;
import fr.soleil.lib.project.swing.icons.Icons;
import fr.soleil.salsa.client.preferences.UIPreferences;
import fr.soleil.salsa.client.preferences.UIPreferencesPersistence;
......@@ -31,7 +33,7 @@ import fr.soleil.salsa.preferences.DevicePreferencesPersistence;
*/
public class PreferencesFrame extends JFrame {
/** Serialization id */
private static final long serialVersionUID = -6831448062302843213L;
private static final long serialVersionUID = -5903033303877197150L;
/** Package of the current class */
private static final String PACKAGE = PreferencesFrame.class.getPackage().getName();
......@@ -52,17 +54,7 @@ public class PreferencesFrame extends JFrame {
private DevicePreferencesPanel devicePreferencesPanel;
/**
* Main for testing
*
* @param args the command lines arguments
* @throws Exception if an error occurred
*/
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame frame = new PreferencesFrame();
frame.setVisible(true);
}
private ProgressDialog progressDialog;
/**
* This is the default constructor
......@@ -78,6 +70,7 @@ public class PreferencesFrame extends JFrame {
*/
public PreferencesFrame(DevicePreferences devicePreferences) {
super();
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
initialize();
setPreferences(devicePreferences);
}
......@@ -93,19 +86,51 @@ public class PreferencesFrame extends JFrame {
prefsPanel = new ButtonBarPreference();
//
getContentPane().add("Center", prefsPanel);
getJContentPane().add(prefsPanel, BorderLayout.CENTER);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if (devicePreferencesPanel != null)
closeAction();
}
});
}
protected ProgressDialog getProgressDialog() {
if (progressDialog == null) {
progressDialog = new ProgressDialog(this);
progressDialog.setProgressIndeterminate(true);
}
return progressDialog;
}
protected void closeAction() {
if (devicePreferencesPanel != null) {
devicePreferencesPanel.validateTable();
}
ProgressDialog progressDialog = getProgressDialog();
progressDialog.setTitle("Saving preferences...");
progressDialog.setMainMessage(progressDialog.getTitle());
progressDialog.pack();
progressDialog.setSize(Math.max(300, progressDialog.getWidth()), progressDialog.getHeight());
progressDialog.setLocationRelativeTo(this);
progressDialog.setVisible(true);
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
UIPreferencesPersistence.save(UIPreferences.getInstance());
DevicePreferencesPersistence.save(getDevicePreferences());
super.windowClosing(e);
return null;
}
});
@Override
protected void done() {
progressDialog.setVisible(false);
setVisible(false);
}
};
worker.execute();
}
/**
......@@ -183,4 +208,18 @@ public class PreferencesFrame extends JFrame {
SwingUtilities.invokeLater(ftf::selectAll);
}
}
/**
* Main for testing
*
* @param args the command lines arguments
* @throws Exception if an error occurred
*/
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame frame = new PreferencesFrame();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment