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