blob: 6f8e4b072cbd7fc3bc593d5a2cf5503aa7d2d222 [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:
* Pierre Allard - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
package org.eclipse.apogy.core.environment.earth.surface.ui.jme3.preferences;
import org.eclipse.apogy.core.environment.earth.surface.ui.jme3.Activator;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.preference.StringFieldEditor;
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 ApogyEarthSurfaceEnvironmentUIJME3PreferencesPage extends PreferencePage
implements IWorkbenchPreferencePage {
private BooleanFieldEditor earthSkyBloomEnableEditor;
private StringFieldEditor earthSkyShadowMapSizeEditor;
private BooleanFieldEditor earthSkySunCastShadowsEnableEditor;
private BooleanFieldEditor earthSkyMoonCastShadowsEnableEditor;
private BooleanFieldEditor earthSkyHorizonVisibleEditor;
/**
* Create the preference page.
*/
public ApogyEarthSurfaceEnvironmentUIJME3PreferencesPage() {
}
/**
* 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));
// Earth Sky.
Group earthSkyGroup = new Group(container, SWT.NONE);
earthSkyGroup.setLayout(new GridLayout(2, true));
earthSkyGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1));
earthSkyGroup.setText("Earth Sky");
Label earthSkyBloomEnableLabel = new Label(earthSkyGroup, SWT.NONE);
earthSkyBloomEnableLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
earthSkyBloomEnableLabel.setText("Sun and Moon Bloom Enable");
this.earthSkyBloomEnableEditor = createBooleanFieldEditor(earthSkyGroup,
ApogyEarthSurfaceEnvironmentUIJME3PreferencesConstants.DEFAULT_BLOOM_ENABLED_ID, "");
Label earthSkyShadowMapSizeLabel = new Label(earthSkyGroup, SWT.NONE);
earthSkyShadowMapSizeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
earthSkyShadowMapSizeLabel.setText("Shadow Map Size");
this.earthSkyShadowMapSizeEditor = createStringFieldEditor(earthSkyGroup,
ApogyEarthSurfaceEnvironmentUIJME3PreferencesConstants.DEFAULT_SHADOW_MAP_SIZE_ID, "");
Label earthSkySunCastShadowsEnableLabel = new Label(earthSkyGroup, SWT.NONE);
earthSkySunCastShadowsEnableLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
earthSkySunCastShadowsEnableLabel.setText("Sun Cast Shadows Enable");
this.earthSkySunCastShadowsEnableEditor = createBooleanFieldEditor(earthSkyGroup,
ApogyEarthSurfaceEnvironmentUIJME3PreferencesConstants.DEFAULT_SUN_CAST_SHADOWS_ENABLED_ID, "");
Label earthSkyMoonCastShadowsEnableLabel = new Label(earthSkyGroup, SWT.NONE);
earthSkyMoonCastShadowsEnableLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
earthSkyMoonCastShadowsEnableLabel.setText("Moon Cast Shadows Enable");
this.earthSkyMoonCastShadowsEnableEditor = createBooleanFieldEditor(earthSkyGroup,
ApogyEarthSurfaceEnvironmentUIJME3PreferencesConstants.DEFAULT_MOON_CAST_SHADOWS_ENABLED_ID, "");
Label earthSkyHorizonVisibleLabel = new Label(earthSkyGroup, SWT.NONE);
earthSkyHorizonVisibleLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
earthSkyHorizonVisibleLabel.setText("Horizon Visible");
this.earthSkyHorizonVisibleEditor = createBooleanFieldEditor(earthSkyGroup,
ApogyEarthSurfaceEnvironmentUIJME3PreferencesConstants.DEFAULT_HORIZON_VISIBLE_ID, "");
this.earthSkyHorizonVisibleEditor
.setPreferenceStore(org.eclipse.apogy.core.environment.ui.Activator.getDefault().getPreferenceStore());
this.earthSkyHorizonVisibleEditor.load();
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.earthSkyBloomEnableEditor.loadDefault();
this.earthSkyShadowMapSizeEditor.loadDefault();
this.earthSkySunCastShadowsEnableEditor.loadDefault();
this.earthSkyMoonCastShadowsEnableEditor.loadDefault();
this.earthSkyHorizonVisibleEditor.loadDefault();
super.performDefaults();
}
private BooleanFieldEditor createBooleanFieldEditor(final Composite container, final String preferenceID,
final String preferenceLabel) {
Composite editorContainer = new Composite(container, SWT.NULL);
editorContainer.setLayout(new GridLayout(1, true));
editorContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
BooleanFieldEditor editor = new BooleanFieldEditor(preferenceID, preferenceLabel, editorContainer);
// Set the editor up to use this page
editor.setPreferenceStore(getPreferenceStore());
editor.load();
return editor;
}
private StringFieldEditor createStringFieldEditor(final Composite container, final String preferenceID,
final String preferenceLabel) {
Composite editorContainer = new Composite(container, SWT.NULL);
editorContainer.setLayout(new GridLayout(1, true));
editorContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
StringFieldEditor editor = new StringFieldEditor(preferenceID, preferenceLabel, editorContainer);
// Set the editor up to use this page
editor.setPreferenceStore(getPreferenceStore());
editor.load();
return editor;
}
private void storePreferences() {
this.earthSkyBloomEnableEditor.store();
this.earthSkyShadowMapSizeEditor.store();
this.earthSkySunCastShadowsEnableEditor.store();
this.earthSkyMoonCastShadowsEnableEditor.store();
this.earthSkyHorizonVisibleEditor.store();
}
}