summaryrefslogtreecommitdiff
path: root/NET/worlds/console/FileSysDialog.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-03 16:38:41 -0700
committerFuwn <[email protected]>2021-05-03 16:38:41 -0700
commite1e781bb2135ef78592226f1a3eaba4925702f1f (patch)
tree8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/FileSysDialog.java
downloadworlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz
worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip
:star:HEADmain
Diffstat (limited to 'NET/worlds/console/FileSysDialog.java')
-rw-r--r--NET/worlds/console/FileSysDialog.java250
1 files changed, 250 insertions, 0 deletions
diff --git a/NET/worlds/console/FileSysDialog.java b/NET/worlds/console/FileSysDialog.java
new file mode 100644
index 0000000..8959724
--- /dev/null
+++ b/NET/worlds/console/FileSysDialog.java
@@ -0,0 +1,250 @@
+/* */ 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;
+/* 40 */ private boolean parentDisabled = false;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ private Frame parent;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 69 */ JFileChooser fc = null;
+/* */
+/* 71 */ private static String OpenFileText = "Open File";
+/* 72 */ 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)
+/* */ {
+/* 78 */ this.receiver = receiver;
+/* 79 */ this.title = title;
+/* 80 */ this.typesAndExts = typesAndExts;
+/* 81 */ this.mode = mode;
+/* 82 */ this.fileName = fileName;
+/* 83 */ this.parent = parent;
+/* 84 */ this.disableParent = disableParent;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 93 */ SwingUtilities.invokeLater(this);
+/* */ }
+/* */
+/* */ public void run()
+/* */ {
+/* 98 */ if ((this.disableParent) &&
+/* 99 */ (this.parent.isEnabled())) {
+/* 100 */ this.parent.setEnabled(false);
+/* 101 */ this.parentDisabled = true;
+/* */ }
+/* */
+/* */ try
+/* */ {
+/* 106 */ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+/* */ }
+/* */ catch (ClassNotFoundException e1) {
+/* 109 */ e1.printStackTrace();
+/* 110 */ return;
+/* */ }
+/* */ catch (InstantiationException e1) {
+/* 113 */ e1.printStackTrace();
+/* 114 */ return;
+/* */ }
+/* */ catch (IllegalAccessException e1) {
+/* 117 */ e1.printStackTrace();
+/* 118 */ return;
+/* */ }
+/* */ catch (UnsupportedLookAndFeelException e1) {
+/* 121 */ e1.printStackTrace();
+/* 122 */ return;
+/* */ }
+/* */
+/* 125 */ File file = null;
+/* */ try {
+/* 127 */ if ((this.fileName != null) && (this.fileName != "")) {
+/* 128 */ file = new File(this.fileName);
+/* 129 */ if ((file != null) && (file.getParent() != null)) {
+/* 130 */ this.fc = new JFileChooser(file.getParent());
+/* */ }
+/* */ }
+/* 133 */ if (this.fc == null)
+/* */ {
+/* 135 */ if ((lastFile != null) && (lastFile.getParent() != null)) {
+/* 136 */ this.fc = new JFileChooser(lastFile.getParent());
+/* */ }
+/* */ }
+/* 139 */ if (this.fc == null) {
+/* 140 */ this.fc = new JFileChooser(".");
+/* */ }
+/* */ } catch (Exception e) {
+/* 143 */ e.printStackTrace();
+/* 144 */ return;
+/* */ }
+/* */
+/* 147 */ this.fc.setFileSelectionMode(0);
+/* 148 */ this.fc.setDialogType(this.mode == 0 ? 0 :
+/* 149 */ 1);
+/* */
+/* 151 */ if (this.title != null)
+/* 152 */ this.fc.setDialogTitle(this.title);
+/* 153 */ if (this.typesAndExts != null) {
+/* 154 */ buildFileChooser(this.fc, this.typesAndExts);
+/* */ }
+/* */
+/* 157 */ if (file != null) {
+/* 158 */ this.fc.setSelectedFile(file);
+/* */ }
+/* 160 */ int retval = this.fc.showDialog(null, this.mode == 0 ? OpenFileText :
+/* 161 */ SaveFileText);
+/* 162 */ if (retval == 0) {
+/* 163 */ approveSelection();
+/* */ } else {
+/* 165 */ cancelSelection();
+/* */ }
+/* 167 */ if ((this.disableParent) && (this.parentDisabled)) {
+/* 168 */ this.parent.setEnabled(true);
+/* 169 */ this.parentDisabled = false;
+/* */ }
+/* */ }
+/* */
+/* */ private static void buildFileChooser(JFileChooser fc2, String specString)
+/* */ {
+/* 175 */ String[] entries = specString.split("\\|");
+/* */
+/* */
+/* 178 */ boolean even = false;
+/* 179 */ String desc = "";
+/* */
+/* 181 */ FileNameExtensionFilter first = null;
+/* 182 */ String[] arrayOfString1; int j = (arrayOfString1 = entries).length; for (int i = 0; i < j; i++) { String entry = arrayOfString1[i];
+/* 183 */ if (even)
+/* */ {
+/* 185 */ String[] fields = entry.split(";");
+/* */
+/* 187 */ for (int i = 0; i < fields.length; i++) {
+/* 188 */ String[] ext = fields[i].split("\\.");
+/* 189 */ if (ext.length > 0) {
+/* 190 */ fields[i] = ext[(ext.length - 1)];
+/* */ }
+/* */ }
+/* 193 */ FileNameExtensionFilter ff = null;
+/* 194 */ switch (fields.length) {
+/* */ case 1:
+/* 196 */ ff = new FileNameExtensionFilter(desc, new String[] { fields[0] });
+/* 197 */ break;
+/* */ case 2:
+/* 199 */ ff = new FileNameExtensionFilter(desc, new String[] { fields[0], fields[1] });
+/* 200 */ break;
+/* */ case 3:
+/* 202 */ ff = new FileNameExtensionFilter(desc, new String[] { fields[0],
+/* 203 */ fields[1], fields[2] });
+/* 204 */ break;
+/* */ case 4:
+/* 206 */ ff = new FileNameExtensionFilter(desc, new String[] { fields[0],
+/* 207 */ fields[1], fields[2], fields[3] });
+/* */ }
+/* */
+/* 210 */ if (ff != null) {
+/* 211 */ fc2.addChoosableFileFilter(ff);
+/* 212 */ if (first == null) {
+/* 213 */ first = ff;
+/* */ }
+/* */ }
+/* 216 */ even = false;
+/* */ } else {
+/* 218 */ desc = entry;
+/* 219 */ even = true;
+/* */ }
+/* */ }
+/* 222 */ if (first != null)
+/* 223 */ fc2.setFileFilter(first);
+/* */ }
+/* */
+/* */ public int getMode() {
+/* 227 */ return this.mode;
+/* */ }
+/* */
+/* */ public void approveSelection() {
+/* 231 */ File file = this.fc.getSelectedFile();
+/* 232 */ lastFile = file;
+/* 233 */ this.fileName = file.getAbsolutePath();
+/* 234 */ this.receiver.dialogDone(this, this.fileName != null);
+/* */ }
+/* */
+/* */ public void cancelSelection() {
+/* 238 */ this.receiver.dialogDone(this, false);
+/* */ }
+/* */
+/* */ public String fileName() {
+/* 242 */ return this.fileName;
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\FileSysDialog.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file