001 /*
002 * $Id: NearCastTrajControl.java,v 1.6 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 package edu.wisc.ssec.mcidasv.control;
031
032 import ucar.unidata.data.DataChoice;
033 import ucar.unidata.data.DataDataChoice;
034 import ucar.unidata.data.DirectDataChoice;
035 import ucar.unidata.data.DataSelection;
036 import ucar.unidata.data.DataCategory;
037
038 import ucar.unidata.data.grid.GridUtil;
039
040 import ucar.unidata.idv.DisplayConventions;
041 import ucar.unidata.idv.IntegratedDataViewer;
042 import ucar.unidata.idv.control.DisplayControlImpl;
043 import ucar.unidata.idv.DisplayControl;
044
045 import ucar.visad.display.DisplayMaster;
046 import ucar.visad.display.DisplayableData;
047 import ucar.visad.display.Displayable;
048 import ucar.visad.display.LineDrawing;
049 import ucar.visad.display.RGBDisplayable;
050
051 import edu.wisc.ssec.mcidasv.data.hydra.HydraRGBDisplayable;
052 import edu.wisc.ssec.mcidasv.data.NearCastTrajDataSource;
053
054 import visad.*;
055 import visad.BaseColorControl;
056 import visad.VisADException;
057 import visad.RemoteVisADException;
058 import visad.ScalarMapListener;
059 import visad.ScalarMapControlEvent;
060 import visad.ScalarMapEvent;
061 import visad.ReferenceException;
062 import visad.georef.MapProjection;
063 import visad.georef.TrivialMapProjection;
064
065
066 import ucar.unidata.idv.ViewManager;
067 import ucar.unidata.idv.ViewDescriptor;
068
069 import ucar.unidata.util.ColorTable;
070 import ucar.unidata.util.Range;
071 import ucar.unidata.util.Misc;
072 import ucar.unidata.util.GuiUtils;
073
074 import ucar.unidata.util.LogUtil;
075
076 import java.awt.Component;
077 import java.awt.Container;
078 import java.awt.FlowLayout;
079 import java.awt.BorderLayout;
080 import java.awt.GridLayout;
081 import java.awt.event.*;
082 import java.awt.geom.Rectangle2D;
083
084
085 import javax.swing.*;
086 import javax.swing.event.*;
087
088
089 import java.util.HashMap;
090 import java.util.Hashtable;
091 import java.util.Enumeration;
092 import java.util.Iterator;
093 import java.util.List;
094
095 import java.awt.Color;
096 import java.awt.Font;
097
098
099 import java.rmi.RemoteException;
100
101
102 public class NearCastTrajControl extends DisplayControlImpl {
103
104 /** Displayable for the data */
105 LineDrawing trajDisplay;
106
107 private DisplayMaster displayMaster;
108
109 FieldImpl trajField = null;
110
111 RealType rgbRealType = null;
112 String paramName = null;
113
114 NearCastTrajDataSource dataSource;
115
116 private DisplayableData rgbDisp;
117
118 float lineWidth = 1.0f;
119
120
121 public NearCastTrajControl() {
122 super();
123 setAttributeFlags(FLAG_COLORTABLE | FLAG_LINEWIDTH);
124 }
125
126 public boolean init(DataChoice dataChoice) throws VisADException, RemoteException {
127 displayMaster = getViewManager().getMaster();
128 dataSource = (NearCastTrajDataSource) ((DirectDataChoice) dataChoice).getDataSource();
129
130 DataSelection dataSelection = getDataSelection();
131 trajField = (FieldImpl) dataChoice.getData(dataSelection);
132
133 FlatField fltFld = null;
134 if (GridUtil.isSequence(trajField)) {
135 FieldImpl fld = (FieldImpl) trajField.getSample(0);
136 if (GridUtil.isSequence(fld)) {
137 fltFld = (FlatField) fld.getSample(0);
138 }
139 }
140 else {
141 fltFld = (FlatField) trajField;
142 }
143 rgbRealType = (RealType) ((FunctionType)fltFld.getType()).getRange();
144 paramName = rgbRealType.getName();
145
146 rgbDisp = new RGBDisplayableImpl("traj", rgbRealType, null, true);
147 rgbDisp.setData(trajField);
148
149 addDisplayable(rgbDisp, FLAG_COLORTABLE);
150
151 return true;
152 }
153
154 public void initDone() {
155 }
156
157 protected void applyLineWidth() throws VisADException, RemoteException {
158 float lw = getLineWidth();
159 if (lw != lineWidth) {
160 rgbDisp.setLineWidth(lw);
161 lineWidth = lw;
162 }
163 }
164
165 protected Range getInitialRange() throws VisADException, RemoteException {
166 //Range rng = getDisplayConventions().getParamRange(paramName, null);
167 Range rng = null;
168 if (rng == null) {
169 return dataSource.getParamRange();
170 }
171 return rng;
172 }
173
174 /**
175 protected ColorTable getInitialColorTable() {
176 return getDisplayConventions().getParamColorTable("image");
177 }
178 */
179
180 private class RGBDisplayableImpl extends RGBDisplayable {
181 RGBDisplayableImpl(String name, RealType rgbRealType, float[][] colorPalette, boolean alphaflag)
182 throws VisADException, RemoteException {
183 super(name, rgbRealType, colorPalette, alphaflag);
184 }
185 }
186
187 @Override public MapProjection getDataProjection() {
188 MapProjection mp = null;
189 Range lonRange = dataSource.getLonRange();
190 Range latRange = dataSource.getLatRange();
191 float delLon = (float) (lonRange.getMax() - lonRange.getMin());
192 float delLat = (float) (latRange.getMax() - latRange.getMin());
193
194 try {
195 mp = new TrivialMapProjection(RealTupleType.SpatialEarth2DTuple,
196 new Rectangle2D.Float((float)lonRange.getMin(), (float)latRange.getMin(),
197 delLon, delLat));
198 } catch (Exception e) {
199 logException("MultiSpectralControl.getDataProjection", e);
200 }
201
202 return mp;
203 }
204
205
206 }