/**
* This file is part of HIDB2.
*
* HIDB2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HIDB2 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 Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser Public License
* along with HIDB2. If not, see <http://www.gnu.org/licenses/>.
*/
package hidb2.gui.preferences;
import hidb2.Activator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
/**
* This class represents the preference page of the image viewer.
*/
public class ImageViewerPrefPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
{
public ImageViewerPrefPage()
{
super(GRID);
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setDescription("Image Viewer Preference page");
}
/**
* Creates the field editors.
*/
public void createFieldEditors()
{
addField(new IntegerFieldEditor(PrefConst.P_IVR_DEFAULT_WIDTH, "Default Width (pixel)", getFieldEditorParent()));
addField(new IntegerFieldEditor(PrefConst.P_IVR_DEFAULT_HEIGHT, "Default Height (pixel)", getFieldEditorParent()));
addField(new IntegerFieldEditor(PrefConst.P_IVR_MIN_ZOOM, "Minimal Zoom Factor (%)", getFieldEditorParent()));
addField(new IntegerFieldEditor(PrefConst.P_IVR_MAX_ZOOM, "Maximal Zoom Factor (%)", getFieldEditorParent()));
}
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
public void init(IWorkbench workbench)
{
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#performOk()
*/
@Override
public boolean performOk()
{
boolean res = super.performOk();
int minz = Activator.getDefault().getPreferenceStore().getInt(PrefConst.P_IVR_MIN_ZOOM);
int maxz = Activator.getDefault().getPreferenceStore().getInt(PrefConst.P_IVR_MAX_ZOOM);
if (minz < 10)
{
MessageDialog.openWarning(getShell(), "Invalid Value", "The Minimum Zoom Factor shall not be below 10%");
return false;
}
if (minz >= maxz)
{
MessageDialog.openWarning(getShell(), "Invalid Value", "The Minimum Zoom Factor shall not be greater than \nthe Maximum Zoom factor");
return false;
}
return res;
}
}