Source code: com/sunwheeltech/sirius/support/SimpleReadOnlyPropertyEditor.java
1 package com.sunwheeltech.sirius.support;
2 /* GPL
3 ulunum java libraries for complex simulation modelling,
4 3d graphics, peer-to-peer networking and other purposes
5
6 version 0.1 released December 2001
7 see the file contents.html for a quick description of whats in
8 each package, and what you can expect to do with it
9
10 Copyright (C) December 2001 Dave Crane dave@cranepeople.co.uk
11
12
13 Find the GNU public license at:
14
15 http://www.gnu.org/copyleft/gpl.html
16
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License
19 as published by the Free Software Foundation; either version 2
20 of the License, or (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 */
31
32
33 import ulu.view.*;
34 import ulu.view.io.*;
35 import ulu.view.ui.*;
36 import ulu.view.sys.fs.*;
37 import ulu.view.sys.refl.*;
38 import ulu.view.ui.sirius.*;
39
40 import ulu.ut.*;
41 import dog.gui.*;
42 import java.awt.*;
43 import java.awt.image.*;
44 import java.awt.event.*;
45 import java.beans.*;
46 import java.io.*;
47 import java.net.*;
48 import java.util.*;
49 /**
50 * <p>Simple property 'editor' that displays current value of a read-only property
51 *
52 * @author Dave Crane Sunwheel Technologies Ltd June 2003
53 */
54 public class SimpleReadOnlyPropertyEditor
55 implements PropertyEditor{
56
57 /** display name to use for a null value */
58 public static final String NULL_VALUE_LABEL="empty";
59
60 /** value being edited */
61 Object value=null;
62
63 /** get the value of the property.
64 * @return The value of the property.
65 */
66 public Object getValue(){
67 return value;
68 }
69
70 /** set the object to be edited
71 * @param obj object to be edited
72 */
73 public void setValue(Object obj){
74 Object old=value;
75 value=obj;
76 System.out.println("setValue(): "+old+" -> "+obj);
77 firePropertyChange(old,value);
78 }
79
80 /** indicate whether a custom editor component is supported
81 @return false, because no custom editor is provided
82 */
83 public boolean supportsCustomEditor(){ return false; }
84 /** get the custom editor component
85 @return the custom editor component, in this case null
86 */
87 public Component getCustomEditor(){ return null; }
88
89 /** whether can paint a representation of current value
90 * @return whether able to paint value (not in this case)
91 */
92 public boolean isPaintable(){ return false; }
93
94 /** Paint a representation of the value into a given area of screen
95 * @param g Graphics object to paint into.
96 * @param box Rectangle within graphics object into which we should paint.
97 */
98 public void paintValue(java.awt.Graphics g, java.awt.Rectangle box){
99 }
100
101 /** get scrap of java code used to initialise the bean
102 * @return A fragment of Java code representing an initializer for the
103 * current value.
104 */
105 public String getJavaInitializationString(){ return "null"; }
106
107 /** Gets the property value as a string suitable for presentation
108 * to a human to edit.
109 *
110 * @return string representation of property value
111 */
112 public String getAsText(){ return ""+value; }
113
114 /** Sets the property value by parsing a given String.
115 * @param str the text to be parsed.
116 */
117 public void setAsText(String str) throws java.lang.IllegalArgumentException{
118 }
119
120 /** get list of accepted values for this bean property
121 * @return The tag values for this property, may be null
122 */
123 public String[] getTags(){ return null; }
124
125
126 /** list of property change listeners to be notified of property updates */
127 protected Vector listeners=new Vector();
128
129 /** add a listener to notify of property changes
130 * @param listener listener to add
131 */
132 public synchronized void addPropertyChangeListener(PropertyChangeListener listener){
133 listeners.addElement(listener);
134 }
135
136 /** remove a listener
137 * @param listener the listener to be removed
138 */
139 public synchronized void removePropertyChangeListener(PropertyChangeListener listener){
140 listeners.removeElement(listener);
141 }
142
143 /** fire update event to all listeners
144 * @param oldv old value of property
145 * @param newv new value of property
146 */
147 public void firePropertyChange(Object oldv,Object newv){
148 PropertyChangeEvent ev=new PropertyChangeEvent(this,null,oldv,newv);
149 for (Enumeration enu=listeners.elements();enu.hasMoreElements();){
150 PropertyChangeListener target=(PropertyChangeListener)(enu.nextElement());
151 target.propertyChange(ev);
152 }
153 }
154
155 }