/*
* org.openmicroscopy.shoola.agents.admin.util.DataPane
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2010 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package org.openmicroscopy.shoola.agents.treeviewer.util;
//Java imports
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
//Third-party libraries
//Application-internal dependencies
/**
* Top-class that sub-classes should extend.
*
* @author Jean-Marie Burel
* <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
* @author Donald MacDonald
* <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
* @version 3.0
* <small>
* (<b>Internal version:</b> $Revision: $Date: $)
* </small>
* @since 3.0-Beta4
*/
abstract class DataPane
extends JPanel
implements DocumentListener
{
/** The mandatory name. */
protected JTextField nameArea;
/** Fires a property allowing or not to save the data. */
private void enableSave()
{
boolean b = isNameValid();
firePropertyChange(AdminDialog.ENABLE_SAVE_PROPERTY, !b, b);
}
/** Creates a new instance. */
DataPane()
{
nameArea = new JTextField();
nameArea.getDocument().addDocumentListener(this);
}
/**
* Returns <code>true</code> if the name is valid, <code>false</code>
* otherwise.
*
* @return See above.
*/
boolean isNameValid()
{
if (nameArea == null) return false;
String name = nameArea.getText();
name = name.trim();
return name.length() > 0;
}
/**
* Fires property indicating that some text has been entered.
* @see DocumentListener#insertUpdate(DocumentEvent)
*/
public void insertUpdate(DocumentEvent e) { enableSave(); }
/**
* Fires property indicating that some text has been entered.
* @see DocumentListener#removeUpdate(DocumentEvent)
*/
public void removeUpdate(DocumentEvent e) { enableSave(); }
/**
* Required by the {@link DocumentListener} I/F but no-operation
* implementation in our case.
* @see DocumentListener#changedUpdate(DocumentEvent)
*/
public void changedUpdate(DocumentEvent e) {}
}