package net.matrix_rad.skang; import java.lang.*; import java.awt.BorderLayout; import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Cursor; import java.awt.Frame; import java.awt.Graphics; import java.awt.Image; import java.awt.Insets; import java.awt.Label; import java.awt.Rectangle; import java.awt.TextComponent; import java.awt.TextField; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.Enumeration; //import java.io.File; // For the developer menu. import net.matrix_rad.skang.*; import net.matrix_rad.NAWS.Grid; import net.matrix_rad.NAWS.PopUp; import net.matrix_rad.NAWS.Tree; /** * SkangAWT is a generic GUI frontend. It allows the actual GUI stuff to be * set from either a network connection or from some other class. This is the * AWT module. * * @.todo TextFields can tab out without triggering the action. * * @.requires Java 1.1.5. * @author David Seikel * @.copyright 1999 David Seikel * @version 0.72 alpha 2004-11-19 16:28:00 * * @.priority Portability - This will need to run on version 4 browsers. * @.priority Simplicity - All software should be as simple to use as possible for the target audience. * @.priority Robustness - Must never crash, and must warn the user if the various connections time out. * @.priority Safety - Privacy and cracking issues need to be taken into consideration. * @.priority Testability - This is a client / server type setup. Must be able to get them to run on the same computer to test. * @.priority Maintainability - Others will work on this one day. * @.priority Reusability - This is supposed to be as generic as possible. * @.priority Speed - There is no need for speed, only a need to keep CPU usage to a minimum while it is just ticking over. For the GUI, responsiveness is a major issue. End to end and back speed is important. * @.priority Size - All else being equal, smaller is better. */ public class SkangAWT extends Skang implements Runnable, ActionListener, WindowListener { public static void main(String someArguments[]) { ignoreBrowserBug = false; Skang.main(someArguments); } public void init() { //ERRLN("->SkangAWT.init() " + this.getClass().getName() + " " + What.me.inBrowser); // getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); // Speeds up Swing JApplets. frameDone = false; if (!areWe.servlet) { What.getGraphicStuff(); if (areWe.standAlone || (!What.isInBrowser)) { // Create Toplevel Window to contain the applet, default title is the name of the class. frame = new Frame(What.me.getClass().getName()); box = frame; frame.pack(); ourInsets = frame.getInsets(); frame.setBounds(new Rectangle(220, 190, ourInsets.left + ourInsets.right + 300, ourInsets.top + ourInsets.bottom + 100)); } else { frame = null; Container parent = What.me.getParent(); box = parent; while (parent != null) { try // to cast it to a frame. {frame = (Frame) parent;} catch (Exception e) {;} if (frame != null) break; parent = parent.getParent(); } ourInsets = frame.getInsets(); } if (box != null) { box.setCursor(new Cursor(Cursor.WAIT_CURSOR)); box.setLayout(null); // If you leave this out the controls will never go where you put them. box.setFont(What.ourFont); if (frame != null) { frame.removeWindowListener(this); new Widget(What.root, "main", 220, 190, 300, 100, What.me.getClass().getName(), frame, What.me); frame.addWindowListener(this); } if (areWe.standAlone || (!What.isInBrowser)) { box.setBackground(Color.green); What.isSplashing = true; } else { if (What.corporateShit) box.setBackground(Color.white); else box.setBackground(Color.black); } if (What.corporateShit) box.setForeground(Color.black); else box.setForeground(Color.white); int w, h, x, y; Rectangle rect = frame.getBounds(); w = rect.width - (ourInsets.left + ourInsets.right); h = rect.height - (ourInsets.top + ourInsets.bottom); x = (w - 150) / 2; y = h / 5; What.status1 = new Widget(What.root, "Status1", "", "5", "_5", "290", "0", "Label", "", null, this); What.status2 = new Widget(What.root, "Status2", "", "5", "_5", "290", "0", "Label", "", null, this); if (What.isSplashing) { What.status1.widget.setBackground(Color.green); What.status2.widget.setBackground(Color.green); } // reshape() is deprecated, but needed to get as far as complaining that the JVM is too old. if (splash1 == null) splash1 = new Label("Loading Skang file."); if (splash2 == null) splash2 = new Label(" Please wait."); box.add(splash1).reshape(ourInsets.left + x, ourInsets.top + (y * 1) - 10, 150, 19); box.add(splash2).reshape(ourInsets.left + x, ourInsets.top + (y * 2) - 10, 150, 19); box.add(What.status1.widget).reshape(ourInsets.left + 5, ourInsets.top + (y * 3) - 10, w - 10, 19); box.add(What.status2.widget).reshape(ourInsets.left + 5, ourInsets.top + (y * 4) - 10, w - 10, 19); box.setVisible(true); What.redirectAndWhinge(); box.validate(); What.doRedirect(); if (areWe.fuckedJava) // Braindead VM's may not run past this point. try {Thread.sleep(10000);} catch (Exception e) {;} else try {Thread.sleep(1000);} catch (Exception e) {;} } } super.init(); //pop.add(new MenuItem("Item 1")); //pop.add(new MenuItem("Item 2")); //pop.addSeparator(); //pop.add(new MenuItem("Item 3")); } public void initGUI() { Component contents[]; //ERRLN("->SkangAWT.initGUI()"); super.initGUI(); if (box != null) { if (frame != null) { contents = frame.getComponents(); for (int i = 0; i < contents.length; i++) { if (contents[i].getClass().getName().compareTo("java.awt.Label") == 0) box.remove(contents[i]); } if ((areWe.standAlone || (!What.isInBrowser)) && (frame != null)) frame.setBounds(new Rectangle(ourInsets.left + ourInsets.right + What.appletWidth, ourInsets.top + ourInsets.bottom + What.appletHeight)); } if (What.corporateShit) { box.setBackground(Color.white); box.setForeground(Color.black); } else { box.setBackground(Color.black); box.setForeground(Color.white); } box.validate(); box.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } // if (What.isSplashing) { if (What.corporateShit) { What.me.setBackground(Color.white); What.me.setForeground(Color.black); What.status1.widget.setBackground(Color.white); What.status2.widget.setBackground(Color.white); } else { What.me.setBackground(Color.black); What.me.setForeground(Color.white); What.status1.widget.setBackground(Color.black); What.status2.widget.setBackground(Color.black); } contents = What.me.getComponents(); for (int i = 0; i < contents.length; i++) contents[i].setVisible(true); } } public void runBit() { // Redirect out/err. What.doRedirect(); } /** * Called whenever your applet needs repainting. Only the widget looks * are handled here, all controls paint themselves. */ public void paint(Graphics g) { // Draw widget images. if (!areWe.stoping) { try { for (Enumeration things = Thing.elements(What.root, Widget.type); things.hasMoreElements();) { try { Leaf leaf = (Leaf) things.nextElement(); if (leaf != null) { if (leaf.getValue() instanceof Widget) { Widget widget = (Widget) leaf.getValue(); if (widget != null) { Image image = null; switch (widget.state) { case Widget.NORMAL : image = widget.normal; break; case Widget.GHOST : image = widget.ghost; break; case Widget.ACTIVE : image = widget.active; break; case Widget.TOGGLE : image = widget.toggle; break; } if ((image != null) && (widget.widget != null)) if (widget.widget.getGraphics() != null) { Graphics wGraphics = widget.widget.getGraphics(); wGraphics.setPaintMode(); if (What.corporateShit) { wGraphics.setColor(Color.white); wGraphics.fillRect(0, 0, widget.bounds.width, widget.bounds.height); wGraphics.drawImage(image, 2, 2, Color.black, this); } else { wGraphics.setColor(Color.black); wGraphics.fillRect(0, 0, widget.bounds.width, widget.bounds.height); wGraphics.setXORMode(Color.white); wGraphics.drawImage(image, 2, 2, this); } } } } } } catch (ClassCastException e) {;} } } // catch (ThingNotFoundException e1) // {;} catch (Exception e1) {e1.printStackTrace();} } super.paint(g); /* Paint the text labels. drawString() seems to have different origins compared to the controls, so I do +12 and +14. This could be more elegant. I can't use Labels here, because I want the background image to show thru. */ } //********************************************************************** /** Handle the actions of some widgets. */ public void actionPerformed(ActionEvent anEvent) { Object source = anEvent.getSource(); //ERRLN("IF " + anEvent.getID() + " == " + ActionEvent.ACTION_PERFORMED); //ERR("ACTION from " + source.getClass().getName() + " "); // Should see if I can get rid of this reference to Tree, it causes applets to download Tree.class when otherwise not needed. if (source instanceof Tree) { if (anEvent.getID() == ActionEvent.ACTION_PERFORMED) // Work around a browser bug. { //ERRLN("TREE - " + anEvent.getID() + ", " + anEvent.getActionCommand() + ", " + anEvent.getModifiers()); pendingDoThing(anEvent.getActionCommand()); } } else { //ERRLN("UNKNOWN - " + anEvent.getActionCommand()); pendingDoThing(anEvent.getActionCommand()); } } public void windowActivated(WindowEvent anEvent) { } public void windowClosed(WindowEvent anEvent) { } public void windowClosing(WindowEvent anEvent) { //ERRLN(this.getClass().getName() + " ->SkangAWT.windowClosing()"); if ((!areWe.standAlone) && (!What.isInBrowser) && (anEvent.getWindow() == frame)) { //OUTLN("!!! Application is ending!!!"); What.me.stop(); What.me.destroy(); } else if ((areWe.standAlone) && (anEvent.getWindow() == frame)) pendingDoThing("quit"); else { Enumeration panes = Thing.elements(What.root, Widget.type); while (panes.hasMoreElements()) { Leaf leaf = (Leaf) panes.nextElement(); if (leaf != null) { if (leaf.getValue() instanceof Widget) { Widget thing = (Widget) leaf.getValue(); try { Window window = (Window) thing.widget; if (window == anEvent.getWindow()) { //ERRLN(this.getClass().getName() + " ->SkangAWT.windowClosing() " + thing.name); try { hideAllWidgets(What.root, thing.name, "0", "0", "", ""); hideWidget(thing.name); } catch (Exception e) {;} if (thing.name.equals("main")) { //OUTLN("!!! Application is ending!!!"); } break; } } catch (Exception e) {;} } } } if (What.me != null) What.me.repaint(); } anEvent.getWindow().dispose(); } public void windowDeactivated(WindowEvent anEvent) { } public void windowDeiconified(WindowEvent anEvent) { } public void windowIconified(WindowEvent anEvent) { } public void windowOpened(WindowEvent anEvent) { } /****************************************************************************************************** Skang keywords. ******************************************************************************************************/ /** Set the alternative action for a widget. * * @.skang taction name,action */ public void tactionWidget(ThingSpace myRoot, String aName, String anAction) throws SkangException { //ERRLN("->SkangAWT.tactionWidget(" + aName + ", " + anAction + ") FOR " + this.getClass().getName()); Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); widget.setActions(null, anAction); } /** Set the action for a widget. * * @.skang action name,action */ public void actionWidget(ThingSpace myRoot, String aName, String anAction) throws SkangException { //ERRLN("->SkangAWT.actionWidget(" + aName + ", " + anAction + ") FOR " + this.getClass().getName()); Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); widget.setActions(anAction, null); } /** Add a pane to the current module. * * @.skang pane name,x,y,w,h,data */ public void addPane(ThingSpace myRoot, String aName, Integer anX, Integer anY, Integer aW, Integer aH, String aTitle) { addPane(myRoot, aName, anX.intValue(), anY.intValue(), aW.intValue(), aH.intValue(), aTitle); } public void addPane(ThingSpace myRoot, String aName, int anX, int anY, int aW, int aH, String aTitle) { Widget pane = new Widget(myRoot, aName, anX, anY, aW, aH, aTitle, null, What.me); if (areWe.servlet) appletPendingDoThing(myRoot, pane.tell); else ((Frame) pane.widget).addWindowListener(this); // Should move the window listener stuff into Pane (Widget, Pane no longer exists). } /** Add a widget to the current skin. * * @.skang widget name,type,lx,ly,lw,lh,data,data */ public void addWidget(ThingSpace myRoot, String aName, String aType, String anX, String anY, String aW, String aH, Integer aValue) { addWidget(myRoot, aName, aType, anX, anY, aW, aH, aValue.toString(), null); } public void addWidget(ThingSpace myRoot, String aName, String aType, String anX, String anY, String aW, String aH, Integer aValue, String anACL) { addWidget(myRoot, aName, aType, anX, anY, aW, aH, aValue.toString(), anACL); } public void addWidget(ThingSpace myRoot, String aName, String aType, String anX, String anY, String aW, String aH) { addWidget(myRoot, aName, aType, anX, anY, aW, aH, (String) null, null); } public void addWidget(ThingSpace myRoot, String aName, String aType, String anX, String anY, String aW, String aH, String aValue) { addWidget(myRoot, aName, aType, anX, anY, aW, aH, aValue.toString(), null); } public void addWidget(ThingSpace myRoot, String aName, String aType, String anX, String anY, String aW, String aH, String aValue, String anACL) { //ERRLN("->SkangAWT.addWidget(" + aName + ") FOR " + this.getClass().getName()); String paneName = null; int pos = aName.indexOf('.'); Widget pane = null; if (pos != -1) { paneName = aName.substring(0, pos); try {pane = Widget.getPane(paneName);} catch (Exception e) {;} } try { Widget widget = new Widget(myRoot, aName, aValue, anX, anY, aW, aH, aType, "", anACL, What.me); try { try { if (checkBoxGroupCount > 0) { // If it's not a Checkbox, this will Except out. ((Checkbox) (widget.widget)).setCheckboxGroup(ourCheckBoxGroup); checkBoxGroupCount--; } } catch (Exception e1) {;} // Should also check if this is a stub, coz applet already has this widget. if (areWe.servlet) ;// appletPendingDoThing(myRoot, widget.tell); else { //if (widget.isSwing) //What.me.getContentPane().add(widget.widget).setBounds(widget.bounds); //else int index = -1; if (areWe.useWinblows) // Winblows completely ignores this anyway. index = 0; if (What.isSplashing) widget.widget.setVisible(false); if (pane == null) What.me.add(widget.widget, index).setBounds(widget.bounds); else ((Container) pane.widget).add(widget.widget, index).setBounds(new Rectangle( pane.insets.left + widget.bounds.x, pane.insets.top + widget.bounds.y, widget.bounds.width, widget.bounds.height)); if (widget.isUnknown) widget.widget.setBackground(Color.red); } } catch (Exception e) {ERRLN("Adding widget " + aName + " " + e.toString());} } catch (NullPointerException e) {ERRLN("NullPointer during addWidget " + e.toString());} } /** Make the next 'number' Checkboxes part of a check box group. * * @.skang checkboxgroup number */ public void checkBoxGroup(Integer aNumber) { checkBoxGroup(aNumber.intValue()); } public void checkBoxGroup(int aNumber) { if (!areWe.servlet) ourCheckBoxGroup = new CheckboxGroup(); checkBoxGroupCount = aNumber; } /** The current skin is cleared of all widgets. * * @.skang clear */ public void clearWidgets(ThingSpace myRoot) { try { if ((!areWe.servlet) && (What.me != null)) What.me.setVisible(false); for (Enumeration things = Thing.elements(myRoot, Widget.type); things.hasMoreElements();) { try { Leaf leaf = (Leaf) things.nextElement(); if (leaf != null) { if (leaf.getValue() instanceof Widget) { Widget widget = (Widget) leaf.getValue(); // Don't clear the main window. if (!((widget.widget instanceof Window) && (widget.name.equals("main")))) { //ERRLN("->clearWidgets() " + widget.name); widget.myRoot.get(Widget.type.toUpperCase()).up().pluck(widget.name); widget.myRoot.pluck(widget.name.replace('.', '_')); } } } } catch (Exception e) {;} } if ((!areWe.servlet) && (What.me != null)) What.me.setVisible(true); System.runFinalization(); System.gc(); } catch (Exception e) {What.ERRLN("SkangAWT.clear(" + myRoot + ") " + e.toString() + " :-: " + e.getMessage()); e.printStackTrace();} } /** Set widget's background and foreground colour. * * @.skang colour name,r,g,b,alpha,r,g,b,alpha * @.secure GGG */ public void colourWidget(String aName, Integer aBackgroundRed, Integer aBackgroundGreen, Integer aBackgroundBlue, Integer aBackgroundAlpha, Integer aForegroundRed, Integer aForegroundGreen, Integer aForegroundBlue, Integer aForegroundAlpha) throws SkangException { colourWidget(aName, aBackgroundRed.intValue(), aBackgroundGreen.intValue(), aBackgroundBlue.intValue(), aBackgroundAlpha.intValue(), aForegroundRed.intValue(), aForegroundGreen.intValue(), aForegroundBlue.intValue(), aForegroundAlpha.intValue()); } public void colourWidget(String aName, int aBackgroundRed, int aBackgroundGreen, int aBackgroundBlue, int aBackgroundAlpha, int aForegroundRed, int aForegroundGreen, int aForegroundBlue, int aForegroundAlpha) throws SkangException { Widget widget = Widget.getWidget(aName); // Java 1.1.5 doesn't do alpha channels, so figure out how to fake it later. // It can sorta be faked with XOR, see NAWS.UberMatrix. widget.colour(true, aBackgroundRed, aBackgroundGreen, aBackgroundBlue,aBackgroundAlpha, aForegroundRed, aForegroundGreen, aForegroundBlue, aForegroundAlpha); } /** Do a widgets action. * * @.skang doaction name * @.secure GGG */ public void doWidget(String aName) throws SkangException { Widget widget = Widget.getWidget(aName); widget.doAction(widget.widget); } /** Disable a widget. * * @.skang disable name * @.secure GGG */ public void disableWidget(String aName) throws SkangException { Widget widget = Widget.getWidget(aName); if (widget.ghost != null) widget.state = Widget.GHOST; else widget.widget.setEnabled(false); paint(What.me.getGraphics()); } /** Enable a widget. * * @.skang enable name * @.secure GGG */ public void enableWidget(String aName) throws SkangException { Widget widget = Widget.getWidget(aName); if (widget.ghost != null) widget.state = Widget.NORMAL; else widget.widget.setEnabled(true); paint(What.me.getGraphics()); } /** Hide a widget. * * @.skang hide name * @.secure GGG */ public void hideWidget(String aName) throws SkangException { Widget widget = Widget.getWidget(aName); if (!What.servlet) { try { Window aWindow = (Window) widget.widget; aWindow.hide(); } catch (Exception e) {widget.widget.setVisible(false);} } widget.closed = true; } /** Hide all widgets. * * @.skang hideall name,lx,ly,lw,lh * @.secure GGG */ public void hideAllWidgets(ThingSpace myRoot, String pane, String anX, String anY, String aW, String aH) { Widget panel = null; try {panel = Widget.getPane(pane);} catch (Exception e) {;} if ((aW == null) || (aW.equals(""))) aW = "" + panel.bounds.width; if ((aH == null) || (aH.equals(""))) aH = "" + panel.bounds.height; Rectangle bounds = Widget.setRectangle(null, anX, anY, aW, aH, panel); for (Enumeration things = Thing.elements(myRoot, Widget.type); things.hasMoreElements();) { try { Leaf leaf = (Leaf) things.nextElement(); if (leaf != null) { if (leaf.getValue() instanceof Widget) { Widget widget = (Widget) leaf.getValue(); // Don't hide anything in other panes, outside the bounds, or the main window. if (((panel == null) || (panel == widget.panel)) // Damn, the documentations says this exists in Java 1.1 // (bounds.contains(widget.bounds.x, widget.bounds.y, widget.bounds.width, widget.bounds.height)) // Instead, I check if both corners are inside bounds. && (bounds.contains(widget.bounds.x, widget.bounds.y) && bounds.contains(widget.bounds.x + widget.bounds.width, widget.bounds.y + widget.bounds.height)) && !((widget.widget instanceof Window) && (widget.name.equals("main")))) { //ERRLN("->hideAllWidgets() " + widget.name); if (!What.servlet) { try { Window aWindow = (Window) widget.widget; aWindow.hide(); } catch (Exception e) {widget.widget.setVisible(false);} } widget.closed = true; } } } } catch (Exception e) {;} } } /** Set the current look of an existing widget. * * @.skang look name,normal,ghost,active,toggle * @.secure GGG */ public void lookWidget(String aName, String aNormal) throws SkangException { lookWidget(aName, aNormal, null, null, null); } public void lookWidget(String aName, String aNormal, String aGhost) throws SkangException { lookWidget(aName, aNormal, aGhost, null, null); } public void lookWidget(String aName, String aNormal, String aGhost, String anActive) throws SkangException { lookWidget(aName, aNormal, aGhost, anActive, null); } public void lookWidget(String aName, String aNormal, String aGhost, String anActive, String aToggle) throws SkangException { //ERRLN("->lookWidget(" + aName + ", " + aNormal + ", " + aGhost + ", " + anActive + ", " + aToggle + ", " + ")"); if (!areWe.servlet) { Widget widget = Widget.getWidget(aName); if (aNormal != null) { widget.normal = What.getImage("docs/images/" + aNormal); widget.widget.prepareImage(widget.normal, this); } if (aGhost != null) { widget.ghost = What.getImage("docs/images/" + aGhost); widget.widget.prepareImage(widget.ghost, this); } if (anActive != null) { widget.active = What.getImage("docs/images/" + anActive); widget.widget.prepareImage(widget.active, this); } if (aToggle != null) { widget.toggle = What.getImage("docs/images/" + aToggle); widget.widget.prepareImage(widget.toggle, this); } paint(getGraphics()); } } /** Set the mask for a widget. * * @.skang mask name,data */ public void maskWidget(String aName, String aMask) throws SkangException { Widget.getWidget(aName).setMask(aMask); } /** Do something on mouse hover. * * @.skang onmouse name,data */ public void onMouse(String aName, String anAction) throws SkangException { Widget.getWidget(aName).setOnMouse(anAction); } /** Do something off mouse hover. * * @.skang offmouse name,data */ public void offMouse(String aName, String anAction) throws SkangException { Widget.getWidget(aName).setOffMouse(anAction); } /** Create a popup. * * @.skang popup name,data,data,data,data * @.secure GGG */ public void popupWidget(String aTitle, String aMessage) { popupWidget(aTitle, aMessage, null, null, null); } public void popupWidget(String aTitle, String aMessage, String anotherMessage) { popupWidget(aTitle, aMessage, anotherMessage, null, null); } public void popupWidget(String aTitle, String aMessage, String anotherMessage, String anOKAction, String aCancelAction) { if (!areWe.servlet) { PopUp popup = new PopUp(What.me, aTitle, aMessage, anotherMessage, anOKAction, aCancelAction); popup.addActionListener((ActionListener) this); } } /** Make a widget read only. * * @.skang readonly name * @.secure GGG */ public void readOnlyWidget(String aName) throws SkangException { Widget widget = Widget.getWidget(aName); if (widget.widget instanceof TextComponent) ((TextComponent) widget.widget).setEditable(false); } /** Make a widget write only. * * @.skang writeonly name * @.secure GGG */ public void writeOnlyWidget(String aName) throws SkangException { Widget widget = Widget.getWidget(aName); if (widget.widget instanceof TextField) ((TextField) widget.widget).setEchoChar('*'); } /** Give me the developers menu. * * @.skang satori x,y * @.secure GGG */ public void satori(ThingSpace myRoot, Integer x, Integer y) { satori(myRoot, x.intValue(), y.intValue()); } public void satori(ThingSpace myRoot, int x, int y) { String developmentModule = "net.matrix_rad.zen.Developer"; boolean notDone = true; int tries = 0; do { try { Module devel = Module.getModule(developmentModule); setThing("developerx", "" + x); setThing("developery", "" + y); setThing("module", What.me.getClass().getName()); if (tries > 0) { Skang module = devel.module; if (module != null) { module.initGUI(); pause(50); } } else pendingDoThing("developmenu"); Widget pane = Widget.getPane("developer"); pane.bounds.x = x; pane.bounds.y = y; ((Frame) pane.widget).setBounds(new Rectangle(pane.bounds.x, pane.bounds.y, pane.insets.left + pane.insets.right + pane.bounds.width, pane.insets.top + pane.insets.bottom + pane.bounds.height)); notDone = false; } catch (ThingNotFoundException e) { if (tries == 0) addModule(myRoot, developmentModule, "rwx~,rwx"); pause(50); } tries++; if (tries > 10) // Safety valve. break; } while (notDone); } /** Show user login window. * * @.skang showloginwindow * @.secure GGG */ public void showLoginWindow(ThingSpace myRoot) throws SkangException { if (!What.useSecurity) return; if (areWe.servlet) { // Should get the applet to show the login window. return; } String loginModule = "net.matrix_rad.security.Who"; boolean notDone = true; int tries = 0; do { try { Module login = Module.getModule(loginModule); if (tries > 0) { Skang module = login.module; if (module != null) { module.initGUI(); pause(50); } } hideWidget("developer"); showWidget("Who"); notDone = false; } catch (ThingNotFoundException e) { if (tries == 0) addModule(myRoot, loginModule, "rwx~,rwx"); pause(50); } tries++; if (tries > 10) // Safety valve. break; } while (notDone); } /** Show a widget. * * @.skang show name * @.secure GGG */ public void showWidget(String aName) throws SkangException { Widget widget = Widget.getWidget(aName); if (!What.servlet) { try { Window aWindow = (Window) widget.widget; aWindow.show(); } catch (Exception e) { widget.widget.invalidate(); widget.widget.validate(); widget.widget.setVisible(true); } } widget.closed = false; } /** Specifies the size and title of the application Frame. * * @.skang window x,y,name * @.secure GGG */ public void setSkangFrame(Integer aW, Integer aH, String aTitle) { setSkangFrame(aW.intValue(), aH.intValue(), aTitle); } public void setSkangFrame(int aW, int aH, String aTitle) { //ERRLN(What.me.getClass().getName() + " ->SkangAWT.setSkangFrame()"); What.appletWidth = aW; What.appletHeight = aH; What.title = aTitle; if (areWe.servlet) return; /* A word about frames. According to the documentation, browsers are the "frame" for applets, yet according to my experiments, the browser "frame" is not a real Java Frame, and cannot be cast to a Frame. The main problem with Java is that you can't hack around such a dilema. This is a problem, because Dialogs can be made modal, but only with respect to their Frame, and you can't get a valid Frame from an applet. What I do here is create a dummy frame, so at least I have a Frame to pass to dialogs, even if the Dialogs can't be modal to the applet. Frames and Dialogs are both subclasses of Window, which in turn is a subclass of Container. Applet is a subclass of Panel, which is a subclass of Container. Windows are automatically modal, but only to their Frame. Dialogs are optionally modal to their Frame, and Frames are never modal. Windows, Frames and Dialogs are "top level windows", meaning that they are seperate windows from the applet, implemented as standard OS windows. There was probably a good reason why Dialogs need a Frame instead of a Container, but I don't know what it is. It probably has something to do with one or more of the things mentioned in this paragraph. This leaves us with two choices for making popups modal. Have the applet do very little other than open a Frame then displaying everything in it, or write stuff to keep track of modality within tha applet (could be very difficult). Method one has a lot going for it, even though the Frame will not be modal to the applet running in the browser. Educated guess :- Java Windows could be created as child microsoft windows of the microsoft window that started the Java VM. This would explain why when you close anything subclassed from a Java Window, it brings to the front almost any microsoft window other than the one with the applet in it. All Dialogs have been converted to Panels, as this avoids all problems but the modal problem. On the other hand, an applet probably has something that can be cast to a frame somewhere in it's container hierarchy, so now I search for it. */ if (!frameDone) { //ERRLN(What.me.getClass().getName() + " ->SkangAWT.setSkangFrame() - !frameDone"); if (areWe.standAlone || (!What.isInBrowser)) { frame.setLayout(new BorderLayout()); frame.add("Center", What.me); } else { //ERRLN(What.me.getClass().getName() + " ->SkangAWT.setSkangFrame() - !standAlone"); // Applets can't really be resized, cause HTML knows the size from the web page, and allocates space before running the applet. Rectangle rect = What.me.getBounds(); What.appletWidth = rect.width; What.appletHeight = rect.height; } //ERRLN(What.me.getClass().getName() + " ->SkangAWT.setSkangFrame() - common"); What.me.setLayout(null); } frameDone = true; if (areWe.standAlone || (!What.isInBrowser)) { frame.setTitle(What.title); ourInsets = frame.getInsets(); // frame.setBounds(new Rectangle(ourInsets.left + ourInsets.right + What.appletWidth, ourInsets.top + ourInsets.bottom + What.appletHeight)); What.me.setBounds(new Rectangle(ourInsets.left, ourInsets.top, What.appletWidth, What.appletHeight)); } if (!What.isSplashing) { if (What.corporateShit) { What.me.setBackground(Color.white); What.me.setForeground(Color.black); } else { What.me.setBackground(Color.black); What.me.setForeground(Color.white); } } try { Widget pane = Widget.getPane("main"); pane.bounds.width = What.appletWidth; pane.bounds.height = What.appletHeight; pane.insets = ((Frame) pane.widget).getInsets(); } catch (ThingNotFoundException e) { // if (frame != null) // { // frame.removeWindowListener(this); // new Widget(myRoot, "main", 220, 190, 300, 100, What.me.getClass().getName(), frame, What.me); // frame.addWindowListener(this); // } ; } //ERRLN(What.me.getClass().getName() + " ->SkangAWT.setSkangFrame() - end"); } /** Set the stuff for a widget's pane. * * @.skang stuff name,data */ public void stuffWidget(String aName, String aStuff) throws SkangException { Widget.getWidget(aName).setStuff(aStuff); } /** Set the stufflet for a widget. * * @.skang stufflet name,data,data */ public void stuffWidget(ThingSpace myRoot, String aName, String aStuff, String aStufflet) throws SkangException { Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); widget.setStufflet(aStuff, aStufflet); } /** List the stuff in this widget. * * @.skang stufflist name,data */ public void stuffListWidget(ThingSpace myRoot, String aName, String aStuff) throws SkangException { Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); widget.listStuff(aStuff); } /** Load the stuff for a widget. * * @.skang stuffload name,data,data */ public void stuffLoadWidget(ThingSpace myRoot, String aName, String aStuff, String aKey) throws SkangException { Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); widget.loadStuff(aStuff, aKey); } /** Save the stuff for a widget. * * @.skang stuffsave name,data,data */ public void stuffSaveWidget(ThingSpace myRoot, String aName, String aStuff, String aKey) throws SkangException { Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); widget.saveStuff(aStuff, aKey); } /** Delete the stuff for a widget. * * @.skang stuffdelete name,data,data * @.secure SSS */ public void stuffDeleteWidget(ThingSpace myRoot, String aName, String aStuff, String aKey) throws SkangException { Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); widget.deleteStuff(aStuff, aKey); } /** Clear the stuff for a widget. * * @.skang stuffclear name,data * @.secure SSS */ public void stuffClearWidget(String aName, String aStuff) throws SkangException { Widget.getWidget(aName).clearStuff(aStuff); } /** Copy Grid row to matching widgets. * * @.skang rowtowidgets name */ public void rowToWidgets(ThingSpace myRoot, String aName) throws SkangException { Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); try { Grid grid = (Grid) widget.widget; String[] row = grid.getSelectedRow(); String[] headings = grid.getHead(); for (int i = 0; i < headings.length; i++) { try { Widget match = (Widget) Widget.get(myRoot, headings[i], Widget.type); match.setText(row[i]); } catch (Exception e) {;} } } catch (Exception e) {;} } /** Copy matching widgets to Grid row. * * skang widgetstorow name,boolean * @.skang widgetstorow name,data */ public void widgetsToRow(ThingSpace myRoot, String aName, String doNewRow) throws SkangException { widgetsToRow(myRoot, aName, What.isBoolean(doNewRow).booleanValue()); } public void widgetsToRow(ThingSpace myRoot, String aName, boolean doNewRow) throws SkangException { //ERRLN(What.me.getClass().getName() + " ->SkangAWT.widgetsToRow(" + myRoot + ", " + aName + ", " + doNewRow + ")"); Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); try { Grid grid = (Grid) widget.widget; String[] headings = grid.getHead(); String[] row = new String[headings.length]; for (int i = 0; i < headings.length; i++) { try { row[i] = What.me.getThing(myRoot, headings[i]); } catch (Exception e) { // Something wrong with the Thing. // Should complain and things (see TODO.html). row[i] = ""; e.printStackTrace(); } } if (doNewRow) grid.addRow(row); else grid.setSelectedRow(row); grid.repaint(); } catch (Exception e) { e.printStackTrace(); } // Then marks that row for insert / update. } /** Clear Grid row and matching widgets. * * @.skang clearrow name */ public void clearRow(ThingSpace myRoot, String aName) throws SkangException { Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); // Make it easy to recover. rowToWidgets(myRoot, aName); try { Grid grid = (Grid) widget.widget; // String[] headings = grid.getHead(); // String[] row = new String[headings.length]; // for (int i = 0; i < headings.length; i++) // row[i] = ""; // grid.setSelectedRow(row); grid.removeSelectedRow(); grid.clearSelections(); grid.repaint(); } catch (Exception e) {;} // And marks the record for deletion. } /** Clear only the Grid row matching widgets. * * @.skang clearrowwidgets name */ public void clearRowWidgets(ThingSpace myRoot, String aName) throws SkangException { Widget widget = (Widget) Widget.get(myRoot, aName, Widget.type); try { Grid grid = (Grid) widget.widget; String[] headings = grid.getHead(); for (int i = 0; i < headings.length; i++) { try { Widget match = (Widget) Widget.get(myRoot, headings[i], Widget.type); match.setText(""); } catch (Exception e) {;} } grid.clearSelections(); grid.repaint(); } catch (Exception e) {;} } //********************************************************************** // private ActionEvent lastEvent = null; private boolean frameDone = false; private Frame frame = null; // Our background frame. private Container box = null; // Our background frame / panel. private Insets ourInsets = null; private Label splash1 = null; private Label splash2 = null; private int checkBoxGroupCount = 0; private CheckboxGroup ourCheckBoxGroup = null; // private PopupMenu pop = new PopupMenu("Test menu"); }