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, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations
015: * under the License.
016: *
017: */
018:
019: /*
020: * Created on May 21, 2004
021: */
022: package org.apache.jmeter.testbeans.gui;
023:
024: import java.awt.Component;
025: import java.awt.event.FocusEvent;
026: import java.awt.event.FocusListener;
027: import java.beans.PropertyEditorSupport;
028:
029: import javax.swing.JScrollPane;
030: import javax.swing.JTextArea;
031:
032: /**
033: * @author mstover
034: *
035: */
036: public class TextAreaEditor extends PropertyEditorSupport implements
037: FocusListener {
038: JTextArea textUI;
039:
040: JScrollPane scroller;
041:
042: /*
043: * (non-Javadoc)
044: *
045: * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
046: */
047: public void focusGained(FocusEvent e) {
048:
049: }
050:
051: /*
052: * (non-Javadoc)
053: *
054: * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
055: */
056: public void focusLost(FocusEvent e) {
057: firePropertyChange();
058:
059: }
060:
061: protected void init() {
062: textUI = new JTextArea();
063: textUI.addFocusListener(this );
064: textUI.setWrapStyleWord(true);
065: textUI.setLineWrap(true);
066: scroller = new JScrollPane(textUI,
067: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
068: JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
069: }
070:
071: /**
072: *
073: */
074: public TextAreaEditor() {
075: super ();
076: init();
077:
078: }
079:
080: /**
081: * @param source
082: */
083: public TextAreaEditor(Object source) {
084: super (source);
085: init();
086: setValue(source);
087: }
088:
089: /*
090: * (non-Javadoc)
091: *
092: * @see java.beans.PropertyEditor#getAsText()
093: */
094: public String getAsText() {
095: return textUI.getText();
096: }
097:
098: /*
099: * (non-Javadoc)
100: *
101: * @see java.beans.PropertyEditor#getCustomEditor()
102: */
103: public Component getCustomEditor() {
104: return scroller;
105: }
106:
107: /*
108: * (non-Javadoc)
109: *
110: * @see java.beans.PropertyEditor#setAsText(java.lang.String)
111: */
112: public void setAsText(String text) throws IllegalArgumentException {
113: textUI.setText(text);
114: }
115:
116: /*
117: * (non-Javadoc)
118: *
119: * @see java.beans.PropertyEditor#setValue(java.lang.Object)
120: */
121: public void setValue(Object value) {
122: if (value != null) {
123: textUI.setText(value.toString());
124: } else {
125: textUI.setText("");
126: }
127: }
128:
129: /*
130: * (non-Javadoc)
131: *
132: * @see java.beans.PropertyEditor#getValue()
133: */
134: public Object getValue() {
135: return textUI.getText();
136: }
137:
138: /*
139: * (non-Javadoc)
140: *
141: * @see java.beans.PropertyEditor#supportsCustomEditor()
142: */
143: public boolean supportsCustomEditor() {
144: return true;
145: }
146: }
|