MOA 12.03
Real Time Analytics for Data Streams
ClassOptionEditComponent.java
Go to the documentation of this file.
00001 /*
00002  *    ClassOptionEditComponent.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.BorderLayout;
00023 import java.awt.event.ActionEvent;
00024 import java.awt.event.ActionListener;
00025 import java.util.HashSet;
00026 
00027 import javax.swing.JButton;
00028 import javax.swing.JPanel;
00029 import javax.swing.JTextField;
00030 import javax.swing.event.ChangeEvent;
00031 import javax.swing.event.ChangeListener;
00032 import javax.swing.event.DocumentEvent;
00033 import javax.swing.event.DocumentListener;
00034 
00035 import moa.options.ClassOption;
00036 import moa.options.Option;
00037 
00044 public class ClassOptionEditComponent extends JPanel implements
00045         OptionEditComponent {
00046 
00047     private static final long serialVersionUID = 1L;
00048 
00049     protected ClassOption editedOption;
00050 
00051     protected JTextField textField = new JTextField();
00052 
00053     protected JButton editButton = new JButton("Edit");
00054 
00056     protected HashSet<ChangeListener> changeListeners = new HashSet<ChangeListener>();
00057 
00058     public ClassOptionEditComponent(ClassOption option) {
00059         this.editedOption = option;
00060         this.textField.setEditable(false);
00061         this.textField.getDocument().addDocumentListener(new DocumentListener() {
00062 
00063             @Override
00064             public void removeUpdate(DocumentEvent e) {
00065                 notifyChangeListeners();
00066             }
00067 
00068             @Override
00069             public void insertUpdate(DocumentEvent e) {
00070                 notifyChangeListeners();
00071             }
00072 
00073             @Override
00074             public void changedUpdate(DocumentEvent e) {
00075                 notifyChangeListeners();
00076             }
00077         });
00078         setLayout(new BorderLayout());
00079         add(this.textField, BorderLayout.CENTER);
00080         add(this.editButton, BorderLayout.EAST);
00081         this.editButton.addActionListener(new ActionListener() {
00082 
00083             @Override
00084             public void actionPerformed(ActionEvent arg0) {
00085                 editObject();
00086             }
00087         });
00088         setEditState(this.editedOption.getValueAsCLIString());
00089     }
00090 
00091     @Override
00092     public void applyState() {
00093         this.editedOption.setValueViaCLIString(this.textField.getText());
00094     }
00095 
00096     @Override
00097     public Option getEditedOption() {
00098         return this.editedOption;
00099     }
00100 
00101     @Override
00102     public void setEditState(String cliString) {
00103         this.textField.setText(cliString);
00104     }
00105 
00106     public void editObject() {
00107         setEditState(ClassOptionSelectionPanel.showSelectClassDialog(this,
00108                 "Editing option: " + this.editedOption.getName(),
00109                 this.editedOption.getRequiredType(), this.textField.getText(),
00110                 this.editedOption.getNullString()));
00111     }
00112 
00119     public void addChangeListener(ChangeListener l) {
00120         changeListeners.add(l);
00121     }
00122 
00128     public void removeChangeListener(ChangeListener l) {
00129         changeListeners.remove(l);
00130     }
00131 
00135     protected void notifyChangeListeners() {
00136         ChangeEvent e = new ChangeEvent(this);
00137         for (ChangeListener l : changeListeners) {
00138             l.stateChanged(e);
00139         }
00140     }
00141 }
 All Classes Namespaces Files Functions Variables Enumerations