KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > dck > items > StringInput


1 package rero.dck.items;
2
3 import java.awt.*;
4 import java.awt.event.*;
5
6 import javax.swing.*;
7 import javax.swing.event.*;
8
9 import rero.config.*;
10 import rero.dck.*;
11
12 public class StringInput extends SuperInput
13 {
14    protected JLabel label;
15    protected String JavaDoc value;
16    protected JTextField text;
17
18    public StringInput(String JavaDoc var, String JavaDoc _value, String JavaDoc _label, int rightGap, char mnemonic)
19    {
20       label = new JLabel(_label);
21
22       setLayout(new BorderLayout());
23      
24       text = new JTextField();
25  
26       add(label, BorderLayout.WEST);
27       add(text, BorderLayout.CENTER);
28       
29       if (rightGap > 0)
30       {
31          JPanel temp = new JPanel();
32          temp.setPreferredSize(new Dimension(rightGap, 0));
33
34          add(temp, BorderLayout.EAST);
35       }
36
37       label.setDisplayedMnemonic(mnemonic);
38
39       variable = var;
40       value = _value;
41    }
42
43    public void save()
44    {
45       ClientState.getClientState().setString(getVariable(), text.getText());
46    }
47
48    public int getEstimatedWidth()
49    {
50       return (int)label.getPreferredSize().getWidth();
51    }
52
53    public void setAlignWidth(int width)
54    {
55       label.setPreferredSize(new Dimension(width, 0));
56       revalidate();
57    }
58
59    public JComponent getComponent()
60    {
61       return this;
62    }
63
64    public void refresh()
65    {
66       text.setText(ClientState.getClientState().getString(getVariable(), value));
67    }
68 }
69
70
71
Popular Tags