001/* 002 * $Id: CurveDrawer.java,v 1.6 2011/03/24 16:06:33 davep Exp $ 003 * 004 * This file is part of McIDAS-V 005 * 006 * Copyright 2007-2011 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 031package edu.wisc.ssec.mcidasv.data.hydra; 032 033import ucar.visad.display.LineDrawing; 034import ucar.visad.display.Displayable; 035 036 037import visad.*; 038import visad.java2d.*; 039 040import visad.java3d.*; 041 042import visad.bom.*; 043 044import java.rmi.RemoteException; 045 046import java.awt.event.InputEvent; 047 048 049/** 050 * Provides support for a Displayable that comprises a set of 051 * drawn curves. The curves can be drawn in in spherical and 052 * other non-Cartesian coordinate systems by selecting the 053 * appropriate RealTypes or RealTupleType.<P> 054 * Sample usage:<P> 055 * <PRE> 056 * CurveDrawer curveDraw = 057 * new CurveDrawer(RealType.Latitude, RealType.Longitude); 058 * curveDraw.addAction(new ActionImpl() { 059 * public void doAction() 060 * throws VisADException, RemoteException 061 * { 062 * UnionSet curves = curveDraw.getData(); 063 * (do something useful with the curves) 064 * } 065 * }); 066 * </PRE> 067 * @author Don Murray 068 * @version $Revision: 1.6 $ 069 */ 070public class CurveDrawer extends LineDrawing { 071 072 /** The type for the drawing space */ 073 private RealTupleType type; 074 075 /** the set of drawn curves */ 076 private UnionSet curves; 077 078 /** mask for mouse events */ 079 private int mask; 080 081 /** data renderer */ 082 private DataRenderer curver; 083 084 /** 085 * Construct a CurveDrawer using xType as the X coordinate and 086 * yType as the Y coordinate of the box. 087 * @param xType RealType of the X coordinate of the box 088 * @param yType RealType of the Y coordinate of the box 089 * @throws VisADException VisAD error 090 * @throws RemoteException Remote error 091 */ 092 public CurveDrawer(RealType xType, RealType yType) 093 throws VisADException, RemoteException { 094 this(new RealTupleType(xType, yType), 0); 095 } 096 097 /** 098 * Construct a CurveDrawer using xType as the X coordinate and 099 * yType as the Y coordinate of the box. 100 * @param xType RealType of the X coordinate of the box 101 * @param yType RealType of the Y coordinate of the box 102 * @param mask key mask to use for mouse button 103 * @throws VisADException VisAD error 104 * @throws RemoteException Remote error 105 */ 106 public CurveDrawer(RealType xType, RealType yType, int mask) 107 throws VisADException, RemoteException { 108 this(new RealTupleType(xType, yType), mask); 109 } 110 111 /** 112 * Construct a CurveDrawer using the RealTupleType 113 * @param type RealTupleType of the drawing space 114 * @throws VisADException VisAD error 115 * @throws RemoteException Remote error 116 */ 117 public CurveDrawer(RealTupleType type) 118 throws VisADException, RemoteException { 119 this(type, 0); 120 } 121 122 /** 123 * Construct a CurveDrawer using the RealTupleType of the drawing 124 * space and a mask for the mouse 125 * @param type RealTupleType of the drawing space 126 * @param mask key mask to use for mouse button 127 * @throws VisADException VisAD error 128 * @throws RemoteException Remote error 129 */ 130 public CurveDrawer(RealTupleType type, int mask) 131 throws VisADException, RemoteException { 132 this(new UnionSet(new Gridded2DSet[]{ 133 new Gridded2DSet(type, new float[][] { 134 { 0.0f }, { 0.0f } 135 }, 1) })); 136 } 137 138 139 /** 140 * Construct a CurveDrawer with a predefined set of curves. 141 * @param curves UnionSet of curves 142 * @throws VisADException VisAD error 143 * @throws RemoteException Remote error 144 */ 145 public CurveDrawer(UnionSet curves) 146 throws VisADException, RemoteException { 147 this(curves, 0); 148 } 149 150 /** 151 * Construct a CurveDrawer with a predefined set of curves. 152 * @param curves UnionSet of curves 153 * @param mask key mask to use for mouse button 154 * 155 * @throws RemoteException Java RMI error 156 * @throws VisADException problem creating VisAD object 157 */ 158 public CurveDrawer(UnionSet curves, int mask) 159 throws VisADException, RemoteException { 160 161 super("Curve Drawer"); 162 163 this.type = ((SetType) curves.getType()).getDomain(); 164 this.mask = mask; 165 setManipulable(true); 166 setData(curves); 167 } 168 169 /** 170 * Constructor for creating a CurveDrawer from another instance 171 * @param that other instance 172 * @throws VisADException VisAD error 173 * @throws RemoteException Remote error 174 */ 175 protected CurveDrawer(CurveDrawer that) 176 throws VisADException, RemoteException { 177 178 super(that); 179 180 this.type = that.type; 181 this.curves = that.curves; 182 this.mask = that.mask; 183 } 184 185 /** 186 * Invoked when box mouse is released. Subclasses should invoke 187 * super.dataChange() to ensure the the curves are set. 188 * 189 * @throws RemoteException Java RMI error 190 * @throws VisADException problem creating VisAD object 191 */ 192 protected void dataChange() throws VisADException, RemoteException { 193 194 curves = (UnionSet) getData(); 195 super.dataChange(); 196 197 } 198 199 /** 200 * Return the curves of the CurveDrawer. The UnionSet that 201 * is returned contains the lines. 202 * @return set containing sets of curves 203 */ 204 public UnionSet getCurves() { 205 return curves; 206 } 207 208 /** 209 * Set the curves of the CurveDrawer. The input must have the 210 * same MathType as this instance. 211 * @param curves set of curves to display 212 * 213 * @throws RemoteException Java RMI error 214 * @throws VisADException problem creating VisAD object 215 */ 216 public void setCurves(UnionSet curves) 217 throws VisADException, RemoteException { 218 219 if ( !((SetType) curves.getType()).getDomain().equals(type)) { 220 throw new IllegalArgumentException("MathType of curve must be " 221 + type); 222 } 223 setData(curves); 224 } 225 226 227 /** 228 * Set whether the curves are manipulable or not. 229 * 230 * @param b true to enable 231 * 232 * @throws RemoteException Java RMI error 233 * @throws VisADException problem creating VisAD object 234 */ 235 public void setDrawingEnabled(boolean b) 236 throws VisADException, RemoteException { 237 setManipulable(b); 238 } 239 240 /** 241 * Set whether the curves are manipulable or not. 242 * @return true if drawing is enabled 243 */ 244 public boolean getDrawingEnabled() { 245 return isManipulable(); 246 } 247 248 /** 249 * Returns a clone of this instance suitable for another VisAD display. 250 * Underlying data objects are not cloned. 251 * @return A semi-deep clone of this instance. 252 * @throws VisADException VisAD failure. 253 * @throws RemoteException Java RMI failure. 254 */ 255 public Displayable cloneForDisplay() 256 throws RemoteException, VisADException { 257 return new CurveDrawer(this); 258 } 259 260 /** 261 * Returns the DataRenderer for this displayable. This method does not 262 * verify that the VisAD display has been set. 263 * @return The DataRenderer associated with this 264 * displayable. 265 */ 266 protected DataRenderer getDataRenderer() { 267 268 LocalDisplay display = getDisplay(); 269 270 return isManipulable() 271 ? (display.getDisplayRenderer() instanceof DisplayRendererJ2D) 272 ? (DataRenderer) new CurveManipulationRendererJ2D() 273 : (DataRenderer) new CurveManipulationRendererJ3D() 274 : (display.getDisplayRenderer() instanceof DisplayRendererJ2D) 275 ? (DataRenderer) new DefaultRendererJ2D() 276 : (DataRenderer) new DefaultRendererJ3D(); 277 } 278} 279 280 281 282 283