001/*****************************************************************************
002 * Copyright by The HDF Group.                                               *
003 * Copyright by the Board of Trustees of the University of Illinois.         *
004 * All rights reserved.                                                      *
005 *                                                                           *
006 * This file is part of the HDF Java Products distribution.                  *
007 * The full copyright notice, including terms governing use, modification,   *
008 * and redistribution, is contained in the files COPYING and Copyright.html. *
009 * COPYING can be found at the root of the source code distribution tree.    *
010 * Or, see https://support.hdfgroup.org/products/licenses.html               *
011 * If you do not have access to either file, you may request a copy from     *
012 * help@hdfgroup.org.                                                        *
013 ****************************************************************************/
014
015package hdf.view.dialog;
016
017import org.eclipse.swt.SWT;
018import org.eclipse.swt.events.SelectionAdapter;
019import org.eclipse.swt.events.SelectionEvent;
020import org.eclipse.swt.layout.GridData;
021import org.eclipse.swt.layout.GridLayout;
022import org.eclipse.swt.widgets.Button;
023import org.eclipse.swt.widgets.Composite;
024import org.eclipse.swt.widgets.Control;
025import org.eclipse.swt.widgets.Label;
026import org.eclipse.swt.widgets.Text;
027
028import hdf.view.Tools;
029import hdf.view.ViewProperties;
030
031/**
032 * UserOptionsHDFPage.java - Configuration page for HDF-specific application
033 * settings.
034 */
035public class UserOptionsHDFPage extends UserOptionsDefaultPage {
036    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(UserOptionsHDFPage.class);
037
038    private Text fileExtField;
039    private Button checkConvertEnum, checkShowRegRefValues, helpButton;
040    private Button checkNativeOrder, checkDecOrder, checkIncOrder;
041    private Button checkIndexName, checkIndexCreateOrder;
042    private Button earlyLibVersion, early18LibVersion, early110LibVersion, early112LibVersion, earlyLateLibVersion;
043    private Button lateLibVersion, late18LibVersion, late110LibVersion, late112LibVersion, lateLateLibVersion;
044
045    /** Default early libversion for files */
046    private static String earlyLibVers;
047
048    /** Default late libversion for files */
049    private static String lateLibVers;
050
051    /** Default index type for files */
052    private static String indexType;
053
054    /** Default index ordering for files */
055    private static String indexOrder;
056
057    /**
058     * Configuration page for HDF-specific application settings.
059     */
060    public UserOptionsHDFPage() {
061        super("HDF Settings");
062    }
063
064    /**
065     * Performs special processing when this page's Defaults button has been pressed.
066     */
067    @Override
068    public void performDefaults() {
069        super.performDefaults();
070        getPreferenceStore();
071
072    }
073
074    /**
075     * Notifies that the OK button if this page's container has been pressed.
076     *
077     * @return <code>false</code> to abort the container's OK processing and <code>true</code> to allow
078     *         the OK to happen
079     */
080    @Override
081    public boolean performOk() {
082        getPreferenceStore();
083
084        if (fileExtField != null) {
085            String ext = fileExtField.getText();
086            if ((ext != null) && (ext.length() > 0)) {
087                ext = ext.trim();
088                ViewProperties.setFileExtension(ext);
089            }
090        }
091
092        log.trace("performOk: save HDF options earlyLibVersion={}", earlyLibVersion);
093        if (earlyLibVersion != null) {
094            if (earlyLibVersion.getSelection())
095                ViewProperties.setEarlyLib("Earliest");
096            else if (early18LibVersion.getSelection())
097                ViewProperties.setEarlyLib("v18");
098            else if (early110LibVersion.getSelection())
099                ViewProperties.setEarlyLib("v110");
100            else if (early112LibVersion.getSelection())
101                ViewProperties.setEarlyLib("v112");
102            else if (earlyLateLibVersion.getSelection())
103                ViewProperties.setEarlyLib("Latest");
104            else
105                ViewProperties.setEarlyLib("Earliest");
106        }
107
108        log.trace("performOk: save HDF options lateLibVersion={}", lateLibVersion);
109        if (lateLibVersion != null) {
110            if (lateLibVersion.getSelection())
111                ViewProperties.setLateLib("Earliest");
112            else if (late18LibVersion.getSelection())
113                ViewProperties.setLateLib("v18");
114            else if (late110LibVersion.getSelection())
115                ViewProperties.setLateLib("v110");
116            else if (late112LibVersion.getSelection())
117                ViewProperties.setLateLib("v112");
118            else if (lateLateLibVersion.getSelection())
119                ViewProperties.setLateLib("Latest");
120            else
121                ViewProperties.setLateLib("Latest");
122        }
123
124        // set index type
125        if (checkIndexName != null) {
126            if (checkIndexName.getSelection())
127                ViewProperties.setIndexType("H5_INDEX_NAME");
128            else
129                ViewProperties.setIndexType("H5_INDEX_CRT_ORDER");
130        }
131
132        // set index order
133        if (checkIncOrder != null) {
134            if (checkIncOrder.getSelection())
135                ViewProperties.setIndexOrder("H5_ITER_INC");
136            else if (checkNativeOrder.getSelection())
137                ViewProperties.setIndexOrder("H5_ITER_NATIVE");
138            else
139                ViewProperties.setIndexOrder("H5_ITER_DEC");
140        }
141
142        if (checkConvertEnum != null)
143            ViewProperties.setConvertEnum(checkConvertEnum.getSelection());
144        if (checkShowRegRefValues != null)
145            ViewProperties.setShowRegRefValue(checkShowRegRefValues.getSelection());
146
147        return true;
148    }
149
150    /**
151     * Loads all stored values in the <code>FieldEditor</code>s.
152     */
153    protected void load() {
154        getPreferenceStore();
155
156        fileExtField.setText(ViewProperties.getFileExtension());
157
158        earlyLibVers = ViewProperties.getEarlyLib();
159        log.trace("performOk: load HDF options earlyLibVers={}", earlyLibVers);
160        earlyLibVersion.setSelection(earlyLibVers.compareTo("Earliest") == 0);
161        early18LibVersion.setSelection(earlyLibVers.compareTo("v18") == 0);
162        early110LibVersion.setSelection(earlyLibVers.compareTo("v110") == 0);
163        early112LibVersion.setSelection(earlyLibVers.compareTo("v112") == 0);
164        earlyLateLibVersion.setSelection(earlyLibVers.compareTo("Latest") == 0);
165
166        lateLibVers = ViewProperties.getLateLib();
167        log.trace("performOk: load HDF options lateLibVers={}", lateLibVers);
168        lateLibVersion.setSelection(lateLibVers.compareTo("Earliest") == 0);
169        late18LibVersion.setSelection(lateLibVers.compareTo("v18") == 0);
170        late110LibVersion.setSelection(lateLibVers.compareTo("v110") == 0);
171        late112LibVersion.setSelection(lateLibVers.compareTo("v112") == 0);
172        lateLateLibVersion.setSelection(lateLibVers.compareTo("Latest") == 0);
173
174        checkConvertEnum.setSelection(ViewProperties.isConvertEnum());
175        checkShowRegRefValues.setSelection(ViewProperties.showRegRefValues());
176
177        indexType = ViewProperties.getIndexType();
178        checkIndexName.setSelection(indexType.compareTo("H5_INDEX_NAME") == 0);
179        checkIndexCreateOrder.setSelection(indexType.compareTo("H5_INDEX_CRT_ORDER") == 0);
180
181        indexOrder = ViewProperties.getIndexOrder();
182        checkIncOrder.setSelection(indexOrder.compareTo("H5_ITER_INC") == 0);
183        checkDecOrder.setSelection(indexOrder.compareTo("H5_ITER_DEC") == 0);
184        checkNativeOrder.setSelection(indexOrder.compareTo("H5_ITER_NATIVE") == 0);
185    }
186
187    /**
188     * Creates and returns the SWT control for the customized body of this
189     * preference page under the given parent composite.
190     *
191     * @param parent the parent composite
192     * @return the new control
193     */
194    @Override
195    protected Control createContents(Composite parent) {
196        Composite composite = new Composite(parent, SWT.NONE);
197        composite.setLayout(new GridLayout(1, false));
198
199        org.eclipse.swt.widgets.Group fileExtensionGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
200        fileExtensionGroup.setLayout(new GridLayout(2, true));
201        fileExtensionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
202        fileExtensionGroup.setFont(curFont);
203        fileExtensionGroup.setText("File Extensions");
204
205        Label label = new Label(fileExtensionGroup, SWT.RIGHT);
206        label.setFont(curFont);
207        label.setText("Extensions: ");
208
209        fileExtField = new Text(fileExtensionGroup, SWT.SINGLE | SWT.BORDER);
210        fileExtField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
211        fileExtField.setFont(curFont);
212
213
214        org.eclipse.swt.widgets.Group defaultLibVersionGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
215        defaultLibVersionGroup.setLayout(new GridLayout());
216        defaultLibVersionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
217        defaultLibVersionGroup.setFont(curFont);
218        defaultLibVersionGroup.setText("Default Lib Version");
219
220        org.eclipse.swt.widgets.Group earlyLibVersionGroup = new org.eclipse.swt.widgets.Group(defaultLibVersionGroup, SWT.NONE);
221        earlyLibVersionGroup.setLayout(new GridLayout(4, true));
222        earlyLibVersionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
223        earlyLibVersionGroup.setFont(curFont);
224        earlyLibVersionGroup.setText("Default Early Lib Version");
225
226        earlyLibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
227        earlyLibVersion.setFont(curFont);
228        earlyLibVersion.setText("Earliest");
229        earlyLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
230
231        early18LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
232        early18LibVersion.setFont(curFont);
233        early18LibVersion.setText("v18");
234        early18LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
235
236        early110LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
237        early110LibVersion.setFont(curFont);
238        early110LibVersion.setText("v110");
239        early110LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
240
241        early112LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
242        early112LibVersion.setFont(curFont);
243        early112LibVersion.setText("v112");
244        early112LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
245
246        earlyLateLibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
247        earlyLateLibVersion.setFont(curFont);
248        earlyLateLibVersion.setText("Latest");
249        earlyLateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
250
251        org.eclipse.swt.widgets.Group lateLibVersionGroup = new org.eclipse.swt.widgets.Group(defaultLibVersionGroup, SWT.NONE);
252        lateLibVersionGroup.setLayout(new GridLayout(4, true));
253        lateLibVersionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
254        lateLibVersionGroup.setFont(curFont);
255        lateLibVersionGroup.setText("Default Late Lib Version");
256
257        lateLibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
258        lateLibVersion.setFont(curFont);
259        lateLibVersion.setText("Earliest");
260        lateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
261
262        late18LibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
263        late18LibVersion.setFont(curFont);
264        late18LibVersion.setText("v18");
265        late18LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
266
267        late110LibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
268        late110LibVersion.setFont(curFont);
269        late110LibVersion.setText("v110");
270        late110LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
271
272        late112LibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
273        late112LibVersion.setFont(curFont);
274        late112LibVersion.setText("v112");
275        late112LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
276
277        lateLateLibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
278        lateLateLibVersion.setFont(curFont);
279        lateLateLibVersion.setText("Latest");
280        lateLateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
281
282        org.eclipse.swt.widgets.Group dataGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
283        dataGroup.setLayout(new GridLayout(4, false));
284        dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
285        dataGroup.setFont(curFont);
286        dataGroup.setText("Data");
287
288        helpButton = new Button(dataGroup, SWT.PUSH);
289        helpButton.setImage(ViewProperties.getHelpIcon());
290        helpButton.setToolTipText("Help on Convert Enum");
291        helpButton.addSelectionListener(new SelectionAdapter() {
292            @Override
293            public void widgetSelected(SelectionEvent e) {
294                final String msg = "Convert enum data to strings. \n"
295                        + "For example, a dataset of an enum type of (R=0, G=, B=2) \n"
296                        + "has values of (0, 2, 2, 2, 1, 1). With conversion, the data values are \n"
297                        + "shown as (R, B, B, B, G, G).\n\n\n";
298
299                Tools.showInformation(getShell(), "Help", msg);
300            }
301        });
302
303        checkConvertEnum = new Button(dataGroup, SWT.CHECK);
304        checkConvertEnum.setFont(curFont);
305        checkConvertEnum.setText("Convert Enum");
306        checkConvertEnum.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false));
307
308        checkShowRegRefValues = new Button(dataGroup, SWT.CHECK);
309        checkShowRegRefValues.setFont(curFont);
310        checkShowRegRefValues.setText("Show RegRef Values");
311        checkShowRegRefValues.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
312
313        org.eclipse.swt.widgets.Group displayIndexingGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
314        displayIndexingGroup.setLayout(new GridLayout());
315        displayIndexingGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
316        displayIndexingGroup.setFont(curFont);
317        displayIndexingGroup.setText("Display Indexing Options");
318
319        org.eclipse.swt.widgets.Group indexingTypeGroup = new org.eclipse.swt.widgets.Group(displayIndexingGroup, SWT.NONE);
320        indexingTypeGroup.setLayout(new GridLayout(2, true));
321        indexingTypeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
322        indexingTypeGroup.setFont(curFont);
323        indexingTypeGroup.setText("Indexing Type");
324
325        checkIndexName = new Button(indexingTypeGroup, SWT.RADIO);
326        checkIndexName.setFont(curFont);
327        checkIndexName.setText("By Name");
328        checkIndexName.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
329
330        checkIndexCreateOrder = new Button(indexingTypeGroup, SWT.RADIO);
331        checkIndexCreateOrder.setFont(curFont);
332        checkIndexCreateOrder.setText("By Creation Order");
333        checkIndexCreateOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
334
335
336        org.eclipse.swt.widgets.Group indexingOrderGroup = new org.eclipse.swt.widgets.Group(displayIndexingGroup, SWT.NONE);
337        indexingOrderGroup.setLayout(new GridLayout(3, true));
338        indexingOrderGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
339        indexingOrderGroup.setFont(curFont);
340        indexingOrderGroup.setText("Indexing Order");
341
342        checkIncOrder = new Button(indexingOrderGroup, SWT.RADIO);
343        checkIncOrder.setFont(curFont);
344        checkIncOrder.setText("Increments");
345        checkIncOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
346
347        checkDecOrder = new Button(indexingOrderGroup, SWT.RADIO);
348        checkDecOrder.setFont(curFont);
349        checkDecOrder.setText("Decrements");
350        checkDecOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
351
352        checkNativeOrder = new Button(indexingOrderGroup, SWT.RADIO);
353        checkNativeOrder.setFont(curFont);
354        checkNativeOrder.setText("Native");
355        checkNativeOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
356
357        load();
358        return composite;
359    }
360}