[Waba-commits] CVS: waba/src/share/classes/waba/ui Button.java,NONE,1.1 Check.java,NONE,1.1 Containe
Status: Abandoned
Brought to you by:
bornet
Update of /cvsroot/waba/waba/src/share/classes/waba/ui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30799/src/share/classes/waba/ui Added Files: Button.java Check.java Container.java Control.java ControlEvent.java Edit.java Event.java IKeys.java KeyEvent.java Label.java MainWindow.java PalmOsPref.java PenEvent.java Radio.java ScrollPane.java ScrollPanel.java Tab.java TabBar.java Timer.java ToolBar.java WabaAbout.java WabaPref.java Welcome.java Window.java Log Message: Moved to new location --- NEW FILE: Button.java --- /* $Id: Button.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; import waba.fx.*; import waba.sys.Vm; /** * Button is a push button control. * <p> * Here is an example showing a push button being used: * * <pre> * public class MyProgram extends MainWindow * { * Button pushB; * * public void onStart() * { * pushB = new Button("Push me"); * pushB.setRect(10, 10, 80, 30); * add(pushB); * } * * public void onEvent(Event event) * { * if (event.type == ControlEvent.PRESSED && * event.target == pushB) * { * ... handle pushB being pressed * </pre> */ public class Button extends Control { //static boolean isToggledDownStaticCopy; Image buttonImage; String text; Font font; boolean armed; boolean isTogglable; boolean isToggledDown; int imgWidth, imgHeight; /** Creates a button displaying the given text. */ public Button(String text) { this.init(text, null, false); } public Button(String text, boolean togglable) { this.init(text, null, togglable); } public Button(Image passedButtonImage) { this.init(null, passedButtonImage, false); } public Button(Image passedButtonImage, boolean togglable) { this.init(null, passedButtonImage, togglable); } public Button(String text, Image passedButtonImage) { this.init(text, passedButtonImage, false); } public Button(String text, Image passedButtonImage, boolean togglable) { this.init(text, passedButtonImage, togglable); } private void init(String text, Image passedButtonImage, boolean togglable) { this.font = MainWindow.defaultFont; this.isTogglable = togglable; this.isToggledDown = false; if(text != null) this.text = text; if(passedButtonImage != null) { buttonImage = passedButtonImage; imgWidth = buttonImage.getWidth(); imgHeight = buttonImage.getHeight(); } } public void press() { armed = true; isToggledDown = true; repaint(); } public void release() { armed = false; isToggledDown = false; repaint(); } /** Sets the text that is displayed in the button. */ public void setText(String text) { this.text = text; repaint(); } /** Gets the text displayed in the button. */ public String getText() { return text; } /** Sets the image that is displayed in the button. */ public void setImage(Image passedButtonImage) { this.buttonImage = passedButtonImage; imgWidth = buttonImage.getWidth(); imgHeight = buttonImage.getHeight(); repaint(); } /** Gets the image that is displayed in the button. */ public Image getImage() { return this.buttonImage; } /** Gets the image that is displayed in the button. */ public int getImageWidth() { return imgWidth; } /** Gets the image that is displayed in the button. */ public int getImageHeight() { return imgHeight; } /** Called by the system to pass events to the button. */ public void onEvent(Event evnt) { if(evnt.type == PenEvent.PEN_DOWN) { armed = true; if(isTogglable) { isToggledDown = !isToggledDown; //isToggledDownStaticCopy = isToggledDown; } repaint(); } else if(evnt.type == PenEvent.PEN_UP) { armed = false; repaint(); PenEvent pe = (PenEvent)evnt; if(pe.x >= 0 && pe.x < this.width && pe.y >= 0 && pe.y < this.height) postEvent(new ControlEvent(ControlEvent.PRESSED, this)); } else if(evnt.type == PenEvent.PEN_DRAG) { PenEvent pe = (PenEvent)evnt; boolean lArmed = false; if(pe.x >= 0 && pe.x < this.width && pe.y >= 0 && pe.y < this.height) lArmed = true; if(armed != lArmed) { armed = lArmed; repaint(); } } } //public static void drawButton(Graphics g, boolean armed, int width, int height) public void drawButton(Graphics g, boolean armed, int width, int height) { boolean isColor = Vm.isColor(); int x2 = width - 1; int y2 = height - 1; if(!isColor) { // draw top, bottom, left and right lines g.setColor(0, 0, 0); g.drawLine(3, 0, x2 - 3, 0); g.drawLine(3, y2, x2 - 3, y2); g.drawLine(0, 3, 0, y2 - 3); g.drawLine(x2, 3, x2, y2 - 3); //if(armed) if( (armed)||(isToggledDown) ) g.fillRect(1, 1, width - 2, height - 2); else { // draw corners (tl, tr, bl, br) g.drawLine(1, 1, 2, 1); g.drawLine(x2 - 2, 1, x2 - 1, 1); g.drawLine(1, y2 - 1, 2, y2 - 1); g.drawLine(x2 - 2, y2 - 1, x2 - 1, y2 - 1); // draw corner dots g.drawLine(1, 2, 1, 2); g.drawLine(x2 - 1, 2, x2 - 1, 2); g.drawLine(1, y2 - 2, 1, y2 - 2); g.drawLine(x2 - 1, y2 - 2, x2 - 1, y2 - 2); } } else { // top, left //if(armed) if( (armed)||(isToggledDown) ) g.setColor(0, 0, 0); else g.setColor(255, 255, 255); g.drawLine(0, 0, x2 - 1, 0); g.drawLine(0, 0, 0, y2 - 1); // top, left shadow //if(armed) if( (armed)||(isToggledDown) ) { g.setColor(130, 130, 130); g.drawLine(1, 1, x2 - 1, 1); g.drawLine(1, 1, 1, y2 - 1); } // bottom, right //if(armed) if( (armed)||(isToggledDown) ) g.setColor(255, 255, 255); else g.setColor(0, 0, 0); g.drawLine(0, y2, x2, y2); g.drawLine(x2, y2, x2, 0); // bottom, right shadow //if(!armed) if( (!armed)||(!isToggledDown) ) { g.setColor(130, 130, 130); g.drawLine(1, y2 - 1, x2 - 1, y2 - 1); g.drawLine(x2 - 1, y2 - 1, x2 - 1, 1); } } } /** Called by the system to draw the button. */ public void onPaint(Graphics g) { drawButton(g, armed, this.width, this.height); // draw label if (armed && !Vm.isColor()) g.setColor(255, 255, 255); else g.setColor(0, 0, 0); g.setFont(font); FontMetrics fm = getFontMetrics(font); int fntX = (this.width - fm.getTextWidth(text)) / 2; int fntY = (this.height - fm.getHeight()) / 2; int imgX = (this.width - imgWidth) / 2; int imgY = (this.height - imgHeight) / 2; int offset = 0; if( (armed)||(isToggledDown) ) { offset = 1; /* fntX++; fntY++; imgX++; imgY++; */ } /* if( (text != null)&&(buttonImage != null) ) { g.drawImage(buttonImage, imgX, imgY); g.drawText(text, fntX, fntY); } */ if(text != null) g.drawText(text, fntX+offset, fntY+offset); if(buttonImage != null) g.drawImage(buttonImage, imgX+offset, imgY+offset); } } --- NEW FILE: Check.java --- /* $Id: Check.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; import waba.fx.*; import waba.sys.Vm; /** * Check is a check control. * <p> * Here is an example showing a check being used: * * <pre> * public class MyProgram extends MainWindow * { * Check check; * * public void onStart() * { * check = new Check("Check me"); * check.setRect(10, 10, 80, 30); * add(check); * } * * public void onEvent(Event event) * { * if (event.type == ControlEvent.PRESSED && * event.target == check) * { * ... handle check being pressed * </pre> */ public class Check extends Control { String text; Font font; boolean checked; /** Creates a check control displaying the given text. */ public Check(String text) { this.text = text; this.font = MainWindow.defaultFont; checked = false; } /** Called by the system to pass events to the check control. */ public void onEvent(Event event) { if (event.type == PenEvent.PEN_DOWN) { checked = !checked; repaint(); PenEvent pe = (PenEvent)event; if (pe.x >= 0 && pe.x < this.width && pe.y >= 0 && pe.y < this.height) postEvent(new ControlEvent(ControlEvent.PRESSED, this)); } } /** Gets the text displayed in the check. */ public String getText() { return text; } /** Returns the checked state of the control. */ public boolean getChecked() { return checked; } /** Sets the checked state of the control. */ public void setChecked(boolean checked) { if (this.checked == checked) return; this.checked = checked; repaint(); } /** Draws the check box graphic at the given position. */ public static void drawCheck(Graphics g, boolean checked, int x, int y) { int x1 = x; int y1 = y; int x2 = x + 12; int y2 = y + 12; if (Vm.isColor()) { g.setColor(130, 130, 130); g.drawLine(x1, y1, x2 - 1, y); g.drawLine(x1, y1 + 1, x1, y2 - 1); g.setColor(0, 0, 0); g.drawLine(x1 + 1, y1 + 1, x2 - 2, y1 + 1); g.drawLine(x1 + 1, y1 + 2, x1 + 1, y2 - 2); g.setColor(200, 200, 200); g.drawLine(x1 + 1, y2 - 1, x2 - 1, y2 - 1); g.drawLine(x2 - 1, y1 + 1, x2 - 1, y2 - 2); g.setColor(255, 255, 255); g.drawLine(x1, y2, x2, y2); g.drawLine(x2, y, x2, y2 - 1); g.fillRect(x + 2, y + 2, 9, 9); } else { g.setColor(0, 0, 0); g.drawRect(x1 + 1, y1 + 1, 11, 11); g.setColor(255, 255, 255); g.fillRect(x1 + 2, y1 + 2, 9, 9); } if (checked) { g.setColor(0, 0, 0); x1 = x + 3; y1 = y + 5; for (int i = 0; i < 7; i++) { g.drawLine(x1, y1, x1, y1 + 2); x1++; if (i < 2) y1++; else y1--; } } } /** Called by the system to draw the check control. */ public void onPaint(Graphics g) { int y = (this.height - 13) / 2; drawCheck(g, checked, 0, y); // draw label g.setColor(0, 0, 0); g.setFont(font); FontMetrics fm = getFontMetrics(font); int fontHeight = fm.getHeight(); y = (this.height - fontHeight) / 2; g.drawText(text, 17, y); } } --- NEW FILE: Container.java --- /* $Id: Container.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; import waba.fx.*; /** * Container is a control that contains child controls. */ public class Container extends Control { /** The children of the container. */ protected Control children; /** The tail of the children list. */ protected Control tail; /** * Adds a child control to this container. */ public void add(Control control) { if(control.parent != null) control.parent.remove(control); // set children, next, prev, tail and parent control.next = null; if (children == null) children = control; else tail.next = control; control.prev = tail; tail = control; control.parent = this; // numChildren++; control.repaint(); } /** * Removes a child control from the container. */ public void remove(Control control) { if(control.parent != this) return; // set children, next, prev, tail and parent Control prev = control.prev; Control next = control.next; if(prev == null) children = next; else prev.next = next; if(next != null) next.prev = prev; if(tail == control) tail = prev; control.next = null; control.prev = null; // numChildren--; control.repaint(); control.parent = null; } /** Returns the child located at the given x and y coordinates. */ public Control findChild(int x, int y) { Container container; Control child; container = this; while(true) { // Search tail to head since paint goes head to tail child = container.tail; while (child != null && !child.contains(x, y)) child = child.prev; if (child == null) return container; if (!(child instanceof Container)) return child; x -= child.x; y -= child.y; container = (Container)child; } } /*** Called by the system to draw the children of the container. ***/ public void paintChildren(Graphics g, int x, int y, int width, int height) { Control child = children; //while (child != null) while(child != null) { int x1 = x; int y1 = y; int x2 = x + width - 1; int y2 = y + height - 1; int cx1 = child.x; int cy1 = child.y; int cx2 = cx1 + child.width - 1; int cy2 = cy1 + child.height - 1; // Trivial clip if(x2 < cx1 || x1 > cx2 || y2 < cy1 || y1 > cy2) { child = child.next; continue; } if (x1 < cx1) x1 = cx1; if (y1 < cy1) y1 = cy1; if (x2 > cx2) x2 = cx2; if (y2 > cy2) y2 = cy2; g.setClip(x1, y1, x2 - x1 + 1, y2 - y1 + 1); g.translate(cx1, cy1); if(child.doRepaint) child.onPaint(g); g.clearClip(); if(child instanceof Container) { Container c = (Container)child; if(child.doRepaint) c.paintChildren(g, x1 - cx1, y1 - cy1, x2 - x1 + 1, y2 - y1 + 1); } g.translate(- cx1, - cy1); child = child.next; }//End of while( (child != null)&&(child.noRepaint) ) }//End of public void paintChildren(Graphics g, int x, int y, int width, int height) }//End of class Container --- NEW FILE: Control.java --- /* $Id: Control.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; import waba.fx.*; /** * Control is the base class for user-interface objects. */ public class Control { /** The control's x location */ protected int x; /** The control's y location */ protected int y; /** The control's width */ protected int width; /** The control's height */ protected int height; /** The parent of the control. */ protected Container parent; /** The control's next sibling. */ protected Control next; /** The control's previous sibling. */ protected Control prev; /*** The control's repainting control by Isao F. Yamashita 09/22/2000 ***/ protected boolean doRepaint = true; public Control() { //doRepaint = true; } /*** The control's repainting control by Isao F. Yamashita 09/22/2000 ***/ public void setRepaint(boolean enable) { doRepaint = enable; } /** * Adds a timer to a control. Each time the timer ticks, a TIMER * event will be posted to the control. The timer does * not interrupt the program during its execution at the timer interval, * it is scheduled along with application events. The timer object * returned from this method can be passed to removeTimer() to * remove the timer. Under Windows, the timer has a minimum resolution * of 55ms due to the native Windows system clock resolution of 55ms. * * @param millis the timer tick interval in milliseconds * @see ControlEvent */ public Timer addTimer(int millis) { MainWindow win = MainWindow.getMainWindow(); return win.addTimer(this, millis); } /** * Removes a timer from a control. True is returned if the timer was * found and removed and false is returned if the timer could not be * found (meaning it was not active). */ public boolean removeTimer(Timer timer) { MainWindow win = MainWindow.getMainWindow(); return win.removeTimer(timer); } /** Returns the font metrics for a given font. */ public FontMetrics getFontMetrics(Font font) { MainWindow win = MainWindow.getMainWindow(); return win.getFontMetrics(font); } /** Sets or changes a control's position and size. */ public void setRect(int x, int y, int width, int height) { if(parent != null) repaint(); this.x = x; this.y = y; this.width = width; this.height = height; if(parent != null) repaint(); } /** * Returns a copy of the control's rectangle. A control's rectangle * defines its location and size. */ public Rect getRect() { return new Rect(this.x, this.y, this.width, this.height); } /** Returns the control's parent container. */ public Container getParent() { return parent; } /** Returns the next child in the parent's list of controls. */ public Control getNext() { return next; } /** * Returns true if the given x and y coordinate in the parent's * coordinate system is contained within this control. */ public boolean contains(int x, int y) { int rx = this.x; int ry = this.y; if (x < rx || x >= rx + this.width || y < ry || y > ry + this.height) return false; return true; } /** Redraws the control. */ public void repaint() { int x = 0; int y = 0; Control c = this; while(!(c instanceof Window)) { x += c.x; y += c.y; c = c.parent; if(c == null) return; } Window win = (Window)c; win.damageRect(x, y, this.width, this.height); } /** * Creates a Graphics object which can be used to draw in the control. * This method finds the surface associated with the control, creates * a graphics assoicated with it and translates the graphics to the * origin of the control. It does not set a clipping rectangle on the * graphics. */ public Graphics createGraphics() { int x = 0; int y = 0; Control c = this; while(!(c instanceof Window)) { x += c.x; y += c.y; c = c.parent; if(c == null) return null; } Window win = (Window)c; Graphics g = new Graphics(win); g.translate(x, y); return g; } /** * Posts an event. The event pass will be posted to this control * and all the parent controls of this control (all the containers * this control is within). * @see Event */ public void postEvent(Event event) { Control c; c = this; while(c != null) { c.onEvent(event); c = c.parent; } } /** * Called to process key, pen, control and other posted events. * @param event the event to process * @see Event * @see KeyEvent * @see PenEvent */ public void onEvent(Event event) { } /** * Called to draw the control. When this method is called, the graphics * object passed has been translated into the coordinate system of the * control and the area behind the control has * already been painted. The background is painted by the top-level * window control. * @param g the graphics object for drawing * @see Graphics */ public void onPaint(Graphics g) { } }//End of class Control --- NEW FILE: ControlEvent.java --- /* $Id: ControlEvent.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; import waba.sys.*; /** * ControlEvent is an event posted by a control. */ public class ControlEvent extends Event { /** The event type for a pressed event. */ public static final int PRESSED = 300; /** The event type for a focus in event. */ public static final int FOCUS_IN = 301; /** The event type for a focus out event. */ public static final int FOCUS_OUT = 302; /** The event type for a timer event. */ public static final int TIMER = 303; public ControlEvent() { } /** * Constructs a control event of the given type. * @param type the type of event * @param c the target control */ public ControlEvent(int type, Control c) { this.type = type; target = c; timeStamp = Vm.getTimeStamp(); } } --- NEW FILE: Edit.java --- /* $Id: Edit.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; import waba.fx.*; import waba.sys.Vm; /** * Edit is a text entry control. * <p> * Here is an example showing an edit control being used: * * <pre> * public class MyProgram extends MainWindow * { * Edit edit; * * public void onStart() * { * edit = new Edit(); * edit.setRect(10, 10, 80, 30); * add(edit); * } * </pre> */ public class Edit extends Control { Font font; FontMetrics fm; Graphics drawg; // only valid while the edit has focus Timer blinkTimer; // only valid while the edit has focus //NOTE: later these should be bitflags in a state int in the Control class boolean hasFocus = false; boolean cursorShowing = false; boolean isPalmOS = false; /* Make it protected so as to be accessible by a subclass */ protected char chars[] = new char[4]; byte charWidths[] = new byte[4]; Rect clipRect; // allocated when used and reused in many cases (see code) int totalCharWidth = 0; int len = 0; int insertPosition, lastInsertPosition; int startSelectPos; int xOffset; public Edit() { String platformStr = "PalmOS"; if( platformStr.equals(Vm.getPlatform()) ) isPalmOS = true; this.font = MainWindow.defaultFont; fm = getFontMetrics (this.font); clearPosState(); } /** Return the display representation of an internal character at a given position. @param i position @return the display representation */ protected char getDisplayChar (int i) { return chars [i]; } /** Return the display representation of a given character. @param c the character @return the display representation */ protected char getDisplayChar (char c) { return c; } /** Return the display representation of all the internal characters. @return the display representation */ protected char [] getDisplayChars () { return chars; } private void clearPosState() { insertPosition = 0; lastInsertPosition = 0; startSelectPos = -1; if(Vm.isColor()) xOffset = 4; else xOffset = 1; } private int XToCharPos(int x) { int cx = xOffset; for (int i = 0; i < len; i++) { int cw = charWidths[i]; if (x <= cx + (cw / 2)) return i; cx += cw; } return len; } private int CharPosToX(int n) { int cx = xOffset; if (n > len) n = len; for (int i = 0; i < n; i++) cx += charWidths[i]; return cx; } /** * Returns the text displayed in the edit control. */ public String getText() { return new String(chars, 0, len); } /** * Sets the text displayed in the edit control. */ public void setText(String s) { chars = s.toCharArray(); len = chars.length; charWidths = null; totalCharWidth = 0; clearPosState(); repaint(); } private void draw(Graphics g, boolean cursorOnly) { /* to prevent Null exception pointer as suggested in bug #450570 */ if( g == null ) return; g.setFont(font); if(charWidths == null) { charWidths = new byte[len]; totalCharWidth = 0; for(int i = 0; i < len; i++) { int charWidth = fm.getCharWidth(getDisplayChar (i)); charWidths[i] = (byte)charWidth; totalCharWidth += charWidth; } } int height = fm.getHeight(); int xMin; int xMax; int y; if(Vm.isColor()) { xMin = 4; xMax = this.width - 4 - 1; height -= 1; y = this.height - height - 1; } else { xMin = 1; xMax = this.width - 1 - 1; y = this.height - height - 1; } if(clipRect == null) clipRect = new Rect(0, 0, 0, 0); //Get current clip rect and intersect with edit rect to set a new clip to draw in int cx1 = xMin; int cy1 = y; int cx2 = xMax; int cy2 = y + height - 1; Rect clip = g.getClip(clipRect); if(clip != null) { //Intersect current clip rect and edit rect if (cx1 < clip.x) cx1 = clip.x; if (cy1 < clip.y) cy1 = clip.y; int clipX2 = clip.x + clip.width - 1; if (cx2 > clipX2) cx2 = clipX2; int clipY2 = clip.y + clip.height - 1; if (cy2 > clipY2) cy2 = clipY2; } g.setClip(cx1, cy1, cx2 - cx1 + 1, cy2 - cy1 + 1); int x = xOffset; if(cursorOnly) ; else if(startSelectPos == -1) { //Draw unselected chars g.setColor(255, 255, 255); //Color after the text. if(isPalmOS) g.setBackColor(255, 255, 255); //Edit field background g.fillRect(xMin, y, xMax - xMin + 1, height); g.setColor(0, 0, 0); g.setTextColor(0, 0, 0); g.drawText(getDisplayChars (), 0, len, x, y); } else { //Character regions are: //0 to selection start-1 (sel1-1) to selection start (sel1) to //selection end-1 (sel2-1) to selection end (sel2) to last character int sel1 = startSelectPos; int sel2 = insertPosition; if(sel1 > sel2) { int temp = sel1; sel1 = sel2; sel2 = temp; } int sel1X = CharPosToX(sel1); int sel2X = CharPosToX(sel2); //0 to selection start-1 (sel1-1) to selection end (sel2) to last_char if(isPalmOS) g.setBackColor(255, 255, 255); g.fillRect(xMin, y, sel1X - xMin, height); g.fillRect(sel2X, y, xMax - sel2X + 1, height); //<--- Here's the glitch 05/06/2000 last cursor doesn't go away. g.setColor(0, 0, 0); if(isPalmOS) g.setTextColor(0, 0, 0); g.drawText(getDisplayChars (), 0, sel1, x, y); g.drawText(getDisplayChars (), sel2, len - sel2, sel2X, y); //Draw selection start (sel1) to selection end-1 (sel2-1) if(isPalmOS) g.setColor(255, 255, 0); else g.setColor(0, 0, 120); g.fillRect(sel1X, y, sel2X - sel1X, height); if(isPalmOS) g.setBackColor(255, 255, 0); else g.setColor(255, 255, 255); g.drawText(getDisplayChars (), sel1, sel2 - sel1, sel1X, y); } // restore clip rect if (clip == null) g.clearClip(); else g.setClip(clip.x, clip.y, clip.width, clip.height); if(!cursorOnly) { //Erase the space for the cursor at (xMin - 1) g.setColor(255, 255, 255); g.drawLine(xMin-1, y, xMin-1, y+height-1); if(isPalmOS) g.drawCursor((CharPosToX(lastInsertPosition)-1), y, 1, height); } if(hasFocus) { //Draw cursor if(isPalmOS) { if(cursorShowing) g.setColor(0, 0, 0); g.drawCursor((CharPosToX(insertPosition)-1), y, 1, height); //Immediately set back to white. //Otherwise you'll see ugly black band behind the last character. g.setColor(255, 255, 255); } else { int cx = CharPosToX(insertPosition)-1; g.drawCursor(cx, y, 1, height); } if(cursorOnly) cursorShowing = !cursorShowing; else cursorShowing = true; } else cursorShowing = false; } /** Called by the system to pass events to the edit control. */ public void onEvent(Event event) { if(charWidths == null) return; // widths have not been initialized - not added to hierarchy boolean redraw = false; boolean extendSelect = false; boolean clearSelect = false; int newinsertPosition = insertPosition; switch(event.type) { case ControlEvent.TIMER: { draw(drawg, true); return; } case ControlEvent.FOCUS_IN: { drawg = createGraphics(); hasFocus = true; redraw = true; blinkTimer = addTimer(350); break; } case ControlEvent.FOCUS_OUT: { hasFocus = false; clearPosState(); newinsertPosition = lastInsertPosition = 0; redraw = true; removeTimer(blinkTimer); break; } case KeyEvent.KEY_PRESS: { KeyEvent ke = (KeyEvent)event; boolean isPrintable; if (ke.key > 0 && ke.key < 65536 && (ke.modifiers & IKeys.ALT) == 0 && (ke.modifiers & IKeys.CONTROL) == 0) isPrintable = true; else isPrintable = false; boolean isDelete = (ke.key == IKeys.DELETE); boolean isBackspace = (ke.key == IKeys.BACKSPACE); int del1 = -1; int del2 = -1; int sel1 = startSelectPos; int sel2 = insertPosition; if(sel1 > sel2) { int temp = sel1; sel1 = sel2; sel2 = temp; } if(sel1 != -1 && (isPrintable || isDelete || isBackspace)) { del1 = sel1; del2 = sel2 - 1; } else if(isDelete) { del1 = insertPosition; del2 = insertPosition; } else if(isBackspace) { del1 = insertPosition - 1; del2 = insertPosition - 1; } if(del1 >= 0 && del2 < len) { int deleteCount = del2 - del1 + 1; int numOnRight = len - del2 - 1; for(int i = del1; i <= del2; i++) totalCharWidth -= charWidths[i]; if(numOnRight > 0) { Vm.copyArray(chars, del2 + 1, chars, del1, numOnRight); Vm.copyArray(charWidths, del2 + 1, charWidths, del1, numOnRight); } len -= deleteCount; newinsertPosition = del1; redraw = true; clearSelect = true; } if(isPrintable) { // grow the array if required (grows by 8) if(len == chars.length) { char newChars[] = new char[len + 8]; Vm.copyArray(chars, 0, newChars, 0, len); chars = newChars; byte newCharWidths[] = new byte[len + 8]; Vm.copyArray(charWidths, 0, newCharWidths, 0, len); charWidths = newCharWidths; } char c = (char)ke.key; int charWidth = fm.getCharWidth(getDisplayChar (c)); if(newinsertPosition != len) { int i = newinsertPosition; int l = len - newinsertPosition; Vm.copyArray(chars, i, chars, i + 1, l); Vm.copyArray(charWidths, i, charWidths, i + 1, l); } chars[newinsertPosition] = c; charWidths[newinsertPosition] = (byte)charWidth; len++; lastInsertPosition = newinsertPosition; //Isao newinsertPosition++; totalCharWidth += charWidth; redraw = true; clearSelect = true; } boolean isMove = false; switch (ke.key) { case IKeys.HOME: case IKeys.END: case IKeys.LEFT: case IKeys.RIGHT: case IKeys.UP: case IKeys.DOWN: { isMove = true; break; } } if(isMove) { if (ke.key == IKeys.HOME) newinsertPosition = 0; else if (ke.key == IKeys.END) newinsertPosition = len; else if (ke.key == IKeys.LEFT || ke.key == IKeys.UP) newinsertPosition--; else if (ke.key == IKeys.RIGHT || ke.key == IKeys.DOWN) newinsertPosition++; if(newinsertPosition != insertPosition) { lastInsertPosition = insertPosition; if((ke.modifiers & IKeys.SHIFT) > 0) extendSelect = true; else clearSelect = true; } } break; } case PenEvent.PEN_DOWN: { PenEvent pe = (PenEvent)event; newinsertPosition = XToCharPos(pe.x); if((pe.modifiers & IKeys.SHIFT) > 0) // shift extendSelect = true; else clearSelect = true; break; } case PenEvent.PEN_DRAG: { PenEvent pe = (PenEvent)event; newinsertPosition = XToCharPos(pe.x); if (newinsertPosition != insertPosition) { lastInsertPosition = insertPosition; extendSelect = true; } break; } default: return; } if(extendSelect) { if(startSelectPos == -1) { lastInsertPosition = insertPosition; startSelectPos = insertPosition; } else if (newinsertPosition == startSelectPos) { lastInsertPosition = -1; startSelectPos = -1; } redraw = true; } if(clearSelect && startSelectPos != -1) { lastInsertPosition = -1; startSelectPos = -1; redraw = true; } if (newinsertPosition > len) newinsertPosition = len; if (newinsertPosition < 0) newinsertPosition = 0; Graphics g = drawg; boolean insertChanged = (newinsertPosition != insertPosition); if(insertChanged && !redraw && cursorShowing) { lastInsertPosition = insertPosition; draw(g, true); // erase cursor at old insert position } if(insertChanged) { int xMin; int xMax; if(Vm.isColor()) { xMin = 4; xMax = this.width - 4 - 1; } else { //xMin = 1; //xMax = this.width - 1 - 1; xMin = 1; xMax = this.width - 1; } int x = CharPosToX(newinsertPosition); if(x - 5 < xMin) { // characters hidden on left - jump xOffset += (xMin - x) + 20; if(xOffset > xMin) xOffset = xMin; redraw = true; } if(x + 5 > xMax) { // characters hidden on right - jump xOffset -= (x - xMax) + 20; if (xOffset < xMax - totalCharWidth) xOffset = xMax - totalCharWidth; redraw = true; } if(totalCharWidth < xMax - xMin && xOffset != xMin) { xOffset = xMin; redraw = true; } } lastInsertPosition = insertPosition; insertPosition = newinsertPosition; if(redraw) draw(g, false); else if(insertChanged) { //Draw cursor at new insert position //changed by Isao F. Yamashita 01/29/2001 if(isPalmOS) draw(g, false); else draw(g, true); } if(event.type == ControlEvent.FOCUS_OUT) { drawg = null; clipRect = null; } } /** Called by the system to draw the edit control. */ public void onPaint(Graphics g) { int width = this.width; int height = this.height; int x2 = width - 1; int y2 = height - 1; if(Vm.isColor()) { // top, left g.setColor(127, 127, 127); g.drawLine(0, 0, x2 - 1, 0); g.drawLine(0, 0, 0, y2 - 1); // top, left shadow g.setColor(0, 0, 0); g.drawLine(1, 1, x2 - 2, 1); g.drawLine(1, 1, 1, y2 - 2); // bottom, right g.setColor(208, 208, 208); g.drawLine(0, y2, x2, y2); g.drawLine(x2, y2, x2, 0); g.setColor(255, 255, 255); g.fillRect(2, 2, width - 4, height - 4); } else { g.setColor(0, 0, 0); g.drawDots(0, y2, x2, y2); } draw(g, false); clipRect = null; }//End of public void onPaint(Graphics g) } --- NEW FILE: Event.java --- /* $Id: Event.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; /** * Event is the base class for all events. */ public class Event { /** The type of event. */ public int type; /** * The target of the event. For user-interface events, this is the * control the event is associated with. */ public Object target; /** * The event's timestamp. * @see waba.sys.Vm#getTimeStamp() */ public int timeStamp; } --- NEW FILE: IKeys.java --- /* $Id: IKeys.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; /** * IKeys is an interface containing values for special keys and modifiers. * <p> * Below is an example of IKeys being used. * * <pre> * public void onEvent(Event event) * { * if (event.type == KeyEvent.KEY_PRESS) * { * KeyEvent ke = (KeyEvent)event; * if ((ke.modifiers & CONTROL) > 0) * ... control key was held down * if (ke.key == PAGE_DOWN) * ... page down key pressed * </pre> */ public interface IKeys { // NOTE: The WabaVM indexes directly to these values /** modifier for alt key */ public static final int ALT = (1 << 0); /** modifier for control key */ public static final int CONTROL = (1 << 1); /** modifier for shift key */ public static final int SHIFT = (1 << 2); /** special key */ public static final int PAGE_UP = 75000; /** special key */ public static final int PAGE_DOWN = 75001; /** special key */ public static final int HOME = 75002; /** special key */ public static final int END = 75003; /** special key */ public static final int UP = 75004; /** special key */ public static final int DOWN = 75005; /** special key */ public static final int LEFT = 75006; /** special key */ public static final int RIGHT = 75007; /** special key */ public static final int INSERT = 75008; /** special key */ public static final int ENTER = 75009; /** special key */ public static final int TAB = 75010; /** special key */ public static final int BACKSPACE = 75011; /** special key */ public static final int ESCAPE = 75012; /** special key */ public static final int DELETE = 75013; /** special key */ public static final int MENU = 75014; /** special key */ public static final int COMMAND = 75015; } --- NEW FILE: KeyEvent.java --- /* $Id: KeyEvent.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; /** * KeyEvent is a key press event. */ public class KeyEvent extends Event { /** The event type for a key press event. */ public static final int KEY_PRESS = 100; /** * The key pressed or entered by other means (grafitti input). This * is either a normal character key (if the value is < 70000) or * one of the special keys defined in the IKeys interface. * @see IKeys */ public int key; /** * The state of the modifier keys when the event occured. This is a * OR'ed combination of the modifiers present in the IKeys interface. * @see IKeys */ public int modifiers; } --- NEW FILE: Label.java --- /* $Id: Label.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; import waba.fx.*; /** * Label is a text label control. * <p> * Here is an example showing a label being used: * * <pre> * public class MyProgram extends MainWindow * { * public void onStart() * { * Label label = new Label("Value:"); * label.setRect(10, 10, 80, 30); * add(label); * } * </pre> */ public class Label extends Control { /** Constant for left alignment. */ public static final int LEFT = 0; /** Constant for center alignment. */ public static final int CENTER = 1; /** Constant for right alignment. */ public static final int RIGHT = 2; Image labelImg; String text; Font font; int align; int imgWidth, imgHeight; /** * Creates a label displaying the given text with left alignment. */ public Label(String text) { this(text, LEFT); } /** * Creates a label displaying the given text with the given alignment. * @param text the text displayed * @param align the alignment * @see #LEFT * @see #RIGHT * @see #CENTER */ public Label(String text, int align) { this.text = text; this.align = align; this.font = MainWindow.defaultFont; } public Label(Image labelImage) { this.text = null; this.align = LEFT; this.labelImg = labelImage; this.font = MainWindow.defaultFont; imgWidth = labelImg.getWidth(); imgHeight = labelImg.getHeight(); } public Label(String text, Image passedlabelImg, int align) { this.text = text; this.align = align; this.labelImg = passedlabelImg; this.font = MainWindow.defaultFont; imgWidth = labelImg.getWidth(); imgHeight = labelImg.getHeight(); } /** Sets the image that is displayed in the label. */ public void setImage(Image passedlabelImg) { this.labelImg = passedlabelImg; imgWidth = labelImg.getWidth(); imgHeight = labelImg.getHeight(); repaint(); } public Image getImage() { return this.labelImg; } /** Sets the font that to be used in the label. */ public void setFont(Font font) { this.font = font; } /** Sets the font that to be used in the label. */ public Font getFont() { return this.font; } /** Sets the text that is displayed in the label. */ public void setText(String text) { this.text = text; repaint(); } /** Gets the text that is displayed in the label. */ public String getText() { return text; } /** Called by the system to draw the button. */ public void onPaint(Graphics g) { // draw label g.setColor(0, 0, 0); g.setFont(font); FontMetrics fm = getFontMetrics(font); int fntX = 0; int fntY = (this.height - fm.getHeight()) / 2; int imgX = (this.width - imgWidth) / 2; int imgY = (this.height - imgHeight) / 2; if (align == CENTER) fntX = (this.width - fm.getTextWidth(text)) / 2; else if (align == RIGHT) fntX = this.width - fm.getTextWidth(text); if(text != null) g.drawText(text, fntX, fntY); if(labelImg != null) g.drawImage(labelImg, imgX, imgY); } } --- NEW FILE: MainWindow.java --- /* $Id: MainWindow.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBILITY FOR SOFTWARE ALTERED, MODIFIED, OR CONVERTED BY YOU OR A THIRD PARTY, DAMAGES RESULTING FROM ACCIDENT, ABUSE OR MISAPPLICATION, OR FOR PROBLEMS DUE TO THE MALFUNCTION OF YOUR EQUIPMENT OR SOFTWARE NOT SUPPLIED BY WABASOFT. */ package waba.ui; import waba.fx.*; import waba.sys.Vm; /** * MainWindow is the main window of a UI based application. * <p> * All Waba programs with a user-interface must have a main window. * <p> * Here is an example showing a basic application: * * <pre> * public class MyProgram extends MainWindow * { * public void onStart() * { * ... initialization code ... * Label label = new Label("Name:"); * label.setRect(..); * add(label); * } * } * </pre> */ public class MainWindow extends Window { Timer timers; Font _cachedFont; FontMetrics _cachedFontMetrics; public static Font defaultFont = new Font("Helvetica", Font.PLAIN, 12); static MainWindow _mainWindow; /** Constructs a main window. */ public MainWindow() { _mainWindow = this; _nativeCreate(); } private native void _nativeCreate(); /** * Notifies the application that it should stop executing and exit. It will * exit after executing any pending events. If the underlying system supports * it, the exitCode passed is returned to the program that started the app. */ public native void exit(int exitCode); /** Returns the MainWindow of the current application. */ public static MainWindow getMainWindow() { return _mainWindow; } /** Returns the font metrics for a given font. */ public FontMetrics getFontMetrics(Font font) { if (font == _cachedFont) return _cachedFontMetrics; _cachedFont = font; _cachedFontMetrics = new FontMetrics(font, this); return _cachedFontMetrics; } /** * Change the font of the MainWindow */ public void setFont( Font font ) { defaultFont = font; } /** * Adds a timer to a control. This method is protected, the public * method to add a timer to a control is the addTimer() method in * the Control class. */ protected Timer addTimer(Control target, int millis) { Timer t = new Timer(); t.target = target; t.millis = millis; t.lastTick = Vm.getTimeStamp(); t.next = timers; timers = t; _onTimerTick(); return t; } /** * Removes a timer. This method returns true if the timer was found * and removed and false if the given timer could not be found. */ public boolean removeTimer(Timer timer) { if (timer == null) return false; Timer t = timers; Timer prev = null; while (t != timer) { if (t == null) return false; prev = t; t = t.next; } if (prev == null) timers = t.next; else prev.next = t.next; _onTimerTick(); return true; } /** * Called just before an application exits. */ public void onExit() { } /** * Called when an application starts. Initialization code is usually either placed * in this method or simply in the app's constructor. This method is called * just after the app's constructor is called. */ public void onStart() { } /** * Called by the VM to process timer interrupts. This method is not private * to prevent the compiler from removing it during optimization. */ public void _onTimerTick() { int minInterval = 0; int now = Vm.getTimeStamp(); Timer timer = timers; while (timer != null) { int diff = now - timer.lastTick; if (diff < 0) diff += (1 << 30); // wrap around - max stamp is (1 << 30) int interval; if (diff >= timer.millis) { // post TIMER event Control c = timer.target; _controlEvent.type = ControlEvent.TIMER; _controlEvent.target = c; c.postEvent(_controlEvent); timer.lastTick = now; interval = timer.millis; } else interval = timer.millis - diff; if (interval < minInterval || minInterval == 0) minInterval = interval; timer = timer.next; } _setTimerInterval(minInterval); if (needsPaint) _doPaint(paintX, paintY, paintWidth, paintHeight); } /** * Called to set the VM's timer interval. This method is not public, * you should use the addTimer() method in the Control class to * create a timer. */ protected native void _setTimerInterval(int milliseconds); /** * Called by the Waba VM to copy back the graphics on the off-screen buffer. * <p> * For the ultimate flexisibility, * also an user can call this method to update the screen immediately. */ public static final native void paint(); } --- NEW FILE: PalmOsPref.java --- /* $Id: PalmOsPref.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ PalmOsPref.java Copyright (c) 2000 Amy High Craft, Ltd. All rights are reserved. **************************************** 01/18/2001 Isao F. Yamashita : Inital coding. */ package waba.ui; import waba.fx.*; public class PalmOsPref extends Container { Button lBtn, rBtn; Font boldFont; Font plainFont; Label screenDepthLabel, tmpLbl; String screenDepthChoice[] = {"Automatic", "Black & White", "4 Level Gray", "16 Level Gray", "256 Color", "65536 Color"}; //Notice, that I can't use bit shift operation to easily set the value here, //since '-1' and '24' is included in the selection. byte screenDepthValue[] = {-1, 1, 2, 4, 8, 16 /*, 24, 32 ... in the future */}; int screenDepthChoiceIndex = 0; byte palmOsPrefData[] = new byte[1]; byte tmpData; public PalmOsPref() { boldFont = new Font("Helvetica", Font.BOLD, 12); plainFont = new Font("Helvetica", Font.PLAIN, 12); if(getPalmOsPref(palmOsPrefData, 0, 1) != -1) { for( screenDepthChoiceIndex = 0; (screenDepthValue[screenDepthChoiceIndex] != palmOsPrefData[0])&&(screenDepthChoiceIndex < 5); screenDepthChoiceIndex++); } screenDepthLabel = new Label(screenDepthChoice[screenDepthChoiceIndex], Label.CENTER); //screenDepthLabel = new Label(String.valueOf(palmOsPrefData[0]), Label.CENTER); screenDepthLabel.setRect(38, 40, 80, 20); add(screenDepthLabel); //tmpLbl = new Label(String.valueOf(screenDepthChoiceIndex), Label.CENTER); //tmpLbl.setRect(38, 95, 80, 20); //add(tmpLbl); lBtn = new Button("<"); rBtn = new Button(">"); lBtn.setRect(38, 70, 40, 20); rBtn.setRect(78, 70, 40, 20); add(lBtn); add(rBtn); }//End of constructor public void onEvent(Event evnt) { if(evnt.type == ControlEvent.PRESSED) { if(evnt.target == lBtn) { if(screenDepthChoiceIndex > 0) screenDepthChoiceIndex--; }//End of if(evnt.target == lBtn) else if(evnt.target == rBtn) { if(screenDepthChoiceIndex < 5) screenDepthChoiceIndex++; }//End of else if(evnt.target == rBtn) palmOsPrefData[0] = screenDepthValue[screenDepthChoiceIndex]; setPalmOsPref(palmOsPrefData); screenDepthLabel.setText(screenDepthChoice[screenDepthChoiceIndex]); //screenDepthLabel.setText(String.valueOf(palmOsPrefData[0])); //tmpLbl.setText(String.valueOf(screenDepthChoiceIndex)); repaint(); }//End of if(evnt.type == ControlEvent.PRESSED) }//End of onEvent() public void onPaint(Graphics scrn) { scrn.setColor(0, 0, 0); scrn.setFont(boldFont); scrn.drawText("Force Color Setting of", 28, 10); scrn.drawText("Waba for This PalmOS to:", 18, 20); }//End of onPaint() //private final native byte[] getPalmOsPref(); private final native int getPalmOsPref(byte buf[], int start, int count); private final native void setPalmOsPref(byte[] prefData); }//End of class PalmOsPref --- NEW FILE: PenEvent.java --- /* $Id: PenEvent.java,v 1.1 2004/07/10 14:18:02 mriem Exp $ Copyright (c) 1998, 1999 Wabasoft All rights reserved. This software is furnished under a license and may be used only in accordance with the terms of that license. This software and documentation, and its copyrights are owned by Wabasoft and are protected by copyright law. THIS SOFTWARE AND REFERENCE MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY AS TO THEIR PERFORMANCE, MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT. WABASOFT ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE THIS SOFTWARE. WABASOFT SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES RESULTING FROM THE USE OF THIS PRODUCT. WABASOFT SHALL HAVE NO LIABILITY OR RESPONSIBI... [truncated message content] |