summaryrefslogtreecommitdiff
path: root/NET/worlds/console/WebBrowser.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/WebBrowser.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/WebBrowser.java')
-rw-r--r--NET/worlds/console/WebBrowser.java340
1 files changed, 340 insertions, 0 deletions
diff --git a/NET/worlds/console/WebBrowser.java b/NET/worlds/console/WebBrowser.java
new file mode 100644
index 0000000..d73c04f
--- /dev/null
+++ b/NET/worlds/console/WebBrowser.java
@@ -0,0 +1,340 @@
+package NET.worlds.console;
+
+import NET.worlds.core.IniFile;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Stack;
+
+public class WebBrowser {
+ private static Stack<WebBrowser> browsers = new Stack<WebBrowser>();
+ private static boolean disabled = IniFile.gamma().getIniInt("DISABLEIE", 0) != 0;
+ private static boolean everWorked;
+ private int nativeBrowserPointer;
+ private InternetExplorer _activeX;
+ private static boolean toolbarON = true;
+ private static boolean windowFrameON = true;
+ private static boolean _stayMinimized = false;
+ private String browserTag = null;
+
+ public static WebBrowser reuseOrMake(String url, String postData) throws IOException {
+ return reuseOrMake(url, postData, defaultPlacement());
+ }
+
+ public static void useToolbar() {
+ toolbarON = true;
+ }
+
+ public static void dontUseToolbar() {
+ toolbarON = false;
+ }
+
+ public static void useWindowFrame() {
+ windowFrameON = true;
+ }
+
+ public static void dontUseWindowFrame() {
+ windowFrameON = false;
+ }
+
+ public static void forceMinimized(boolean force) {
+ _stayMinimized = force;
+ }
+
+ public static WebBrowser findTag(String tag) {
+ Enumeration<WebBrowser> e = browsers.elements();
+
+ while (e.hasMoreElements()) {
+ WebBrowser browser = e.nextElement();
+ if (tag != null) {
+ if (tag.equals(browser.getTag())) {
+ return browser;
+ }
+ } else if (browser.getTag() == null) {
+ return browser;
+ }
+ }
+
+ return null;
+ }
+
+ public static WebBrowser reuseOrMake(String url, String postData, Rectangle placement) throws IOException {
+ Enumeration<WebBrowser> e = browsers.elements();
+
+ while (e.hasMoreElements()) {
+ WebBrowser browser = e.nextElement();
+ if (browser.getTag() == null) {
+ try {
+ browser.browse(url, postData, null);
+ return browser;
+ } catch (IOException var6) {
+ }
+ }
+ }
+
+ return new WebBrowser(url, postData, placement);
+ }
+
+ private String getTag() {
+ return this.browserTag;
+ }
+
+ public static WebBrowser reuseOrMake(String url, String postData, Rectangle placement, String tag) throws IOException {
+ Enumeration<WebBrowser> e = browsers.elements();
+
+ while (e.hasMoreElements()) {
+ WebBrowser browser = e.nextElement();
+ if (tag.equals(browser.getTag())) {
+ try {
+ browser.browse(url, postData, null);
+ return browser;
+ } catch (IOException var7) {
+ }
+ }
+ }
+
+ return new WebBrowser(url, postData, placement, tag);
+ }
+
+ public static Rectangle defaultPlacement() {
+ Console c = Console.getActive();
+ return c instanceof DefaultConsole ? ((DefaultConsole)c).getBrowserPlacement() : new Rectangle(0, 0, 200, 200);
+ }
+
+ public static boolean isDisabled() {
+ return disabled;
+ }
+
+ public static void setDisabled(boolean be) {
+ IniFile.gamma().setIniInt("DISABLEIE", be ? 1 : 0);
+ disabled = be;
+ }
+
+ public WebBrowser(String url, String postData) throws IOException {
+ this(url, postData, defaultPlacement());
+ }
+
+ public WebBrowser(String url, String postData, Rectangle placement) throws IOException {
+ this(url, postData, placement, null);
+ }
+
+ public WebBrowser(String url, String postData, Rectangle placement, String tag) throws IOException {
+ if (!disabled) {
+ this._activeX = new InternetExplorer(this);
+
+ try {
+ this.nativeBrowserPointer = openBrowser();
+ } catch (IOException var9) {
+ try {
+ this._activeX.Release();
+ } catch (OLEInvalidObjectException var8) {
+ assert false;
+ }
+
+ this._activeX = null;
+ disabled = true;
+ throw var9;
+ }
+
+ browsers.push(this);
+ if (tag != null) {
+ this.browserTag = tag;
+ }
+
+ try {
+ this.browse(url, postData, placement);
+ everWorked = true;
+ } catch (IOException var7) {
+ if (!everWorked) {
+ disabled = true;
+ }
+
+ throw var7;
+ }
+ } else {
+ throw new IOException();
+ }
+ }
+
+ public void browse(String url, String postData, Rectangle placement) throws IOException {
+ if (this.nativeBrowserPointer != 0) {
+ int x = -1;
+ int y = -1;
+ int w = -1;
+ int h = -1;
+ if (placement != null) {
+ x = placement.x;
+ y = placement.y;
+ w = placement.width;
+ h = placement.height;
+ }
+
+ try {
+ browse(url, postData, x, y, w, h, this.nativeBrowserPointer);
+ } catch (IOException var9) {
+ this.close();
+ throw var9;
+ }
+ } else {
+ throw new IOException();
+ }
+ }
+
+ public void close() {
+ if (this.nativeBrowserPointer != 0) {
+ closeBrowser(this.nativeBrowserPointer);
+ this.nativeBrowserPointer = 0;
+
+ try {
+ this._activeX.Release();
+ } catch (OLEInvalidObjectException var2) {
+ assert false;
+ }
+
+ this._activeX = null;
+ browsers.removeElement(this);
+ }
+ }
+
+ private static native void browse(String var0, String var1, int var2, int var3, int var4, int var5, int var6) throws IOException;
+
+ private static native int openBrowser() throws IOException;
+
+ private static native void closeBrowser(int var0);
+
+ public static Rectangle getMapPartPlacement() {
+ Rectangle placement = null;
+ Console c = Console.getActive();
+ if (c != null) {
+ MapPart ap = null;
+ Enumeration<FramePart> e = c.getParts();
+
+ while (e.hasMoreElements()) {
+ Object o = e.nextElement();
+ if (o instanceof MapPart) {
+ ap = (MapPart)o;
+ break;
+ }
+ }
+
+ if (ap != null) {
+ placement = new Rectangle(ap.getLocationOnScreen(), ap.getSize());
+ placement.grow(0, 10);
+ placement.translate(0, -9);
+ }
+ }
+
+ return placement;
+ }
+
+ public static Rectangle getAdPartPlacement() {
+ Rectangle placement = null;
+ Console c = Console.getActive();
+ if (c != null) {
+ AdPart ap = null;
+ Enumeration<FramePart> e = c.getParts();
+
+ while (e.hasMoreElements()) {
+ Object o = e.nextElement();
+ if (o instanceof AdPart) {
+ ap = (AdPart)o;
+ break;
+ }
+ }
+
+ if (ap != null) {
+ placement = new Rectangle(ap.getLocationOnScreen(), ap.getSize());
+ placement.grow(0, 10);
+ placement.translate(0, -9);
+ }
+ }
+
+ return placement;
+ }
+
+ public static Rectangle getRenderPartPlacement() {
+ Rectangle placement = null;
+ Console c = Console.getActive();
+ if (c != null) {
+ RenderCanvas ap = null;
+ Enumeration<FramePart> e = c.getParts();
+
+ while (e.hasMoreElements()) {
+ Object o = e.nextElement();
+ if (o instanceof RenderCanvas) {
+ ap = (RenderCanvas)o;
+ break;
+ }
+ }
+
+ if (ap != null) {
+ placement = new Rectangle(ap.getLocationOnScreen(), ap.getSize());
+ placement.grow(2, 10);
+ placement.translate(-1, 7);
+ }
+ }
+
+ return placement;
+ }
+
+ public static Rectangle getLeftRenderPartPlacement() {
+ Rectangle placement = null;
+ Console c = Console.getActive();
+ if (c != null) {
+ RenderCanvas ap = null;
+ Enumeration<FramePart> e = c.getParts();
+
+ while (e.hasMoreElements()) {
+ Object o = e.nextElement();
+ if (o instanceof RenderCanvas) {
+ ap = (RenderCanvas)o;
+ break;
+ }
+ }
+
+ if (ap != null) {
+ placement = new Rectangle(ap.getLocationOnScreen(), ap.getSize());
+ placement.grow(2, 10);
+ placement.translate(-1, 7);
+ Dimension d = placement.getSize();
+ placement.setSize(d.width / 2, d.height);
+ }
+ }
+
+ return placement;
+ }
+
+ public static Rectangle getOutsidePlacement() {
+ Rectangle placement = null;
+ Console c = Console.getActive();
+ if (c != null) {
+ RenderCanvas ap = null;
+ Enumeration<FramePart> e = c.getParts();
+
+ while (e.hasMoreElements()) {
+ Object o = e.nextElement();
+ if (o instanceof RenderCanvas) {
+ ap = (RenderCanvas)o;
+ break;
+ }
+ }
+
+ if (ap != null) {
+ Point ploc = ap.getLocationOnScreen();
+ Dimension d = new Dimension(250, 500);
+ Point bloc = new Point(0, ploc.y);
+ if (ploc.x > 254) {
+ bloc.x = ploc.x - 254;
+ } else {
+ bloc.x = 0;
+ }
+
+ placement = new Rectangle(bloc, d);
+ }
+ }
+
+ return placement;
+ }
+}