trackeditor: add delete objects to terrain object map properties
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8949 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 44c408246f59b7e66c3ffdddf63d375425a79b70 Former-commit-id: 2bbd3015a05b68f049798e2b41ce1afb67a1c8f1
This commit is contained in:
parent
95cde08886
commit
0bd6cac05e
3 changed files with 139 additions and 8 deletions
|
@ -4,12 +4,18 @@ import java.awt.Color;
|
|||
import java.awt.Component;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
@ -20,12 +26,15 @@ import javax.swing.JButton;
|
|||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
@ -539,6 +548,12 @@ public class ObjectMapProperties extends PropertyPanel
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeRowAt(int row)
|
||||
{
|
||||
data.removeElementAt(row);
|
||||
fireTableRowsDeleted(row - 1, data.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpNameColumn(JTable table, TableColumn nameColumn, Set<String> names)
|
||||
|
@ -584,6 +599,27 @@ public class ObjectMapProperties extends PropertyPanel
|
|||
|
||||
setUpNameColumn(table, table.getColumnModel().getColumn(1), names);
|
||||
|
||||
table.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent me)
|
||||
{
|
||||
if (SwingUtilities.isRightMouseButton(me) == true)
|
||||
{
|
||||
int row = table.rowAtPoint(me.getPoint());
|
||||
if (row != -1)
|
||||
{
|
||||
table.setRowSelectionInterval(row, row);
|
||||
if (me.getComponent() instanceof JTable )
|
||||
{
|
||||
JPopupMenu popup = createPopupMenu(objectTablePanel);
|
||||
popup.show(me.getComponent(), me.getX(), me.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
add(scrollPane);
|
||||
}
|
||||
|
||||
|
@ -592,6 +628,105 @@ public class ObjectMapProperties extends PropertyPanel
|
|||
model.fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public JPopupMenu createPopupMenu(ObjectTablePanel panel)
|
||||
{
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
JMenuItem deleteItem = new JMenuItem("Delete Object");
|
||||
JMenuItem deleteAllColorItem = new JMenuItem("Delete All Objects With This Color");
|
||||
JMenuItem deleteAllNameItem = new JMenuItem("Delete All Objects With This Name");
|
||||
|
||||
deleteItem.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
int row = panel.table.getSelectedRow();
|
||||
if (row != -1)
|
||||
{
|
||||
if (JOptionPane.showConfirmDialog(null, "Delete this object?", "Delete Object", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
|
||||
{
|
||||
panel.model.removeRowAt(panel.table.convertRowIndexToModel(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
deleteAllColorItem.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
int row = panel.table.getSelectedRow();
|
||||
if (row != -1)
|
||||
{
|
||||
if (JOptionPane.showConfirmDialog(null, "Delete all objects with this color?", "Delete Objects With Color", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
|
||||
{
|
||||
int color = data.elementAt(panel.table.convertRowIndexToModel(row)).color;
|
||||
Vector<Integer> toDelete = new Vector<Integer>();
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
{
|
||||
if (color == data.elementAt(i).color)
|
||||
{
|
||||
toDelete.add(i);
|
||||
}
|
||||
}
|
||||
Collections.sort(toDelete, new Comparator<Integer>()
|
||||
{
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2)
|
||||
{
|
||||
// Changing the order of the elements
|
||||
return o2 - o1;
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < toDelete.size(); i++)
|
||||
{
|
||||
panel.model.removeRowAt(toDelete.elementAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
deleteAllNameItem.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
int row = panel.table.getSelectedRow();
|
||||
if (row != -1)
|
||||
{
|
||||
if (JOptionPane.showConfirmDialog(null, "Delete all objects with this name?", "Delete Objects with Name", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
|
||||
{
|
||||
String name = new String(data.elementAt(panel.table.convertRowIndexToModel(row)).name);
|
||||
Vector<Integer> toDelete = new Vector<Integer>();
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
{
|
||||
if (name.equals(data.elementAt(i).name))
|
||||
{
|
||||
toDelete.add(i);
|
||||
}
|
||||
}
|
||||
Collections.sort(toDelete, new Comparator<Integer>()
|
||||
{
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2)
|
||||
{
|
||||
// Changing the order of the elements
|
||||
return o2 - o1;
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < toDelete.size(); i++)
|
||||
{
|
||||
panel.model.removeRowAt(toDelete.elementAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.add(deleteItem);
|
||||
popupMenu.add(deleteAllColorItem);
|
||||
popupMenu.add(deleteAllNameItem);
|
||||
|
||||
return popupMenu;
|
||||
}
|
||||
}
|
||||
|
||||
public void exit()
|
||||
|
|
|
@ -314,11 +314,12 @@ public class ReliefProperties extends PropertyPanel
|
|||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if (table.getSelectedRow() != -1)
|
||||
int row = table.getSelectedRow();
|
||||
if (row != -1)
|
||||
{
|
||||
if (JOptionPane.showConfirmDialog(null, "Delete this row?", "Delete Row", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
|
||||
{
|
||||
model.removeRowAt(table.getSelectedRow());
|
||||
model.removeRowAt(table.convertRowIndexToModel(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -328,11 +329,6 @@ public class ReliefProperties extends PropertyPanel
|
|||
|
||||
add(scrollPane);
|
||||
}
|
||||
|
||||
void dataChanged()
|
||||
{
|
||||
model.fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class Properties
|
|||
private static Properties instance = new Properties();
|
||||
private Vector<ActionListener> propertiesListeners = new Vector<ActionListener>();
|
||||
public final String title = "sd2-trackeditor";
|
||||
public final String version = "1.2.17";
|
||||
public final String version = "1.2.18";
|
||||
private String path;
|
||||
|
||||
private double imageScale = 1;
|
||||
|
|
Loading…
Reference in a new issue