trackeditor: add support for sectors
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8517 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 5ee1b81a1249e9a13cbdce63bd344fb4a85f2652 Former-commit-id: 4057e23d82a26bfd3f0c6cb0fd4fb95bf269b9f4
This commit is contained in:
parent
23fd79c296
commit
ca13517377
8 changed files with 330 additions and 2 deletions
|
@ -46,6 +46,7 @@ IF(Java_Development_FOUND AND Java_FOUND)
|
|||
gui/properties/PitProperties.java
|
||||
gui/properties/PropertiesDialog.java
|
||||
gui/properties/PropertyPanel.java
|
||||
gui/properties/SectorProperties.java
|
||||
gui/properties/StartingGridProperties.java
|
||||
gui/properties/SurfaceProperties.java
|
||||
gui/properties/TerrainProperties.java
|
||||
|
@ -91,6 +92,7 @@ IF(Java_Development_FOUND AND Java_FOUND)
|
|||
utils/circuit/ObjShapeTerrain.java
|
||||
utils/circuit/ObjectMap.java
|
||||
utils/circuit/Pits.java
|
||||
utils/circuit/Sector.java
|
||||
utils/circuit/Segment.java
|
||||
utils/circuit/SegmentListener.java
|
||||
utils/circuit/SegmentSide.java
|
||||
|
|
|
@ -61,6 +61,7 @@ public class PropertiesDialog extends JDialog
|
|||
private ObjectProperties objectProperties = null;
|
||||
private CameraProperties cameraProperties = null;
|
||||
private TrackLightProperties trackLightProperties = null;
|
||||
private SectorProperties sectorProperties = null;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -113,6 +114,7 @@ public class PropertiesDialog extends JDialog
|
|||
tabbedPane.addTab("Objects", null, getObjectProperties(), null);
|
||||
tabbedPane.addTab("Cameras", null, getCameraProperties(), null);
|
||||
tabbedPane.addTab("Lights", null, getTrackLightProperties(), null);
|
||||
tabbedPane.addTab("Sector", null, getSectorProperties(), null);
|
||||
tabbedPane.addTab("Image", null, getImageProperties(), null);
|
||||
tabbedPane.setSelectedIndex(editorFrame.getProject().getPropertiesEditorTab());
|
||||
}
|
||||
|
@ -357,6 +359,18 @@ public class PropertiesDialog extends JDialog
|
|||
return trackLightProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes sectorProperties
|
||||
*
|
||||
* @return gui.properties.SectorProperties
|
||||
*/
|
||||
private SectorProperties getSectorProperties() {
|
||||
if (sectorProperties == null) {
|
||||
sectorProperties = new SectorProperties(editorFrame);
|
||||
}
|
||||
return sectorProperties;
|
||||
}
|
||||
|
||||
// Exit when window close
|
||||
|
||||
protected void processWindowEvent(WindowEvent e)
|
||||
|
@ -389,6 +403,7 @@ public class PropertiesDialog extends JDialog
|
|||
this.objectProperties.exit();
|
||||
this.cameraProperties.exit();
|
||||
this.trackLightProperties.exit();
|
||||
this.sectorProperties.exit();
|
||||
Editor.getProperties().valueChanged();
|
||||
APPROVE = true;
|
||||
cancel();
|
||||
|
|
205
src/tools/trackeditor/gui/properties/SectorProperties.java
Normal file
205
src/tools/trackeditor/gui/properties/SectorProperties.java
Normal file
|
@ -0,0 +1,205 @@
|
|||
package gui.properties;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import gui.EditorFrame;
|
||||
import utils.circuit.Sector;
|
||||
|
||||
/**
|
||||
* @author Robert Reif
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to Window -
|
||||
* Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class SectorProperties extends PropertyPanel
|
||||
{
|
||||
private JButton addSectorButton = null;
|
||||
private JButton deleteSectorButton = null;
|
||||
private JTabbedPane tabbedPane = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SectorProperties(EditorFrame editorFrame)
|
||||
{
|
||||
super(editorFrame);
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes this
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private void initialize()
|
||||
{
|
||||
this.setLayout(null);
|
||||
this.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
|
||||
this.add(getTabbedPane(), null);
|
||||
this.add(getAddSectorButton(), null);
|
||||
this.add(getDeleteSectorButton(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes addSectorpingButton
|
||||
*
|
||||
* @return javax.swing.JButton
|
||||
*/
|
||||
private JButton getAddSectorButton()
|
||||
{
|
||||
if (addSectorButton == null)
|
||||
{
|
||||
addSectorButton = new JButton();
|
||||
addSectorButton.setBounds(10, 120, 120, 25);
|
||||
addSectorButton.setText("Add Sector");
|
||||
addSectorButton.addActionListener(new java.awt.event.ActionListener()
|
||||
{
|
||||
public void actionPerformed(java.awt.event.ActionEvent e)
|
||||
{
|
||||
String name = "" + (tabbedPane.getTabCount() + 1);
|
||||
|
||||
tabbedPane.addTab(name, null, new SectorPanel(name, Double.NaN), null);
|
||||
tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
return addSectorButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes deleteSectorButton
|
||||
*
|
||||
* @return javax.swing.JButton
|
||||
*/
|
||||
private JButton getDeleteSectorButton()
|
||||
{
|
||||
if (deleteSectorButton == null)
|
||||
{
|
||||
deleteSectorButton = new JButton();
|
||||
deleteSectorButton.setBounds(140, 120, 130, 25);
|
||||
deleteSectorButton.setText("Delete Sector");
|
||||
deleteSectorButton.addActionListener(new java.awt.event.ActionListener()
|
||||
{
|
||||
public void actionPerformed(java.awt.event.ActionEvent e)
|
||||
{
|
||||
if (tabbedPane.getTabCount() > 0)
|
||||
{
|
||||
tabbedPane.removeTabAt(tabbedPane.getSelectedIndex());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return deleteSectorButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes tabbedPane
|
||||
*
|
||||
* @return javax.swing.JTabbedPane
|
||||
*/
|
||||
private JTabbedPane getTabbedPane()
|
||||
{
|
||||
if (tabbedPane == null)
|
||||
{
|
||||
tabbedPane = new JTabbedPane();
|
||||
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||
tabbedPane.setBounds(10, 10, 510, 100);
|
||||
|
||||
Vector<Sector> sectors = getEditorFrame().getTrackData().getSectors();
|
||||
|
||||
for (int i = 0; i < sectors.size(); i++)
|
||||
{
|
||||
Sector sector = sectors.elementAt(i);
|
||||
tabbedPane.addTab(sector.getName(), null, new SectorPanel(sector.getName(), sector.getDistanceFromStart()), null);
|
||||
}
|
||||
}
|
||||
return tabbedPane;
|
||||
}
|
||||
|
||||
private class SectorPanel extends JPanel
|
||||
{
|
||||
private JLabel nameLabel = new JLabel();
|
||||
private JTextField nameTextField = new JTextField();
|
||||
private JLabel distanceFromStartLabel = new JLabel();
|
||||
private JTextField distanceFromStartTextField = new JTextField();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SectorPanel(String name, double distanceFromStart)
|
||||
{
|
||||
super();
|
||||
initialize(name, distanceFromStart);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void initialize(String name, double distanceFromStart)
|
||||
{
|
||||
setLayout(null);
|
||||
|
||||
addLabel(this, 0, nameLabel, "Name", 150);
|
||||
addLabel(this, 1, distanceFromStartLabel, "Distance From Start", 150);
|
||||
|
||||
addTextField(this, 0, nameTextField, name, 160, 225);
|
||||
addTextField(this, 1, distanceFromStartTextField, distanceFromStart, 160, 225);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void exit()
|
||||
{
|
||||
MutableString stringResult = new MutableString();
|
||||
MutableDouble doubleResult = new MutableDouble();
|
||||
Vector<Sector> sectors = getEditorFrame().getTrackData().getSectors();
|
||||
int minCount = Math.min(sectors.size(), tabbedPane.getTabCount());
|
||||
if (sectors.size() != tabbedPane.getTabCount())
|
||||
{
|
||||
getEditorFrame().documentIsModified = true;
|
||||
}
|
||||
for (int i = 0; i < minCount; i++)
|
||||
{
|
||||
Sector sector = sectors.elementAt(i);
|
||||
SectorPanel panel = (SectorPanel) tabbedPane.getComponentAt(i);
|
||||
if (isDifferent(panel.nameTextField.getText(), sector.getName(), stringResult))
|
||||
{
|
||||
sector.setName(stringResult.getValue());
|
||||
getEditorFrame().documentIsModified = true;
|
||||
}
|
||||
if (isDifferent(panel.distanceFromStartTextField.getText(), sector.getDistanceFromStart(), doubleResult))
|
||||
{
|
||||
sector.setDistanceFromStart(doubleResult.getValue());
|
||||
getEditorFrame().documentIsModified = true;
|
||||
}
|
||||
}
|
||||
if (sectors.size() > tabbedPane.getTabCount())
|
||||
{
|
||||
// need to trim Sectors
|
||||
while (sectors.size() > tabbedPane.getTabCount())
|
||||
{
|
||||
sectors.remove(sectors.size() - 1);
|
||||
}
|
||||
}
|
||||
else if (sectors.size() < tabbedPane.getTabCount())
|
||||
{
|
||||
// need to add to sectors
|
||||
while (sectors.size() < tabbedPane.getTabCount())
|
||||
{
|
||||
SectorPanel panel = (SectorPanel) tabbedPane.getComponentAt(sectors.size());
|
||||
Sector sector = new Sector();
|
||||
sector.setName(panel.nameTextField.getText());
|
||||
sector.setDistanceFromStart(getDouble(panel.distanceFromStartTextField.getText()));
|
||||
sectors.add(sector);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // @jve:decl-index=0:visual-constraint="10,10"
|
|
@ -48,6 +48,7 @@ import utils.circuit.Surface;
|
|||
import utils.circuit.TrackLight;
|
||||
import utils.circuit.TrackObject;
|
||||
import utils.circuit.ObjectMap;
|
||||
import utils.circuit.Sector;
|
||||
|
||||
/**
|
||||
* @author Charalampos Alexopoulos
|
||||
|
@ -146,6 +147,7 @@ public class XmlReader
|
|||
setGraphic(root);
|
||||
setCameras(root);
|
||||
setMainTrack(root);
|
||||
setSectors(root);
|
||||
}
|
||||
|
||||
private synchronized void setMainTrack(Element root)
|
||||
|
@ -288,6 +290,32 @@ public class XmlReader
|
|||
editorFrame.getTrackData().setTrackLights(lightData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root
|
||||
*/
|
||||
private void setSectors(Element root)
|
||||
{
|
||||
Element sectors = getChildWithName(root, "Sectors");
|
||||
|
||||
if (sectors == null)
|
||||
return;
|
||||
|
||||
Vector<Sector> sectorData = new Vector<Sector>();
|
||||
List<Element> sections = sectors.getChildren();
|
||||
Iterator<Element> it = sections.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Sector sector = new Sector();
|
||||
|
||||
Element element = it.next();
|
||||
sector.setName(element.getAttribute("name").getValue());
|
||||
sector.setDistanceFromStart(getAttrNumValue(element, "distance from start", "m"));
|
||||
|
||||
sectorData.add(sector);
|
||||
}
|
||||
editorFrame.getTrackData().setSectors(sectorData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root
|
||||
*/
|
||||
|
|
|
@ -38,6 +38,7 @@ import utils.circuit.Camera;
|
|||
import utils.circuit.Curve;
|
||||
import utils.circuit.EnvironmentMapping;
|
||||
import utils.circuit.ObjectMap;
|
||||
import utils.circuit.Sector;
|
||||
import utils.circuit.Segment;
|
||||
import utils.circuit.SegmentSide;
|
||||
import utils.circuit.Straight;
|
||||
|
@ -97,6 +98,7 @@ public class XmlWriter
|
|||
root.addContent(getGrid());
|
||||
root.addContent(getTrack());
|
||||
root.addContent(getCameras());
|
||||
root.addContent(getSectors());
|
||||
}
|
||||
|
||||
private synchronized void writeToFile(String fileName, Document doc) throws FileNotFoundException, IOException, SecurityException
|
||||
|
@ -606,6 +608,30 @@ public class XmlWriter
|
|||
|
||||
return lights;
|
||||
}
|
||||
private synchronized Element getSectors()
|
||||
{
|
||||
Element sectors = new Element("section");
|
||||
sectors.setAttribute(new Attribute("name", "Sectors"));
|
||||
|
||||
Vector<Sector> sectorData = editorFrame.getTrackData().getSectors();
|
||||
|
||||
if (sectorData == null)
|
||||
return sectors;
|
||||
|
||||
for (int i = 0; i < sectorData.size(); i++)
|
||||
{
|
||||
Sector sector = sectorData.get(i);
|
||||
|
||||
Element el = new Element("section");
|
||||
el.setAttribute(new Attribute("name", sector.getName()));
|
||||
|
||||
addContent(el, "distance from start", "m", sector.getDistanceFromStart());
|
||||
|
||||
sectors.addContent(el);
|
||||
}
|
||||
|
||||
return sectors;
|
||||
}
|
||||
|
||||
private synchronized Element getObjects()
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ import utils.circuit.Graphic;
|
|||
import utils.circuit.Header;
|
||||
import utils.circuit.LocalInfo;
|
||||
import utils.circuit.MainTrack;
|
||||
import utils.circuit.Sector;
|
||||
import utils.circuit.Segment;
|
||||
import utils.circuit.StartingGrid;
|
||||
import utils.circuit.Surface;
|
||||
|
@ -52,6 +53,7 @@ public final class TrackData
|
|||
private Vector<TrackLight> trackLights = new Vector<TrackLight>();
|
||||
private MainTrack mainTrack = new MainTrack();
|
||||
private Vector<Segment> segments = null;
|
||||
private Vector<Sector> sectors = new Vector<Sector>();
|
||||
|
||||
/**
|
||||
* @return Returns the header.
|
||||
|
@ -203,4 +205,22 @@ public final class TrackData
|
|||
{
|
||||
this.segments = segments;
|
||||
}
|
||||
|
||||
public Vector<TrackObject> getTrackObjects()
|
||||
{
|
||||
return trackObjects;
|
||||
}
|
||||
public void setTrackObjects(Vector<TrackObject> trackObjects)
|
||||
{
|
||||
this.trackObjects = trackObjects;
|
||||
}
|
||||
|
||||
public Vector<Sector> getSectors()
|
||||
{
|
||||
return sectors;
|
||||
}
|
||||
public void setSectors(Vector<Sector> sectors)
|
||||
{
|
||||
this.sectors = sectors;
|
||||
}
|
||||
}
|
||||
|
|
32
src/tools/trackeditor/utils/circuit/Sector.java
Normal file
32
src/tools/trackeditor/utils/circuit/Sector.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package utils.circuit;
|
||||
|
||||
public class Sector
|
||||
{
|
||||
private String name;
|
||||
private double distanceFromStart;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getDistanceFromStart()
|
||||
{
|
||||
return distanceFromStart;
|
||||
}
|
||||
public void setDistanceFromStart(double distanceFromStart)
|
||||
{
|
||||
this.distanceFromStart = distanceFromStart;
|
||||
}
|
||||
|
||||
public void dump(String indent)
|
||||
{
|
||||
System.out.println(indent + "Sector");
|
||||
System.out.println(indent + " name : " + name);
|
||||
System.out.println(indent + " distanceFromStart : " + distanceFromStart);
|
||||
}
|
||||
}
|
|
@ -162,8 +162,8 @@ public final class TrackLight {
|
|||
|
||||
public void dump(String indent)
|
||||
{
|
||||
System.out.println(indent + "Surface");
|
||||
System.out.println(indent + " name : " + name);
|
||||
System.out.println(indent + "TrackLight");
|
||||
System.out.println(indent + " name : " + name);
|
||||
System.out.println(indent + " role : " + role);
|
||||
System.out.println(indent + " topLeft : " + topLeft.x + " " + topLeft.y + " " + topLeft.z);
|
||||
System.out.println(indent + " bottomRight : " + bottomRight.x + " " + bottomRight.y + " " + bottomRight.z);
|
||||
|
|
Loading…
Reference in a new issue