From f9e06300dc338d51890beff7bf496909edbd6475 Mon Sep 17 00:00:00 2001 From: iobyte Date: Mon, 20 Jun 2022 18:58:48 +0000 Subject: [PATCH] trackeditor: really make JFileChooser read only git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8233 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: c43d0c89c84c7acbb39ad95186581fdc90012e61 Former-commit-id: fb15d820e0ac3fd910ff92f83a3d67380c4c16d1 --- src/tools/trackeditor/CMakeLists.txt | 1 - src/tools/trackeditor/gui/EditorFrame.java | 17 +++++--- .../gui/properties/EnvMapProperties.java | 10 +++-- .../gui/properties/GraphicProperties.java | 10 +++-- .../gui/properties/ImageProperties.java | 10 +++-- .../gui/properties/SurfaceProperties.java | 17 +++++--- .../gui/properties/TerrainProperties.java | 24 ++++++++---- .../gui/properties/TrackLightProperties.java | 17 +++++--- .../miscel/NoNewFolderFileChooser.java | 39 ------------------- .../trackeditor/plugin/torcs/TorcsPlugin.java | 10 +++-- 10 files changed, 81 insertions(+), 74 deletions(-) delete mode 100644 src/tools/trackeditor/miscel/NoNewFolderFileChooser.java diff --git a/src/tools/trackeditor/CMakeLists.txt b/src/tools/trackeditor/CMakeLists.txt index ead9181a..be68a955 100644 --- a/src/tools/trackeditor/CMakeLists.txt +++ b/src/tools/trackeditor/CMakeLists.txt @@ -45,7 +45,6 @@ IF(Java_Development_FOUND AND Java_FOUND) gui/view/CircuitViewSelectionEvent.java gui/view/CircuitViewSelectionListener.java miscel/EPMath.java - miscel/NoNewFolderFileChooser.java plugin/Plugin.java plugin/torcs/NoOpEntityResolver.java plugin/torcs/TorcsPlugin.java diff --git a/src/tools/trackeditor/gui/EditorFrame.java b/src/tools/trackeditor/gui/EditorFrame.java index fae31707..84b2c242 100644 --- a/src/tools/trackeditor/gui/EditorFrame.java +++ b/src/tools/trackeditor/gui/EditorFrame.java @@ -23,7 +23,6 @@ package gui; import gui.properties.PropertiesDialog; import gui.splash.SplashScreen; import gui.view.CircuitView; -import miscel.NoNewFolderFileChooser; import java.awt.AWTEvent; import java.awt.BorderLayout; @@ -48,6 +47,7 @@ import java.util.Vector; import javax.swing.AbstractAction; import javax.swing.ImageIcon; import javax.swing.JButton; +import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -57,6 +57,7 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JToggleButton; import javax.swing.JToolBar; +import javax.swing.UIManager; import javax.swing.filechooser.FileNameExtensionFilter; import plugin.Plugin; @@ -223,7 +224,9 @@ public class EditorFrame extends JFrame { String tmp = ""; String filename = Editor.getProperties().getPath() +sep+"project.xml"; - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -236,7 +239,8 @@ public class EditorFrame extends JFrame filter.setDescription("*.prj.xml"); fc.setFileFilter(filter); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { tmp = fc.getSelectedFile().toString(); filename = tmp; @@ -1303,7 +1307,9 @@ public class EditorFrame extends JFrame { String tmp = ""; // String filename = Editor.getProperties().getPath(); - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -1315,7 +1321,8 @@ public class EditorFrame extends JFrame fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(System.getProperty("user.dir") + "/tracks")); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { tmp = fc.getSelectedFile().toString(); //Editor.getProperties().setImage(tmp); diff --git a/src/tools/trackeditor/gui/properties/EnvMapProperties.java b/src/tools/trackeditor/gui/properties/EnvMapProperties.java index bddab1a0..c858de37 100644 --- a/src/tools/trackeditor/gui/properties/EnvMapProperties.java +++ b/src/tools/trackeditor/gui/properties/EnvMapProperties.java @@ -24,14 +24,15 @@ import java.io.File; import java.util.Vector; import javax.swing.JButton; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; +import javax.swing.UIManager; import javax.swing.filechooser.FileNameExtensionFilter; import gui.EditorFrame; -import miscel.NoNewFolderFileChooser; import utils.Editor; import utils.circuit.EnvironmentMapping; @@ -205,7 +206,9 @@ public class EnvMapProperties extends PropertyPanel protected void envMapFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -217,7 +220,8 @@ public class EnvMapProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); diff --git a/src/tools/trackeditor/gui/properties/GraphicProperties.java b/src/tools/trackeditor/gui/properties/GraphicProperties.java index 92412d63..35d4f47b 100644 --- a/src/tools/trackeditor/gui/properties/GraphicProperties.java +++ b/src/tools/trackeditor/gui/properties/GraphicProperties.java @@ -25,12 +25,13 @@ import java.io.File; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JTextField; +import javax.swing.UIManager; import javax.swing.filechooser.FileNameExtensionFilter; import gui.EditorFrame; -import miscel.NoNewFolderFileChooser; import utils.Editor; /** @@ -204,7 +205,9 @@ public class GraphicProperties extends PropertyPanel protected void backgroundImageFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -216,7 +219,8 @@ public class GraphicProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); diff --git a/src/tools/trackeditor/gui/properties/ImageProperties.java b/src/tools/trackeditor/gui/properties/ImageProperties.java index 58172cda..941f9607 100644 --- a/src/tools/trackeditor/gui/properties/ImageProperties.java +++ b/src/tools/trackeditor/gui/properties/ImageProperties.java @@ -23,12 +23,13 @@ package gui.properties; import java.io.File; import javax.swing.JButton; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JTextField; +import javax.swing.UIManager; import javax.swing.filechooser.FileNameExtensionFilter; import gui.EditorFrame; -import miscel.NoNewFolderFileChooser; import utils.Editor; /** @@ -103,7 +104,9 @@ public class ImageProperties extends PropertyPanel { String tmp = ""; String filename = Editor.getProperties().getImage(); - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -124,7 +127,8 @@ public class ImageProperties extends PropertyPanel FileNameExtensionFilter filter = new FileNameExtensionFilter("RGB and PNG images", "rgb", "png"); fc.addChoosableFileFilter(filter); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { pathTextField.setText(fc.getSelectedFile().toString()); } diff --git a/src/tools/trackeditor/gui/properties/SurfaceProperties.java b/src/tools/trackeditor/gui/properties/SurfaceProperties.java index ada174bd..ee20217f 100644 --- a/src/tools/trackeditor/gui/properties/SurfaceProperties.java +++ b/src/tools/trackeditor/gui/properties/SurfaceProperties.java @@ -25,14 +25,15 @@ import java.util.Vector; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; +import javax.swing.UIManager; import javax.swing.filechooser.FileNameExtensionFilter; import gui.EditorFrame; -import miscel.NoNewFolderFileChooser; import utils.Editor; import utils.circuit.Surface; @@ -346,7 +347,9 @@ public class SurfaceProperties extends PropertyPanel protected void textureNameFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -358,7 +361,8 @@ public class SurfaceProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); @@ -394,7 +398,9 @@ public class SurfaceProperties extends PropertyPanel protected void racelineNameFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -406,7 +412,8 @@ public class SurfaceProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); diff --git a/src/tools/trackeditor/gui/properties/TerrainProperties.java b/src/tools/trackeditor/gui/properties/TerrainProperties.java index 2165c2e1..5fe7cac3 100644 --- a/src/tools/trackeditor/gui/properties/TerrainProperties.java +++ b/src/tools/trackeditor/gui/properties/TerrainProperties.java @@ -28,14 +28,15 @@ import java.util.Vector; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; +import javax.swing.UIManager; import javax.swing.filechooser.FileNameExtensionFilter; import gui.EditorFrame; -import miscel.NoNewFolderFileChooser; import utils.Editor; import utils.circuit.ObjectMap; import utils.circuit.Surface; @@ -270,7 +271,9 @@ public class TerrainProperties extends PropertyPanel protected void elevationMapFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -282,7 +285,8 @@ public class TerrainProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); @@ -295,7 +299,9 @@ public class TerrainProperties extends PropertyPanel protected void reliefFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -307,7 +313,8 @@ public class TerrainProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); @@ -517,7 +524,9 @@ public class TerrainProperties extends PropertyPanel protected void objectMapFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -529,7 +538,8 @@ public class TerrainProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); diff --git a/src/tools/trackeditor/gui/properties/TrackLightProperties.java b/src/tools/trackeditor/gui/properties/TrackLightProperties.java index 567bf8f2..342e87bc 100644 --- a/src/tools/trackeditor/gui/properties/TrackLightProperties.java +++ b/src/tools/trackeditor/gui/properties/TrackLightProperties.java @@ -24,14 +24,15 @@ import java.io.File; import java.util.Vector; import javax.swing.JButton; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; +import javax.swing.UIManager; import javax.swing.filechooser.FileNameExtensionFilter; import gui.EditorFrame; -import miscel.NoNewFolderFileChooser; import utils.Editor; import utils.circuit.TrackLight; @@ -286,7 +287,9 @@ public class TrackLightProperties extends PropertyPanel protected void textureOnFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -298,7 +301,8 @@ public class TrackLightProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); @@ -311,7 +315,9 @@ public class TrackLightProperties extends PropertyPanel protected void textureOffFile() { - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -323,7 +329,8 @@ public class TrackLightProperties extends PropertyPanel fc.addChoosableFileFilter(filter); fc.setCurrentDirectory(new File(Editor.getProperties().getPath())); int result = fc.showOpenDialog(this); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result == JFileChooser.APPROVE_OPTION) { String fileName = fc.getSelectedFile().toString(); int index = fileName.lastIndexOf(sep); diff --git a/src/tools/trackeditor/miscel/NoNewFolderFileChooser.java b/src/tools/trackeditor/miscel/NoNewFolderFileChooser.java deleted file mode 100644 index 449d32e7..00000000 --- a/src/tools/trackeditor/miscel/NoNewFolderFileChooser.java +++ /dev/null @@ -1,39 +0,0 @@ -package miscel; - -import java.awt.Component; -import java.awt.Container; - -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.JPanel; - -public class NoNewFolderFileChooser extends JFileChooser -{ - public NoNewFolderFileChooser() - { - super(); - disableNewFolder(this); - } - - private void disableNewFolder(Container container) - { - int cnt = container.getComponentCount(); - for (int i = 0; i < cnt; i++) - { - Component comp = container.getComponent(i); - if (comp instanceof JButton) - { - JButton btn = (JButton)comp; - if (btn.getToolTipText().indexOf("New Folder") > -1) - { - btn.setVisible(false); - return; - } - } - else if (comp instanceof JPanel) - { - disableNewFolder((Container) comp); - } - } - } -} diff --git a/src/tools/trackeditor/plugin/torcs/TorcsPlugin.java b/src/tools/trackeditor/plugin/torcs/TorcsPlugin.java index e5ad6771..2a7604e9 100644 --- a/src/tools/trackeditor/plugin/torcs/TorcsPlugin.java +++ b/src/tools/trackeditor/plugin/torcs/TorcsPlugin.java @@ -21,13 +21,14 @@ package plugin.torcs; import gui.EditorFrame; -import miscel.NoNewFolderFileChooser; import java.awt.event.ActionEvent; import java.io.File; import javax.swing.AbstractAction; import javax.swing.ImageIcon; +import javax.swing.JFileChooser; import javax.swing.JMenuItem; +import javax.swing.UIManager; import plugin.Plugin; import utils.CustomFileFilter; @@ -64,7 +65,9 @@ public class TorcsPlugin implements Plugin public void importTrack() { String tmp = ""; - NoNewFolderFileChooser fc = new NoNewFolderFileChooser(); + Boolean old = UIManager.getBoolean("FileChooser.readOnly"); + UIManager.put("FileChooser.readOnly", Boolean.TRUE); + JFileChooser fc = new JFileChooser(); fc.setSelectedFiles(null); fc.setSelectedFile(null); fc.rescanCurrentDirectory(); @@ -80,7 +83,8 @@ public class TorcsPlugin implements Plugin filter.setDescription("*.xml"); fc.setFileFilter(filter); int result = fc.showOpenDialog(editor); - if (result == NoNewFolderFileChooser.APPROVE_OPTION) + UIManager.put("FileChooser.readOnly", old); + if (result ==JFileChooser.APPROVE_OPTION) { tmp = fc.getSelectedFile().toString(); Editor.getProperties().getHeader().setName(tmp.substring(tmp.lastIndexOf(sep) + 1, tmp.lastIndexOf(".")));