001: /*
002: * Created on 20.06.2005
003: *
004: * CVS information:
005: * $Author: javamap $
006: * $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
007: * $ID$
008: * $Rev: 856 $
009: * $Id: OKCancelListener.java 856 2007-06-19 04:15:27Z javamap $
010: * $Log$
011: * Revision 1.2 2007/02/03 14:19:29 mentaer
012: * modified debug output for pirol stuff
013: *
014: * Revision 1.1 2006/11/23 18:53:51 mentaer
015: * added EditAttributeByFormula Plugin by Pirol including some parts of the baseclasses - note: plugin needs java 1.5
016: *
017: * Revision 1.4 2006/01/09 12:55:24 orahn
018: * korrektere Fehlerausgabe
019: *
020: * Revision 1.3 2005/07/06 13:02:46 orahn
021: * Code bereinigen, Performance erhöhen(?)
022: *
023: * Revision 1.2 2005/06/30 10:43:30 orahn
024: * Standard ok/Cancel-Listener erweitert um die Möglichkeit, den OK Button ausser Funktion zu setzen, wenn die Eingabewert nicht schlüssig sind...
025: *
026: * Revision 1.1 2005/06/20 18:18:23 orahn
027: * Vorbereitung für Formeleditor
028: *
029: */
030: package de.fho.jump.pirol.ui.eventHandling;
031:
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.util.ArrayList;
035:
036: import javax.swing.JButton;
037: import javax.swing.JDialog;
038:
039: import de.fho.jump.pirol.ui.panels.OkCancelButtonPanel;
040: import de.fho.jump.pirol.ui.tools.ValueChecker;
041: import de.fho.jump.pirol.utilities.debugOutput.DebugUserIds;
042: import de.fho.jump.pirol.utilities.debugOutput.PersonalLogger;
043:
044: /**
045: *
046: * Class that implements a default Action Listener behavior for
047: * an OKCancelButtonPanel. It remembers if ok was clicked and closes
048: * a given dialog.
049: *
050: * @author Ole Rahn
051: * <br>
052: * <br>FH Osnabrück - University of Applied Sciences Osnabrück,
053: * <br>Project: PIROL (2005),
054: * <br>Subproject: Daten- und Wissensmanagement
055: *
056: * @version $Rev: 856 $
057: */
058: public class OKCancelListener implements ActionListener {
059:
060: protected boolean okWasClicked = false;
061:
062: protected JDialog dialog = null;
063:
064: protected PersonalLogger logger = new PersonalLogger(
065: DebugUserIds.ALL);
066:
067: protected ArrayList valueCheckers = new ArrayList();
068:
069: /**
070: * @param dialog dialog to be closed after ok or cancel was clicked.
071: */
072: public OKCancelListener(JDialog dialog) {
073: super ();
074: this .dialog = dialog;
075: }
076:
077: /**
078: * The first invokation of this method enables value checking (enables/disables funtionality of the ok button)
079: *@param valChecker object that checks if the given value are ok or not
080: */
081: public void addValueChecker(ValueChecker valChecker) {
082: this .valueCheckers.add(valChecker);
083: }
084:
085: /**
086: * @inheritDoc
087: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
088: */
089: public void actionPerformed(ActionEvent arg0) {
090: try {
091: JButton button = (JButton) arg0.getSource();
092:
093: if (button.getActionCommand().equals(
094: OkCancelButtonPanel.OK_BUTTON_ACTION_COMMAND)) {
095:
096: // disable ok button, if value are not ok!
097: if (!this .valuesOk())
098: return;
099:
100: this .okWasClicked = true;
101: }
102:
103: if (this .dialog != null) {
104: this .dialog.setVisible(false);
105: this .dialog.dispose();
106: }
107:
108: } catch (ClassCastException e) {
109: this .logger.printError(e.getLocalizedMessage());
110: e.printStackTrace();
111: }
112: }
113:
114: /**
115: * asks the existent value checkers (if any), if the values are ok
116: *@return true if values are ok, else false
117: */
118: protected boolean valuesOk() {
119: if (this .valueCheckers.isEmpty())
120: return true;
121:
122: boolean valsOk = true;
123: ValueChecker[] valueCheckerArray = (ValueChecker[]) this .valueCheckers
124: .toArray(new ValueChecker[0]);
125:
126: for (int i = 0; i < valueCheckerArray.length; i++) {
127: valsOk = valsOk && (valueCheckerArray[i].areValuesOk());
128: }
129:
130: return valsOk;
131: }
132:
133: /**
134: * Tells you, if ok was clicked to close the dialog
135: * @return Returns the okWasClicked.
136: */
137: public boolean wasOkClicked() {
138: return okWasClicked;
139: }
140: }
|