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 http://hdfgroup.org/products/hdf-java/doc/Copyright.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; 016 017import java.awt.BorderLayout; 018import java.awt.Color; 019import java.awt.Dimension; 020import java.awt.GraphicsEnvironment; 021import java.awt.GridBagConstraints; 022import java.awt.GridBagLayout; 023import java.awt.GridLayout; 024import java.awt.Insets; 025import java.awt.Point; 026import java.awt.event.ActionEvent; 027import java.awt.event.ActionListener; 028import java.awt.event.ItemEvent; 029import java.awt.event.ItemListener; 030import java.io.File; 031import java.util.Vector; 032 033import javax.swing.BorderFactory; 034import javax.swing.ButtonGroup; 035import javax.swing.JButton; 036import javax.swing.JCheckBox; 037import javax.swing.JComboBox; 038import javax.swing.JDialog; 039import javax.swing.JFileChooser; 040import javax.swing.JFrame; 041import javax.swing.JLabel; 042import javax.swing.JOptionPane; 043import javax.swing.JPanel; 044import javax.swing.JRadioButton; 045import javax.swing.JTabbedPane; 046import javax.swing.JTextField; 047import javax.swing.border.BevelBorder; 048import javax.swing.border.SoftBevelBorder; 049import javax.swing.border.TitledBorder; 050 051/** 052 * UserOptionsDialog displays components for choosing user options. 053 * 054 * @author Peter X. Cao 055 * @version 2.4 9/6/2007 056 */ 057public class UserOptionsDialog extends JDialog implements ActionListener, ItemListener 058{ 059 private static final long serialVersionUID = -8521813136101442590L; 060 061 /** 062 * The main HDFView. 063 */ 064 private final JFrame viewer; 065 066 private String H4toH5Path; 067 private JTextField H4toH5Field, UGField, workField, fileExtField, maxMemberField, startMemberField; 068 @SuppressWarnings("rawtypes") 069 private JComboBox fontSizeChoice, fontTypeChoice, delimiterChoice, imageOriginChoice, indexBaseChoice; 070 @SuppressWarnings("rawtypes") 071 private JComboBox choiceTreeView, choiceMetaDataView, choiceTextView, choiceTableView, choiceImageView, 072 choicePaletteView; 073 private String rootDir, workDir; 074 private JCheckBox checkCurrentUserDir, checkAutoContrast, checkConvertEnum, checkShowValues, checkShowRegRefValues; 075 private JButton currentDirButton; 076 private JRadioButton checkReadOnly, checkIndexType, checkIndexOrder, checkIndexNative, checkLibVersion, 077 checkReadAll; 078 079 private int fontSize; 080 081 private boolean isFontChanged; 082 083 private boolean isUserGuideChanged; 084 085 private boolean isWorkDirChanged; 086 087 /** default index type for files */ 088 private static String indexType; 089 090 /** default index ordering for files */ 091 private static String indexOrder; 092 093 /** a list of tree view implementation. */ 094 private static Vector<String> treeViews; 095 096 /** a list of image view implementation. */ 097 private static Vector<String> imageViews; 098 099 /** a list of tree table implementation. */ 100 private static Vector<String> tableViews; 101 102 /** a list of Text view implementation. */ 103 private static Vector<String> textViews; 104 105 /** a list of metadata view implementation. */ 106 private static Vector<String> metaDataViews; 107 108 /** a list of palette view implementation. */ 109 private static Vector<String> paletteViews; 110 111 // private JList srbJList; 112 // private JTextField srbFields[]; 113 // private Vector srbVector; 114 115 /** 116 * constructs an UserOptionsDialog. 117 * 118 * @param view 119 * The HDFView. 120 */ 121 public UserOptionsDialog(JFrame view, String viewroot) { 122 super(view, "User Options", true); 123 124 viewer = view; 125 rootDir = viewroot; 126 isFontChanged = false; 127 isUserGuideChanged = false; 128 isWorkDirChanged = false; 129 // srbJList = null; 130 fontSize = ViewProperties.getFontSize(); 131 workDir = ViewProperties.getWorkDir(); 132 if (workDir == null) { 133 workDir = rootDir; 134 } 135 treeViews = ViewProperties.getTreeViewList(); 136 metaDataViews = ViewProperties.getMetaDataViewList(); 137 textViews = ViewProperties.getTextViewList(); 138 tableViews = ViewProperties.getTableViewList(); 139 imageViews = ViewProperties.getImageViewList(); 140 paletteViews = ViewProperties.getPaletteViewList(); 141 // srbVector = ViewProperties.getSrbAccount(); 142 indexType = ViewProperties.getIndexType(); 143 indexOrder = ViewProperties.getIndexOrder(); 144 145 JPanel contentPane = (JPanel) getContentPane(); 146 contentPane.setLayout(new BorderLayout(8, 8)); 147 contentPane.setBorder(BorderFactory.createEmptyBorder(15, 5, 5, 5)); 148 149 int w = 700 + (ViewProperties.getFontSize() - 12) * 15; 150 int h = 550 + (ViewProperties.getFontSize() - 12) * 16; 151 contentPane.setPreferredSize(new Dimension(w, h)); 152 153 JTabbedPane tabbedPane = new JTabbedPane(); 154 155 tabbedPane.addTab("General Setting", createGeneralOptionPanel()); 156 tabbedPane.addTab("Default Module", createModuleOptionPanel()); 157 158 /* 159 * try { Class.forName("hdf.srb.SRBFileDialog"); 160 * tabbedPane.addTab("SRB Connection", createSrbConnectionPanel()); } 161 * catch (Exception ex) {;} 162 */ 163 164 tabbedPane.setSelectedIndex(0); 165 166 JPanel buttonP = new JPanel(); 167 JButton b = new JButton(" Ok "); 168 b.setActionCommand("Set options"); 169 b.addActionListener(this); 170 b.setName("Ok"); 171 buttonP.add(b); 172 b = new JButton("Cancel"); 173 b.setActionCommand("Cancel"); 174 b.addActionListener(this); 175 buttonP.add(b); 176 177 contentPane.add("Center", tabbedPane); 178 contentPane.add("South", buttonP); 179 180 // locate the H5Property dialog 181 Point l = getParent().getLocation(); 182 l.x += 250; 183 l.y += 80; 184 setLocation(l); 185 validate(); 186 pack(); 187 } 188 189 public void setVisible(boolean b) { 190 if (b) { // reset flags 191 isFontChanged = false; 192 isUserGuideChanged = false; 193 isWorkDirChanged = false; 194 fontSize = ViewProperties.getFontSize(); 195 workDir = ViewProperties.getWorkDir(); 196 if (workDir == null) { 197 workDir = rootDir; 198 } 199 } 200 super.setVisible(b); 201 } 202 203 @SuppressWarnings({ "unchecked", "rawtypes" }) 204 private JPanel createGeneralOptionPanel() { 205 String[] fontSizeChoices = { "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36", "48" }; 206 fontSizeChoice = new JComboBox(fontSizeChoices); 207 fontSizeChoice.setSelectedItem(String.valueOf(ViewProperties.getFontSize())); 208 209 String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); 210 String fname = ViewProperties.getFontType(); 211 fontTypeChoice = new JComboBox(fontNames); 212 213 boolean isFontValid = false; 214 if (fontNames != null) { 215 for (int i = 0; i < fontNames.length; i++) { 216 if (fontNames[i].equalsIgnoreCase(fname)) { 217 isFontValid = true; 218 } 219 } 220 } 221 if (!isFontValid) { 222 fname = (viewer).getFont().getFamily(); 223 ViewProperties.setFontType(fname); 224 } 225 fontTypeChoice.setSelectedItem(fname); 226 227 String[] delimiterChoices = { ViewProperties.DELIMITER_TAB, ViewProperties.DELIMITER_COMMA, 228 ViewProperties.DELIMITER_SPACE, ViewProperties.DELIMITER_COLON, ViewProperties.DELIMITER_SEMI_COLON }; 229 delimiterChoice = new JComboBox(delimiterChoices); 230 delimiterChoice.setSelectedItem(ViewProperties.getDataDelimiter()); 231 232 String[] imageOriginChoices = { ViewProperties.ORIGIN_UL, ViewProperties.ORIGIN_LL, ViewProperties.ORIGIN_UR, 233 ViewProperties.ORIGIN_LR }; 234 imageOriginChoice = new JComboBox(imageOriginChoices); 235 imageOriginChoice.setSelectedItem(ViewProperties.getImageOrigin()); 236 237 JPanel centerP = new JPanel(); 238 GridBagConstraints c = new GridBagConstraints(); 239 // natural height, maximum width 240 c.fill = GridBagConstraints.HORIZONTAL; 241 c.weightx = 0.5; 242 c.fill = GridBagConstraints.HORIZONTAL; 243 centerP.setLayout(new GridBagLayout()); 244 centerP.setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); 245 246 JPanel p0 = new JPanel(); 247 p0.setLayout(new BorderLayout()); 248 p0.add(checkCurrentUserDir = new JCheckBox("\"Current Working Directory\" or", false), BorderLayout.WEST); 249 checkCurrentUserDir.addActionListener(this); 250 checkCurrentUserDir.setActionCommand("Set current dir to user.home"); 251 p0.add(workField = new JTextField(workDir), BorderLayout.CENTER); 252 JButton b = new JButton("Browse..."); 253 currentDirButton = b; 254 b.setActionCommand("Browse current dir"); 255 b.addActionListener(this); 256 p0.add(b, BorderLayout.EAST); 257 TitledBorder tborder = new TitledBorder("Default Working Directory"); 258 tborder.setTitleColor(Color.darkGray); 259 p0.setBorder(tborder); 260 c.gridx = 0; 261 c.gridy = 0; 262 centerP.add(p0, c); 263 264 p0 = new JPanel(); 265 p0.setLayout(new BorderLayout()); 266 p0.add(new JLabel("User's Guide: "), BorderLayout.WEST); 267 p0.add(UGField = new JTextField(ViewProperties.getUsersGuide()), BorderLayout.CENTER); 268 b = new JButton("Browse..."); 269 b.setActionCommand("Browse UG"); 270 b.addActionListener(this); 271 p0.add(b, BorderLayout.EAST); 272 tborder = new TitledBorder("Help Document"); 273 tborder.setTitleColor(Color.darkGray); 274 p0.setBorder(tborder); 275 c.gridx = 0; 276 c.gridy = 1; 277 centerP.add(p0, c); 278 279 p0 = new JPanel(); 280 p0.setLayout(new GridLayout(1, 3, 8, 8)); 281 282 JPanel p00 = new JPanel(); 283 p00.setLayout(new BorderLayout()); 284 p00.add(new JLabel("Extension: "), BorderLayout.WEST); 285 p00.add(fileExtField = new JTextField(ViewProperties.getFileExtension()), BorderLayout.CENTER); 286 tborder = new TitledBorder("File Extension"); 287 tborder.setTitleColor(Color.darkGray); 288 p00.setBorder(tborder); 289 290 JPanel p01 = new JPanel(); 291 p01.setLayout(new GridLayout(1, 2, 8, 8)); 292 p01.add(checkReadOnly = new JRadioButton("Read Only", ViewProperties.isReadOnly())); 293 JRadioButton rw = new JRadioButton("Read/Write", !ViewProperties.isReadOnly()); 294 p01.add(rw); 295 ButtonGroup bgrp = new ButtonGroup(); 296 bgrp.add(checkReadOnly); 297 bgrp.add(rw); 298 tborder = new TitledBorder("Default File Access Mode"); 299 tborder.setTitleColor(Color.darkGray); 300 p01.setBorder(tborder); 301 302 JPanel p02 = new JPanel(); 303 p02.setLayout(new GridLayout(1, 2, 8, 8)); 304 p02.add(checkLibVersion = new JRadioButton("Earliest", ViewProperties.isEarlyLib())); 305 JRadioButton latestLib = new JRadioButton("Latest", !ViewProperties.isEarlyLib()); 306 p02.add(latestLib); 307 bgrp = new ButtonGroup(); 308 bgrp.add(checkLibVersion); 309 bgrp.add(latestLib); 310 tborder = new TitledBorder("Default Lib Version"); 311 tborder.setTitleColor(Color.darkGray); 312 p02.setBorder(tborder); 313 314 p0.add(p01); 315 p0.add(p00); 316 p0.add(p02); 317 c.gridx = 0; 318 c.gridy = 2; 319 centerP.add(p0, c); 320 321 p0 = new JPanel(); 322 p0.setLayout(new GridLayout(1, 2, 8, 8)); 323 p00 = new JPanel(); 324 p00.setLayout(new BorderLayout()); 325 p00.add(new JLabel("Font Size:"), BorderLayout.WEST); 326 p00.add(fontSizeChoice, BorderLayout.CENTER); 327 p0.add(p00); 328 p00 = new JPanel(); 329 p00.setLayout(new BorderLayout()); 330 p00.add(new JLabel("Font Type:"), BorderLayout.WEST); 331 p00.add(fontTypeChoice, BorderLayout.CENTER); 332 p0.add(p00); 333 tborder = new TitledBorder("Text Font"); 334 tborder.setTitleColor(Color.darkGray); 335 p0.setBorder(tborder); 336 c.gridx = 0; 337 c.gridy = 3; 338 centerP.add(p0, c); 339 340 p0 = new JPanel(); 341 p0.setLayout(new GridLayout(1, 4, 8, 8)); 342 343 p00 = new JPanel(); 344 p00.setLayout(new BorderLayout()); 345 checkAutoContrast = new JCheckBox("Autogain Image Contrast"); 346 checkAutoContrast.setSelected(ViewProperties.isAutoContrast()); 347 checkAutoContrast.setName("autogain"); 348 p00.add(checkAutoContrast, BorderLayout.CENTER); 349 JButton button = new JButton(ViewProperties.getHelpIcon()); 350 button.setToolTipText("Help on Auto Contrast"); 351 button.setMargin(new Insets(0, 0, 0, 0)); 352 button.addActionListener(this); 353 button.setActionCommand("Help on Auto Contrast"); 354 p00.add(button, BorderLayout.WEST); 355 p0.add(p00); 356 357 p0.add(checkShowValues = new JCheckBox("Show Values")); 358 checkShowValues.setSelected(ViewProperties.showImageValues()); 359 360 p00 = new JPanel(); 361 p00.setLayout(new BorderLayout()); 362 p00.add(new JLabel("Image Origin:"), BorderLayout.WEST); 363 p00.add(imageOriginChoice, BorderLayout.CENTER); 364 p0.add(p00); 365 366 tborder = new TitledBorder("Image"); 367 tborder.setTitleColor(Color.darkGray); 368 p0.setBorder(tborder); 369 c.gridx = 0; 370 c.gridy = 4; 371 centerP.add(p0, c); 372 373 p0 = new JPanel(); 374 p0.setLayout(new GridLayout(2, 3, 20, 4)); 375 376 p00 = new JPanel(); 377 p00.setLayout(new BorderLayout()); 378 button = new JButton(ViewProperties.getHelpIcon()); 379 button.setToolTipText("Help on Convert Enum"); 380 button.setMargin(new Insets(0, 0, 0, 0)); 381 button.addActionListener(this); 382 button.setActionCommand("Help on Convert Enum"); 383 p00.add(button, BorderLayout.WEST); 384 checkConvertEnum = new JCheckBox("Convert Enum"); 385 checkConvertEnum.setSelected(ViewProperties.isConvertEnum()); 386 p00.add(checkConvertEnum, BorderLayout.CENTER); 387 p0.add(p00, BorderLayout.NORTH); 388 389 checkShowRegRefValues = new JCheckBox("Show RegRef Values"); 390 checkShowRegRefValues.setSelected(ViewProperties.showRegRefValues()); 391 p0.add(checkShowRegRefValues, BorderLayout.NORTH); 392 393 p00 = new JPanel(); 394 p00.setLayout(new BorderLayout()); 395 396 String[] indexBaseChoices = { "0-based", "1-based" }; 397 indexBaseChoice = new JComboBox(indexBaseChoices); 398 if (ViewProperties.isIndexBase1()) 399 indexBaseChoice.setSelectedIndex(1); 400 else 401 indexBaseChoice.setSelectedIndex(0); 402 403 p00.add(new JLabel("Index Base: "), BorderLayout.WEST); 404 p00.add(indexBaseChoice, BorderLayout.CENTER); 405 p0.add(p00, BorderLayout.SOUTH); 406 407 p00 = new JPanel(); 408 p00.setLayout(new BorderLayout()); 409 p00.add(new JLabel("Data Delimiter:"), BorderLayout.WEST); 410 p00.add(delimiterChoice, BorderLayout.CENTER); 411 p0.add(p00, BorderLayout.SOUTH); 412 413 tborder = new TitledBorder("Data"); 414 tborder.setTitleColor(Color.darkGray); 415 p0.setBorder(tborder); 416 c.gridx = 0; 417 c.gridy = 5; 418 centerP.add(p0, c); 419 420 p0 = new JPanel(); 421 p0.setLayout(new GridLayout(1, 3, 8, 8)); 422 423 int nMax = ViewProperties.getMaxMembers(); 424 checkReadAll = new JRadioButton("Open All", (nMax<=0) || (nMax==Integer.MAX_VALUE)); 425 checkReadAll.addItemListener(this); 426 p0.add(checkReadAll); 427 428 p00 = new JPanel(); 429 p00.setLayout(new BorderLayout()); 430 p00.add(new JLabel("Start Member: "), BorderLayout.WEST); 431 p00.add(startMemberField = new JTextField(String.valueOf(ViewProperties.getStartMembers())), 432 BorderLayout.CENTER); 433 p0.add(p00); 434 435 p00 = new JPanel(); 436 p00.setLayout(new BorderLayout()); 437 p00.add(new JLabel("Member Count: "), BorderLayout.WEST); 438 p00.add(maxMemberField = new JTextField(String.valueOf(ViewProperties.getMaxMembers())), BorderLayout.CENTER); 439 p0.add(p00); 440 441 startMemberField.setEnabled(!checkReadAll.isSelected()); 442 maxMemberField.setEnabled(!checkReadAll.isSelected()); 443 444 tborder = new TitledBorder("Objects to Open"); 445 tborder.setTitleColor(Color.darkGray); 446 p0.setBorder(tborder); 447 c.gridx = 0; 448 c.gridy = 6; 449 centerP.add(p0, c); 450 451 p0 = new JPanel(); 452 p0.setLayout(new GridLayout(1, 2, 8, 8)); 453 454 JPanel pType = new JPanel(); 455 pType.setLayout(new GridLayout(1, 2, 8, 8)); 456 checkIndexType = new JRadioButton("By Name", indexType.compareTo("H5_INDEX_NAME") == 0); 457 pType.add(checkIndexType); 458 JRadioButton checkIndexCreateOrder = new JRadioButton("By Creation Order", 459 indexType.compareTo("H5_INDEX_CRT_ORDER") == 0); 460 pType.add(checkIndexCreateOrder); 461 ButtonGroup bTypegrp = new ButtonGroup(); 462 bTypegrp.add(checkIndexType); 463 bTypegrp.add(checkIndexCreateOrder); 464 tborder = new TitledBorder("Indexing Type"); 465 tborder.setTitleColor(Color.darkGray); 466 pType.setBorder(tborder); 467 p0.add(pType); 468 469 JPanel pOrder = new JPanel(); 470 pOrder.setLayout(new GridLayout(1, 3, 8, 8)); 471 checkIndexOrder = new JRadioButton("Increments", indexOrder.compareTo("H5_ITER_INC") == 0); 472 pOrder.add(checkIndexOrder); 473 JRadioButton checkIndexDecrement = new JRadioButton("Decrements", indexOrder.compareTo("H5_ITER_DEC") == 0); 474 pOrder.add(checkIndexDecrement); 475 checkIndexNative = new JRadioButton("Native", indexOrder.compareTo("H5_ITER_NATIVE") == 0); 476 pOrder.add(checkIndexNative); 477 ButtonGroup bOrdergrp = new ButtonGroup(); 478 bOrdergrp.add(checkIndexOrder); 479 bOrdergrp.add(checkIndexDecrement); 480 bOrdergrp.add(checkIndexNative); 481 tborder = new TitledBorder("Indexing Order"); 482 tborder.setTitleColor(Color.darkGray); 483 pOrder.setBorder(tborder); 484 p0.add(pOrder); 485 486 tborder = new TitledBorder("Display Indexing Options"); 487 tborder.setTitleColor(Color.darkGray); 488 p0.setBorder(tborder); 489 c.gridx = 0; 490 c.gridy = 7; 491 centerP.add(p0, c); 492 493 if (workDir.equals(System.getProperty("user.home"))) { 494 checkCurrentUserDir.setSelected(true); 495 workField.setEnabled(false); 496 } 497 498 return centerP; 499 } 500 501 @SuppressWarnings({ "unchecked", "rawtypes" }) 502 private JPanel createModuleOptionPanel() { 503 choiceTreeView = new JComboBox(treeViews); 504 choiceTableView = new JComboBox(tableViews); 505 choiceTextView = new JComboBox(textViews); 506 choiceImageView = new JComboBox(imageViews); 507 choiceMetaDataView = new JComboBox(metaDataViews); 508 choicePaletteView = new JComboBox(paletteViews); 509 510 JPanel moduleP = new JPanel(); 511 moduleP.setLayout(new GridLayout(6, 1, 10, 10)); 512 moduleP.setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); 513 514 JPanel treeP = new JPanel(); 515 TitledBorder tborder = new TitledBorder("TreeView"); 516 tborder.setTitleColor(Color.darkGray); 517 treeP.setBorder(tborder); 518 moduleP.add(treeP); 519 treeP.setLayout(new BorderLayout(5, 5)); 520 treeP.add(choiceTreeView, BorderLayout.CENTER); 521 522 JPanel attrP = new JPanel(); 523 tborder = new TitledBorder("MetaDataView"); 524 tborder.setTitleColor(Color.darkGray); 525 attrP.setBorder(tborder); 526 moduleP.add(attrP); 527 attrP.setLayout(new BorderLayout(5, 5)); 528 attrP.add(choiceMetaDataView, BorderLayout.CENTER); 529 530 JPanel textP = new JPanel(); 531 tborder = new TitledBorder("TextView"); 532 tborder.setTitleColor(Color.darkGray); 533 textP.setBorder(tborder); 534 moduleP.add(textP); 535 textP.setLayout(new BorderLayout(5, 5)); 536 textP.add(choiceTextView, BorderLayout.CENTER); 537 538 JPanel tableP = new JPanel(); 539 tborder = new TitledBorder("TableView"); 540 tborder.setTitleColor(Color.darkGray); 541 tableP.setBorder(tborder); 542 moduleP.add(tableP); 543 tableP.setLayout(new BorderLayout(5, 5)); 544 tableP.add(choiceTableView, BorderLayout.CENTER); 545 546 JPanel imageP = new JPanel(); 547 tborder = new TitledBorder("ImageView"); 548 tborder.setTitleColor(Color.darkGray); 549 imageP.setBorder(tborder); 550 moduleP.add(imageP); 551 imageP.setLayout(new BorderLayout(5, 5)); 552 imageP.add(choiceImageView, BorderLayout.CENTER); 553 554 JPanel palP = new JPanel(); 555 tborder = new TitledBorder("PaletteView"); 556 tborder.setTitleColor(Color.darkGray); 557 palP.setBorder(tborder); 558 moduleP.add(palP); 559 palP.setLayout(new BorderLayout(5, 5)); 560 palP.add(choicePaletteView, BorderLayout.CENTER); 561 562 return moduleP; 563 } 564 565 /* 566 * private JPanel createSrbConnectionPanel() { JPanel p = new JPanel(); 567 * p.setLayout(new BorderLayout(5,5)); TitledBorder tborder = new 568 * TitledBorder("SRB Connections"); tborder.setTitleColor(Color.darkGray); 569 * p.setBorder(tborder); 570 * 571 * DefaultListModel listModel = new DefaultListModel(); srbJList = new 572 * JList(listModel); 573 * srbJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 574 * srbJList.addListSelectionListener(this); 575 * 576 * srbFields = new JTextField[7]; 577 * 578 * if (srbVector!= null) { int n=srbVector.size(); 579 * 580 * String srbaccount[] = null; for (int i=0; i<n; i++) { srbaccount = 581 * (String[])srbVector.get(i); if (srbaccount != null) { 582 * listModel.addElement(srbaccount[0]); } } } 583 * 584 * JPanel cp = new JPanel(); cp.setLayout(new BorderLayout(5,5)); 585 * 586 * JPanel cpc = new JPanel(); cpc.setLayout(new GridLayout(7,1,5,5)); 587 * cpc.add(srbFields[0] = new JTextField()); cpc.add(srbFields[1] = new 588 * JTextField()); cpc.add(srbFields[2] = new JTextField()); 589 * cpc.add(srbFields[3] = new JTextField()); cpc.add(srbFields[4] = new 590 * JTextField()); cpc.add(srbFields[5] = new JTextField()); 591 * cpc.add(srbFields[6] = new JTextField()); cp.add(cpc, 592 * BorderLayout.CENTER); 593 * 594 * JPanel cpl = new JPanel(); cpl.setLayout(new GridLayout(7,1,5,5)); 595 * cpl.add(new JLabel("Host Machine: ", SwingConstants.RIGHT)); cpl.add(new 596 * JLabel("Port Number: ", SwingConstants.RIGHT)); cpl.add(new 597 * JLabel("User Name: ", SwingConstants.RIGHT)); cpl.add(new 598 * JLabel("Password: ", SwingConstants.RIGHT)); cpl.add(new 599 * JLabel("Home Directory: ", SwingConstants.RIGHT)); cpl.add(new 600 * JLabel("Domain Name/Zone: ", SwingConstants.RIGHT)); cpl.add(new 601 * JLabel(" Default Storage Resource: ", SwingConstants.RIGHT)); cp.add(cpl, 602 * BorderLayout.WEST); 603 * 604 * JPanel lp = new JPanel(); lp.setLayout(new BorderLayout(5,5)); JPanel lpb 605 * = new JPanel(); JButton add = new JButton("Save"); 606 * add.addActionListener(this); add.setActionCommand("Add srb connsction"); 607 * lpb.add(add); JButton del = new JButton("Delete"); 608 * del.addActionListener(this); 609 * del.setActionCommand("Delete srb connsction"); lpb.add(del); lp.add(lpb, 610 * BorderLayout.SOUTH); JScrollPane listScroller = new 611 * JScrollPane(srbJList); int w = 120 + 612 * (ViewProperties.getFontSize()-12)*10; int h = 200 + 613 * (ViewProperties.getFontSize()-12)*15; listScroller.setPreferredSize(new 614 * Dimension(w, h)); lp.add(listScroller, BorderLayout.CENTER); 615 * 616 * JPanel sp = new JPanel(); sp.setLayout(new GridLayout(3,1,5,15)); 617 * sp.add(new JLabel(" ")); 618 * 619 * p.add(cp, BorderLayout.CENTER); p.add(lp, BorderLayout.WEST); p.add(sp, 620 * BorderLayout.SOUTH); 621 * 622 * if ((srbVector !=null) && (srbVector.size()>0)) { 623 * srbJList.setSelectedIndex(0); } 624 * 625 * return p; } 626 */ 627 628 @SuppressWarnings("unchecked") 629 public void actionPerformed(ActionEvent e) { 630 Object source = e.getSource(); 631 String cmd = e.getActionCommand(); 632 633 if (cmd.equals("Set options")) { 634 setUserOptions(); 635 setVisible(false); 636 } 637 else if (cmd.equals("Cancel")) { 638 isFontChanged = false; 639 setVisible(false); 640 } 641 else if (cmd.equals("Set current dir to user.home")) { 642 boolean isCheckCurrentUserDirSelected = checkCurrentUserDir.isSelected(); 643 workField.setEnabled(!isCheckCurrentUserDirSelected); 644 currentDirButton.setEnabled(!isCheckCurrentUserDirSelected); 645 } 646 else if (cmd.equals("Browse UG")) { 647 final JFileChooser fchooser = new JFileChooser(rootDir); 648 int returnVal = fchooser.showOpenDialog(this); 649 650 if (returnVal != JFileChooser.APPROVE_OPTION) { 651 return; 652 } 653 654 File choosedFile = fchooser.getSelectedFile(); 655 if (choosedFile == null) { 656 return; 657 } 658 659 String fname = choosedFile.getAbsolutePath(); 660 if (fname == null) { 661 return; 662 } 663 UGField.setText(fname); 664 } 665 else if (cmd.equals("Browse current dir")) { 666 final JFileChooser fchooser = new JFileChooser(workDir); 667 fchooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 668 int returnVal = fchooser.showDialog(this, "Select"); 669 670 if (returnVal != JFileChooser.APPROVE_OPTION) { 671 return; 672 } 673 674 File choosedFile = fchooser.getSelectedFile(); 675 if (choosedFile == null) { 676 return; 677 } 678 679 String fname = choosedFile.getAbsolutePath(); 680 if (fname == null) { 681 return; 682 } 683 workField.setText(fname); 684 } 685 else if (cmd.equals("Browse h4toh5")) { 686 final JFileChooser fchooser = new JFileChooser(rootDir); 687 int returnVal = fchooser.showOpenDialog(this); 688 689 if (returnVal != JFileChooser.APPROVE_OPTION) { 690 return; 691 } 692 693 File choosedFile = fchooser.getSelectedFile(); 694 if (choosedFile == null) { 695 return; 696 } 697 698 String fname = choosedFile.getAbsolutePath(); 699 if (fname == null) { 700 return; 701 } 702 H4toH5Path = fname; 703 H4toH5Field.setText(fname); 704 } 705 else if (cmd.startsWith("Add Module")) { 706 String newModule = JOptionPane.showInputDialog(this, "Type the full path of the new module:", cmd, 707 JOptionPane.PLAIN_MESSAGE); 708 709 if ((newModule == null) || (newModule.length() < 1)) { 710 return; 711 } 712 713 // enables use of JHDF5 in JNLP (Web Start) applications, the system 714 // class loader with reflection first. 715 try { 716 Class.forName(newModule); 717 } 718 catch (Exception ex) { 719 try { 720 ViewProperties.loadExtClass().loadClass(newModule); 721 } 722 catch (ClassNotFoundException ex2) { 723 JOptionPane.showMessageDialog(this, "Cannot find module:\n " + newModule 724 + "\nPlease check the module name and classpath.", "HDFView", JOptionPane.ERROR_MESSAGE); 725 return; 726 } 727 } 728 729 if (cmd.endsWith("TreeView") && !treeViews.contains(newModule)) { 730 treeViews.add(newModule); 731 choiceTreeView.addItem(newModule); 732 } 733 else if (cmd.endsWith("MetadataView") && !metaDataViews.contains(newModule)) { 734 metaDataViews.add(newModule); 735 choiceMetaDataView.addItem(newModule); 736 } 737 else if (cmd.endsWith("TextView") && !textViews.contains(newModule)) { 738 textViews.add(newModule); 739 choiceTextView.addItem(newModule); 740 } 741 else if (cmd.endsWith("TableView") && !tableViews.contains(newModule)) { 742 tableViews.add(newModule); 743 choiceTableView.addItem(newModule); 744 } 745 else if (cmd.endsWith("ImageView") && !imageViews.contains(newModule)) { 746 imageViews.add(newModule); 747 choiceImageView.addItem(newModule); 748 } 749 else if (cmd.endsWith("PaletteView") && !paletteViews.contains(newModule)) { 750 paletteViews.add(newModule); 751 choicePaletteView.addItem(newModule); 752 } 753 } 754 else if (cmd.startsWith("Delete Module")) { 755 @SuppressWarnings("rawtypes") 756 JComboBox theChoice = (JComboBox) source; 757 758 if (theChoice.getItemCount() == 1) { 759 JOptionPane.showMessageDialog(this, "Cannot delete the last module.", cmd, JOptionPane.ERROR_MESSAGE); 760 return; 761 } 762 763 int reply = JOptionPane.showConfirmDialog(this, "Do you want to delete the selected module?", cmd, 764 JOptionPane.YES_NO_OPTION); 765 if (reply == JOptionPane.NO_OPTION) { 766 return; 767 } 768 769 String moduleName = (String) theChoice.getSelectedItem(); 770 theChoice.removeItem(moduleName); 771 if (cmd.endsWith("TreeView")) { 772 treeViews.remove(moduleName); 773 } 774 else if (cmd.endsWith("MetadataView")) { 775 metaDataViews.remove(moduleName); 776 } 777 else if (cmd.endsWith("TextView")) { 778 textViews.remove(moduleName); 779 } 780 else if (cmd.endsWith("TableView")) { 781 tableViews.remove(moduleName); 782 } 783 else if (cmd.endsWith("ImageView")) { 784 imageViews.remove(moduleName); 785 } 786 else if (cmd.endsWith("PaletteView")) { 787 paletteViews.remove(moduleName); 788 } 789 } 790 /* 791 * else if (cmd.equals("Add srb connsction")) { String srbaccount[] = 792 * new String[7]; for (int i=0; i<7; i++) { srbaccount[i] = 793 * srbFields[i].getText(); if (srbaccount[i] == null) { return; } } 794 * DefaultListModel lm = (DefaultListModel)srbJList.getModel(); 795 * 796 * if (lm.contains(srbaccount[0])) { int n = 797 * srbJList.getSelectedIndex(); if ( n<0 ) return; String 798 * srbaccountOld[] = (String[])srbVector.get(n); for (int i=0; i<7; i++) 799 * srbaccountOld[i] = srbaccount[i]; } else { srbVector.add(srbaccount); 800 * lm.addElement(srbaccount[0]); 801 * srbJList.setSelectedValue(srbaccount[0], true); } } else if 802 * (cmd.equals("Delete srb connsction")) { int n = 803 * srbJList.getSelectedIndex(); if (n<0) { return; } 804 * 805 * int resp = JOptionPane.showConfirmDialog(this, 806 * "Are you sure you want to delete the following SRB connection?\n"+ 807 * " \""+srbJList.getSelectedValue()+"\"", 808 * "Delete SRB Connection", JOptionPane.YES_NO_OPTION); if (resp == 809 * JOptionPane.NO_OPTION) { return; } 810 * 811 * DefaultListModel lm = (DefaultListModel)srbJList.getModel(); 812 * lm.removeElementAt(n); srbVector.remove(n); for (int i=0; i<7; i++) { 813 * srbFields[i].setText(""); } } 814 */ 815 else if (cmd.equals("Help on Auto Contrast")) { 816 final String msg = "Auto Contrast does the following to compute a gain/bias \n" 817 + "that will stretch the pixels in the image to fit the pixel \n" 818 + "values of the graphics system. For example, it stretches unsigned\n" 819 + "short data to fit the full range of an unsigned short. Later \n" 820 + "code simply takes the high order byte and passes it to the graphics\n" 821 + "system (which expects 0-255). It uses some statistics on the pixels \n" 822 + "to prevent outliers from throwing off the gain/bias calculations much.\n\n" 823 + "To compute the gain/bias we... \n" 824 + "Find the mean and std. deviation of the pixels in the image \n" + "min = mean - 3 * std.dev. \n" 825 + "max = mean + 3 * std.dev. \n" + "small fudge factor because this tends to overshoot a bit \n" 826 + "Stretch to 0-USHRT_MAX \n" + " gain = USHRT_MAX / (max-min) \n" 827 + " bias = -min \n" + "\n" + "To apply the gain/bias to a pixel, use the formula \n" 828 + "data[i] = (data[i] + bias) * gain \n" + "\n" 829 // + 830 // "Finally, for auto-ranging the sliders for gain/bias, we do the following \n" 831 // + "gain_min = 0 \n" 832 // + "gain_max = gain * 3.0 \n" 833 // + "bias_min = -fabs(bias) * 3.0 \n" 834 // + "bias_max = fabs(bias) * 3.0 \n" 835 + "\n\n"; 836 JOptionPane.showMessageDialog(this, msg); 837 } 838 else if (cmd.equals("Help on Convert Enum")) { 839 final String msg = "Convert enum data to strings. \n" 840 + "For example, a dataset of an enum type of (R=0, G=, B=2) \n" 841 + "has values of (0, 2, 2, 2, 1, 1). With conversion, the data values are \n" 842 + "shown as (R, B, B, B, G, G).\n\n\n"; 843 JOptionPane.showMessageDialog(this, msg); 844 } 845 } 846 847 /* 848 * public void valueChanged(ListSelectionEvent e) { Object src = 849 * e.getSource(); 850 * 851 * if (!src.equals(srbJList)) { return; } 852 * 853 * int n = srbJList.getSelectedIndex(); if ( n<0 ) { return; } 854 * 855 * String srbaccount[] = (String[])srbVector.get(n); if (srbaccount == null) 856 * { return; } 857 * 858 * n = Math.min(7, srbaccount.length); for (int i=0; i<n; i++) { 859 * srbFields[i].setText(srbaccount[i]); } } 860 */ 861 862 @SuppressWarnings("unchecked") 863 private void setUserOptions() { 864 String UGPath = UGField.getText(); 865 if ((UGPath != null) && (UGPath.length() > 0)) { 866 UGPath = UGPath.trim(); 867 isUserGuideChanged = !UGPath.equals(ViewProperties.getUsersGuide()); 868 ViewProperties.setUsersGuide(UGPath); 869 } 870 871 String workPath = workField.getText(); 872 if (checkCurrentUserDir.isSelected()) { 873 workPath = "user.home"; 874 } 875 876 if ((workPath != null) && (workPath.length() > 0)) { 877 workPath = workPath.trim(); 878 isWorkDirChanged = !workPath.equals(ViewProperties.getWorkDir()); 879 ViewProperties.setWorkDir(workPath); 880 } 881 882 String ext = fileExtField.getText(); 883 if ((ext != null) && (ext.length() > 0)) { 884 ext = ext.trim(); 885 ViewProperties.setFileExtension(ext); 886 } 887 888 if (checkReadOnly.isSelected()) 889 ViewProperties.setReadOnly(true); 890 else 891 ViewProperties.setReadOnly(false); 892 893 if (checkLibVersion.isSelected()) 894 ViewProperties.setEarlyLib(true); 895 else 896 ViewProperties.setEarlyLib(false); 897 898 // set font size 899 int fsize = 12; 900 try { 901 fsize = Integer.parseInt((String) fontSizeChoice.getSelectedItem()); 902 ViewProperties.setFontSize(fsize); 903 904 if ((fontSize != ViewProperties.getFontSize())) { 905 isFontChanged = true; 906 } 907 } 908 catch (Exception ex) { 909 } 910 911 // set font type 912 String ftype = (String) fontTypeChoice.getSelectedItem(); 913 if (!ftype.equalsIgnoreCase(ViewProperties.getFontType())) { 914 isFontChanged = true; 915 ViewProperties.setFontType(ftype); 916 } 917 918 // set data delimiter 919 ViewProperties.setDataDelimiter((String) delimiterChoice.getSelectedItem()); 920 ViewProperties.setImageOrigin((String) imageOriginChoice.getSelectedItem()); 921 922 // set index type 923 if (checkIndexType.isSelected()) 924 ViewProperties.setIndexType("H5_INDEX_NAME"); 925 else 926 ViewProperties.setIndexType("H5_INDEX_CRT_ORDER"); 927 928 // set index order 929 if (checkIndexOrder.isSelected()) 930 ViewProperties.setIndexOrder("H5_ITER_INC"); 931 else if (checkIndexNative.isSelected()) 932 ViewProperties.setIndexOrder("H5_ITER_NATIVE"); 933 else 934 ViewProperties.setIndexOrder("H5_ITER_DEC"); 935 936 if (checkReadAll.isSelected()) { 937 ViewProperties.setStartMembers(0); 938 ViewProperties.setMaxMembers(-1); 939 } else { 940 try { 941 int maxsize = Integer.parseInt(maxMemberField.getText()); 942 ViewProperties.setMaxMembers(maxsize); 943 } 944 catch (Exception ex) { 945 } 946 947 try { 948 int startsize = Integer.parseInt(startMemberField.getText()); 949 ViewProperties.setStartMembers(startsize); 950 } 951 catch (Exception ex) { 952 } 953 } 954 955 @SuppressWarnings("rawtypes") 956 Vector[] moduleList = { treeViews, metaDataViews, textViews, tableViews, imageViews, paletteViews }; 957 @SuppressWarnings("rawtypes") 958 JComboBox[] choiceList = { choiceTreeView, choiceMetaDataView, choiceTextView, choiceTableView, 959 choiceImageView, choicePaletteView }; 960 for (int i = 0; i < 6; i++) { 961 Object theModule = choiceList[i].getSelectedItem(); 962 moduleList[i].remove(theModule); 963 moduleList[i].add(0, theModule); 964 } 965 966 ViewProperties.setAutoContrast(checkAutoContrast.isSelected()); 967 ViewProperties.setShowImageValue(checkShowValues.isSelected()); 968 ViewProperties.setConvertEnum(checkConvertEnum.isSelected()); 969 ViewProperties.setShowRegRefValue(checkShowRegRefValues.isSelected()); 970 971 if (indexBaseChoice.getSelectedIndex() == 0) 972 ViewProperties.setIndexBase1(false); 973 else 974 ViewProperties.setIndexBase1(true); 975 } 976 977 public boolean isFontChanged() { 978 return isFontChanged; 979 } 980 981 public boolean isUserGuideChanged() { 982 return isUserGuideChanged; 983 } 984 985 public boolean isWorkDirChanged() { 986 return isWorkDirChanged; 987 } 988 989 @Override 990 public void itemStateChanged(ItemEvent e) { 991 Object source = e.getSource(); 992 993 if (source.equals(checkReadAll)) { 994 startMemberField.setEnabled(!checkReadAll.isSelected()); 995 maxMemberField.setEnabled(!checkReadAll.isSelected()); 996 997 } 998 } 999}