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    
029    package edu.wisc.ssec.mcidasv.ui;
030    
031    import java.awt.BorderLayout;
032    import java.awt.Insets;
033    import java.awt.event.ItemEvent;
034    import java.awt.event.ItemListener;
035    import java.util.ArrayList;
036    import java.util.Hashtable;
037    import java.util.List;
038    
039    import javax.swing.BorderFactory;
040    import javax.swing.JCheckBox;
041    import javax.swing.JComponent;
042    import javax.swing.JPanel;
043    
044    import ucar.unidata.idv.DisplayControl;
045    import ucar.unidata.idv.ui.SideLegend;
046    import ucar.unidata.idv.ui.SideLegend.CategoryPanel;
047    //import ucar.unidata.idv.ui.SideLegend.DisplayControlLegendPanel;
048    import ucar.unidata.util.GuiUtils;
049    
050    public class McvSideLegend extends SideLegend {
051    
052            // since you're gonna have to redo a significant portion of this, you might
053            // as well add in something to convey the ViewManager's active layer...
054            // may as well make it a tree, too.
055            // parent nodes don't get checks unless *all* kids are checked
056            // i like the UI from this link:
057            // http://rabbit-hole.blogspot.com/2006/11/tree-and-tree-table-with-checkboxes.html
058    //      @Override protected void fillLegendSafely() {
059    //        List controls = viewManager.getControlsForLegend();
060    //        for (int i = 0; i < categoryPanels.size(); i++) {
061    //            CategoryPanel categoryPanel =
062    //                (CategoryPanel) categoryPanels.get(i);
063    //            //            categoryPanel.clear();
064    //            categoryPanel.reInitialize();
065    //            categoryPanel.getContents().setVisible(true);
066    //        }
067    //
068    //        Hashtable seen = new Hashtable();
069    //        for (int i = controls.size() - 1; i >= 0; i--) {
070    //            final DisplayControl control  = (DisplayControl) controls.get(i);
071    //            String               category = control.getDisplayCategory();
072    //            System.err.println("debug: category=" + category);
073    //            if ((category == null) || (category.length() == 0)) {
074    //                category = "Displays";
075    //            }
076    //            CategoryPanel categoryPanel =
077    //               (CategoryPanel) categoryToPanel.get(category);
078    //            if (categoryPanel == null) {
079    //                categoryPanel = new CategoryPanel(this, category);
080    //                categoryPanels.add(categoryPanel);
081    //                categoryToPanel.put(category, categoryPanel);
082    //                Boolean b = (Boolean) categoryToPanelOpen.get(category);
083    //                if (b != null) {
084    //                    categoryPanel.setInnerVisible(b.booleanValue());
085    //                }
086    //            }
087    //            seen.put(categoryPanel, categoryPanel);
088    //            DisplayControlLegendPanel legendPanel =
089    //                (DisplayControlLegendPanel) control.getTransientProperty(
090    //                    "SIDELEGEND");
091    //            if (legendPanel == null) {
092    //                JCheckBox    visCbx = control.doMakeVisibilityControl("");
093    //                ItemListener itemListener = new ItemListener() {
094    //                    public void itemStateChanged(ItemEvent event) {
095    //                        displayControlVisibilityChanged(control,
096    //                                event.getStateChange() == ItemEvent.SELECTED);
097    //                    }
098    //                };
099    //                visCbx.addItemListener(itemListener);
100    //                visCbx.setBorder(BorderFactory.createEmptyBorder());
101    //                JComponent sideLegendLabel =
102    //                    control.getLegendLabel(control.SIDE_LEGEND);
103    //                sideLegendLabel.setBorder(BorderFactory.createEmptyBorder(0,
104    //                        5, 0, 3));
105    //                legendPanel = new DisplayControlLegendPanel(control,
106    //                        sideLegendLabel, false,
107    //                        GuiUtils.inset(visCbx, new Insets(0, 0, 0, 2)),
108    //                        control.getLegendButtons(control.SIDE_LEGEND));
109    //
110    //                JComponent controlLegend =
111    //                    control.getLegendComponent(control.SIDE_LEGEND);
112    //                legendPanel.add(controlLegend, false);
113    //                control.putTransientProperty("SIDELEGEND", legendPanel);
114    //            }
115    //            categoryPanel.add(control, legendPanel.getContents());
116    //        }
117    //
118    //        List orderedCategoryPanels = new ArrayList();
119    //        for (int i = 0; i < categoryPanels.size(); i++) {
120    //            CategoryPanel categoryPanel =
121    //                (CategoryPanel) categoryPanels.get(i);
122    //            if (seen.get(categoryPanel) != null) {
123    //                orderedCategoryPanels.add(categoryPanel.getContents());
124    //            } else {
125    //                categoryPanel.clear();
126    //            }
127    //        }
128    //
129    //
130    //        JPanel panels = GuiUtils.vbox(orderedCategoryPanels);
131    //        //        synchronized (legendsPanel.getTreeLock()) {
132    //        legendsPanel.removeAll();
133    //        legendsPanel.add(panels, BorderLayout.NORTH);
134    //        legendsPanel.invalidate();
135    //        //        }
136    //    }
137    
138            
139    }