cbxmapper.addItem(resources.getString("=======NONE======="));
if (DoubleValueMapper.doubleValueMappers!=null)
for (int i =0; i<DoubleValueMapper.doubleValueMappers.size(); ++i) {
DoubleValueMapper tm = (DoubleValueMapper)DoubleValueMapper.doubleValueMappers.get(i);
cbxmapper.addItem(tm);
}
box.add(cbxmapper);
box.add(Box.createHorizontalGlue());
box.add(beditmapper = new JButton(resources.getString("Edit")));
box.add(bnewmapper = new JButton(resources.getString("New")));
box.add(bdelmapper = new JButton(resources.getString("Delete")));
box.add(bduplicatemapper = new JButton(resources.getString("Duplicate")));
// If "no mapper" is selected -> disable edit and del buttons
cbxmapper.setSelectedIndex(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 (selectedDoubleMapper==null) return;
selectedDoubleMapper.editDialog(AffineTransformDataPanel.this.getOwner());
cbxmapper.repaint(); // in case of name change
}
});
bnewmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectedDoubleMapper = DoubleValueMapper.createDoubleValueMapperDialog(AffineTransformDataPanel.this.getOwner());
DoubleValueMapper.doubleValueMappers.add(selectedDoubleMapper);
cbxmapper.addItem(selectedDoubleMapper);
cbxmapper.setSelectedItem(selectedDoubleMapper);
}
});
bdelmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedDoubleMapper==null) return;
if (DoubleValueMapper.doubleValueMappers!=null) DoubleValueMapper.doubleValueMappers.remove(selectedDoubleMapper);
cbxmapper.removeItem(selectedDoubleMapper);
cbxmapper.setSelectedIndex(0);
for (int i =0; i<doubleValueMappers.length; ++i) {
if (doubleValueMappers[i]==selectedDoubleMapper)
doubleValueMappers[i]=null;
}
selectedDoubleMapper = null;
bdelmapper.setEnabled(false);
bduplicatemapper.setEnabled(false);
beditmapper.setEnabled(false);
}
});
bduplicatemapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedDoubleMapper==null){
return;
}
try {
DoubleValueMapper tm = (DoubleValueMapper)((DoubleValueMapper)selectedDoubleMapper).clone();
if (DoubleValueMapper.doubleValueMappers != null) {
DoubleValueMapper.doubleValueMappers.add(tm);
}
selectedDoubleMapper = tm;
cbxmapper.addItem(selectedDoubleMapper);