summaryrefslogtreecommitdiff
path: root/NET/worlds/console/FileSysDialog.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/FileSysDialog.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/FileSysDialog.java')
-rw-r--r--NET/worlds/console/FileSysDialog.java179
1 files changed, 179 insertions, 0 deletions
diff --git a/NET/worlds/console/FileSysDialog.java b/NET/worlds/console/FileSysDialog.java
new file mode 100644
index 0000000..699f1ec
--- /dev/null
+++ b/NET/worlds/console/FileSysDialog.java
@@ -0,0 +1,179 @@
+package NET.worlds.console;
+
+import java.awt.Frame;
+import java.io.File;
+import javax.swing.JFileChooser;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.filechooser.FileNameExtensionFilter;
+
+public class FileSysDialog implements Runnable {
+ public static final int OPEN = 0;
+ public static final int SAVE = 1;
+ private String title;
+ private String typesAndExts;
+ private String fileName;
+ private static File lastFile;
+ private int mode;
+ private DialogReceiver receiver;
+ private boolean parentDisabled = false;
+ private Frame parent;
+ JFileChooser fc = null;
+ private static String OpenFileText = "Open File";
+ private static String SaveFileText = "Save File";
+ private boolean disableParent;
+
+ public FileSysDialog(Frame parent, DialogReceiver receiver, String title, int mode, String typesAndExts, String fileName, boolean disableParent) {
+ this.receiver = receiver;
+ this.title = title;
+ this.typesAndExts = typesAndExts;
+ this.mode = mode;
+ this.fileName = fileName;
+ this.parent = parent;
+ this.disableParent = disableParent;
+ SwingUtilities.invokeLater(this);
+ }
+
+ @Override
+ public void run() {
+ if (this.disableParent && this.parent.isEnabled()) {
+ this.parent.setEnabled(false);
+ this.parentDisabled = true;
+ }
+
+ try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ } catch (ClassNotFoundException var3) {
+ var3.printStackTrace();
+ return;
+ } catch (InstantiationException var4) {
+ var4.printStackTrace();
+ return;
+ } catch (IllegalAccessException var5) {
+ var5.printStackTrace();
+ return;
+ } catch (UnsupportedLookAndFeelException var6) {
+ var6.printStackTrace();
+ return;
+ }
+
+ File file = null;
+
+ try {
+ if (this.fileName != null && this.fileName != "") {
+ file = new File(this.fileName);
+ if (file != null && file.getParent() != null) {
+ this.fc = new JFileChooser(file.getParent());
+ }
+ }
+
+ if (this.fc == null && lastFile != null && lastFile.getParent() != null) {
+ this.fc = new JFileChooser(lastFile.getParent());
+ }
+
+ if (this.fc == null) {
+ this.fc = new JFileChooser(".");
+ }
+ } catch (Exception var7) {
+ var7.printStackTrace();
+ return;
+ }
+
+ this.fc.setFileSelectionMode(0);
+ this.fc.setDialogType(this.mode == 0 ? 0 : 1);
+ if (this.title != null) {
+ this.fc.setDialogTitle(this.title);
+ }
+
+ if (this.typesAndExts != null) {
+ buildFileChooser(this.fc, this.typesAndExts);
+ }
+
+ if (file != null) {
+ this.fc.setSelectedFile(file);
+ }
+
+ int retval = this.fc.showDialog(null, this.mode == 0 ? OpenFileText : SaveFileText);
+ if (retval == 0) {
+ this.approveSelection();
+ } else {
+ this.cancelSelection();
+ }
+
+ if (this.disableParent && this.parentDisabled) {
+ this.parent.setEnabled(true);
+ this.parentDisabled = false;
+ }
+ }
+
+ private static void buildFileChooser(JFileChooser fc2, String specString) {
+ String[] entries = specString.split("\\|");
+ boolean even = false;
+ String desc = "";
+ FileNameExtensionFilter first = null;
+
+ for (String entry : entries) {
+ if (!even) {
+ desc = entry;
+ even = true;
+ } else {
+ String[] fields = entry.split(";");
+
+ for (int i = 0; i < fields.length; i++) {
+ String[] ext = fields[i].split("\\.");
+ if (ext.length > 0) {
+ fields[i] = ext[ext.length - 1];
+ }
+ }
+
+ FileNameExtensionFilter ff = null;
+ switch (fields.length) {
+ case 1:
+ ff = new FileNameExtensionFilter(desc, fields[0]);
+ break;
+ case 2:
+ ff = new FileNameExtensionFilter(desc, fields[0], fields[1]);
+ break;
+ case 3:
+ ff = new FileNameExtensionFilter(desc, fields[0], fields[1], fields[2]);
+ break;
+ case 4:
+ ff = new FileNameExtensionFilter(desc, fields[0], fields[1], fields[2], fields[3]);
+ }
+
+ if (ff != null) {
+ fc2.addChoosableFileFilter(ff);
+ if (first == null) {
+ first = ff;
+ }
+ }
+
+ even = false;
+ }
+ }
+
+ if (first != null) {
+ fc2.setFileFilter(first);
+ }
+ }
+
+ public int getMode() {
+ return this.mode;
+ }
+
+ public void approveSelection() {
+ File file = this.fc.getSelectedFile();
+ lastFile = file;
+ this.fileName = file.getAbsolutePath();
+ this.receiver.dialogDone(this, this.fileName != null);
+ }
+
+ public void cancelSelection() {
+ this.receiver.dialogDone(this, false);
+ }
+
+ public String fileName() {
+ return this.fileName;
+ }
+}