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