MOA 12.03
Real Time Analytics for Data Streams
IntOptionEditComponent.java
Go to the documentation of this file.
00001 /*
00002  *    IntOptionEditComponent.java
00003  *    Copyright (C) 2007 University of Waikato, Hamilton, New Zealand
00004  *    @author Richard Kirkby (rkirkby@cs.waikato.ac.nz)
00005  *
00006  *    This program is free software; you can redistribute it and/or modify
00007  *    it under the terms of the GNU General Public License as published by
00008  *    the Free Software Foundation; either version 3 of the License, or
00009  *    (at your option) any later version.
00010  *
00011  *    This program is distributed in the hope that it will be useful,
00012  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *    GNU General Public License for more details.
00015  *
00016  *    You should have received a copy of the GNU General Public License
00017  *    along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  *    
00019  */
00020 package moa.gui;
00021 
00022 import java.awt.GridLayout;
00023 
00024 import javax.swing.JPanel;
00025 import javax.swing.JSlider;
00026 import javax.swing.JSpinner;
00027 import javax.swing.SpinnerNumberModel;
00028 import javax.swing.event.ChangeEvent;
00029 import javax.swing.event.ChangeListener;
00030 
00031 import moa.options.IntOption;
00032 import moa.options.Option;
00033 
00040 public class IntOptionEditComponent extends JPanel implements
00041         OptionEditComponent {
00042 
00043     private static final long serialVersionUID = 1L;
00044 
00045     protected IntOption editedOption;
00046 
00047     protected JSpinner spinner;
00048 
00049     protected JSlider slider;
00050 
00051     public IntOptionEditComponent(IntOption option) {
00052         this.editedOption = option;
00053         int minVal = option.getMinValue();
00054         int maxVal = option.getMaxValue();
00055         setLayout(new GridLayout(1, 0));
00056         this.spinner = new JSpinner(new SpinnerNumberModel(option.getValue(),
00057                 minVal, maxVal, 1));
00058         add(this.spinner);
00059         if ((minVal > Integer.MIN_VALUE) && (maxVal < Integer.MAX_VALUE)) {
00060             this.slider = new JSlider(minVal, maxVal, option.getValue());
00061             add(this.slider);
00062             this.slider.addChangeListener(new ChangeListener() {
00063 
00064                 @Override
00065                 public void stateChanged(ChangeEvent e) {
00066                     IntOptionEditComponent.this.spinner.setValue(IntOptionEditComponent.this.slider.getValue());
00067                 }
00068             });
00069             this.spinner.addChangeListener(new ChangeListener() {
00070 
00071                 @Override
00072                 public void stateChanged(ChangeEvent e) {
00073                     IntOptionEditComponent.this.slider.setValue(((Integer) IntOptionEditComponent.this.spinner.getValue()).intValue());
00074                 }
00075             });
00076         }
00077     }
00078 
00079     @Override
00080     public void applyState() {
00081         this.editedOption.setValue(((Integer) this.spinner.getValue()).intValue());
00082     }
00083 
00084     @Override
00085     public Option getEditedOption() {
00086         return this.editedOption;
00087     }
00088 
00089     @Override
00090     public void setEditState(String cliString) {
00091         this.spinner.setValue(IntOption.cliStringToInt(cliString));
00092     }
00093 }
 All Classes Namespaces Files Functions Variables Enumerations