001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.lcdui;
028:
029: import com.sun.midp.events.EventTypes;
030: import com.sun.midp.events.Event;
031:
032: import javax.microedition.lcdui.Display;
033:
034: /**
035: * An subclass for events of REPAINT_EVENT type. These events are generated by
036: * LCDUI for its own purposes.
037: */
038: class RepaintEvent extends Event {
039: /** X1 for the paint event. */
040: int paintX1;
041: /** Y1 for the paint event. */
042: int paintY1;
043: /** X2 for the paint event. */
044: int paintX2;
045: /** Y2 for the paint event. */
046: int paintY2;
047: /** Target for the paint event. */
048: Object paintTarget;
049: /** Per use ID for tracking events in serviceRepaints. */
050: int perUseID;
051: /** Target display of the event. */
052: DisplayEventConsumer display;
053:
054: /**
055: * Construct an event that has no parameters.
056: *
057: * @param type event ID type
058: */
059: private RepaintEvent(int type) {
060: super (type);
061: }
062:
063: /**
064: * Create a repaint event.
065: *
066: * @param d The Display
067: * @param x The x origin coordinate
068: * @param y The y origin coordinate
069: * @param w The width
070: * @param h The height
071: * @param target The optional paint target
072: *
073: * @return initialized event
074: */
075: static RepaintEvent createRepaintEvent(DisplayEventConsumer d,
076: int x, int y, int w, int h, Object target) {
077: RepaintEvent e = new RepaintEvent(EventTypes.REPAINT_EVENT);
078: e.setRepaintFields(d, x, y, w, h, target);
079: return e;
080: }
081:
082: /**
083: * Set the fields of a repaint event.
084: *
085: * @param d The Display
086: * @param x The x origin coordinate
087: * @param y The y origin coordinate
088: * @param w The width
089: * @param h The height
090: * @param target The optional paint target
091: */
092: void setRepaintFields(DisplayEventConsumer d, int x, int y, int w,
093: int h, Object target) {
094: display = d;
095:
096: w += x; // convert from width, height to absolute
097: h += y; // x2, y2
098:
099: if (x < 0) {
100: x = 0;
101: }
102:
103: if (y < 0) {
104: y = 0;
105: }
106:
107: paintX1 = x;
108: paintY1 = y;
109: paintX2 = w;
110: paintY2 = h;
111: paintTarget = target;
112: }
113: }
|