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
This commit is contained in:
iobyte 2022-06-20 18:58:48 +00:00
parent 66cfaba548
commit f9e06300dc
10 changed files with 81 additions and 74 deletions

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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());
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);
}
}
}
}

View file

@ -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(".")));