📄 uipreferencepage.java
字号:
package net.sf.pim.plugin;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import net.sf.pim.UiUtil;import net.sf.util.ConfigHelper;import org.eclipse.jface.preference.FieldEditorPreferencePage;import org.eclipse.jface.preference.PreferenceStore;import org.eclipse.jface.preference.StringFieldEditor;import org.eclipse.jface.util.IPropertyChangeListener;import org.eclipse.jface.util.PropertyChangeEvent;import org.eclipse.ui.IWorkbench;import org.eclipse.ui.IWorkbenchPreferencePage;/** * This class represents a preference page that is contributed to the * Preferences dialog. By subclassing <samp>FieldEditorPreferencePage </samp>, * we can use the field support built into JFace that allows us to create a page * that is small and knows how to save, restore and apply itself. * <p> * This page is used to modify preferences only. They are stored in the * preference store that belongs to the main plug-in class. That way, * preferences can be accessed directly via the preference store. */public class UIPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { private PreferenceStore ps; public UIPreferencePage() { super(GRID); ps = new PreferenceStore(); try { ps.load((new FileInputStream("work.properties"))); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } setPreferenceStore(ps); } /** * Creates the field editors. Field editors are abstractions of the common * GUI blocks needed to manipulate various types of preferences. Each field * editor knows how to save and restore itself. */ public void createFieldEditors() { String[] list = ps.preferenceNames(); for (int i = 0; i < list.length; i++) { String key = list[i]; String mc = (String) ConfigHelper.getPropMcList().get(key); StringFieldEditor sfe = new StringFieldEditor(key, mc, getFieldEditorParent()); sfe.setPreferenceStore(ps); if (mc.indexOf("不可修改") == -1) { sfe .setValidateStrategy(StringFieldEditor.VALIDATE_ON_FOCUS_LOST); sfe.setPropertyChangeListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { StringFieldEditor sf = (StringFieldEditor) event .getSource(); sf.store(); } }); } sfe.load(); addField(sfe); } } public void init(IWorkbench workbench) { } /* * (non-Javadoc) * * @see org.eclipse.jface.preference.IPreferencePage#performOk() */ public boolean performOk() { super.performOk(); try { ps.save(new FileOutputStream("work.properties"), ""); ConfigHelper.init(); UiUtil.init(); } catch (Exception ex) { ex.printStackTrace(); } return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -