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