Source Code Cross Referenced for JLabeledTextArea.java in  » Testing » jakarta-jmeter » org » apache » jorphan » gui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jorphan.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jorphan.gui;
020:
021:        import java.awt.BorderLayout;
022:        import java.awt.event.FocusEvent;
023:        import java.awt.event.FocusListener;
024:        import java.util.ArrayList;
025:        import java.util.LinkedList;
026:        import java.util.List;
027:
028:        import javax.swing.JLabel;
029:        import javax.swing.JPanel;
030:        import javax.swing.JScrollPane;
031:        import javax.swing.JTextArea;
032:        import javax.swing.event.ChangeEvent;
033:        import javax.swing.event.ChangeListener;
034:        import javax.swing.text.Document;
035:
036:        /**
037:         * A Helper component that wraps a JTextField with a label into a JPanel (this).
038:         * This component also has an efficient event handling mechanism for handling
039:         * the text changing in the Text Field. The registered change listeners are only
040:         * called when the text has changed.
041:         * 
042:         */
043:        public class JLabeledTextArea extends JPanel implements  JLabeledField,
044:                FocusListener {
045:            private JLabel mLabel;
046:
047:            private JTextArea mTextArea;
048:
049:            // Maybe move to vector if MT problems occur
050:            private ArrayList mChangeListeners = new ArrayList(3);
051:
052:            // A temporary cache for the focus listener
053:            private String oldValue = "";
054:
055:            /**
056:             * Default constructor, The label and the Text field are left empty.
057:             */
058:            public JLabeledTextArea() {
059:                this ("", null);
060:            }
061:
062:            /**
063:             * Constructs a new component with the label displaying the passed text.
064:             * 
065:             * @param label
066:             *            The text to display in the label.
067:             */
068:            public JLabeledTextArea(String label) {
069:                this (label, null);
070:            }
071:
072:            /**
073:             * Constructs a new component with the label displaying the passed text.
074:             * 
075:             * @param pLabel
076:             *            The text to display in the label.
077:             * @param docModel the document for the text area
078:             */
079:            public JLabeledTextArea(String pLabel, Document docModel) {
080:                super ();
081:                mLabel = new JLabel(pLabel);
082:                init();
083:                if (docModel != null) {
084:                    mTextArea.setDocument(docModel);
085:                }
086:            }
087:
088:            public List getComponentList() {
089:                List comps = new LinkedList();
090:                comps.add(mLabel);
091:                comps.add(mTextArea);
092:                return comps;
093:            }
094:
095:            public void setDocumentModel(Document docModel) {
096:                mTextArea.setDocument(docModel);
097:            }
098:
099:            /**
100:             * Initialises all of the components on this panel.
101:             */
102:            private void init() {
103:                setLayout(new BorderLayout());
104:
105:                mTextArea = new JTextArea();
106:                mTextArea.setRows(4);
107:                mTextArea.setLineWrap(true);
108:                mTextArea.setWrapStyleWord(true);
109:                // Register the handler for focus listening. This handler will
110:                // only notify the registered when the text changes from when
111:                // the focus is gained to when it is lost.
112:                mTextArea.addFocusListener(this );
113:
114:                // Add the sub components
115:                this .add(mLabel, BorderLayout.NORTH);
116:                this .add(new JScrollPane(mTextArea), BorderLayout.CENTER);
117:            }
118:
119:            /**
120:             * Callback method when the focus to the Text Field component is lost.
121:             * 
122:             * @param pFocusEvent
123:             *            The focus event that occured.
124:             */
125:            public void focusLost(FocusEvent pFocusEvent) {
126:                // Compare if the value has changed, since we received focus.
127:                if (!oldValue.equals(mTextArea.getText())) {
128:                    notifyChangeListeners();
129:                }
130:            }
131:
132:            /**
133:             * Catch what the value was when focus was gained.
134:             */
135:            public void focusGained(FocusEvent pFocusEvent) {
136:                oldValue = mTextArea.getText();
137:            }
138:
139:            /**
140:             * Set the text displayed in the label.
141:             * 
142:             * @param pLabel
143:             *            The new label text.
144:             */
145:            public void setLabel(String pLabel) {
146:                mLabel.setText(pLabel);
147:            }
148:
149:            /**
150:             * Set the text displayed in the Text Field.
151:             * 
152:             * @param pText
153:             *            The new text to display in the text field.
154:             */
155:            public void setText(String pText) {
156:                mTextArea.setText(pText);
157:            }
158:
159:            /**
160:             * Returns the text in the Text Field.
161:             * 
162:             * @return The text in the Text Field.
163:             */
164:            public String getText() {
165:                return mTextArea.getText();
166:            }
167:
168:            /**
169:             * Returns the text of the label.
170:             * 
171:             * @return The text of the label.
172:             */
173:            public String getLabel() {
174:                return mLabel.getText();
175:            }
176:
177:            public void setEnabled(boolean enable) {
178:                super .setEnabled(enable);
179:                mTextArea.setEnabled(enable);
180:            }
181:
182:            /**
183:             * Adds a change listener, that will be notified when the text in the text
184:             * field is changed. The ChangeEvent that will be passed to registered
185:             * listeners will contain this object as the source, allowing the new text
186:             * to be extracted using the {@link #getText() getText} method.
187:             * 
188:             * @param pChangeListener
189:             *            The listener to add
190:             */
191:            public void addChangeListener(ChangeListener pChangeListener) {
192:                mChangeListeners.add(pChangeListener);
193:            }
194:
195:            /**
196:             * Removes a change listener.
197:             * 
198:             * @param pChangeListener
199:             *            The change listener to remove.
200:             */
201:            public void removeChangeListener(ChangeListener pChangeListener) {
202:                mChangeListeners.remove(pChangeListener);
203:            }
204:
205:            /**
206:             * Notify all registered change listeners that the text in the text field
207:             * has changed.
208:             */
209:            private void notifyChangeListeners() {
210:                ChangeEvent ce = new ChangeEvent(this );
211:                for (int index = 0; index < mChangeListeners.size(); index++) {
212:                    ((ChangeListener) mChangeListeners.get(index))
213:                            .stateChanged(ce);
214:                }
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.