1 package com.instantbank.lettertemplate.editor.applet;
2
3 import javax.swing.JPanel;
4 import javax.swing.JTextField;
5 import javax.swing.JButton;
6 import java.awt.BorderLayout;
7 import javax.swing.JDialog;
8 import javax.swing.JOptionPane;
9 import javax.swing.JComboBox;
10 import java.awt.Dimension;
11 import java.awt.event.ActionListener;
12 import java.awt.event.ActionEvent;
13 import com.instantbank.lettertemplate.editor.util.LetterOp;
14 import com.instantbank.common.utilcomponents.CodeDescription;
15 import com.instantbank.common.uiutils.GetLineFromListDialog;
16 import com.instantbank.component.lettertemplate.util.LetterComponent;
17
18
24
25 public class ComponentNameDisplay extends JPanel {
26
29 JButton btn = new JButton("...");
30
31
34 JTextField txtName = new JTextField();
35
36
39 CodeDescription[] compNames;
40
41
45 int mode;
46
47
50 String compType;
51
52
53
68 public ComponentNameDisplay(CodeDescription[] cmpNames, String type, int mode) {
69 this.compNames = cmpNames;
70 this.compType = type;
71 this.mode = mode;
72 init();
73 }
74
75
76
79 public void init() {
80 setLayout(new BorderLayout());
81 add(txtName, BorderLayout.CENTER);
82 if(mode == LetterOp.LOAD) {
83 txtName.setEditable(false);
84 }
85
86 if(mode == LetterOp.SAVEAS) {
87 add(btn, BorderLayout.EAST);
88 }
89
90 btn.addActionListener(
91 new ActionListener() {
92 public void actionPerformed(ActionEvent e) {
93
94
95 if(compNames.length == 0) {
96 JOptionPane.showMessageDialog(
97 null, "There are no " + compType + " to choose");
98 }
99 else {
100
103 Object[] answer = new Object[2];
104 JDialog gld =
105 new GetLineFromListDialog(
106 "Choosing a " + compType,
107 "Existing " + LetterComponent.typeToPlural(compType),
108 CodeDescription.toDescriptions(compNames),
109 answer);
110 gld.setLocationRelativeTo(ComponentNameDisplay.this);
111 gld.show();
112
113 int ansVal = ((Integer)answer[0]).intValue();
114
115 if(ansVal == GetLineFromListDialog.CANCEL) {
116 return;
117 }
118
119 String selected = (String)answer[1];
120 if(selected == null) {
121 return;
122 }
123
124 txtName.setText(selected);
125
126 }
127 }
128 });
129 }
130
131
132
138 public String getName() {
139 return txtName.getText().trim().toLowerCase();
140 }
141
142
143
148 public void setName(String s) {
149 txtName.setText(s);
150 }
151
152
153
156 public void grabFocus() {
157 txtName.grabFocus();
158 }
159
160
161
165 public void selectAll() {
166 txtName.selectAll();
167 }
168
169 }
170
171