-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppleFoundationClasses.java
609 lines (545 loc) · 15 KB
/
AppleFoundationClasses.java
1
import java.awt.*;import java.applet.*;import java.lang.*;import java.util.*;import java.awt.image.*;public class AppleFoundationClasses extends Object{ MAE theApplet; Desktop theDesktop; Application theApplication; Frame theFrame; Image zoomImage,closeImage,clickedImage,growImage; private Vector NewEventQueue = new Vector(); public Vector theWindows = new Vector(); public NewMenuBar theMenuBar; private long initialTime; public short xMousePos = 0; public short yMousePos = 0; public boolean mouseDown = false; public boolean insideApplet = false; public boolean keydown = false; private AudioClip beep; private static final byte pixels1[] = { 0,0,0,0,0,0,0,0,0,0,0, 0,1,1,1,1,1,1,1,1,1,1, 0,1,2,2,2,2,0,2,2,0,1, 0,1,2,2,2,2,0,2,2,0,1, 0,1,2,2,2,2,0,2,2,0,1, 0,1,2,2,2,2,0,2,2,0,1, 0,1,0,0,0,0,0,2,2,0,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,0,0,0,0,0,0,0,0,1, 0,1,1,1,1,1,1,1,1,1,1 }; private static final byte rbmap1[] = {(byte)0x31,(byte)0xCE,(byte)0xA5}; private static final byte gbmap1[] = {(byte)0x31,(byte)0xCE,(byte)0xA5}; private static final byte bbmap1[] = {(byte)0x63,(byte)0xFF,(byte)0xA5}; private static final byte pixels2[] = { 0,0,0,0,0,0,0,0,0,0,0, 0,1,1,1,1,0,1,1,1,1,0, 0,1,0,1,1,0,1,1,0,1,0, 0,1,1,0,1,0,1,0,1,1,0, 0,1,1,1,1,1,1,1,1,1,0, 0,0,0,0,1,1,1,0,0,0,0, 0,1,1,1,1,1,1,1,1,1,0, 0,1,1,0,1,0,1,0,1,1,0, 0,1,0,1,1,0,1,1,0,1,0, 0,1,1,1,1,0,1,1,1,1,0, 0,0,0,0,0,0,0,0,0,0,0 }; private static final byte rbmap2[] = {(byte)0x00,(byte)0x7A}; private static final byte gbmap2[] = {(byte)0x00,(byte)0x7A}; private static final byte bbmap2[] = {(byte)0x00,(byte)0x9C}; private static final byte pixels3[] = { 0,0,0,0,0,0,0,0,0,0,0, 0,1,1,1,1,1,1,1,1,1,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,2,2,2,2,2,2,2,0,1, 0,1,0,0,0,0,0,0,0,0,1, 0,1,1,1,1,1,1,1,1,1,1 }; private static final byte rbmap3[] = {(byte)0x31,(byte)0xCE,(byte)0xA5}; private static final byte gbmap3[] = {(byte)0x31,(byte)0xCE,(byte)0xA5}; private static final byte bbmap3[] = {(byte)0x63,(byte)0xFF,(byte)0xA5}; private static final byte pixels4[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,1,1,1,1,1,1,0,0,0,0,0,0, 0,0,1,2,2,2,2,2,1,1,1,1,0,0, 0,0,1,2,3,3,3,1,2,2,2,2,0,0, 0,0,1,2,3,3,3,1,4,4,4,1,0,0, 0,0,1,2,3,3,3,1,4,4,4,1,0,0, 0,0,1,2,1,1,1,1,4,4,4,1,0,0, 0,0,0,1,2,4,4,4,4,4,4,1,0,0, 0,0,0,1,2,4,4,4,4,4,4,1,0,0, 0,0,0,1,2,4,4,4,4,4,4,1,0,0, 0,0,0,1,2,1,1,1,1,1,1,1,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; private static final byte rbmap4[] = {(byte)0xEF,(byte)0x31,(byte)0xCE,(byte)0xBD,(byte)0xA5}; private static final byte gbmap4[] = {(byte)0xEF,(byte)0x31,(byte)0xCE,(byte)0xBD,(byte)0xA5}; private static final byte bbmap4[] = {(byte)0xEF,(byte)0x63,(byte)0xFF,(byte)0xBD,(byte)0xA5}; public AppleFoundationClasses(Application application) { IndexColorModel model; theDesktop = application.theDesktop; theMenuBar = application.theMenuBar; theFrame = application.theApplet.theFrame; initialTime = System.currentTimeMillis(); theApplet = application.theApplet; model = new IndexColorModel(2,3,rbmap1,gbmap1,bbmap1,4); zoomImage = theApplet.createImage(new MemoryImageSource(11,11,model,pixels1,0,11)); model = new IndexColorModel(2,3,rbmap3,gbmap3,bbmap3,4); closeImage = theApplet.createImage(new MemoryImageSource(11,11,model,pixels3,0,11)); model = new IndexColorModel(1,2,rbmap2,gbmap2,bbmap2,3); clickedImage = theApplet.createImage(new MemoryImageSource(11,11,model,pixels2,0,11)); model = new IndexColorModel(3,5,rbmap4,gbmap4,bbmap4,6); growImage = theApplet.createImage(new MemoryImageSource(14,14,model,pixels4,0,14)); beep = theApplet.getAudioClip(theApplet.getDocumentBase(),"Sosumi.au"); } // Event Manager public NewEvent EventAvail(short eventMask) { int i; NewEvent Temp; i = 0; while (i < NewEventQueue.size()) { Temp = (NewEvent)NewEventQueue.elementAt(i); if (((short)Math.pow(2,(double)Temp.what) & eventMask) != 0) return Temp; i++; } return null; } public NewEvent GetNextEvent(short eventMask) { int i; NewEvent Temp; i = 0; while (i < NewEventQueue.size()) { Temp = (NewEvent)NewEventQueue.elementAt(i); if (((short)Math.pow(2,(double)Temp.what) & eventMask) != 0) { NewEventQueue.removeElementAt(i); return Temp; } i++; } return null; } public void FlushEvents(short whichMask,short stopMask) { int i; NewEvent Temp; i = 0; while (i < NewEventQueue.size()) { Temp = (NewEvent)NewEventQueue.elementAt(i); if (((short)Math.pow(2,(double)Temp.what) & stopMask) != 0) return; if (((short)Math.pow(2,(double)Temp.what) & whichMask) != 0) NewEventQueue.removeElementAt(i); i++; } } public void PostNewEvent(short whatEvent) { NewEvent theEvent; theEvent = new NewEvent((int)whatEvent); theEvent.x = xMousePos; theEvent.y = yMousePos; theEvent.when = TickCount(); if (NewEventQueue.size() == 40) NewEventQueue.removeElementAt(0); NewEventQueue.addElement(theEvent); } public void PostNewEvent(short whatEvent, int key) { NewEvent theEvent; theEvent = new NewEvent((int)whatEvent); theEvent.message = key; theEvent.when = TickCount(); if (NewEventQueue.size() == 40) NewEventQueue.removeElementAt(0); NewEventQueue.addElement(theEvent); } public Point GetMouse() { return new Point(xMousePos,yMousePos); } public boolean StillDown() { return mouseDown; } public boolean WaitMouseUp() { int i; NewEvent Temp; i = 0; while (i < NewEventQueue.size()) { Temp = (NewEvent)NewEventQueue.elementAt(i); if (((short)Math.pow(2,(double)Temp.what) & 4) != 0) // Mouse up event mask { NewEventQueue.removeElementAt(i); return true; } i++; } return false; } public long TickCount() { return System.currentTimeMillis() - initialTime; } public long GetDblTime() { return (long)1000; } public long GetCaretTime() { return (long)1000; }// Window Manager public FindWindowResult FindWindow(int x,int y) { int i; NewWindow Temp; Enumeration e; Control TempControl; if (y<theMenuBar.MenuBarHeight()) return new FindWindowResult(1); i = theWindows.size(); while (i>0) { Temp = (NewWindow)theWindows.elementAt(i-1); if (Temp.inWindow(x,y)) { if (Temp.highlighted) { x -= Temp.xPos; y -= Temp.yPos; if (Temp.zoombox & x>=Temp.zoomRect.x & x<Temp.zoomRect.x+Temp.zoomRect.width & y>=Temp.zoomRect.y & y<Temp.zoomRect.y+Temp.zoomRect.height) { if (Temp.xPos==Temp.stdState.x & Temp.yPos==Temp.stdState.y & Temp.width==Temp.stdState.width-Temp.stdState.x+1 & Temp.height==Temp.stdState.height-Temp.stdState.y+1) return new FindWindowResult(8,Temp); else return new FindWindowResult(7,Temp); } if (Temp.closebox & x>=Temp.closeRect.x & x<Temp.closeRect.x+Temp.closeRect.width & y>=Temp.closeRect.y & y<Temp.closeRect.y+Temp.closeRect.height) return new FindWindowResult(6,Temp); if (Temp.growbox & x>=Temp.growRect.x & x<Temp.growRect.x+Temp.growRect.width & y>=Temp.growRect.y & y<Temp.growRect.y+Temp.growRect.height) return new FindWindowResult(5,Temp); if (Temp.drag & y<18) return new FindWindowResult(4,Temp); else return new FindWindowResult(3,Temp); } else return new FindWindowResult(3,Temp); } i--; } return new FindWindowResult(0); } public boolean TrackBox(NewWindow theWindow,int x,int y,int partCode) { boolean isSet = false; Graphics g; g = theDesktop.getGraphics(); if (!theWindow.zoombox) return false; else { do { x -= theWindow.xPos; y -= theWindow.yPos; if (x >= theWindow.zoomRect.x & x < theWindow.zoomRect.x + theWindow.zoomRect.width & y >= theWindow.zoomRect.y & y < theWindow.zoomRect.y + theWindow.zoomRect.height) { if (!isSet) { g.drawImage(clickedImage,theWindow.zoomRect.x+theWindow.xPos,theWindow.zoomRect.y+theWindow.yPos,null); isSet = true; } } else { if (isSet) { g.drawImage(zoomImage,theWindow.zoomRect.x+theWindow.xPos,theWindow.zoomRect.y+theWindow.yPos,null); isSet = false; } } x = xMousePos; y = yMousePos; } while (!WaitMouseUp()); g.drawImage(zoomImage,theWindow.zoomRect.x+theWindow.xPos,theWindow.zoomRect.y+theWindow.yPos,null); return isSet; } } public boolean TrackGoAway(NewWindow theWindow,int x,int y,int partCode) { boolean isSet = false; Graphics g; g = theDesktop.getGraphics(); if (!theWindow.closebox) return false; else { do { x -= theWindow.xPos; y -= theWindow.yPos; if (x >= theWindow.closeRect.x & x < theWindow.closeRect.x + theWindow.closeRect.width & y >= theWindow.closeRect.y & y < theWindow.closeRect.y + theWindow.closeRect.height) { if (!isSet) { g.drawImage(clickedImage,theWindow.closeRect.x+theWindow.xPos,theWindow.closeRect.y+theWindow.yPos,null); isSet = true; } } else { if (isSet) { g.drawImage(closeImage,theWindow.closeRect.x+theWindow.xPos,theWindow.closeRect.y+theWindow.yPos,null); isSet = false; } } x = xMousePos; y = yMousePos; } while (!WaitMouseUp()); g.drawImage(closeImage,theWindow.closeRect.x+theWindow.xPos,theWindow.closeRect.y+theWindow.yPos,null); return isSet; } } public NewWindow FrontWindow() { int i; NewWindow Temp; i = theWindows.size(); while (i>0) { Temp = (NewWindow)theWindows.elementAt(i-1); if (Temp.visible) return Temp; i--; } return null; } public void NewWindow(int x1,int y1,int x2,int y2,String title,boolean visible, NewWindow theWindow,NewWindow behind,boolean goAwayFlag,int refCon) { Enumeration e; NewWindow Temp; int i = 0; if (behind == null) { if (visible) { Temp = FrontWindow(); if (Temp != null) { Temp.HiliteWindow(false); Temp.Deactivate(); } theWindow.highlighted = true; } else theWindow.highlighted = false; theWindows.addElement(theWindow); theWindow.Add2Desktop(title,x1,y1,x2-x1,y2-y1,visible,goAwayFlag,theDesktop,theApplet,refCon); } else { e = theWindows.elements(); while (e.hasMoreElements()) { Temp = (NewWindow)e.nextElement(); if (Temp == behind) { theWindows.insertElementAt(theWindow,i); theWindow.highlighted = false; theWindow.Add2Desktop(title,x1,y1,x2-x1,y2-y1,visible,goAwayFlag,theDesktop,theApplet,refCon); break; } i++; } if (theWindows.size() == i) // Windows is in front after all... { if (visible) { Temp = FrontWindow(); if (Temp != null) { Temp.HiliteWindow(false); Temp.Deactivate(); } theWindow.highlighted = true; } else theWindow.highlighted = false; theWindows.addElement(theWindow); theWindow.Add2Desktop(title,x1,y1,x2-x1,y2-y1,visible,goAwayFlag,theDesktop,theApplet,refCon); } else // Redraw all windows that are oon top of the inserted window { if (visible) { for (i += 1;i<theWindows.size();i++) { Temp = (NewWindow)theWindows.elementAt(i); Temp.Redraw(); } } } } if (visible) { theMenuBar.Redraw(); redrawDesktop(); } }// Dialog Manager public void Alert(String theString, int theIcon, int DialogWidth) { int maxWidth,LineWidth,TempWidth,DialogHeight,Lines,i; FontMetrics fm; AlertWindow theWindow; StringTokenizer StringCopy = new StringTokenizer(theString," ",true); StringBuffer Line = new StringBuffer(); String Word; Font helvFont = new Font("Helvetica", Font.BOLD, 12); NewEvent theEvent; FindWindowResult theResult; FindControlResult result2; Point location; boolean waitMore = true; NewButton theButton; theWindow = new AlertWindow(theString,theIcon); maxWidth = DialogWidth - 36; if (theIcon != 0) maxWidth = maxWidth - 65; if (maxWidth < 150) { DialogWidth = DialogWidth + (150 - maxWidth); maxWidth = 150; } theDesktop.offScreenImageGC.setFont(helvFont); fm = theDesktop.offScreenImageGC.getFontMetrics(theDesktop.offScreenImageGC.getFont()); LineWidth = 0; Lines = 0; while (StringCopy.hasMoreTokens()) { Word = StringCopy.nextToken(); TempWidth = fm.stringWidth(Word); if (LineWidth + TempWidth > maxWidth) { theWindow.Lines.addElement(Line.toString()); Lines = Lines + 1; Line = new StringBuffer(Word); LineWidth = TempWidth; } else { Line.append(Word); LineWidth = LineWidth + TempWidth; } } theWindow.Lines.addElement(Line.toString()); Lines = Lines + 1; DialogHeight = (Lines * 17) + 67; NewWindow((theDesktop.DesktopWidth - DialogWidth)/2,(theDesktop.DesktopHeight - DialogHeight)/3,((theDesktop.DesktopWidth - DialogWidth)/2)+DialogWidth,(theDesktop.DesktopHeight - DialogHeight)/3+DialogHeight,"",true,theWindow,null,true,0); FrontWindow().NewControl(new NewButton(),new Rectangle(DialogWidth-87,18+Lines*17,DialogWidth-27,0),"Ok",true,0,0,0,1); while (waitMore) { theEvent = GetNextEvent((short)0xFF); if (theEvent != null) { switch (theEvent.what) { case (1): // mouseDown { theResult = FindWindow(theEvent.x,theEvent.y); switch (theResult.part) { case (0): // inDesk { SysBeep(); break; } case (1): // inMenuBar { SysBeep(); break; } case (3): // inContent { if (FrontWindow() != theResult.theWindow) SysBeep(); else { location = theResult.theWindow.GlobalToLocal(new Point(theEvent.x,theEvent.y)); result2 = theResult.theWindow.FindControl(location); if (result2.part != 0) { i = result2.theControl.TrackControl(location); if (i != 0) waitMore = false; } } break; } } break; } case (3): // keyDown { if (theEvent.message == 10) { theButton = (NewButton)FrontWindow().theControls.elementAt(0); theButton.push(); } break; } case (4): // keyUp { if (theEvent.message == 10) { theButton = (NewButton)FrontWindow().theControls.elementAt(0); theButton.pull(); waitMore = false; } break; } } } } FrontWindow().CloseWindow(); } public boolean Confirm(String theString, int theIcon) { return true; } // Other public void SysBeep() { beep.play(); } public void InitCursor() { theFrame.setCursor(Frame.DEFAULT_CURSOR); } public void watchCursor() { theFrame.setCursor(Frame.WAIT_CURSOR); } public void iBeamCursor() { theFrame.setCursor(Frame.TEXT_CURSOR); } public void crossCursor() { theFrame.setCursor(Frame.CROSSHAIR_CURSOR); } public void redrawDesktop() { Graphics g; g = theDesktop.getGraphics(); g.drawImage(theDesktop.offScreenImage,0,0,null); }}