001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -----------------
028: * DetailEditor.java
029: * -----------------
030: * (C) Copyright 2004, by Thomas Morgner and Contributors.
031: *
032: * Original Author: Thomas Morgner;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: DetailEditor.java,v 1.3 2005/10/18 13:23:37 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 07-Jun-2004 : Added JCommon header (DG);
040: *
041: */
042:
043: package org.jfree.ui.tabbedui;
044:
045: import javax.swing.JComponent;
046:
047: /**
048: * A detail editor.
049: *
050: * @author Thomas Morgner
051: */
052: public abstract class DetailEditor extends JComponent {
053:
054: /** The object, that is edited. */
055: private Object object;
056: /** whether the edit process has been confirmed (user pressed OK). */
057: private boolean confirmed;
058:
059: /**
060: * Creates a new editor.
061: */
062: public DetailEditor() {
063: // nothing required
064: }
065:
066: /**
067: * Updates the object.
068: */
069: public void update() {
070: if (this .object == null) {
071: throw new IllegalStateException();
072: } else {
073: updateObject(this .object);
074: }
075: setConfirmed(false);
076: }
077:
078: /**
079: * Returns the object.
080: *
081: * @return The object.
082: */
083: public Object getObject() {
084: return this .object;
085: }
086:
087: /**
088: * Sets the object to be edited.
089: *
090: * @param object the object.
091: */
092: public void setObject(final Object object) {
093: if (object == null) {
094: throw new NullPointerException();
095: }
096: this .object = object;
097: setConfirmed(false);
098: fillObject();
099: }
100:
101: /**
102: * Parses an integer.
103: *
104: * @param text the text.
105: * @param def the default value.
106: *
107: * @return The parsed integer, or the default value if the string didn't contain a
108: * value.
109: */
110: protected static int parseInt(final String text, final int def) {
111: try {
112: return Integer.parseInt(text);
113: } catch (NumberFormatException fe) {
114: return def;
115: }
116: }
117:
118: /**
119: * Clears the editor.
120: */
121: public abstract void clear();
122:
123: /**
124: * Edits the object. The object itself should not be modified, until
125: * update or create was called.
126: */
127: protected abstract void fillObject();
128:
129: /**
130: * Updates the object.
131: *
132: * @param object the object.
133: */
134: protected abstract void updateObject(Object object);
135:
136: /**
137: * Returns the confirmed flag.
138: *
139: * @return The confirmed flag.
140: */
141: public boolean isConfirmed() {
142: return this .confirmed;
143: }
144:
145: /**
146: * Sets the confirmed flag.
147: *
148: * @param confirmed the confirmed flag.
149: */
150: protected void setConfirmed(final boolean confirmed) {
151: final boolean oldConfirmed = this .confirmed;
152: this .confirmed = confirmed;
153: firePropertyChange("confirmed", oldConfirmed, confirmed);
154: }
155:
156: }
|