1 /* -------------------------------------------------------------------
2 * Java source file for the class CompilableStringEditor
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: CompilableStringEditor.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 import net.jbeans.util.text.*;
30
31 /*====================================================================
32 Implementation of class CompilableStringEditor
33 ====================================================================*/
34 /***
35 * A property editor for editing strings.
36 *
37 * @version $Revision: 1.1.1.1 $
38 * @author Masahiro Takatsuka (masa@jbeans.net)
39 * @see EditorSupport
40 */
41
42 public final class CompilableStringEditor extends EditorSupport {
43 private JTextField textfield;
44
45 public CompilableStringEditor() {
46 this.textfield = new JTextField();
47 this.textfield.setDocument(new CompilableStringDocument());
48 this.textfield.addKeyListener(new KeyAdapter() {
49 /* XXX - JTextfield should send an actionPerformed event.
50 this was broken for 1.3 beta but fixed in 1.3. This
51 is the workaround.
52 */
53 public final void keyPressed(KeyEvent evt) {
54 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
55 setValue(CompilableStringEditor.this.textfield.getText());
56 }
57 }
58 });
59
60 JPanel panel = new JPanel();
61 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
62 panel.add(this.textfield);
63 setPanel(panel);
64 }
65
66 public final void setValue(Object value) {
67 super.setValue(value);
68 if (value != null) {
69 this.textfield.setText(value.toString());
70 } else {
71 this.textfield.setText("");
72 }
73 }
74
75 public final String getJavaInitializationString() {
76 return "\"" + getValue() + "\"";
77 }
78
79 }
This page was automatically generated by Maven