1 /* -------------------------------------------------------------------
2 * Java source file for the class StringEditor
3 *
4 * Copyright (c), 2002, Masahiro Takatsuka.
5 * All Rights Researved.
6 *
7 * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8 * $Author: takatsukam $
9 *
10 * $Date: 2003/07/25 04:51:45 $
11 *
12 * $Id: StringEditor.java,v 1.1.1.1 2003/07/25 04:51:45 takatsukam Exp $
13 *
14 * Reference: Document no:
15 * ___ ___
16 *
17 * To Do:
18 * ___
19 *
20 ------------------------------------------------------------------- */
21
22 /* --------------------------- Package ---------------------------- */
23 package net.jbeans.bean.property.editor;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">color="#329900"> ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900"> ------------------ Import classes (packages) ------------------- */
26 import java.awt.event.*;
27 import javax.swing.*;
28
29 /*====================================================================
30 Implementation of class StringEditor
31 ====================================================================*/
32 /***
33 * A property editor for editing strings.
34 *
35 * @version $Revision: 1.1.1.1 $
36 * @author Masahiro Takatsuka (masa@jbeans.net)
37 * @see EditorSupport
38 */
39
40 public final class StringEditor extends EditorSupport {
41 private JTextField textfield;
42
43 public StringEditor() {
44 this.textfield = new JTextField();
45 this.textfield.addKeyListener(new KeyAdapter() {
46 // XXX - JTextfield should send an actionPerformed event.
47 // this was broken for 1.3 beta but fixed in 1.3. This
48 // is the workaround.
49 public final void keyPressed(KeyEvent evt) {
50 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
51 setValue(StringEditor.this.textfield.getText());
52 }
53 }
54 });
55
56 JPanel panel = new JPanel();
57 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
58 panel.add(this.textfield);
59 setPanel(panel);
60 }
61
62 public final void setValue(Object value) {
63 super.setValue(value);
64 if (value != null) {
65 this.textfield.setText(value.toString());
66 } else {
67 this.textfield.setText("");
68 }
69 }
70
71 public final String getJavaInitializationString() {
72 String value = (String) getValue();
73 value = value.replaceAll("\"", "//\"");
74 return "\"" + value + "\"";
75 }
76 }
This page was automatically generated by Maven