001    /*
002     * $Id: HydraPlanViewControl.java,v 1.8 2012/02/19 17:35:38 davep Exp $
003     *
004     * This file is part of McIDAS-V
005     *
006     * Copyright 2007-2012
007     * Space Science and Engineering Center (SSEC)
008     * University of Wisconsin - Madison
009     * 1225 W. Dayton Street, Madison, WI 53706, USA
010     * https://www.ssec.wisc.edu/mcidas
011     * 
012     * All Rights Reserved
013     * 
014     * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015     * some McIDAS-V source code is based on IDV and VisAD source code.  
016     * 
017     * McIDAS-V is free software; you can redistribute it and/or modify
018     * it under the terms of the GNU Lesser Public License as published by
019     * the Free Software Foundation; either version 3 of the License, or
020     * (at your option) any later version.
021     * 
022     * McIDAS-V is distributed in the hope that it will be useful,
023     * but WITHOUT ANY WARRANTY; without even the implied warranty of
024     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025     * GNU Lesser Public License for more details.
026     * 
027     * You should have received a copy of the GNU Lesser Public License
028     * along with this program.  If not, see http://www.gnu.org/licenses.
029     */
030    
031    package edu.wisc.ssec.mcidasv.control;
032    
033    
034    import ucar.unidata.data.DataChoice;
035    import ucar.unidata.data.grid.GridUtil;
036    
037    import ucar.unidata.idv.DisplayConventions;
038    import ucar.unidata.idv.control.ImagePlanViewControl;
039    
040    import ucar.unidata.ui.colortable.ColorTableManager;
041    import ucar.unidata.util.GuiUtils;
042    import ucar.unidata.util.Misc;
043    import ucar.unidata.util.Range;
044    import ucar.unidata.util.ColorTable;
045    
046    import ucar.visad.display.DisplayableData;
047    import ucar.visad.display.Grid2DDisplayable;
048    
049    import visad.*;
050    import visad.VisADException;
051    
052    import java.rmi.RemoteException;
053    
054    import java.util.List;
055    
056    /**
057     * Class for controlling the display of images.
058     * @author IDV Development Group
059     * @version $Revision: 1.8 $
060     */
061    public class HydraPlanViewControl extends ImagePlanViewControl {
062    
063        /**
064         * Default constructor.  Sets the attribute flags used by
065         * this particular <code>PlanViewControl</code>
066         */
067        public HydraPlanViewControl() {
068            super();
069            setAttributeFlags(FLAG_COLORTABLE | FLAG_DISPLAYUNIT
070                              | FLAG_ZPOSITION | FLAG_SKIPFACTOR);
071        }
072    
073        /**
074         * Method to create the particular <code>DisplayableData</code> that
075         * this this instance uses for data depictions.
076         * @return Contour2DDisplayable for this instance.
077         *
078         * @throws VisADException   VisAD error
079         * @throws RemoteException   RMI error
080         */
081        protected DisplayableData createPlanDisplay()
082                throws VisADException, RemoteException {
083            Grid2DDisplayable gridDisplay = 
084                new Grid2DDisplayable("ImagePlanViewControl_" + ((datachoice != null)
085                    ? datachoice.toString()
086                    : ""), true);
087            gridDisplay.setTextureEnable(true);
088            /* TODO: Find out why this causes redisplays
089            if (BaseImageControl.EMPTY_IMAGE != null) {
090                gridDisplay.loadData(BaseImageControl.EMPTY_IMAGE);
091            }
092            */
093            //gridDisplay.setUseRGBTypeForSelect(true);
094            addAttributedDisplayable(gridDisplay);
095            return gridDisplay;
096        }
097    
098        /**
099         * Get the initial color table for the data
100         *
101         * @return  intitial color table
102         */
103        protected ColorTable getInitialColorTable() {
104    /*
105            DisplayConventions dc = getDisplayConventions();
106            List colorNames = dc.getColorNameList();
107            ColorTable colorTable = super.getInitialColorTable();
108            if (colorTable.getName().equalsIgnoreCase("default")) {
109                colorTable = dc.getParamColorTable("image");
110            }
111    */
112            ColorTableManager ctm = getControlContext().getColorTableManager();
113            ColorTable colorTable = ctm.getColorTable("ColorTable_AOD");
114            return colorTable;
115        }
116    
117    
118        /**
119         * Get whether this display should allow smoothing
120         * @return true if allows smoothing.
121         */
122        public boolean getAllowSmoothing() {
123            return false;
124        }
125    
126    
127        /**
128         * Get the initial range for the data and color table.
129         * @return  initial range
130         *
131         * @throws RemoteException  Java RMI error
132         * @throws VisADException   VisAD Error
133         */
134        protected Range getInitialRange() throws RemoteException, VisADException {
135            Range range = getDisplayConventions().getParamRange(paramName,
136                              getDisplayUnit());
137            System.out.println(paramName);
138            System.out.println(range);
139            //Don't do this for now
140            /**
141            if (range == null) {
142                range = getRangeFromColorTable();
143                if ((range != null) && (range.getMin() == range.getMax())) {
144                    range = null;
145                }
146            }
147    
148            if (range == null) {
149                range = getDisplayConventions().getParamRange("image",
150                        getDisplayUnit());
151            }
152            if (range == null) {
153                return new Range(0, 255);
154            }
155            **/
156            range = new Range((double)0.0, (double)0.99);
157            return range;
158        }
159    
160        /**
161         * Get the slice for the display
162         *
163         * @param slice  slice to use
164         *
165         * @return slice with skip value applied
166         *
167         * @throws VisADException  problem subsetting the slice
168         */
169        protected FieldImpl getSliceForDisplay(FieldImpl slice)
170                throws VisADException {
171            checkImageSize(slice);
172            if (getSkipValue() <= 0) {
173                return slice;
174            }
175            return GridUtil.subset(slice, getSkipValue() + 1);
176        }
177    
178        /**
179         * Return the label that is to be used for the skip widget
180         * This allows derived classes to override this and provide their
181         * own name,
182         *
183         * @return Label used for the line width widget
184         */
185        public String getSkipWidgetLabel() {
186            return "Pixel Sampling";
187        }
188    
189    }