blob: 32e2eab5d95c0fd70a2115ee6bce499c5637e6dc [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
<<<<<<< HEAD
* Pierre Allard - initial API and implementation
* Regent L'Archeveque
*
=======
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
>>>>>>> refs/heads/eclipse_pa
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.addons.sensors.imaging.ui.preferences;
import org.eclipse.apogy.addons.sensors.imaging.ui.Activator;
import org.eclipse.apogy.common.topology.ui.MeshPresentationMode;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class MRTImagingPreferencesPage extends PreferencePage implements IWorkbenchPreferencePage {
private BooleanFieldEditor imageSnapshotVisibilityFOVBooleanFieldEditor;
private BooleanFieldEditor imageSnapshotImageFOVVisibilityBooleanFieldEditor;
private BooleanFieldEditor imageSnapshotImageProjectionBooleanFieldEditor;
private BooleanFieldEditor imageSnapshotImageProjectionOnFOVBooleanFieldEditor;
private RadioGroupFieldEditor imageSnapshotFOVPresentationModeRadioGroupFieldEditor;
private ColorFieldEditor imageSnapshotFOVColorFieldEditor;
private BooleanFieldEditor imageSnapshotAxisVisibilityBooleanFieldEditor;
/**
* Create the preference page.
*/
public MRTImagingPreferencesPage() {
}
/**
* Create contents of the preference page.
*
* @param parent
*/
@Override
public Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout(1, true));
// Image Snapshot FOV
Group grpImageSnapshotFOV = new Group(container, SWT.NONE);
grpImageSnapshotFOV.setLayout(new GridLayout(3, true));
grpImageSnapshotFOV.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1));
grpImageSnapshotFOV.setText("Image Snaphot");
Label circularSectorFOVVisibilityLabel = new Label(grpImageSnapshotFOV, SWT.NONE);
circularSectorFOVVisibilityLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
circularSectorFOVVisibilityLabel.setText("Visibility");
this.imageSnapshotVisibilityFOVBooleanFieldEditor = createBooleanFieldEditor(grpImageSnapshotFOV,
MRTImagingPreferencesConstants.DEFAULT_IMAGE_SNAPSHOT_VISIBILITY_ID, "");
Label imageSnapshotImageFOVVisiblityLabel = new Label(grpImageSnapshotFOV, SWT.NONE);
imageSnapshotImageFOVVisiblityLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
imageSnapshotImageFOVVisiblityLabel.setText("FOV Visible");
this.imageSnapshotImageFOVVisibilityBooleanFieldEditor = createBooleanFieldEditor(grpImageSnapshotFOV,
MRTImagingPreferencesConstants.DEFAULT_IMAGE_SNAPSHOT_FOV_VISIBLE_ID, "");
Label imageSnapshotImageProjectionOnFOVLabel = new Label(grpImageSnapshotFOV, SWT.NONE);
imageSnapshotImageProjectionOnFOVLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
imageSnapshotImageProjectionOnFOVLabel.setText("Project Image On FOV");
this.imageSnapshotImageProjectionOnFOVBooleanFieldEditor = createBooleanFieldEditor(grpImageSnapshotFOV,
MRTImagingPreferencesConstants.DEFAULT_IMAGE_SNAPSHOT_SHOW_PROJECTION_ON_FOV_ID, "");
Label imageSnapshotImageProjectionLabel = new Label(grpImageSnapshotFOV, SWT.NONE);
imageSnapshotImageProjectionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
imageSnapshotImageProjectionLabel.setText("Show Projection");
this.imageSnapshotImageProjectionBooleanFieldEditor = createBooleanFieldEditor(grpImageSnapshotFOV,
MRTImagingPreferencesConstants.DEFAULT_IMAGE_SNAPSHOT_SHOW_PROJECTION_ID, "");
this.imageSnapshotFOVColorFieldEditor = createColorFieldEditor(grpImageSnapshotFOV,
MRTImagingPreferencesConstants.DEFAULT_IMAGE_SNAPSHOT_FOV_COLOR_ID, "Default Color:");
Label circularSectorFOVModeLabel = new Label(grpImageSnapshotFOV, SWT.NONE);
circularSectorFOVModeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
circularSectorFOVModeLabel.setText("Presentation Mode:");
this.imageSnapshotFOVPresentationModeRadioGroupFieldEditor = createRadioGroupFieldEditor(grpImageSnapshotFOV,
MRTImagingPreferencesConstants.DEFAULT_IMAGE_SNAPSHOT_FOV_PRESENTATION_MODE_ID, "");
Label imageSnapshotImageAxisVisiblityLabel = new Label(grpImageSnapshotFOV, SWT.NONE);
imageSnapshotImageAxisVisiblityLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
imageSnapshotImageAxisVisiblityLabel.setText("FOV Axis Visible");
this.imageSnapshotAxisVisibilityBooleanFieldEditor = createBooleanFieldEditor(grpImageSnapshotFOV,
MRTImagingPreferencesConstants.DEFAULT_IMAGE_SNAPSHOT_AXIS_VISIBLE_ID, "");
return container;
}
/**
* Initialize the preference page.
*/
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
}
@Override
public boolean performOk() {
storePreferences();
return super.performOk();
}
@Override
protected void performApply() {
storePreferences();
super.performApply();
}
@Override
protected void performDefaults() {
this.imageSnapshotVisibilityFOVBooleanFieldEditor.loadDefault();
this.imageSnapshotImageProjectionBooleanFieldEditor.loadDefault();
this.imageSnapshotImageProjectionOnFOVBooleanFieldEditor.loadDefault();
this.imageSnapshotFOVPresentationModeRadioGroupFieldEditor.loadDefault();
this.imageSnapshotFOVColorFieldEditor.loadDefault();
this.imageSnapshotImageFOVVisibilityBooleanFieldEditor.loadDefault();
this.imageSnapshotAxisVisibilityBooleanFieldEditor.loadDefault();
super.performDefaults();
}
private String[][] getModeLabelsAndValues() {
String[][] labelAndValues = new String[MeshPresentationMode.VALUES.size()][2];
int i = 0;
for (MeshPresentationMode value : MeshPresentationMode.VALUES) {
labelAndValues[i][0] = value.getName();
labelAndValues[i][1] = Integer.toString(value.getValue());
i++;
}
return labelAndValues;
}
private BooleanFieldEditor createBooleanFieldEditor(final Composite container, final String preferenceID,
final String preferenceLabel) {
BooleanFieldEditor editor = new BooleanFieldEditor(preferenceID, preferenceLabel, container);
// Set the editor up to use this page
editor.setPreferenceStore(getPreferenceStore());
editor.load();
return editor;
}
private RadioGroupFieldEditor createRadioGroupFieldEditor(final Composite container, final String preferenceID,
final String preferenceLabel) {
Composite editorContainer = new Composite(container, SWT.NULL);
editorContainer.setLayout(new GridLayout(1, true));
RadioGroupFieldEditor editor = new RadioGroupFieldEditor(preferenceID, preferenceLabel, 1,
getModeLabelsAndValues(), editorContainer, false);
// Set the editor up to use this page
editor.setPreferenceStore(getPreferenceStore());
editor.load();
return editor;
}
private ColorFieldEditor createColorFieldEditor(final Composite container, final String preferenceID,
final String preferenceLabel) {
ColorFieldEditor colorEditor = new ColorFieldEditor(preferenceID, preferenceLabel, container);
// Set the editor up to use this page
colorEditor.setPreferenceStore(getPreferenceStore());
colorEditor.load();
return colorEditor;
}
private void storePreferences() {
this.imageSnapshotVisibilityFOVBooleanFieldEditor.store();
this.imageSnapshotImageProjectionBooleanFieldEditor.store();
this.imageSnapshotImageProjectionOnFOVBooleanFieldEditor.store();
this.imageSnapshotFOVPresentationModeRadioGroupFieldEditor.store();
this.imageSnapshotFOVColorFieldEditor.store();
this.imageSnapshotImageFOVVisibilityBooleanFieldEditor.store();
this.imageSnapshotAxisVisibilityBooleanFieldEditor.store();
}
}