@Override
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
int selectedRow = tilesetTable.getSelectedRow();
Vector<?> tilesets = map.getTilesets();
TileSet set = null;
try {
set = (TileSet) tilesets.get(selectedRow);
} catch (IndexOutOfBoundsException e) {
}
if (command.equals(CLOSE_BUTTON)) {
dispose();
} else if (command.equals(EDIT_BUTTON)) {
if (map != null && selectedRow >= 0) {
TileDialog tileDialog = new TileDialog(this, set, map);
tileDialog.setVisible(true);
}
} else if (command.equals(REMOVE_BUTTON)) {
if (checkSetUsage(set) > 0) {
int ret = JOptionPane.showConfirmDialog(this, Resources.getString("action.tileset.remove.in-use.message"),
Resources.getString("action.tileset.remove.in-use.title"), JOptionPane.YES_NO_OPTION);
if (ret != JOptionPane.YES_OPTION) {
return;
}
}
try {
map.removeTileset(set);
updateTilesetTable();
} catch (LayerLockedException e) {
JOptionPane.showMessageDialog(this, Resources.getString("action.tileset.remove.error.layer-locked.message"),
Resources.getString("action.tileset.remove.error.title"), JOptionPane.ERROR_MESSAGE);
}
} else if (command.equals(SAVE_AS_BUTTON)) {
JFileChooser ch = new ConfirmingFileChooser(map.getFilename());
MapHelper.addExtension(ch);
int ret = ch.showSaveDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
String filename = ch.getSelectedFile().getAbsolutePath();
try {
MapHelper.saveTileset(set, filename);
set.setSource(filename);
embedButton.setEnabled(true);
saveButton.setEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (command.equals(SAVE_BUTTON)) {
try {
MapHelper.saveTileset(set, set.getSource());
} catch (Exception e) {
e.printStackTrace();
}
} else if (command.equals(EMBED_BUTTON)) {
set.setSource(null);
embedButton.setEnabled(false);
saveButton.setEnabled(false);
} else if (command.equals(MOVE_UP_BUTTON)) {
if (selectedRow > 0) {
int newRow = selectedRow - 1;