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, earlyLateLibVersion;
043    private Button lateLibVersion, late18LibVersion, late110LibVersion, 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 (earlyLateLibVersion.getSelection())
101                ViewProperties.setEarlyLib("Latest");
102            else
103                ViewProperties.setEarlyLib("Earliest");
104        }
105
106        log.trace("performOk: save HDF options lateLibVersion={}", lateLibVersion);
107        if (lateLibVersion != null) {
108            if (lateLibVersion.getSelection())
109                ViewProperties.setLateLib("Earliest");
110            else if (late18LibVersion.getSelection())
111                ViewProperties.setLateLib("v18");
112            else if (late110LibVersion.getSelection())
113                ViewProperties.setLateLib("v110");
114            else if (lateLateLibVersion.getSelection())
115                ViewProperties.setLateLib("Latest");
116            else
117                ViewProperties.setLateLib("Latest");
118        }
119
120        // set index type
121        if (checkIndexName != null) {
122            if (checkIndexName.getSelection())
123                ViewProperties.setIndexType("H5_INDEX_NAME");
124            else
125                ViewProperties.setIndexType("H5_INDEX_CRT_ORDER");
126        }
127
128        // set index order
129        if (checkIncOrder != null) {
130            if (checkIncOrder.getSelection())
131                ViewProperties.setIndexOrder("H5_ITER_INC");
132            else if (checkNativeOrder.getSelection())
133                ViewProperties.setIndexOrder("H5_ITER_NATIVE");
134            else
135                ViewProperties.setIndexOrder("H5_ITER_DEC");
136        }
137
138        if (checkConvertEnum != null)
139            ViewProperties.setConvertEnum(checkConvertEnum.getSelection());
140        if (checkShowRegRefValues != null)
141            ViewProperties.setShowRegRefValue(checkShowRegRefValues.getSelection());
142
143        return true;
144    }
145
146    /**
147     * Loads all stored values in the <code>FieldEditor</code>s.
148     */
149    protected void load() {
150        getPreferenceStore();
151
152        fileExtField.setText(ViewProperties.getFileExtension());
153
154        earlyLibVers = ViewProperties.getEarlyLib();
155        log.trace("performOk: load HDF options earlyLibVers={}", earlyLibVers);
156        earlyLibVersion.setSelection(earlyLibVers.compareTo("Earliest") == 0);
157        early18LibVersion.setSelection(earlyLibVers.compareTo("v18") == 0);
158        early110LibVersion.setSelection(earlyLibVers.compareTo("v110") == 0);
159        earlyLateLibVersion.setSelection(earlyLibVers.compareTo("Latest") == 0);
160
161        lateLibVers = ViewProperties.getLateLib();
162        log.trace("performOk: load HDF options lateLibVers={}", lateLibVers);
163        lateLibVersion.setSelection(lateLibVers.compareTo("Earliest") == 0);
164        late18LibVersion.setSelection(lateLibVers.compareTo("v18") == 0);
165        late110LibVersion.setSelection(lateLibVers.compareTo("v110") == 0);
166        lateLateLibVersion.setSelection(lateLibVers.compareTo("Latest") == 0);
167
168        checkConvertEnum.setSelection(ViewProperties.isConvertEnum());
169        checkShowRegRefValues.setSelection(ViewProperties.showRegRefValues());
170
171        indexType = ViewProperties.getIndexType();
172        checkIndexName.setSelection(indexType.compareTo("H5_INDEX_NAME") == 0);
173        checkIndexCreateOrder.setSelection(indexType.compareTo("H5_INDEX_CRT_ORDER") == 0);
174
175        indexOrder = ViewProperties.getIndexOrder();
176        checkIncOrder.setSelection(indexOrder.compareTo("H5_ITER_INC") == 0);
177        checkDecOrder.setSelection(indexOrder.compareTo("H5_ITER_DEC") == 0);
178        checkNativeOrder.setSelection(indexOrder.compareTo("H5_ITER_NATIVE") == 0);
179    }
180
181    /**
182     * Creates and returns the SWT control for the customized body of this
183     * preference page under the given parent composite.
184     *
185     * @param parent the parent composite
186     * @return the new control
187     */
188    @Override
189    protected Control createContents(Composite parent) {
190        Composite composite = new Composite(parent, SWT.NONE);
191        composite.setLayout(new GridLayout(1, false));
192
193        org.eclipse.swt.widgets.Group fileExtensionGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
194        fileExtensionGroup.setLayout(new GridLayout(2, true));
195        fileExtensionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
196        fileExtensionGroup.setFont(curFont);
197        fileExtensionGroup.setText("File Extensions");
198
199        Label label = new Label(fileExtensionGroup, SWT.RIGHT);
200        label.setFont(curFont);
201        label.setText("Extensions: ");
202
203        fileExtField = new Text(fileExtensionGroup, SWT.SINGLE | SWT.BORDER);
204        fileExtField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
205        fileExtField.setFont(curFont);
206
207
208        org.eclipse.swt.widgets.Group defaultLibVersionGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
209        defaultLibVersionGroup.setLayout(new GridLayout());
210        defaultLibVersionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
211        defaultLibVersionGroup.setFont(curFont);
212        defaultLibVersionGroup.setText("Default Lib Version");
213
214        org.eclipse.swt.widgets.Group earlyLibVersionGroup = new org.eclipse.swt.widgets.Group(defaultLibVersionGroup, SWT.NONE);
215        earlyLibVersionGroup.setLayout(new GridLayout(4, true));
216        earlyLibVersionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
217        earlyLibVersionGroup.setFont(curFont);
218        earlyLibVersionGroup.setText("Default Early Lib Version");
219
220        earlyLibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
221        earlyLibVersion.setFont(curFont);
222        earlyLibVersion.setText("Earliest");
223        earlyLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
224
225        early18LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
226        early18LibVersion.setFont(curFont);
227        early18LibVersion.setText("v18");
228        early18LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
229
230        early110LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
231        early110LibVersion.setFont(curFont);
232        early110LibVersion.setText("v110");
233        early110LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
234
235        earlyLateLibVersion = new Button(earlyLibVersionGroup, SWT.RADIO);
236        earlyLateLibVersion.setFont(curFont);
237        earlyLateLibVersion.setText("Latest");
238        earlyLateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
239
240        org.eclipse.swt.widgets.Group lateLibVersionGroup = new org.eclipse.swt.widgets.Group(defaultLibVersionGroup, SWT.NONE);
241        lateLibVersionGroup.setLayout(new GridLayout(4, true));
242        lateLibVersionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
243        lateLibVersionGroup.setFont(curFont);
244        lateLibVersionGroup.setText("Default Late Lib Version");
245
246        lateLibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
247        lateLibVersion.setFont(curFont);
248        lateLibVersion.setText("Earliest");
249        lateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
250
251        late18LibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
252        late18LibVersion.setFont(curFont);
253        late18LibVersion.setText("v18");
254        late18LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
255
256        late110LibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
257        late110LibVersion.setFont(curFont);
258        late110LibVersion.setText("v110");
259        late110LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
260
261        lateLateLibVersion = new Button(lateLibVersionGroup, SWT.RADIO);
262        lateLateLibVersion.setFont(curFont);
263        lateLateLibVersion.setText("Latest");
264        lateLateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
265
266        org.eclipse.swt.widgets.Group dataGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
267        dataGroup.setLayout(new GridLayout(4, false));
268        dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
269        dataGroup.setFont(curFont);
270        dataGroup.setText("Data");
271
272        helpButton = new Button(dataGroup, SWT.PUSH);
273        helpButton.setImage(ViewProperties.getHelpIcon());
274        helpButton.setToolTipText("Help on Convert Enum");
275        helpButton.addSelectionListener(new SelectionAdapter() {
276            @Override
277            public void widgetSelected(SelectionEvent e) {
278                final String msg = "Convert enum data to strings. \n"
279                        + "For example, a dataset of an enum type of (R=0, G=, B=2) \n"
280                        + "has values of (0, 2, 2, 2, 1, 1). With conversion, the data values are \n"
281                        + "shown as (R, B, B, B, G, G).\n\n\n";
282
283                Tools.showInformation(getShell(), "Help", msg);
284            }
285        });
286
287        checkConvertEnum = new Button(dataGroup, SWT.CHECK);
288        checkConvertEnum.setFont(curFont);
289        checkConvertEnum.setText("Convert Enum");
290        checkConvertEnum.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false));
291
292        checkShowRegRefValues = new Button(dataGroup, SWT.CHECK);
293        checkShowRegRefValues.setFont(curFont);
294        checkShowRegRefValues.setText("Show RegRef Values");
295        checkShowRegRefValues.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
296
297        org.eclipse.swt.widgets.Group displayIndexingGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
298        displayIndexingGroup.setLayout(new GridLayout());
299        displayIndexingGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
300        displayIndexingGroup.setFont(curFont);
301        displayIndexingGroup.setText("Display Indexing Options");
302
303        org.eclipse.swt.widgets.Group indexingTypeGroup = new org.eclipse.swt.widgets.Group(displayIndexingGroup, SWT.NONE);
304        indexingTypeGroup.setLayout(new GridLayout(2, true));
305        indexingTypeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
306        indexingTypeGroup.setFont(curFont);
307        indexingTypeGroup.setText("Indexing Type");
308
309        checkIndexName = new Button(indexingTypeGroup, SWT.RADIO);
310        checkIndexName.setFont(curFont);
311        checkIndexName.setText("By Name");
312        checkIndexName.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
313
314        checkIndexCreateOrder = new Button(indexingTypeGroup, SWT.RADIO);
315        checkIndexCreateOrder.setFont(curFont);
316        checkIndexCreateOrder.setText("By Creation Order");
317        checkIndexCreateOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
318
319
320        org.eclipse.swt.widgets.Group indexingOrderGroup = new org.eclipse.swt.widgets.Group(displayIndexingGroup, SWT.NONE);
321        indexingOrderGroup.setLayout(new GridLayout(3, true));
322        indexingOrderGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
323        indexingOrderGroup.setFont(curFont);
324        indexingOrderGroup.setText("Indexing Order");
325
326        checkIncOrder = new Button(indexingOrderGroup, SWT.RADIO);
327        checkIncOrder.setFont(curFont);
328        checkIncOrder.setText("Increments");
329        checkIncOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
330
331        checkDecOrder = new Button(indexingOrderGroup, SWT.RADIO);
332        checkDecOrder.setFont(curFont);
333        checkDecOrder.setText("Decrements");
334        checkDecOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
335
336        checkNativeOrder = new Button(indexingOrderGroup, SWT.RADIO);
337        checkNativeOrder.setFont(curFont);
338        checkNativeOrder.setText("Native");
339        checkNativeOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
340
341        load();
342        return composite;
343    }
344}