From 8a1ab64213758adcaa39a11279f3153a73e4a97e Mon Sep 17 00:00:00 2001 From: iobyte Date: Sun, 18 Sep 2022 00:13:10 +0000 Subject: [PATCH] trackeditor: add comment to sector git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8518 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: d0af3314c51c1e0ded6256b52ac3688b57772be0 Former-commit-id: b820e7a0cb669ac738f45458d003a44c6c403562 --- .../gui/properties/PropertiesDialog.java | 2 +- .../gui/properties/SectorProperties.java | 35 ++++++++++++------- .../trackeditor/plugin/torcs/XmlReader.java | 1 + .../trackeditor/plugin/torcs/XmlWriter.java | 2 +- .../trackeditor/utils/circuit/Sector.java | 15 ++++++-- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/tools/trackeditor/gui/properties/PropertiesDialog.java b/src/tools/trackeditor/gui/properties/PropertiesDialog.java index 7982a1390..f258c1715 100644 --- a/src/tools/trackeditor/gui/properties/PropertiesDialog.java +++ b/src/tools/trackeditor/gui/properties/PropertiesDialog.java @@ -114,7 +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("Sectors", null, getSectorProperties(), null); tabbedPane.addTab("Image", null, getImageProperties(), null); tabbedPane.setSelectedIndex(editorFrame.getProject().getPropertiesEditorTab()); } diff --git a/src/tools/trackeditor/gui/properties/SectorProperties.java b/src/tools/trackeditor/gui/properties/SectorProperties.java index 9ab756429..3e34605c1 100644 --- a/src/tools/trackeditor/gui/properties/SectorProperties.java +++ b/src/tools/trackeditor/gui/properties/SectorProperties.java @@ -56,15 +56,16 @@ public class SectorProperties extends PropertyPanel if (addSectorButton == null) { addSectorButton = new JButton(); - addSectorButton.setBounds(10, 120, 120, 25); + addSectorButton.setBounds(10, 147, 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); + Sector sector = new Sector(); + sector.setName("" + (tabbedPane.getTabCount() + 1)); - tabbedPane.addTab(name, null, new SectorPanel(name, Double.NaN), null); + tabbedPane.addTab(sector.getName(), null, new SectorPanel(sector), null); tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1); } }); @@ -82,7 +83,7 @@ public class SectorProperties extends PropertyPanel if (deleteSectorButton == null) { deleteSectorButton = new JButton(); - deleteSectorButton.setBounds(140, 120, 130, 25); + deleteSectorButton.setBounds(140, 147, 130, 25); deleteSectorButton.setText("Delete Sector"); deleteSectorButton.addActionListener(new java.awt.event.ActionListener() { @@ -109,14 +110,14 @@ public class SectorProperties extends PropertyPanel { tabbedPane = new JTabbedPane(); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); - tabbedPane.setBounds(10, 10, 510, 100); + tabbedPane.setBounds(10, 10, 510, 127); Vector 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); + tabbedPane.addTab(sector.getName(), null, new SectorPanel(sector), null); } } return tabbedPane; @@ -126,30 +127,34 @@ public class SectorProperties extends PropertyPanel { private JLabel nameLabel = new JLabel(); private JTextField nameTextField = new JTextField(); + private JLabel commentLabel = new JLabel(); + private JTextField commentTextField = new JTextField(); private JLabel distanceFromStartLabel = new JLabel(); private JTextField distanceFromStartTextField = new JTextField(); /** * */ - public SectorPanel(String name, double distanceFromStart) + public SectorPanel(Sector sector) { super(); - initialize(name, distanceFromStart); + initialize(sector); } /** * */ - private void initialize(String name, double distanceFromStart) + private void initialize(Sector sector) { setLayout(null); addLabel(this, 0, nameLabel, "Name", 150); - addLabel(this, 1, distanceFromStartLabel, "Distance From Start", 150); + addLabel(this, 1, commentLabel, "Comment", 150); + addLabel(this, 2, distanceFromStartLabel, "Distance From Start", 150); - addTextField(this, 0, nameTextField, name, 160, 225); - addTextField(this, 1, distanceFromStartTextField, distanceFromStart, 160, 225); + addTextField(this, 0, nameTextField, sector.getName(), 160, 125); + addTextField(this, 1, commentTextField, sector.getComment(), 160, 335); + addTextField(this, 2, distanceFromStartTextField, sector.getDistanceFromStart(), 160, 125); } } @@ -175,6 +180,11 @@ public class SectorProperties extends PropertyPanel sector.setName(stringResult.getValue()); getEditorFrame().documentIsModified = true; } + if (isDifferent(panel.commentTextField.getText(), sector.getComment(), stringResult)) + { + sector.setComment(stringResult.getValue()); + getEditorFrame().documentIsModified = true; + } if (isDifferent(panel.distanceFromStartTextField.getText(), sector.getDistanceFromStart(), doubleResult)) { sector.setDistanceFromStart(doubleResult.getValue()); @@ -197,6 +207,7 @@ public class SectorProperties extends PropertyPanel SectorPanel panel = (SectorPanel) tabbedPane.getComponentAt(sectors.size()); Sector sector = new Sector(); sector.setName(panel.nameTextField.getText()); + sector.setComment(panel.commentTextField.getText()); sector.setDistanceFromStart(getDouble(panel.distanceFromStartTextField.getText())); sectors.add(sector); } diff --git a/src/tools/trackeditor/plugin/torcs/XmlReader.java b/src/tools/trackeditor/plugin/torcs/XmlReader.java index b1e60497f..14a8d8276 100644 --- a/src/tools/trackeditor/plugin/torcs/XmlReader.java +++ b/src/tools/trackeditor/plugin/torcs/XmlReader.java @@ -309,6 +309,7 @@ public class XmlReader Element element = it.next(); sector.setName(element.getAttribute("name").getValue()); + sector.setComment(getAttrStrValue(element, "comment")); sector.setDistanceFromStart(getAttrNumValue(element, "distance from start", "m")); sectorData.add(sector); diff --git a/src/tools/trackeditor/plugin/torcs/XmlWriter.java b/src/tools/trackeditor/plugin/torcs/XmlWriter.java index bdf0f351c..1b21ae762 100644 --- a/src/tools/trackeditor/plugin/torcs/XmlWriter.java +++ b/src/tools/trackeditor/plugin/torcs/XmlWriter.java @@ -624,7 +624,7 @@ public class XmlWriter Element el = new Element("section"); el.setAttribute(new Attribute("name", sector.getName())); - + addContent(el, "comment", sector.getComment()); addContent(el, "distance from start", "m", sector.getDistanceFromStart()); sectors.addContent(el); diff --git a/src/tools/trackeditor/utils/circuit/Sector.java b/src/tools/trackeditor/utils/circuit/Sector.java index 2dd8bf1c7..ccd88dd00 100644 --- a/src/tools/trackeditor/utils/circuit/Sector.java +++ b/src/tools/trackeditor/utils/circuit/Sector.java @@ -2,8 +2,9 @@ package utils.circuit; public class Sector { - private String name; - private double distanceFromStart; + private String name = null; + private String comment = null; + private double distanceFromStart = Double.NaN; public String getName() { @@ -14,6 +15,15 @@ public class Sector this.name = name; } + public String getComment() + { + return comment; + } + public void setComment(String comment) + { + this.comment = comment; + } + public double getDistanceFromStart() { return distanceFromStart; @@ -27,6 +37,7 @@ public class Sector { System.out.println(indent + "Sector"); System.out.println(indent + " name : " + name); + System.out.println(indent + " comment : " + comment); System.out.println(indent + " distanceFromStart : " + distanceFromStart); } }