|
| 1 | +/* |
| 2 | + * Copyright 1997-2017 Unidata Program Center/University Corporation for |
| 3 | + * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307, |
| 4 | + |
| 5 | + * |
| 6 | + * This library is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2.1 of the License, or (at |
| 9 | + * your option) any later version. |
| 10 | + * |
| 11 | + * This library is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
| 14 | + * General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with this library; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | + */ |
| 20 | + |
| 21 | +package ucar.unidata.apps.cas; |
| 22 | + |
| 23 | + |
| 24 | +import java.awt.event.ActionEvent; |
| 25 | +import java.awt.event.ActionListener; |
| 26 | +import java.rmi.RemoteException; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +import javax.swing.JCheckBox; |
| 30 | + |
| 31 | +import ucar.unidata.idv.control.WrapperWidget; |
| 32 | +import ucar.unidata.util.GuiUtils; |
| 33 | +import ucar.visad.display.DisplayableData; |
| 34 | +import ucar.visad.display.Grid2DDisplayable; |
| 35 | +import visad.VisADException; |
| 36 | + |
| 37 | + |
| 38 | +/** |
| 39 | + * Class for displaying cross sections as color shaded displays. |
| 40 | + * @author Jeff McWhirter |
| 41 | + * @version $Revision: 1.24 $ |
| 42 | + */ |
| 43 | +public class ColorMultiSegmentCrossSectionControl extends MultiSegmentCrossSectionControl { |
| 44 | + |
| 45 | + /** flag for smoothing */ |
| 46 | + boolean isSmoothed = false; |
| 47 | + |
| 48 | + /** flag for allowing smoothing */ |
| 49 | + boolean allowSmoothing = true; |
| 50 | + |
| 51 | + /** |
| 52 | + * Default constructor |
| 53 | + */ |
| 54 | + public ColorMultiSegmentCrossSectionControl() {} |
| 55 | + |
| 56 | + /** |
| 57 | + * Create the <code>DisplayableData</code> that will be used |
| 58 | + * to depict the data in the main display. |
| 59 | + * @return depictor for data in main display |
| 60 | + * @throws VisADException unable to create depictor |
| 61 | + * @throws RemoteException unable to create depictor (shouldn't happen) |
| 62 | + */ |
| 63 | + protected DisplayableData createXSDisplay() |
| 64 | + throws VisADException, RemoteException { |
| 65 | + Grid2DDisplayable display = new Grid2DDisplayable("vcs_col" |
| 66 | + + paramName, true); |
| 67 | + display.setTextureEnable( !isSmoothed); |
| 68 | + display.setUseRGBTypeForSelect(true); |
| 69 | + addAttributedDisplayable(display, FLAG_COLORTABLE | FLAG_SELECTRANGE); |
| 70 | + return display; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Create the <code>DisplayableData</code> that will be used |
| 75 | + * to depict the data in the control's display. |
| 76 | + * @return depictor for data in main display |
| 77 | + * @throws VisADException unable to create depictor |
| 78 | + * @throws RemoteException unable to create depictor (shouldn't happen) |
| 79 | + */ |
| 80 | + protected DisplayableData createVCSDisplay() |
| 81 | + throws VisADException, RemoteException { |
| 82 | + Grid2DDisplayable display = new Grid2DDisplayable("vcs_" + paramName, |
| 83 | + true); |
| 84 | + display.setTextureEnable( !isSmoothed); |
| 85 | + display.setUseRGBTypeForSelect(true); |
| 86 | + addAttributedDisplayable(display, FLAG_COLORTABLE | FLAG_SELECTRANGE); |
| 87 | + return display; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Create the <code>DisplayableData</code> that will be used |
| 92 | + * to depict the data in the control's display. |
| 93 | + * @return depictor for data in main display |
| 94 | + * @throws VisADException unable to create depictor |
| 95 | + * @throws RemoteException unable to create depictor (shouldn't happen) |
| 96 | + */ |
| 97 | + protected DisplayableData createMapTransectDisplay() |
| 98 | + throws VisADException, RemoteException { |
| 99 | + Grid2DDisplayable display = new Grid2DDisplayable("vcsmap_" + paramName, |
| 100 | + true); |
| 101 | + display.setTextureEnable( !isSmoothed); |
| 102 | + display.setUseRGBTypeForSelect(true); |
| 103 | + addAttributedDisplayable(display, FLAG_COLORTABLE | FLAG_SELECTRANGE); |
| 104 | + return display; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Add any specialized control widgets for this control |
| 109 | + * to the list. |
| 110 | + * @param controlWidgets <code>List</code> to add to. |
| 111 | + * @throws VisADException unable to create controls |
| 112 | + * @throws RemoteException unable to create controls (shouldn't happen) |
| 113 | + */ |
| 114 | + public void getControlWidgets(List controlWidgets) |
| 115 | + throws VisADException, RemoteException { |
| 116 | + super.getControlWidgets(controlWidgets); |
| 117 | + if (getAllowSmoothing()) { |
| 118 | + JCheckBox toggle = new JCheckBox("", isSmoothed); |
| 119 | + toggle.addActionListener(new ActionListener() { |
| 120 | + public void actionPerformed(ActionEvent e) { |
| 121 | + try { |
| 122 | + isSmoothed = ((JCheckBox) e.getSource()).isSelected(); |
| 123 | + ((Grid2DDisplayable) getXSDisplay()).setTextureEnable( |
| 124 | + !isSmoothed); |
| 125 | + ((Grid2DDisplayable) getVerticalCSDisplay()) |
| 126 | + .setTextureEnable( !isSmoothed); |
| 127 | + } catch (Exception ve) { |
| 128 | + logException("setSmoothed", ve); |
| 129 | + } |
| 130 | + } |
| 131 | + }); |
| 132 | + controlWidgets.add(new WrapperWidget(this, |
| 133 | + GuiUtils.rLabel("Shade Colors:"), toggle)); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Set whether the depictions should show smooth or blocky shading. |
| 139 | + * Used by XML persistence. |
| 140 | + * @param v true to use smoothed depictions |
| 141 | + */ |
| 142 | + public void setSmoothed(boolean v) { |
| 143 | + isSmoothed = v; |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Get whether the depictions show smooth or blocky shading. |
| 148 | + * @return true if using smoothed depictions |
| 149 | + */ |
| 150 | + public boolean getSmoothed() { |
| 151 | + return isSmoothed; |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * Set whether this display should allow smoothed colors or blocky. Used |
| 156 | + * by XML persistence (bundles) for the most part. |
| 157 | + * @param v true to allowing smoothing. |
| 158 | + */ |
| 159 | + public void setAllowSmoothing(boolean v) { |
| 160 | + allowSmoothing = v; |
| 161 | + if ( !allowSmoothing) { |
| 162 | + setSmoothed(false); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Get whether this display should allow smoothing |
| 168 | + * @return true if allows smoothing. |
| 169 | + */ |
| 170 | + public boolean getAllowSmoothing() { |
| 171 | + return allowSmoothing; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Is this a raster display? |
| 176 | + * |
| 177 | + * @return true if raster |
| 178 | + */ |
| 179 | + public boolean getIsRaster() { |
| 180 | + return true; |
| 181 | + } |
| 182 | +} |
0 commit comments