1 /* -------------------------------------------------------------------
2 * Java source file for the class StringArrayEditor
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: StringArrayEditor.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 StringArrayEditor
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 StringArrayEditor extends EditorSupport {
43 private JTextField textfield;
44
45 public StringArrayEditor() {
46 this.textfield = new JTextField();
47 this.textfield.addKeyListener(new KeyAdapter() {
48 // XXX - JTextfield should send an actionPerformed event.
49 // this was broken for 1.3 beta but fixed in 1.3. This
50 // is the workaround.
51 public final void keyPressed(KeyEvent evt) {
52 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
53 setValue(StringArray.toArray(StringArrayEditor.this.textfield.getText()));
54 }
55 }
56 });
57
58 JPanel panel = new JPanel();
59 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
60 panel.add(this.textfield);
61 setPanel(panel);
62 }
63
64 public final void setValue(Object value) {
65 super.setValue(value);
66 if (value != null) {
67 this.textfield.setText(StringArray.toString((String[]) value, ","));
68 } else {
69 this.textfield.setText("");
70 }
71 }
72
73 public final String getJavaInitializationString() {
74 String strings = (String) getValue();
75 strings = (strings == null) ? "" : strings;
76 String[] stringArray = StringArray.toArray(strings);
77 StringBuffer buff = new StringBuffer("{");
78 for (int i = 0; i < stringArray.length; i++) {
79 if (i > 0) {
80 buff.append(", ");
81 }
82 buff.append("\"" + stringArray[i] + "\"");
83 }
84 buff.append("}");
85 return buff.toString();
86 }
87 }
This page was automatically generated by Maven