1 package net.mograsim.plugin;
3 import static net.mograsim.logic.model.preferences.RenderPreferences.ACTION_BUTTON;
4 import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_ONE_DASH;
5 import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_U_DASH;
6 import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_X_DASH;
7 import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_ZERO_DASH;
8 import static net.mograsim.logic.model.preferences.RenderPreferences.BIT_Z_DASH;
9 import static net.mograsim.logic.model.preferences.RenderPreferences.DEBUG_HLSSHELL_DEPTH;
10 import static net.mograsim.logic.model.preferences.RenderPreferences.DEBUG_OPEN_HLSSHELL;
11 import static net.mograsim.logic.model.preferences.RenderPreferences.DEFAULT_LINE_WIDTH;
12 import static net.mograsim.logic.model.preferences.RenderPreferences.DRAG_BUTTON;
13 import static net.mograsim.logic.model.preferences.RenderPreferences.WIRE_WIDTH_MULTIBIT;
14 import static net.mograsim.logic.model.preferences.RenderPreferences.WIRE_WIDTH_SINGLEBIT;
15 import static net.mograsim.logic.model.preferences.RenderPreferences.ZOOM_BUTTON;
16 import static net.mograsim.plugin.preferences.PluginPreferences.MPM_EDITOR_BITS_AS_COLUMN_NAME;
18 import java.util.function.Consumer;
20 import org.eclipse.jface.preference.BooleanFieldEditor;
21 import org.eclipse.jface.preference.ComboFieldEditor;
22 import org.eclipse.jface.preference.FieldEditorPreferencePage;
23 import org.eclipse.jface.preference.IntegerFieldEditor;
24 import org.eclipse.jface.preference.StringFieldEditor;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Group;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.ui.IWorkbench;
32 import org.eclipse.ui.IWorkbenchPreferencePage;
34 import net.mograsim.logic.model.preferences.RenderPreferences;
35 import net.mograsim.plugin.preferences.PluginPreferences;
36 import net.mograsim.plugin.util.DoubleFieldEditor;
37 import net.mograsim.preferences.Preferences;
39 public class MainPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
41 private static final String[][] MOUSE_BUTTONS = { { "left", "1" }, { "middle", "2" }, { "right", "3" }, { "4th", "4" },
44 public MainPreferencePage()
50 public void init(IWorkbench workbench)
52 setPreferenceStore(MograsimActivator.instance().getPreferenceStore());
56 protected void createFieldEditors()
58 Composite parent = getFieldEditorParent();
59 addBoolean(DEBUG_OPEN_HLSSHELL, "Open the debug HLS shell", parent);
60 addInt(DEBUG_HLSSHELL_DEPTH, "Depth of components to list in the debug HLS shell (0: unbounded)", parent);
61 addIntCombo(ACTION_BUTTON, "Mouse button for actions", MOUSE_BUTTONS, parent);
62 addIntCombo(DRAG_BUTTON, "Mouse button for dragging", MOUSE_BUTTONS, parent);
63 addIntCombo(ZOOM_BUTTON, "Mouse button for zooming", MOUSE_BUTTONS, parent);
64 addBoolean(MPM_EDITOR_BITS_AS_COLUMN_NAME, "Use the raw bit indices of MPM columns as column titles in the MPM editor", parent);
66 insertSeparator(parent);
67 addDouble(WIRE_WIDTH_SINGLEBIT, "Line width for single-bit wires", parent);
68 addDouble(WIRE_WIDTH_MULTIBIT, "Line width for multi-bit wires", parent);
69 addDouble(DEFAULT_LINE_WIDTH, "Line width for other wires", parent);
70 addDashesGroup(parent);
71 // TODO add other preferences
74 private void addDashesGroup(Composite parent)
76 Composite dashesGroupParent = new Composite(parent, SWT.NONE);
77 dashesGroupParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
78 GridLayout dashesGroupParentLayout = new GridLayout();
79 dashesGroupParentLayout.marginWidth = 0;
80 dashesGroupParentLayout.marginHeight = 0;
81 dashesGroupParent.setLayout(dashesGroupParentLayout);
83 Group dashesGroup = new Group(dashesGroupParent, SWT.NONE);
84 dashesGroup.setText("Line dashes");
85 dashesGroup.setLayout(new GridLayout());
86 dashesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
88 Composite content = new Composite(dashesGroup, SWT.NONE);
89 content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
90 GridLayout contentLayout = new GridLayout(2, false);
91 contentLayout.marginWidth = 0;
92 contentLayout.marginHeight = 0;
93 content.setLayout(contentLayout);
95 Label dashesDescription = new Label(content, SWT.WRAP);
96 dashesDescription.setText("Line dashes for single-bit wires displaying the respective value.\n"
97 + "Format: A comma-separated list of doubles. The first value is the width of the first segment,\n"
98 + "the second is the spacing between the first and second segments,\n"
99 + "the third is the width of the second segment and so on.");
100 dashesDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
101 addString(BIT_ZERO_DASH, "0", content);
102 addString(BIT_Z_DASH, "Z", content);
103 addString(BIT_X_DASH, "X", content);
104 addString(BIT_U_DASH, "U", content);
105 addString(BIT_ONE_DASH, "1", content);
108 private void addBoolean(String name, String label, Composite parent)
110 defaultsPreferenceStore(name).getBoolean(name);
111 addField(new BooleanFieldEditor(name, label, parent));
114 private void addInt(String name, String label, Composite parent)
116 defaultsPreferenceStore(name).getInt(name);
117 addField(new IntegerFieldEditor(name, label, parent));
120 private void addDouble(String name, String label, Composite parent)
122 defaultsPreferenceStore(name).getDouble(name);
123 addField(new DoubleFieldEditor(name, label, parent));
126 private void addIntCombo(String name, String label, String[][] entryNamesAndValues, Composite parent)
128 addCombo(name, label, entryNamesAndValues, parent, defaultsPreferenceStore(name)::getInt);
131 private void addCombo(String name, String label, String[][] entryNamesAndValues, Composite parent, Consumer<String> initializeDefault)
133 initializeDefault.accept(name);
134 addField(new ComboFieldEditor(name, label, entryNamesAndValues, parent));
137 private void addString(String name, String label, Composite parent)
139 defaultsPreferenceStore(name).getString(name);
140 addField(new StringFieldEditor(name, label, parent));
143 private static void insertSeparator(Composite parent)
145 new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
148 private static Preferences defaultsPreferenceStore(String name)
150 // TODO is it a good idea to list all preference systems here?
151 // Maybe rather split the page into one per preference system
152 MograsimActivator mograsim = MograsimActivator.instance();
153 if (name.startsWith(RenderPreferences.PREFIX))
154 return mograsim.getRenderPrefs();
155 else if (name.startsWith(PluginPreferences.PREFIX))
156 return mograsim.getPluginPrefs();
158 throw new IllegalArgumentException("The preference system containing " + name + " is not known");