001 /* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2013 005 * Space Science and Engineering Center (SSEC) 006 * University of Wisconsin - Madison 007 * 1225 W. Dayton Street, Madison, WI 53706, USA 008 * https://www.ssec.wisc.edu/mcidas 009 * 010 * All Rights Reserved 011 * 012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and 013 * some McIDAS-V source code is based on IDV and VisAD source code. 014 * 015 * McIDAS-V is free software; you can redistribute it and/or modify 016 * it under the terms of the GNU Lesser Public License as published by 017 * the Free Software Foundation; either version 3 of the License, or 018 * (at your option) any later version. 019 * 020 * McIDAS-V is distributed in the hope that it will be useful, 021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 023 * GNU Lesser Public License for more details. 024 * 025 * You should have received a copy of the GNU Lesser Public License 026 * along with this program. If not, see http://www.gnu.org/licenses. 027 */ 028 package edu.wisc.ssec.mcidasv.chooser; 029 030 import java.awt.Component; 031 import java.awt.Container; 032 import java.io.File; 033 034 import javax.swing.JFileChooser; 035 import javax.swing.JLabel; 036 037 /** 038 * An extension of JFileChooser, particular to Suomi NPP data. 039 * Mostly that means check for presence of separate HDF5 geolocation 040 * files when needed to bless granules for selection. 041 * 042 * @author Tommy Jasmin 043 */ 044 045 public class SuomiNPPFileChooser extends JFileChooser { 046 047 /** 048 * default for serializable class 049 */ 050 private static final long serialVersionUID = 1L; 051 052 /** 053 * ref to caller 054 */ 055 private SuomiNPPChooser snppc = null; 056 057 /** 058 * Create the file chooser 059 * 060 * @param path the initial path 061 * @param snppc the enclosing Suomi Chooser 062 */ 063 064 public SuomiNPPFileChooser(String path, SuomiNPPChooser snppc) { 065 super(path); 066 this.snppc = snppc; 067 setControlButtonsAreShown(false); 068 setMultiSelectionEnabled(true); 069 setAcceptAllFileFilterUsed(false); 070 processChildren(this); 071 } 072 073 private void processChildren(Container c) { 074 Component [] components = c.getComponents(); 075 if (components != null) { 076 // loop through all components, looking for the JLabel children of 077 // components we want to remove 078 for (int i = 0; i < components.length; i++) { 079 if (components[i] instanceof JLabel) { 080 String text = ((JLabel) components[i]).getText(); 081 if (text.equals("File Name:")) { 082 hideChildren((Container) components[i].getParent()); 083 continue; 084 } 085 if (text.equals("Files of Type:")) { 086 hideChildren((Container) components[i].getParent()); 087 continue; 088 } 089 } 090 // now check this component for any children 091 processChildren((Container) components[i]); 092 } 093 } 094 } 095 096 private void hideChildren(Container c) { 097 Component [] components = c.getComponents(); 098 for (int i = 0; i < components.length; i++) { 099 components[i].setVisible(false); 100 } 101 c.setVisible(false); 102 } 103 104 /** 105 * Approve the selection 106 */ 107 public void approveSelection() { 108 snppc.doLoad(); 109 } 110 111 /** 112 * Set the selected files 113 * 114 * @param selectedFiles the selected files 115 */ 116 public void setSelectedFiles(File[] selectedFiles) { 117 super.setSelectedFiles(selectedFiles); 118 snppc.setHaveData( !((selectedFiles == null) || (selectedFiles.length == 0))); 119 } 120 }