Java tutorial
/************** * APE: AnsProlog* Programming Environment plug-in for the Eclipse platform * Copyright (C) 2006 Adrian Sureshkumar * * 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 uk.ac.bath.cs.asp.ide.smodels.internal.preferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.FileFieldEditor; import org.eclipse.swt.graphics.FontMetrics; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.preferences.ScopedPreferenceStore; import uk.ac.bath.cs.asp.ide.smodels.SmodelsPreferenceConstants; /** * Preference page for Smodels * * @author Adrian Sureshkumar */ public class SmodelsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { public SmodelsPreferencePage() { super(GRID); setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(), "uk.ac.bath.cs.asp.ide.smodels")); } protected void createFieldEditors() { final Composite parent = getFieldEditorParent(); final FileFieldEditor locationEditor = new FileFieldEditor( SmodelsPreferenceConstants.SMODELS_PROGRAM_LOCATION, "Program Location", parent); // locationEditor.setEmptyStringAllowed(false); // Limit the width of the text field to 20 characters final Text fileText = locationEditor.getTextControl(parent); final GC gc = new GC(fileText); gc.setFont(fileText.getFont()); final FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); final int width = Dialog.convertWidthInCharsToPixels(fontMetrics, 20); final GridData gridData = (GridData) fileText.getLayoutData(); gridData.widthHint = width; gridData.grabExcessHorizontalSpace = true; // Add the field to the page addField(locationEditor); } public void init(IWorkbench workbench) { // TODO Auto-generated method stub } }