KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > tabbedui > DetailEditor


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -----------------
28  * DetailEditor.java
29  * -----------------
30  * (C) Copyright 2004, by Thomas Morgner and Contributors.
31  *
32  * Original Author: Thomas Morgner;
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: DetailEditor.java,v 1.3 2005/10/18 13:23:37 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 07-Jun-2004 : Added JCommon header (DG);
40  *
41  */

42
43 package org.jfree.ui.tabbedui;
44
45 import javax.swing.JComponent JavaDoc;
46
47 /**
48  * A detail editor.
49  *
50  * @author Thomas Morgner
51  */

52 public abstract class DetailEditor extends JComponent JavaDoc {
53
54     /** The object, that is edited. */
55     private Object JavaDoc object;
56     /** whether the edit process has been confirmed (user pressed OK). */
57     private boolean confirmed;
58
59     /**
60      * Creates a new editor.
61      */

62     public DetailEditor() {
63         // nothing required
64
}
65
66     /**
67      * Updates the object.
68      */

69     public void update() {
70         if (this.object == null) {
71             throw new IllegalStateException JavaDoc();
72         }
73         else {
74             updateObject(this.object);
75         }
76         setConfirmed(false);
77     }
78
79     /**
80      * Returns the object.
81      *
82      * @return The object.
83      */

84     public Object JavaDoc getObject() {
85         return this.object;
86     }
87
88     /**
89      * Sets the object to be edited.
90      *
91      * @param object the object.
92      */

93     public void setObject(final Object JavaDoc object) {
94         if (object == null) {
95             throw new NullPointerException JavaDoc();
96         }
97         this.object = object;
98         setConfirmed(false);
99         fillObject();
100     }
101
102     /**
103      * Parses an integer.
104      *
105      * @param text the text.
106      * @param def the default value.
107      *
108      * @return The parsed integer, or the default value if the string didn't contain a
109      * value.
110      */

111     protected static int parseInt(final String JavaDoc text, final int def) {
112         try {
113             return Integer.parseInt(text);
114         }
115         catch (NumberFormatException JavaDoc fe) {
116             return def;
117         }
118     }
119
120     /**
121      * Clears the editor.
122      */

123     public abstract void clear();
124
125     /**
126      * Edits the object. The object itself should not be modified, until
127      * update or create was called.
128      */

129     protected abstract void fillObject();
130
131     /**
132      * Updates the object.
133      *
134      * @param object the object.
135      */

136     protected abstract void updateObject(Object JavaDoc object);
137
138     /**
139      * Returns the confirmed flag.
140      *
141      * @return The confirmed flag.
142      */

143     public boolean isConfirmed() {
144         return this.confirmed;
145     }
146
147     /**
148      * Sets the confirmed flag.
149      *
150      * @param confirmed the confirmed flag.
151      */

152     protected void setConfirmed(final boolean confirmed) {
153         final boolean oldConfirmed = this.confirmed;
154         this.confirmed = confirmed;
155         firePropertyChange("confirmed", oldConfirmed, confirmed);
156     }
157
158     
159 }
160
Popular Tags