summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/URLEditorDialog.java
blob: 034ccdd071cdb5994c8c767e066f41246a9c4f56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.network.URL;
import java.net.MalformedURLException;
import java.util.Vector;

class URLEditorDialog extends FieldWithListEditorDialog {
   Property property;
   FileList extChecker;

   URLEditorDialog(EditTile parent, String title, Property property, Vector files, FileList extChecker) {
      super(parent, title + " dir: " + URL.getBestContainer((SuperRoot)property.getOwner()), files);
      this.property = property;
      this.extChecker = extChecker;
      this.ready();
   }

   @Override
   protected String getValue() {
      SuperRoot context = (SuperRoot)this.property.getOwner();
      if (context != null && this.property.getName().equals("Source URL")) {
         context = context.getOwner();
      }

      String s = URL.getRelativeTo((URL)this.property.get(), context);
      return s == null ? "" : s;
   }

   @Override
   protected boolean setValue(String text) {
      URL url = null;
      if (text.length() == 0) {
         if (!this.property.canSetNull()) {
            return false;
         }
      } else {
         if (this.extChecker != null && !this.extChecker.extMatches(text)) {
            Console.println(Console.message("extension-match") + this.extChecker.getExtList());
            return false;
         }

         try {
            url = new URL((SuperRoot)this.property.getOwner(), text);
         } catch (MalformedURLException var4) {
            Console.println(Console.message("Illegal-URL") + var4);
            return false;
         }
      }

      this.parent.addUndoableSet(this.property, url);
      return true;
   }
}