trackeditor: add object map object edit to properties dialog

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9117 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
iobyte 2023-07-27 00:39:34 +00:00
parent 516516f1a7
commit d925d0d3a8
5 changed files with 209 additions and 54 deletions

View File

@ -105,6 +105,7 @@ IF(Java_Development_FOUND AND Java_FOUND)
utils/circuit/ObjShapeObject.java
utils/circuit/ObjShapeRelief.java
utils/circuit/ObjShapeTerrain.java
utils/circuit/ObjectData.java
utils/circuit/ObjectMap.java
utils/circuit/Pits.java
utils/circuit/Reliefs.java

View File

@ -3,6 +3,7 @@ package gui;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import java.util.Vector;
import javax.swing.JButton;
@ -15,6 +16,7 @@ import javax.swing.JTextField;
import utils.circuit.GraphicObject;
import utils.circuit.ObjShapeObject;
import utils.circuit.ObjectData;
import utils.circuit.TrackObject;
public class TrackObjectDialog extends JDialog
@ -22,6 +24,7 @@ public class TrackObjectDialog extends JDialog
private EditorFrame editorFrame = null;
private GraphicObject graphicObject = null;
private ObjShapeObject objectShape = null;
private ObjectData objectData = null;
private Vector<TrackObject> objects = null;
private boolean ignoreActions = true;
private boolean changed = false;
@ -96,20 +99,105 @@ public class TrackObjectDialog extends JDialog
initialize(x, y);
}
public TrackObjectDialog(EditorFrame editorFrame, boolean all, ObjectData objectData)
{
super();
this.objectData = objectData;
setTitle("Add Object");
this.editorFrame = editorFrame;
initialize(0, 0);
}
public boolean isChanged()
{
return changed;
}
private int getRGB()
{
if (objectShape != null)
{
return objectShape.getRGB();
}
return objectData.color;
}
private void setRGB(int rgb)
{
if (objectShape != null)
{
objectShape.setRGB(rgb);
return;
}
objectData.color = rgb;
}
private String getObjectName()
{
if (objectShape != null)
{
return objectShape.getName();
}
return objectData.name;
}
private void setObjectName(String name)
{
if (objectShape != null)
{
objectShape.setName(name);
return;
}
objectData.name = name;
}
private Point2D.Double getTrackLocation()
{
if (objectShape != null)
{
return objectShape.getTrackLocation();
}
return new Point2D.Double(objectData.trackX, objectData.trackY);
}
private double getImageX()
{
if (objectShape != null)
{
return objectShape.getImageX();
}
return objectData.imageX;
}
private double getImageY()
{
if (objectShape != null)
{
return objectShape.getImageY();
}
return objectData.imageY;
}
private void initialize(int x, int y)
{
isGraphicObject = objectShape.getType().equals("graphic object");
isGraphicObject = objectShape != null && objectShape.getType().equals("graphic object");
setLayout(null);
setSize(320, 252);
setResizable(false);
setLocation(x, y);
if (objectData == null)
{
setLocation(x, y);
}
else
{
setLocationRelativeTo(getParent());
}
defaultCheckBox.setText("Default Objects");
defaultCheckBox.setBounds(120, 10, 150, 23);
defaultCheckBox.addActionListener(new ActionListener()
@ -138,7 +226,7 @@ public class TrackObjectDialog extends JDialog
int objectIndex = -1;
for (int i = 0; i < objects.size(); i++)
{
if (objects.get(i).getColor() == objectShape.getRGB())
if (objects.get(i).getColor() == getRGB())
{
defaultCheckBox.setSelected(false);
objectIndex = i;
@ -152,7 +240,7 @@ public class TrackObjectDialog extends JDialog
objects = editorFrame.getDefaultObjects();
for (int i = 0; i < objects.size(); i++)
{
if (objects.get(i).getColor() == objectShape.getRGB())
if (objects.get(i).getColor() == getRGB())
{
defaultCheckBox.setSelected(true);
objectIndex = i;
@ -177,7 +265,7 @@ public class TrackObjectDialog extends JDialog
nameLabel.setText("Name");
nameLabel.setBounds(10, 37, 120, 23);
nameTextField.setText(objectShape.getName());
nameTextField.setText(getObjectName());
nameTextField.setBounds(120, 37, 170, 23);
}
@ -190,7 +278,7 @@ public class TrackObjectDialog extends JDialog
trackLocationLabel.setText("Track Location");
trackLocationLabel.setBounds(10, 118, 120, 23);
trackLocationTextField.setText(String.format("%.3f", objectShape.getTrackLocation().x) + ", " + String.format("%.3f", objectShape.getTrackLocation().y));
trackLocationTextField.setText(String.format("%.3f", getTrackLocation().x) + ", " + String.format("%.3f", getTrackLocation().y));
trackLocationTextField.setBounds(120, 118, 170, 23);
trackLocationTextField.setEnabled(false);
@ -199,7 +287,7 @@ public class TrackObjectDialog extends JDialog
imageLocationLabel.setText("Image Location");
imageLocationLabel.setBounds(10, 145, 120, 23);
imageLocationTextField.setText(objectShape.getImageX() + ", " + objectShape.getImageY());
imageLocationTextField.setText(getImageX() + ", " + getImageY());
imageLocationTextField.setBounds(120, 145, 170, 23);
imageLocationTextField.setEnabled(false);
}
@ -280,13 +368,15 @@ public class TrackObjectDialog extends JDialog
return;
}
if (isGraphicObject)
if (!isGraphicObject || objectData != null)
{
imageLocationTextField.setText(objectShape.getImageX() + ", " + objectShape.getImageY());
imageLocationTextField.setText(getImageX() + ", " + getImageY());
}
trackLocationTextField.setText(String.format("%.3f", objectShape.getTrackLocation().x) + ", " + String.format("%.3f", objectShape.getTrackLocation().y));
trackLocationTextField.setText(String.format("%.3f", getTrackLocation().x) + ", " + String.format("%.3f", getTrackLocation().y));
setObjectName(objects.get(objectComboBox.getSelectedIndex()).getName());
rgb = objects.get(objectComboBox.getSelectedIndex()).getColor();
Color backgroundColor = new Color((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff);
@ -324,7 +414,7 @@ public class TrackObjectDialog extends JDialog
{
objectComboBox.addItem(objects.get(i).getName());
if (objects.get(i).getColor() == objectShape.getRGB())
if (objects.get(i).getColor() == getRGB())
{
objectIndex = i;
}
@ -343,7 +433,7 @@ public class TrackObjectDialog extends JDialog
return;
}
objectShape.setRGB(rgb);
setRGB(rgb);
if (isGraphicObject)
{

View File

@ -45,8 +45,10 @@ import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import gui.EditorFrame;
import gui.TrackObjectDialog;
import utils.Editor;
import utils.circuit.ObjShapeObject;
import utils.circuit.ObjectData;
import utils.circuit.ObjectMap;
public class ObjectMapProperties extends PropertyPanel
@ -145,29 +147,9 @@ public class ObjectMapProperties extends PropertyPanel
private ObjectTablePanel objectTablePanel = null;
private ObjectMap objectMap = null;
public class Data
{
String name;
Integer color;
Integer imageX;
Integer imageY;
Double trackX;
Double trackY;
private Vector<ObjectData> data = new Vector<ObjectData>();
Data(String name, Integer color, Integer imageX, Integer imageY, double trackX, double trackY)
{
this.name = name;
this.color = color;
this.imageX = imageX;
this.imageY = imageY;
this.trackX = trackX;
this.trackY = trackY;
}
}
private Vector<Data> data = new Vector<Data>();
public Vector<Data> getData()
public Vector<ObjectData> getData()
{
return data;
}
@ -394,7 +376,7 @@ public class ObjectMapProperties extends PropertyPanel
}
Point2D.Double real = new Point2D.Double();
getEditorFrame().getCircuitView().imageToReal(x, y, imageWidth, imageHeight, real);
data.add(new Data(name, rgb, x, y, real.x, real.y));
data.add(new ObjectData(name, rgb, x, y, real.x, real.y));
}
}
}
@ -416,7 +398,7 @@ public class ObjectMapProperties extends PropertyPanel
Point2D.Double real = new Point2D.Double();
getEditorFrame().getCircuitView().imageToReal(object.getImageX(), object.getImageY(), objectMap.getImageWidth(), objectMap.getImageHeight(), real);
data.add(new Data(name, object.getRGB(), object.getImageX(), object.getImageY(), real.x, real.y));
data.add(new ObjectData(name, object.getRGB(), object.getImageX(), object.getImageY(), real.x, real.y));
}
}
@ -509,7 +491,7 @@ public class ObjectMapProperties extends PropertyPanel
public Object getValueAt(int rowIndex, int columnIndex)
{
Data datum = data.get(rowIndex);
ObjectData datum = data.get(rowIndex);
switch (columnIndex)
{
@ -533,7 +515,7 @@ public class ObjectMapProperties extends PropertyPanel
public void setValueAt(Object value, int rowIndex, int columnIndex)
{
Data datum = data.get(rowIndex);
ObjectData datum = data.get(rowIndex);
switch (columnIndex)
{
@ -657,15 +639,72 @@ public class ObjectMapProperties extends PropertyPanel
}
}
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");
JMenuItem moveToObjects = new JMenuItem("Move To Objects");
JMenuItem moveAllToObjects = new JMenuItem("Move All To Objects");
public JPopupMenu createPopupMenu(ObjectTablePanel panel)
{
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem editItem = new JMenuItem("Edit Object");
JMenuItem editAllColorItem = new JMenuItem("Edit All Objects With This Color");
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");
JMenuItem moveToObjects = new JMenuItem("Move To Objects");
JMenuItem moveAllToObjects = new JMenuItem("Move All To Objects");
editItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int row = panel.table.getSelectedRow();
if (row != -1)
{
ObjectData datum = data.elementAt(panel.table.convertRowIndexToModel(row));
TrackObjectDialog editObjectDialog = new TrackObjectDialog(getEditorFrame(), false, datum);
editObjectDialog.setModal(true);
editObjectDialog.setVisible(true);
if (editObjectDialog.isChanged())
{
panel.model.setValueAt(datum.name, row, 1);
panel.model.setValueAt(datum.color, row, 2);
getEditorFrame().documentIsModified = true;
}
}
}
});
editAllColorItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int row = panel.table.getSelectedRow();
if (row != -1)
{
ObjectData datum = data.elementAt(panel.table.convertRowIndexToModel(row));
int oldColor = datum.color;
TrackObjectDialog editObjectDialog = new TrackObjectDialog(getEditorFrame(), false, datum);
editObjectDialog.setModal(true);
editObjectDialog.setVisible(true);
if (editObjectDialog.isChanged())
{
for (int i = 0; i < data.size(); i++)
{
if (data.elementAt(i).color == oldColor)
{
panel.model.setValueAt(datum.name, i, 1);
panel.model.setValueAt(datum.color, i, 2);
}
}
getEditorFrame().documentIsModified = true;
}
}
}
});
deleteItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
@ -759,7 +798,7 @@ public class ObjectMapProperties extends PropertyPanel
{
if (JOptionPane.showConfirmDialog(null, "Move this object?", "Move Object", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
Data datum = data.elementAt(panel.table.convertRowIndexToModel(row));
ObjectData datum = data.elementAt(panel.table.convertRowIndexToModel(row));
String name = getEditorFrame().getObjectColorName(datum.color) + "-" + data.size();
GraphicObjectData graphicObjectData = new GraphicObjectData(name, datum.color, datum.trackX, datum.trackY, Double.NaN);
getEditorFrame().getGraphicObjectProperties().addData(graphicObjectData);
@ -777,7 +816,7 @@ public class ObjectMapProperties extends PropertyPanel
{
if (JOptionPane.showConfirmDialog(null, "Move all objects with this name?", "Move Objects with Name", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
Data datum = data.elementAt(panel.table.convertRowIndexToModel(row));
ObjectData datum = data.elementAt(panel.table.convertRowIndexToModel(row));
Vector<Integer> toMove = new Vector<Integer>();
for (int i = 0; i < data.size(); i++)
{
@ -798,7 +837,7 @@ public class ObjectMapProperties extends PropertyPanel
int size = data.size();
for (int i = 0; i < toMove.size(); i++)
{
Data datum1 = data.elementAt(i);
ObjectData datum1 = data.elementAt(i);
String name = getEditorFrame().getObjectColorName(datum.color) + "-" + size++;
GraphicObjectData graphicObjectData = new GraphicObjectData(name, datum.color, datum1.trackX, datum1.trackY, Double.NaN);
getEditorFrame().getGraphicObjectProperties().addData(graphicObjectData);
@ -812,9 +851,13 @@ public class ObjectMapProperties extends PropertyPanel
}
});
popupMenu.add(editItem);
popupMenu.add(editAllColorItem);
popupMenu.addSeparator();
popupMenu.add(deleteItem);
popupMenu.add(deleteAllColorItem);
popupMenu.add(deleteAllNameItem);
//popupMenu.addSeparator();
//popupMenu.add(moveToObjects);
//popupMenu.add(moveAllToObjects);
@ -852,7 +895,7 @@ public class ObjectMapProperties extends PropertyPanel
getEditorFrame().documentIsModified = true;
}
Vector<ObjectMapPanel.Data> data = panel.getData();
Vector<ObjectData> data = panel.getData();
Vector<ObjShapeObject> objects = objectMap.getObjects();
int minDataCount = Math.min(data.size(), objects.size());
@ -863,7 +906,7 @@ public class ObjectMapProperties extends PropertyPanel
}
for (int j = 0; j < minDataCount; j++)
{
ObjectMapPanel.Data datum = data.get(j);
ObjectData datum = data.get(j);
ObjShapeObject object = objects.get(j);
if (!datum.color.equals(object.getRGB()))
@ -912,7 +955,7 @@ public class ObjectMapProperties extends PropertyPanel
// need to add to objects
while (objects.size() < data.size())
{
ObjectMapPanel.Data datum = data.get(objects.size());
ObjectData datum = data.get(objects.size());
objects.add(new ObjShapeObject(datum.color, datum.imageX, datum.imageY));
}

View File

@ -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.3.15";
public final String version = "1.3.16";
private String path;
private double imageScale = 1;

View File

@ -0,0 +1,21 @@
package utils.circuit;
public class ObjectData
{
public String name;
public Integer color;
public Integer imageX;
public Integer imageY;
public Double trackX;
public Double trackY;
public ObjectData(String name, Integer color, Integer imageX, Integer imageY, double trackX, double trackY)
{
this.name = name;
this.color = color;
this.imageX = imageX;
this.imageY = imageY;
this.trackX = trackX;
this.trackY = trackY;
}
}