KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > relatedevents > RelatedEventText


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.metadata.range.swing.relatedevents;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.event.*;
23 import java.awt.event.KeyListener JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.swing.JTextArea JavaDoc;
27
28 import org.openharmonise.vfs.metadata.*;
29 import org.openharmonise.vfs.metadata.range.*;
30 import org.openharmonise.vfs.metadata.value.*;
31
32
33 /**
34  * @author Michael Bell
35  * @version $Revision: 1.1 $
36  *
37  */

38 public class RelatedEventText extends JTextArea JavaDoc implements KeyListener JavaDoc {
39     
40     private PropertyInstance m_propInst = null;
41     
42     private static final String JavaDoc INVALID_TEXT = "--Invalid--";
43
44     /**
45      *
46      */

47     public RelatedEventText(PropertyInstance propInst) {
48         super();
49         m_propInst = propInst;
50         setup();
51     }
52
53     /**
54      *
55      */

56     private void setup() {
57         this.setRows(3);
58         this.setColumns(30);
59         
60         List JavaDoc vals = m_propInst.getValues();
61         
62         if(vals.size() > 0) {
63             StringValue val = (StringValue) vals.get(0);
64             if(val.getValue().length() > 0) {
65                 this.setText(val.getValue());
66             }
67         } else {
68             setForeground(Color.RED);
69             setText(INVALID_TEXT);
70         }
71         
72         this.addKeyListener(this);
73     }
74
75     /* (non-Javadoc)
76      * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
77      */

78     public void keyPressed(KeyEvent e) {
79     }
80
81     /* (non-Javadoc)
82      * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
83      */

84     public void keyReleased(KeyEvent e) {
85         String JavaDoc sValue = getText();
86         
87         List JavaDoc vals = m_propInst.getValues();
88         StringValue val = null;
89         if(vals.size()>0) {
90             val = (StringValue) vals.get(0);
91         } else {
92             val = (StringValue)m_propInst.getNewValueInstance();
93         }
94         if(sValue != null && sValue.length() > 0) {
95             val.setValue(sValue);
96             m_propInst.setValue(val);
97         } else {
98             m_propInst.removeValue(val);
99         }
100         
101         firePropertyChange(RelatedEventValueDisplay.PROPERTY_METADATA_CHANGE, null, null);
102     }
103
104     /* (non-Javadoc)
105      * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
106      */

107     public void keyTyped(KeyEvent e) {
108     }
109
110     /**
111      * @return
112      */

113     public boolean isMetadataValid() {
114         boolean bIsValid = false;
115         Property prop = m_propInst.getDefinition();
116
117         StringRange range = (StringRange)prop.getRange();
118         
119         List JavaDoc vals = m_propInst.getValues();
120         
121         if(vals.size() > 0) {
122             bIsValid = range.validate(vals).isValid();
123         } else {
124             bIsValid = false;
125             this.setText(INVALID_TEXT);
126         }
127         
128         if(bIsValid == false) {
129             setForeground(Color.RED);
130         } else {
131             setForeground(Color.BLACK);
132         }
133         
134         revalidate();
135
136         return bIsValid;
137     }
138
139 }
Popular Tags