From f3fa7281de6d9d01dc38766c634fbd3191f91410 Mon Sep 17 00:00:00 2001 From: iobyte Date: Mon, 11 Dec 2023 22:23:55 +0000 Subject: [PATCH] trackeditor: add option to show object and segment names when cursor is on them git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9229 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 35c15a25910222ab69fb7f2e086ab4ec7c3d164e Former-commit-id: 5c610c67dcf993f3de53ac6f8f5800b665b97715 --- src/tools/trackeditor/gui/EditorFrame.java | 16 +++++ .../trackeditor/gui/PreferencesDialog.java | 25 +++++++- .../trackeditor/gui/view/CircuitView.java | 59 ++++++++++++++++++- src/tools/trackeditor/utils/Properties.java | 2 +- 4 files changed, 97 insertions(+), 5 deletions(-) diff --git a/src/tools/trackeditor/gui/EditorFrame.java b/src/tools/trackeditor/gui/EditorFrame.java index 57b79f081..56324a0ce 100644 --- a/src/tools/trackeditor/gui/EditorFrame.java +++ b/src/tools/trackeditor/gui/EditorFrame.java @@ -234,6 +234,8 @@ public class EditorFrame extends JFrame private final static String INTERACTIVE_FIXES = "InteractiveFixes"; private boolean cursorCoordinates = false; private final static String CURSOR_COORDINATES = "CursorCoordinates"; + private boolean cursorNames = false; + private final static String CURSOR_NAMES = "CursorNames"; private TrackData trackData = null; private Vector defaultSurfaces = new Vector(); @@ -375,6 +377,7 @@ public class EditorFrame extends JFrame recentFilesMax = Integer.parseInt(preferences.get(RECENT_FILES_MAX, "10")); interactiveFixes = preferences.getBoolean(INTERACTIVE_FIXES, false); cursorCoordinates = preferences.getBoolean(CURSOR_COORDINATES, false); + cursorNames = preferences.getBoolean(CURSOR_NAMES, false); if (dataDirectory == null) { @@ -521,6 +524,18 @@ public class EditorFrame extends JFrame preferences.putBoolean(CURSOR_COORDINATES, cursorCoordinates); } + public boolean getCursorNames() + { + return cursorNames; + } + + public void setCursorNames(boolean value) + { + cursorNames = value; + + preferences.putBoolean(CURSOR_NAMES, cursorNames); + } + private void updateRecentFiles(String filename) { recentFiles.remove(filename); @@ -1359,6 +1374,7 @@ public class EditorFrame extends JFrame setRecentFilesMax(preferencesDialog.getRecentFilesMax()); setInteractiveFixes(preferencesDialog.getInteractiveFixes()); setCursorCoordinates(preferencesDialog.getCursorCoordinates()); + setCursorNames(preferencesDialog.getCursorNames()); readDefaultSurfaces(); readDefaultObjects(); view.redrawCircuit(); diff --git a/src/tools/trackeditor/gui/PreferencesDialog.java b/src/tools/trackeditor/gui/PreferencesDialog.java index 16fc4d256..ea3c219db 100644 --- a/src/tools/trackeditor/gui/PreferencesDialog.java +++ b/src/tools/trackeditor/gui/PreferencesDialog.java @@ -34,6 +34,7 @@ public class PreferencesDialog extends JDialog private JTextField recentFilesMaxTextField = null; private JCheckBox interactiveFixesCheckBox = null; private JCheckBox cursorCoordinatesCheckBox = null; + private JCheckBox cursorNamesCheckBox = null; private JButton okButton = null; private JButton cancelButton = null; @@ -46,7 +47,7 @@ public class PreferencesDialog extends JDialog private void initialize() { - this.setSize(600, 285); + this.setSize(600, 307); //285); this.setContentPane(getJPanel()); this.setModal(true); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); @@ -96,6 +97,7 @@ public class PreferencesDialog extends JDialog jPanel.add(getRecentFilesMaxTextField(), null); jPanel.add(getInteractiveFixesCheckBox(), null); jPanel.add(getCursorCoordinatesCheckBox(), null); + jPanel.add(getCursorNamesCheckBox(), null); jPanel.add(getOkButton(), null); jPanel.add(getCancelButton(), null); } @@ -287,12 +289,24 @@ public class PreferencesDialog extends JDialog return cursorCoordinatesCheckBox; } + private JCheckBox getCursorNamesCheckBox() + { + if (cursorNamesCheckBox == null) + { + cursorNamesCheckBox = new JCheckBox(); + cursorNamesCheckBox.setBounds(200, 183, 290, 23); + cursorNamesCheckBox.setText("Cursor Names"); + cursorNamesCheckBox.setSelected(editorFrame.getCursorNames()); + } + return cursorNamesCheckBox; + } + private JButton getOkButton() { if (okButton == null) { okButton = new JButton(); - okButton.setBounds(160, 210, 78, 25); + okButton.setBounds(160, 232, 78, 25); okButton.setText("Ok"); okButton.addActionListener(new ActionListener() { @@ -310,7 +324,7 @@ public class PreferencesDialog extends JDialog if (cancelButton == null) { cancelButton = new JButton(); - cancelButton.setBounds(350, 210, 78, 25); + cancelButton.setBounds(350, 232, 78, 25); cancelButton.setText("Cancel"); cancelButton.addActionListener(new ActionListener() { @@ -375,6 +389,11 @@ public class PreferencesDialog extends JDialog return getCursorCoordinatesCheckBox().isSelected(); } + public boolean getCursorNames() + { + return getCursorNamesCheckBox().isSelected(); + } + protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); diff --git a/src/tools/trackeditor/gui/view/CircuitView.java b/src/tools/trackeditor/gui/view/CircuitView.java index ff51fac2c..bb0986233 100644 --- a/src/tools/trackeditor/gui/view/CircuitView.java +++ b/src/tools/trackeditor/gui/view/CircuitView.java @@ -137,6 +137,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene private ObjShapeObject objectShape = null; /** offset between mouse click position and object position */ private Point2D.Double objectOffset = new Point2D.Double(); + private String objectName = null; private ObjShapeRelief reliefShape = null; private int reliefPointIndex = 0; @@ -1046,6 +1047,28 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene { case STATE_NONE : { + // must check for a object under the mouse + Segment obj = findObjAtMousePos(); + + if (obj != null) + { + if (obj.getType().equals("graphic object") || + obj.getType().equals("object") || + obj.getType().equals("rgt") || + obj.getType().equals("lft") || + obj.getType().equals("str")) + { + objectName = new String(obj.getName()); + invalidate(); + repaint(); + } + } + else if (objectName != null) + { + objectName = null; + invalidate(); + repaint(); + } } break; @@ -1134,6 +1157,32 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene invalidate(); repaint(); } + + if (editorFrame.getCursorNames()) + { + // must check for a object under the mouse + Segment obj = findObjAtMousePos(); + + if (obj != null) + { + if (obj.getType().equals("graphic object") || + obj.getType().equals("object") || + obj.getType().equals("rgt") || + obj.getType().equals("lft") || + obj.getType().equals("str")) + { + objectName = new String(obj.getName()); + invalidate(); + repaint(); + } + } + else if (objectName != null) + { + objectName = null; + invalidate(); + repaint(); + } + } } // /** input events management */ @@ -1587,7 +1636,15 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene graphics.drawString(coordinates, r.x + 10, r.y + 20); } } - + + if (editorFrame.getCursorNames()) + { + if (objectName != null) + { + graphics.drawString(objectName, r.x + 10, r.y + 40); + } + } + if (editorFrame.getTrackData() != null && editorFrame.getTrackData().getSegments() != null) { if (boundingRectangle == null) diff --git a/src/tools/trackeditor/utils/Properties.java b/src/tools/trackeditor/utils/Properties.java index 33ee3dde5..3f0b638fa 100644 --- a/src/tools/trackeditor/utils/Properties.java +++ b/src/tools/trackeditor/utils/Properties.java @@ -34,7 +34,7 @@ public class Properties private static Properties instance = new Properties(); private Vector propertiesListeners = new Vector(); public final String title = "sd2-trackeditor"; - public final String version = "1.3.28"; + public final String version = "1.3.29"; private String path; private double imageScale = 1;