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