001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2024
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 https://www.gnu.org/licenses/.
027 */
028package edu.wisc.ssec.mcidasv.control;
029
030import java.awt.Container;
031import java.awt.FlowLayout;
032import java.rmi.RemoteException;
033import java.util.Hashtable;
034import java.util.Iterator;
035
036import javax.swing.Box;
037import javax.swing.JButton;
038import javax.swing.JLabel;
039import javax.swing.JPanel;
040import javax.swing.JTextField;
041
042import net.miginfocom.swing.MigLayout;
043
044import ucar.unidata.data.DataChoice;
045import ucar.unidata.data.DataSelection;
046import ucar.unidata.idv.control.DisplayControlImpl;
047import ucar.unidata.util.ColorTable;
048import ucar.unidata.util.LogUtil;
049import ucar.visad.display.DisplayMaster;
050
051import visad.BaseColorControl;
052import visad.CoordinateSystem;
053import visad.Data;
054import visad.FieldImpl;
055import visad.FlatField;
056import visad.FunctionType;
057import visad.ScalarMap;
058import visad.ScalarMapControlEvent;
059import visad.ScalarMapEvent;
060import visad.ScalarMapListener;
061import visad.VisADException;
062import visad.georef.MapProjection;
063
064import edu.wisc.ssec.mcidasv.data.hydra.ImageRGBDisplayable;
065
066public class RGBCompositeControl extends DisplayControlImpl {
067
068    public final static String FORMULA_IN_PROGRESS_FLAG = "Formula_Active";
069
070    /** Displayable for the data */
071    private ImageRGBDisplayable imageDisplay;
072
073    private DisplayMaster displayMaster;
074
075    private ScalarMap redMap = null;
076    private ScalarMap grnMap = null;
077    private ScalarMap bluMap = null;
078
079    float[][] redTable = null;
080    float[][] grnTable = null;
081    float[][] bluTable = null;
082
083    final private double[] redRange = { Double.NaN, Double.NaN };
084    final private double[] grnRange = { Double.NaN, Double.NaN };
085    final private double[] bluRange = { Double.NaN, Double.NaN };
086
087    final double[] initRedRange = { Double.NaN, Double.NaN };
088    final double[] initGrnRange = { Double.NaN, Double.NaN };
089    final double[] initBluRange = { Double.NaN, Double.NaN };
090
091    private FieldImpl imageField = null;
092    private MapProjection mapProjection = null;
093
094    private double gamma = 1.0;
095
096    private double redGamma = 1.0;
097    private double grnGamma = 1.0;
098    private double bluGamma = 1.0;
099
100    private final JTextField gammaTxtFld =
101        new JTextField(Float.toString(1.0f), 4);
102    private final JTextField redGammaTxtFld =
103        new JTextField(Float.toString(1.0f), 4);
104    private final JTextField grnGammaTxtFld =
105        new JTextField(Float.toString(1.0f), 4);
106    private final JTextField bluGammaTxtFld =
107        new JTextField(Float.toString(1.0f), 4);
108
109    private final JTextField redLowTxtFld =
110        new JTextField(Float.toString(1.0f), 10);
111    private final JTextField redHighTxtFld =
112        new JTextField(Float.toString(1.0f), 10);
113    private final JTextField grnLowTxtFld =
114        new JTextField(Float.toString(1.0f), 10);
115    private final JTextField grnHighTxtFld =
116        new JTextField(Float.toString(1.0f), 10);
117    private final JTextField bluLowTxtFld =
118        new JTextField(Float.toString(1.0f), 10);
119    private final JTextField bluHighTxtFld =
120        new JTextField(Float.toString(1.0f), 10);
121
122    public boolean init(DataChoice dataChoice) throws VisADException, RemoteException {
123
124        displayMaster = getViewManager().getMaster();
125        DataSelection dataSelection = getDataSelection();
126
127        // TJJ Jul 2014
128        // by sharing a property via the active View Manager, we can signal all three
129        // preview windows they are part of an in-progress RGB Composite. If so, it
130        // appears we need to use a shared HydraContext so our geographic coverage
131        // subset applies across channels.
132
133        Hashtable ht = getIdv().getViewManager().getProperties();
134        ht.put(FORMULA_IN_PROGRESS_FLAG, true);
135
136        imageField = (FieldImpl) dataChoice.getData(dataSelection);
137
138        imageDisplay = new ImageRGBDisplayable("rgb composite", null, false, imageField);
139
140        ht.put(FORMULA_IN_PROGRESS_FLAG, false);
141
142        Iterator iter = imageDisplay.getScalarMapSet().iterator();
143        while (iter.hasNext()) {
144            ScalarMap map = (ScalarMap) iter.next();
145            if (map.getScalarName().startsWith("redimage")) {
146                redMap = map;
147            }
148            if (map.getScalarName().startsWith("greenimage")) {
149                grnMap = map;
150            }
151            if (map.getScalarName().startsWith("blueimage")) {
152                bluMap = map;
153            }
154        }
155
156        if (checkRange()) { //- from unpersistence if true, initialize gui, ScalarMaps
157            double[] redRange = getRedRange();
158            double[] grnRange = getGrnRange();
159            double[] bluRange = getBluRange();
160
161            initRedRange[0] = redRange[0];
162            initRedRange[1] = redRange[1];
163            initGrnRange[0] = grnRange[0];
164            initGrnRange[1] = grnRange[1];
165            initBluRange[0] = bluRange[0];
166            initBluRange[1] = bluRange[1];
167
168            redLowTxtFld.setText(Float.toString((float)redRange[0]));
169            redHighTxtFld.setText(Float.toString((float)redRange[1]));
170            grnLowTxtFld.setText(Float.toString((float)grnRange[0]));
171            grnHighTxtFld.setText(Float.toString((float)grnRange[1]));
172            bluLowTxtFld.setText(Float.toString((float)bluRange[0]));
173            bluHighTxtFld.setText(Float.toString((float)bluRange[1]));
174
175            gammaTxtFld.setText(Float.toString((float)gamma));
176            redGammaTxtFld.setText(Float.toString((float)redGamma));
177            grnGammaTxtFld.setText(Float.toString((float)grnGamma));
178            bluGammaTxtFld.setText(Float.toString((float)bluGamma));
179
180            redMap.setRange(redRange[0], redRange[1]);
181            grnMap.setRange(grnRange[0], grnRange[1]);
182            bluMap.setRange(bluRange[0], bluRange[1]);
183        } else {
184            redMap.resetAutoScale();
185            grnMap.resetAutoScale();
186            bluMap.resetAutoScale();
187
188            redMap.addScalarMapListener(new ColorMapListener(redMap, initRedRange, redRange, redLowTxtFld, redHighTxtFld));
189            grnMap.addScalarMapListener(new ColorMapListener(grnMap, initGrnRange, grnRange, grnLowTxtFld, grnHighTxtFld));
190            bluMap.addScalarMapListener(new ColorMapListener(bluMap, initBluRange, bluRange, bluLowTxtFld, bluHighTxtFld));
191        }
192
193        setShowInDisplayList(true);
194
195        addDisplayable(imageDisplay, FLAG_COLORTABLE | FLAG_ZPOSITION);
196
197        return true;
198    }
199
200    public void initDone() {
201        while (true) {
202            if (null != redMap.getControl()) {
203                redTable = ((BaseColorControl) redMap.getControl()).getTable();
204                break;
205            }
206        }
207        while (true) {
208            if (null != grnMap.getControl()) {
209                grnTable = ((BaseColorControl) grnMap.getControl()).getTable();
210                break;
211            }
212        }
213
214        while (true) {
215            if (null != bluMap.getControl()) {
216                bluTable = ((BaseColorControl) bluMap.getControl()).getTable();
217                break;
218            }
219        }
220
221        float[][] newRedTbl = getZeroOutArray(redTable);
222        float[][] newGrnTbl = getZeroOutArray(grnTable);
223        float[][] newBluTbl = getZeroOutArray(bluTable);
224
225        for (int k=0; k<redTable[0].length; k++) {
226            newRedTbl[0][k] = (float) Math.pow(redTable[0][k], redGamma);
227            newGrnTbl[1][k] = (float) Math.pow(grnTable[1][k], grnGamma);
228            newBluTbl[2][k] = (float) Math.pow(bluTable[2][k], bluGamma);
229        }
230
231        try {
232            displayMaster.setDisplayInactive();
233            ((BaseColorControl)redMap.getControl()).setTable(newRedTbl);
234            ((BaseColorControl)grnMap.getControl()).setTable(newGrnTbl);
235            ((BaseColorControl)bluMap.getControl()).setTable(newBluTbl);
236            imageDisplay.loadData(imageField);
237            displayMaster.setDisplayActive();
238        } catch (Exception ex) {
239            LogUtil.logException("setDisplayInactive", ex);
240        }
241    }
242
243    public MapProjection getDataProjection() {
244        CoordinateSystem cs = null;
245        try {
246            if (imageField instanceof FlatField) {
247                cs = ((FunctionType)imageField.getType()).getDomain().getCoordinateSystem();
248            }
249            else if (imageField instanceof FieldImpl) {
250                Data dat = imageField.getSample(0, false);
251                if (dat instanceof FlatField) {
252                    FlatField img = (FlatField) dat;
253                    cs = ((FunctionType)img.getType()).getDomain().getCoordinateSystem();
254                }
255            }
256        }
257        catch (Exception ex) {
258            LogUtil.logException("problem accessing data", ex);
259        }
260
261        if (cs instanceof MapProjection) {
262            mapProjection = (MapProjection)cs;
263        }
264
265        return mapProjection;
266    }
267
268    boolean checkRange() {
269        return !(Double.isNaN(redRange[0]) || Double.isNaN(grnRange[0]) || Double.isNaN(bluRange[0]));
270    }
271
272    private void updateRedRange(double lo, double hi) {
273        redRange[0] = lo;
274        redRange[1] = hi;
275        redHighTxtFld.setText(Float.toString((float)hi));
276        redLowTxtFld.setText(Float.toString((float)lo));
277        try {
278            redMap.setRange(lo, hi);
279        } catch (VisADException | RemoteException ex) {
280            LogUtil.logException("redMap.setRange", ex);
281        }
282    }
283
284    public void setRedRange(double[] range) {
285        redRange[0] = range[0];
286        redRange[1] = range[1];
287    }
288
289    public double[] getRedRange() {
290        return new double[] {redRange[0], redRange[1]};
291    }
292
293    private void updateGrnRange(double lo, double hi) {
294        grnRange[0] = lo;
295        grnRange[1] = hi;
296        grnHighTxtFld.setText(Float.toString((float)hi));
297        grnLowTxtFld.setText(Float.toString((float)lo));
298        try {
299            grnMap.setRange(lo, hi);
300        } catch (VisADException | RemoteException ex) {
301            LogUtil.logException("grnMap.setRange", ex);
302        }
303    }
304
305    public void setGrnRange(double[] range) {
306        grnRange[0] = range[0];
307        grnRange[1] = range[1];
308    }
309
310    public double[] getGrnRange() {
311        return new double[] {grnRange[0], grnRange[1]};
312    }
313
314    private void updateBluRange(double lo, double hi) {
315        bluRange[0] = lo;
316        bluRange[1] = hi;
317        bluHighTxtFld.setText(Float.toString((float)hi));
318        bluLowTxtFld.setText(Float.toString((float)lo));
319        try {
320            bluMap.setRange(lo, hi);
321        } catch (VisADException | RemoteException ex) {
322            LogUtil.logException("bluMap.setRange", ex);
323        }
324    }
325
326    public void setBluRange(double[] range) {
327        bluRange[0] = range[0];
328        bluRange[1] = range[1];
329    }
330
331    public double[] getBluRange() {
332        return new double[] {bluRange[0], bluRange[1]};
333    }
334
335    public void setRedGamma(double gamma) {
336        redGamma = gamma;
337    }
338
339    public double getRedGamma() {
340        return redGamma;
341    }
342
343    public void setGrnGamma(double gamma) {
344        grnGamma = gamma;
345    }
346
347    public double getGrnGamma() {
348        return grnGamma;
349    }
350
351    public void setBluGamma(double gamma) {
352        bluGamma = gamma;
353    }
354
355    public double getBluGamma() {
356        return bluGamma;
357    }
358
359    public void setGamma(double gamma) {
360        this.gamma = gamma;
361    }
362
363    public double getGamma() {
364        return gamma;
365    }
366
367    private void updateGamma(double gamma) {
368        setGamma(gamma);
369        setRedGamma(gamma);
370        setGrnGamma(gamma);
371        setBluGamma(gamma);
372        redGammaTxtFld.setText(Float.toString((float)gamma));
373        grnGammaTxtFld.setText(Float.toString((float)gamma));
374        bluGammaTxtFld.setText(Float.toString((float)gamma));
375
376        float[][] newRedTbl = getZeroOutArray(redTable);
377        float[][] newGrnTbl = getZeroOutArray(grnTable);
378        float[][] newBluTbl = getZeroOutArray(bluTable);
379
380        for (int k=0; k<redTable[0].length; k++) {
381            newRedTbl[0][k] = (float) Math.pow(redTable[0][k], gamma);
382            newGrnTbl[1][k] = (float) Math.pow(grnTable[1][k], gamma);
383            newBluTbl[2][k] = (float) Math.pow(bluTable[2][k], gamma);
384        }
385        try {
386            displayMaster.setDisplayInactive();
387            ((BaseColorControl)redMap.getControl()).setTable(newRedTbl);
388            ((BaseColorControl)grnMap.getControl()).setTable(newGrnTbl);
389            ((BaseColorControl)bluMap.getControl()).setTable(newBluTbl);
390            displayMaster.setDisplayActive();
391        } catch (Exception ex) {
392            LogUtil.logException("setDisplayInactive", ex);
393        }
394    }
395
396    private void updateRedGamma(double gamma) {
397        setRedGamma(gamma);
398
399        float[][] newRedTbl = getZeroOutArray(redTable);
400
401        for (int k=0; k<redTable[0].length; k++) {
402            newRedTbl[0][k] = (float) Math.pow(redTable[0][k], gamma);
403        }
404
405        try {
406            displayMaster.setDisplayInactive();
407            ((BaseColorControl)redMap.getControl()).setTable(newRedTbl);
408            displayMaster.setDisplayActive();
409        } catch (Exception ex) {
410            LogUtil.logException("setDisplayInactive", ex);
411        }
412    }
413
414    private void updateGrnGamma(double gamma) {
415        setGrnGamma(gamma);
416
417        float[][] newGrnTbl = getZeroOutArray(grnTable);
418        for (int k=0; k<grnTable[0].length; k++) {
419            newGrnTbl[1][k] = (float) Math.pow(grnTable[1][k], gamma);
420        }
421
422        try {
423            displayMaster.setDisplayInactive();
424            ((BaseColorControl)grnMap.getControl()).setTable(newGrnTbl);
425            displayMaster.setDisplayActive();
426        } catch (Exception ex) {
427            LogUtil.logException("setDisplayInactive", ex);
428        }
429    }
430
431    private void updateBluGamma(double gamma) {
432        setBluGamma(gamma);
433
434        float[][] newBluTbl = getZeroOutArray(bluTable);
435        for (int k=0; k<bluTable[0].length; k++) {
436            newBluTbl[2][k] = (float) Math.pow(bluTable[2][k], gamma);
437        }
438
439        try {
440            displayMaster.setDisplayInactive();
441            ((BaseColorControl)bluMap.getControl()).setTable(newBluTbl);
442            displayMaster.setDisplayActive();
443        } catch (Exception ex) {
444            LogUtil.logException("setDisplayInactive", ex);
445        }
446    }
447
448    public float[][] getZeroOutArray(float[][] array) {
449        float[][] newArray = new float[array.length][array[0].length];
450        for (int i=0; i<newArray.length; i++) {
451            for (int j=0; j<newArray[0].length; j++) {
452                newArray[i][j] = 0.0f;
453            }
454        }
455        return newArray;
456    }
457
458    protected ColorTable getInitialColorTable() {
459        return getDisplayConventions().getParamColorTable("image");
460    }
461
462    public Container doMakeContents() {
463
464        JButton allGammaButton = new JButton("Apply to All Gamma Fields");
465        allGammaButton.addActionListener(e -> {
466            String tmp = gammaTxtFld.getText().trim();
467            updateGamma(Double.valueOf(tmp));
468        });
469
470        gammaTxtFld.addActionListener(e -> {
471            String tmp = gammaTxtFld.getText().trim();
472            updateGamma(Double.valueOf(tmp));
473        });
474
475        redLowTxtFld.addActionListener(e -> {
476            String tmp = redLowTxtFld.getText().trim();
477            updateRedRange(Double.valueOf(tmp), redRange[1]);
478        });
479
480        redHighTxtFld.addActionListener(e -> {
481            String tmp = redHighTxtFld.getText().trim();
482            updateRedRange(redRange[0], Double.valueOf(tmp));
483        });
484
485        redGammaTxtFld.addActionListener(e -> {
486            String tmp = redGammaTxtFld.getText().trim();
487            updateRedGamma(Double.valueOf(tmp));
488        });
489
490        JButton redReset = new JButton("Reset");
491        redReset.addActionListener(e -> {
492            updateRedRange(initRedRange[0], initRedRange[1]);
493            redRange[0] = initRedRange[0];
494            redRange[1] = initRedRange[1];
495            redLowTxtFld.setText(Float.toString((float)redRange[0]));
496            redHighTxtFld.setText(Float.toString((float)redRange[1]));
497            updateRedGamma(1.0);
498            redGammaTxtFld.setText("1.0");
499        });
500
501        grnLowTxtFld.addActionListener(e -> {
502            String tmp = grnLowTxtFld.getText().trim();
503            updateGrnRange(Double.valueOf(tmp), grnRange[1]);
504        });
505
506        grnHighTxtFld.addActionListener(e -> {
507            String tmp = grnHighTxtFld.getText().trim();
508            updateGrnRange(grnRange[0], Double.valueOf(tmp));
509        });
510
511        grnGammaTxtFld.addActionListener(e -> {
512            String tmp = grnGammaTxtFld.getText().trim();
513            updateGrnGamma(Double.valueOf(tmp));
514        });
515
516        JButton grnReset = new JButton("Reset");
517        grnReset.addActionListener(e -> {
518            updateGrnRange(initGrnRange[0], initGrnRange[1]);
519            grnRange[0] = initGrnRange[0];
520            grnRange[1] = initGrnRange[1];
521            grnLowTxtFld.setText(Float.toString((float)grnRange[0]));
522            grnHighTxtFld.setText(Float.toString((float)grnRange[1]));
523            updateGrnGamma(1.0);
524            grnGammaTxtFld.setText("1.0");
525        });
526
527        bluLowTxtFld.addActionListener(e -> {
528            String tmp = bluLowTxtFld.getText().trim();
529            updateBluRange(Double.valueOf(tmp), bluRange[1]);
530        });
531
532        bluHighTxtFld.addActionListener(e -> {
533            String tmp = bluHighTxtFld.getText().trim();
534            updateBluRange(bluRange[0], Double.valueOf(tmp));
535        });
536
537        bluGammaTxtFld.addActionListener(e -> {
538            String tmp = bluGammaTxtFld.getText().trim();
539            updateBluGamma(Double.valueOf(tmp));
540        });
541
542        JButton bluReset = new JButton("Reset");
543        bluReset.addActionListener(e -> {
544            updateBluRange(initBluRange[0], initBluRange[1]);
545            bluRange[0] = initBluRange[0];
546            bluRange[1] = initBluRange[1];
547            bluLowTxtFld.setText(Float.toString((float)bluRange[0]));
548            bluHighTxtFld.setText(Float.toString((float)bluRange[1]));
549            updateBluGamma(1.0);
550            bluGammaTxtFld.setText("1.0");
551        });
552
553        JButton applyButton = new JButton("Apply");
554        applyButton.addActionListener(e -> {
555            String redLow = redLowTxtFld.getText().trim();
556            String redHigh = redHighTxtFld.getText().trim();
557            updateRedRange(Double.valueOf(redLow), Double.valueOf(redHigh));
558            String grnLow = grnLowTxtFld.getText().trim();
559            String grnHigh = grnHighTxtFld.getText().trim();
560            updateGrnRange(Double.valueOf(grnLow), Double.valueOf(grnHigh));
561            String bluLow = bluLowTxtFld.getText().trim();
562            String bluHigh = bluHighTxtFld.getText().trim();
563            updateBluRange(Double.valueOf(bluLow), Double.valueOf(bluHigh));
564
565            String tmp1 = redGammaTxtFld.getText().trim();
566            updateRedGamma(Double.valueOf(tmp1));
567            String tmp2 = grnGammaTxtFld.getText().trim();
568            updateGrnGamma(Double.valueOf(tmp2));
569            String tmp3 = bluGammaTxtFld.getText().trim();
570            updateBluGamma(Double.valueOf(tmp3));
571        });
572
573        JPanel topPanel = new JPanel(new MigLayout());
574        topPanel.add(new JLabel("Red range: "));
575        topPanel.add(redLowTxtFld);
576        topPanel.add(redHighTxtFld);
577        topPanel.add(new JLabel("Red Gamma: "));
578        topPanel.add(redGammaTxtFld);
579        topPanel.add(redReset, "wrap");
580
581        topPanel.add(new JLabel("Green range: "));
582        topPanel.add(grnLowTxtFld);
583        topPanel.add(grnHighTxtFld);
584        topPanel.add(new JLabel("Green Gamma: "));
585        topPanel.add(grnGammaTxtFld);
586        topPanel.add(grnReset, "wrap");
587
588        topPanel.add(new JLabel("Blue range: "));
589        topPanel.add(bluLowTxtFld);
590        topPanel.add(bluHighTxtFld);
591        topPanel.add(new JLabel("Blue Gamma: "));
592        topPanel.add(bluGammaTxtFld);
593        topPanel.add(bluReset, "wrap");
594
595        topPanel.add(Box.createHorizontalStrut(1), "span 5");
596        topPanel.add(applyButton, "wrap");
597
598        JPanel bottomPanel = new JPanel(new MigLayout("", "[align right][fill]"));
599        bottomPanel.add(new JLabel("Common Gamma: "));
600        bottomPanel.add(gammaTxtFld, "flowx, split 2");
601        bottomPanel.add(allGammaButton, "alignx right, wrap");
602        bottomPanel.add(new JLabel("Vertical Position: "));
603        bottomPanel.add(doMakeZPositionSlider());
604
605        JPanel mainPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
606        mainPanel.add(topPanel);
607        mainPanel.add(bottomPanel);
608
609        return mainPanel;
610    }
611
612    private class ColorMapListener implements ScalarMapListener {
613        ScalarMap clrMap;
614
615        double[] range = null;
616        double[] initRange = null;
617
618        JTextField lowTxtFld;
619        JTextField highTxtFld;
620
621        ColorMapListener(ScalarMap clrMap, double[] initRange, double[] range, JTextField lowTxtFld, JTextField highTxtFld) {
622            this.clrMap = clrMap;
623            this.lowTxtFld = lowTxtFld;
624            this.highTxtFld = highTxtFld;
625            this.range = range;
626            this.initRange = initRange;
627        }
628
629        public void controlChanged(ScalarMapControlEvent event) throws RemoteException, VisADException {
630        }
631
632        @Override
633        public void mapChanged(ScalarMapEvent event) throws RemoteException, VisADException {
634            if (event.getId() == ScalarMapEvent.AUTO_SCALE) {
635                double[] rng = clrMap.getRange();
636                boolean shouldRemove = false;
637                //Ghansham: decide whether it is first time. The cleaner way
638                if (!Double.isNaN(rng[0]) && !Double.isNaN(rng[1]) && Double.isNaN(initRange[0]) && Double.isNaN(initRange[1])) {
639                    shouldRemove = true;
640                }
641                range[0] = rng[0];
642                range[1] = rng[1];
643                initRange[0] = rng[0];
644                initRange[1] = rng[1];
645                lowTxtFld.setText(Float.toString((float)rng[0]));
646                highTxtFld.setText(Float.toString((float)rng[1]));
647                //Ghansham:If its first time remove the scalarmaplistener and setRange manually to disable autscaling of the scalarmap
648                if (shouldRemove) {
649                    clrMap.removeScalarMapListener(this);
650                    //-Lock out auto-scaling
651                    clrMap.disableAutoScale();
652                }
653            } else if (event.getId() == ScalarMapEvent.MANUAL) {
654                double[] rng = clrMap.getRange();
655                range[0] = rng[0];
656                range[1] = rng[1];
657            }
658        }
659    }
660}