001    /*
002     * $Id: DisplayState.java,v 1.1 2012/01/04 20:39:39 tommyj Exp $
003     *
004     * This file is part of McIDAS-V
005     *
006     * Copyright 2007-2012
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    
031    package edu.wisc.ssec.mcidasv.control.cyclone;
032    
033    import java.awt.Color;
034    import java.awt.event.ActionEvent;
035    import java.awt.event.ActionListener;
036    
037    import javax.swing.BorderFactory;
038    import javax.swing.JCheckBox;
039    
040    import ucar.unidata.util.LogUtil;
041    
042    /**
043     * 
044     * @author Unidata Development Team
045     * @version $Revision: 1.1 $
046     */
047    
048    public class DisplayState {
049    
050            /** the way display state */
051            private WayDisplayState wayDisplayState;
052    
053            /** for gui */
054            private JCheckBox cbx;
055    
056            /** is this visible */
057            private boolean visible;
058    
059            /** the name */
060            private String name;
061    
062            /**
063             * ctor
064             */
065            public DisplayState() {
066            }
067    
068            /**
069             * ctor
070             * 
071             * 
072             * @param wayDisplayState
073             *            the way display state
074             * @param name
075             *            the name
076             * @param visible
077             *            is this visible
078             */
079            public DisplayState(WayDisplayState wayDisplayState, String name,
080                            boolean visible) {
081                    this.wayDisplayState = wayDisplayState;
082                    this.name = name;
083                    this.visible = visible;
084            }
085    
086            /**
087             * set background color
088             * 
089             * @param c
090             *            color
091             */
092            protected void setBackground(Color c) {
093                    getCheckBox().setBackground(c);
094            }
095    
096            /**
097             * make the checkbox
098             * 
099             * 
100             * @return the checkbox
101             */
102            public JCheckBox getCheckBox() {
103                    if (cbx == null) {
104                            cbx = new JCheckBox("", getVisible());
105                            cbx.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
106                            cbx.setToolTipText(name);
107                            cbx.addActionListener(new ActionListener() {
108                                    public void actionPerformed(ActionEvent ae) {
109                                            try {
110                                                    setVisible(cbx.isSelected());
111                                                    wayDisplayState.getStormDisplayState()
112                                                                    .displayStateChanged(DisplayState.this);
113                                            } catch (Exception exc) {
114                                                    LogUtil.logException("Toggling way visible", exc);
115                                            }
116                                    }
117                            });
118                    }
119                    return cbx;
120            }
121    
122            /**
123             * Set the Visible property.
124             * 
125             * @param value
126             *            The new value for Visible
127             */
128            public void setVisible(boolean value) {
129                    visible = value;
130            }
131    
132            /**
133             * Get the Visible property.
134             * 
135             * @return The Visible
136             */
137            public boolean getVisible() {
138                    return visible;
139            }
140    
141            /**
142             * Set the Name property.
143             * 
144             * @param value
145             *            The new value for Name
146             */
147            public void setName(String value) {
148                    name = value;
149            }
150    
151            /**
152             * Get the Name property.
153             * 
154             * @return The Name
155             */
156            public String getName() {
157                    return name;
158            }
159    
160            /**
161             * Set the WayDisplayState property.
162             * 
163             * @param value
164             *            The new value for WayDisplayState
165             */
166            public void setWayDisplayState(WayDisplayState value) {
167                    wayDisplayState = value;
168            }
169    
170            /**
171             * Get the WayDisplayState property.
172             * 
173             * @return The WayDisplayState
174             */
175            public WayDisplayState getWayDisplayState() {
176                    return wayDisplayState;
177            }
178    
179    }