summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/OpenURLAction.java
blob: 16449f01d5d9fcb3e683a2ffe890dc6756297057 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.console.DefaultConsole;
import NET.worlds.console.NoWebControlException;
import NET.worlds.console.WebControl;
import java.io.IOException;

public class OpenURLAction extends Action {
   String targetURL = "http://www.worlds.com";
   int xPercent = 100;
   int yPercent = 100;
   boolean hasToolbar = true;
   boolean isFixed = false;
   private static Object classCookie = new Object();

   @Override
   public Persister trigger(Event e, Persister seqID) {
      if (seqID != null) {
         return seqID;
      } else {
         Console c = Console.getActive();
         if (c != null && c instanceof DefaultConsole) {
            System.out.println("Opening up a URL now.");
            DefaultConsole dc = (DefaultConsole)c;

            try {
               WebControl wc = new WebControl(dc.getRender(), this.xPercent, this.yPercent, this.hasToolbar, this.isFixed, false);
               wc.activate();
               wc.setURL(this.targetURL);
            } catch (NoWebControlException var6) {
            }

            new SuperRoot();
            return this;
         } else {
            return null;
         }
      }
   }

   @Override
   public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
      Object ret = null;
      switch (index - offset) {
         case 0:
            if (mode == 0) {
               ret = StringPropertyEditor.make(new Property(this, index, "Target URL"));
            } else if (mode == 1) {
               ret = this.targetURL;
            } else if (mode == 2) {
               this.targetURL = (String)value;
            }
            break;
         case 1:
            if (mode == 0) {
               ret = IntegerPropertyEditor.make(new Property(this, index, "X Overlay % or Width"), 0, 1024);
            } else if (mode == 1) {
               ret = new Integer(this.xPercent);
            } else if (mode == 2) {
               this.xPercent = (Integer)value;
            }
            break;
         case 2:
            if (mode == 0) {
               ret = IntegerPropertyEditor.make(new Property(this, index, "Y Overlay % or Height"), 0, 1024);
            } else if (mode == 1) {
               ret = new Integer(this.yPercent);
            } else if (mode == 2) {
               this.yPercent = (Integer)value;
            }
            break;
         case 3:
            if (mode == 0) {
               ret = BooleanPropertyEditor.make(new Property(this, index, "Has Toolbar"), "No", "Yes");
            } else if (mode == 1) {
               ret = new Boolean(this.hasToolbar);
            } else if (mode == 2) {
               this.hasToolbar = (Boolean)value;
            }
            break;
         case 4:
            if (mode == 0) {
               ret = BooleanPropertyEditor.make(new Property(this, index, "Fixed size"), "No - Percentage specified", "Yes - Pixels specified");
            } else if (mode == 1) {
               ret = new Boolean(this.isFixed);
            } else if (mode == 2) {
               this.isFixed = (Boolean)value;
            }
            break;
         default:
            ret = super.properties(index, offset + 4, mode, value);
      }

      return ret;
   }

   @Override
   public void saveState(Saver s) throws IOException {
      s.saveVersion(0, classCookie);
      super.saveState(s);
      s.saveString(this.targetURL);
      s.saveInt(this.xPercent);
      s.saveInt(this.yPercent);
      s.saveBoolean(this.hasToolbar);
      s.saveBoolean(this.isFixed);
   }

   @Override
   public void restoreState(Restorer r) throws IOException, TooNewException {
      switch (r.restoreVersion(classCookie)) {
         case 0:
            super.restoreState(r);
            this.targetURL = r.restoreString();
            this.xPercent = r.restoreInt();
            this.yPercent = r.restoreInt();
            this.hasToolbar = r.restoreBoolean();
            this.isFixed = r.restoreBoolean();
            return;
         default:
            throw new TooNewException();
      }
   }
}