001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2023
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 java.rmi.RemoteException;
031
032import edu.wisc.ssec.mcidasv.McIDASV;
033import ucar.unidata.data.DataChoice;
034
035import visad.VisADException;
036
037/**
038 * Rather trivial extension to the IDV's {@link ucar.unidata.idv.control.ProfilerTimeHeightControl}.
039 * All this class does is {@literal "observe"} changes to its {@code isLatestOnLeft}
040 * field. These get persisted between sessions.
041 */
042public class ProfilerTimeHeightControl 
043    extends ucar.unidata.idv.control.ProfilerTimeHeightControl 
044{
045    /** Pref ID! */
046    public static final String PREF_WIND_PROFILER_LATEST_LEFT = "mcidasv.control.latestleft";
047
048    /**
049     *  Default Constructor; does nothing. See init() for creation actions.
050     */
051    public ProfilerTimeHeightControl() {}
052
053    /**
054     * Construct the {@link ucar.visad.display.DisplayMaster DisplayMaster},
055     * {@link ucar.visad.display.Displayable Displayable}, frame, and
056     * controls. Overridden in McIDAS-V so that we can force the value of 
057     * {@code isLatestOnLeft} to its previous value (defaults to {@code false}).
058     *
059     * @param dataChoice {@link DataChoice} to use.
060     * 
061     * @return boolean {@code true} if {@code dataChoice} is ok.
062     *
063     * @throws RemoteException Java RMI error
064     * @throws VisADException VisAD Error
065     */
066    @Override public boolean init(DataChoice dataChoice) 
067        throws VisADException, RemoteException 
068    {
069        isLatestOnLeft = getIdv().getObjectStore().get(PREF_WIND_PROFILER_LATEST_LEFT, false);
070        return super.init(dataChoice);
071    }
072
073    /**
074     * Set whether latest data is displayed on the left or right
075     * side of the plot. Used by both {@literal "property"} and 
076     * {@literal "XML"} persistence.
077     * 
078     * @param yesorno {@code true} if latest data should appear on the left.
079     */
080    @Override public void setLatestOnLeft(final boolean yesorno) {
081        isLatestOnLeft = yesorno;
082        McIDASV mcv = McIDASV.getStaticMcv();
083        if (getHaveInitialized() && (getIdv() != null)) {
084            getIdv().getObjectStore().put(PREF_WIND_PROFILER_LATEST_LEFT, yesorno);
085        } else if ((mcv != null) && mcv.getHaveInitialized()) {
086            mcv.getObjectStore().put(PREF_WIND_PROFILER_LATEST_LEFT, yesorno);
087        }
088    }
089
090    /**
091     * Set the XAxis values. Overriden in McIDAS-V so that changes to the 
092     * {@code isLatestOnLeft} field are captured.
093     *
094     * @throws VisADException Couldn't set the values
095     */
096    @Override protected void setXAxisValues() throws VisADException {
097        setLatestOnLeft(isLatestOnLeft);
098        super.setXAxisValues();
099    }
100}