/*
* File : GOIMColorPreferences.java
* Created : 27.12.2005
* By : kahless
*
* Gamer's Own Instant Messenger
* Copyright (C) 2005 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package net.sphene.goim.rcp.preferences;
import java.util.ArrayList;
import java.util.List;
import net.sphene.goim.rcp.GOIMPlugin;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FontFieldEditor;
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.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class GOIMSimpleContactListColorPreferences extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {
public GOIMSimpleContactListColorPreferences() {
super(FLAT);
setPreferenceStore(GOIMPlugin.getDefault().getPreferenceStore());
setDescription("Colors and Fonts");
}
public void init(IWorkbench workbench) {
}
Composite colors;
Composite fonts;
List<FieldEditor> colorFieldEditors = new ArrayList<FieldEditor>();
List<FieldEditor> fontsFieldEditors = new ArrayList<FieldEditor>();
protected FieldEditor addEditorToColorGroup(FieldEditor editor) {
colorFieldEditors.add(editor);
return editor;
}
protected FieldEditor addEditorToFontsGroup(FieldEditor editor) {
fontsFieldEditors.add(editor);
return editor;
}
protected void setColorsEnabledState(boolean enable) {
colors.setEnabled(enable);
for(FieldEditor editor : colorFieldEditors) {
editor.setEnabled(enable,colors);
}
}
protected void setFontsEnabledState(boolean enable) {
fonts.setEnabled(enable);
for(FieldEditor editor : fontsFieldEditors) {
editor.setEnabled(enable,fonts);
}
}
@Override
protected void createFieldEditors() {
BooleanFieldEditor customizeColors = new BooleanFieldEditor(PreferenceConstants.P_SIMPLE_CONTACTLIST_CUSTOMIZE_COLORS,"Customize Colors",getFieldEditorParent()) {
protected void valueChanged(boolean oldValue, boolean newValue) {
super.valueChanged(oldValue,newValue);
setColorsEnabledState(newValue);
}
};
addField(customizeColors);
Group colors = new Group(getFieldEditorParent(),SWT.NULL);
colors.setLayout(new GridLayout(2,false));
colors.getParent().setLayout(new GridLayout(1,true));
colors.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
colors.setText("Modify Colors of Simple Contact List");
this.colors = new Composite(colors,SWT.NULL);
this.colors.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
addField(addEditorToColorGroup(new ColorFieldEditor(PreferenceConstants.P_SIMPLE_CONTACTLIST_COLORS_BACKGROUND,"Background Color",this.colors)));
addField(addEditorToColorGroup(new ColorFieldEditor(PreferenceConstants.P_SIMPLE_CONTACTLIST_COLORS_TEXT,"Foreground Color",this.colors)));
BooleanFieldEditor customizeFonts = new BooleanFieldEditor(PreferenceConstants.P_SIMPLE_CONTACTLIST_CUSTOMIZE_FONTS,"Customize Fonts",getFieldEditorParent()) {
protected void valueChanged(boolean oldValue, boolean newValue) {
super.valueChanged(oldValue,newValue);
setFontsEnabledState(newValue);
}
};
addField(customizeFonts);
Group fonts = new Group(getFieldEditorParent(),SWT.NULL);
fonts.getParent().setLayout(new GridLayout(1,false));
fonts.setLayout(new GridLayout(1,false));
fonts.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,4,1));
fonts.setText("Modify Fonts of Simple Contact List");
this.fonts = new Composite(fonts,SWT.NULL);
this.fonts.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
addField(addEditorToFontsGroup(new FontFieldEditor(PreferenceConstants.P_SIMPLE_CONTACTLIST_FONTS_DEFAULT,"Default Font:",this.fonts)));
setColorsEnabledState(getPreferenceStore().getBoolean(PreferenceConstants.P_SIMPLE_CONTACTLIST_CUSTOMIZE_COLORS));
setFontsEnabledState(getPreferenceStore().getBoolean(PreferenceConstants.P_SIMPLE_CONTACTLIST_CUSTOMIZE_FONTS));
}
}