cbxmapper = new JComboBox();
cbxmapper.addItem(resources.getString("=======NONE======="));
int idx = 0;
if (TextMapper.textMappers != null) {
for (int i = 0; i < TextMapper.textMappers.size(); ++i) {
TextMapper tm = (TextMapper) TextMapper.textMappers.get(i);
if (tm.equals(mapper)) {
idx = i + 1;
}
cbxmapper.addItem(tm);
}
}
cbxmapper.setEditable(false);
cbxmapper.setSelectedIndex(idx);
beditmapper = new JButton(resources.getString("Edit"));
bnewmapper = new JButton(resources.getString("New"));
bdelmapper = new JButton(resources.getString("Delete"));
bduplicateMapper = new JButton(resources.getString("Duplicate"));
if (idx == 0) {
beditmapper.setEnabled(false);
bdelmapper.setEnabled(false);
bduplicateMapper.setEnabled(false);
}
cbxmapper.setRenderer(new ListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
String s = value.toString();
if (s.length() > 18) {
s = s.substring(0, 15) + "...";
}
return new JLabel(s);
}
});
beditmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mapper == null) {
return;
}
mapper.editDialog(TextPropertiesPanel.this.getOwner());
cbxmapper.repaint(); // in case of name change
}
});
bnewmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mapper = TextMapper.createTextMapperDialog(TextPropertiesPanel.this.getOwner());
if (TextMapper.textMappers == null) {
TextMapper.textMappers = new Vector();
}
TextMapper.textMappers.add(mapper);
cbxmapper.addItem(mapper);
cbxmapper.setSelectedItem(mapper);
cards.revalidate();
}
});
bdelmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mapper == null) {
return;
}
if (TextMapper.textMappers != null) {
TextMapper.textMappers.remove(mapper);
}
cbxmapper.removeItem(mapper);
cbxmapper.setSelectedIndex(0);
mapper = null;
bdelmapper.setEnabled(false);
bduplicateMapper.setEnabled(false);
beditmapper.setEnabled(false);
}
});
bduplicateMapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mapper == null) {
return;
}
try {
TextMapper tm = (TextMapper)((TextMapper)mapper).clone();
if (TextMapper.textMappers != null) {
TextMapper.textMappers.add(tm);
}
mapper = tm;
cbxmapper.addItem(mapper);