Source Code Cross Referenced for PPCComponentPeer.java in  » 6.0-JDK-Modules » j2me » sun » awt » pocketpc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » sun.awt.pocketpc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)PPCComponentPeer.java	1.11 02/12/16
003:         *
004:         * Copyright  1990-2006 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 sun.awt.pocketpc;
028:
029:        import java.awt.*;
030:        import sun.awt.peer.*;
031:        import sun.awt.ScreenUpdater;
032:        import sun.awt.UpdateClient;
033:        import sun.awt.image.ImageRepresentation;
034:        import java.awt.image.ImageProducer;
035:        import java.awt.image.ImageObserver;
036:        import java.awt.image.ColorModel;
037:        import java.awt.image.DirectColorModel;
038:        import java.awt.event.PaintEvent;
039:        import sun.awt.PeerBasedToolkit;
040:
041:        abstract class PPCComponentPeer extends PPCObjectPeer implements 
042:                ComponentPeer, UpdateClient {
043:
044:            private static native void initIDs();
045:
046:            static {
047:                initIDs();
048:            }
049:
050:            // ComponentPeer implementation
051:
052:            private boolean repaintPending;
053:            private Rectangle repaintRect;
054:
055:            public synchronized native void show();
056:
057:            public synchronized native void hide();
058:
059:            public synchronized native void enable();
060:
061:            public synchronized native void disable();
062:
063:            /* New 1.1 API */
064:            public native Point getLocationOnScreen();
065:
066:            /* New 1.1 API */
067:            public void setVisible(boolean b) {
068:                if (b) {
069:                    show();
070:                } else {
071:                    hide();
072:                }
073:            }
074:
075:            /* New 1.1 API */
076:            public void setEnabled(boolean b) {
077:                if (b) {
078:                    enable();
079:                } else {
080:                    disable();
081:                }
082:            }
083:
084:            /* New 1.1 API */
085:            public void setBounds(int x, int y, int width, int height) {
086:                reshape(x, y, width, height);
087:            }
088:
089:            public void paint(Graphics g) {
090:                g.setColor(((Component) target).getForeground());
091:                g.setFont(((Component) target).getFont());
092:                ((Component) target).paint(g);
093:            }
094:
095:            public void repaint(long tm, int x, int y, int width, int height) {
096:                addRepaintArea(x, y, width, height);
097:                ScreenUpdater.updater.notify(this , tm);
098:            }
099:
100:            public void print(Graphics g) {
101:                /*
102:                    ((Component)target).print(g);
103:                ((PPCGraphics)g).print(this);
104:                 */
105:            }
106:
107:            public synchronized native void reshape(int x, int y, int width,
108:                    int height);
109:
110:            native void nativeHandleEvent(AWTEvent e);
111:
112:            public void handleEvent(AWTEvent e) {
113:                int id = e.getID();
114:
115:                switch (id) {
116:                //might want to update the paint stuff with PP code
117:                case PaintEvent.PAINT:
118:                case PaintEvent.UPDATE:
119:                    Graphics g = null;
120:                    Rectangle r = ((PaintEvent) e).getUpdateRect();
121:                    synchronized (this ) {
122:                        g = ((Component) target).getGraphics();
123:                    }
124:                    if (g == null) {
125:                        return;
126:                    }
127:                    g.clipRect(r.x, r.y, r.width, r.height);
128:                    if (id == PaintEvent.PAINT) {
129:                        clearRectBeforePaint(g, r);
130:                        ((Component) target).paint(g);
131:                    } else {
132:                        ((Component) target).update(g);
133:                    }
134:                    g.dispose();
135:                }
136:
137:                // Call the native code
138:                nativeHandleEvent(e);
139:            }
140:
141:            // Do a clearRect() before paint for most Components.  This is
142:            // overloaded to do nothing for native components.
143:            void clearRectBeforePaint(Graphics g, Rectangle r) {
144:                g.clearRect(r.x, r.y, r.width, r.height);
145:            }
146:
147:            public Dimension getMinimumSize() {
148:                return ((Component) target).getSize();
149:            }
150:
151:            public Dimension getPreferredSize() {
152:                return getMinimumSize();
153:            }
154:
155:            public boolean isFocusTraversable() {
156:                return false;
157:            }
158:
159:            public boolean isDoubleBuffered() {
160:                return false;
161:            }
162:
163:            public ColorModel getColorModel() {
164:                return PPCToolkit.getStaticColorModel();
165:            }
166:
167:            public java.awt.Toolkit getToolkit() {
168:                return Toolkit.getDefaultToolkit();
169:            }
170:
171:            public Graphics getGraphics() {
172:                Graphics g = new PPCGraphics(this );
173:                g.setColor(((Component) target).getForeground());
174:                g.setFont(((Component) target).getFont());
175:                return g;
176:            }
177:
178:            public FontMetrics getFontMetrics(Font font) {
179:                return PPCFontMetrics.getFontMetrics(font);
180:            }
181:
182:            /*
183:             * Subclasses should override disposeImpl() instead of dispose(). Client
184:             * code should always invoke dispose(), never disposeImpl().
185:             */
186:            public void dispose() {
187:                /* Can this be removed?
188:                    if (!(this instanceof PPCWindowPeer)) {
189:                        Container parent =
190:                	PeerBasedToolkit.getNativeContainer((Component)target);
191:                        if (parent != null) {
192:                            PPCContainerPeer parentPeer = (PPCContainerPeer) PPCToolkit.getComponentPeer(parent);
193:                            if (parentPeer != null)
194:                                parentPeer.remove(this);
195:                        }
196:                    }
197:                 */
198:                disposeNative();
199:            }
200:
201:            private native void disposeNative();
202:
203:            public synchronized void setForeground(Color c) {
204:                _setForeground(c.getRGB());
205:            }
206:
207:            public synchronized void setBackground(Color c) {
208:                _setBackground(c.getRGB());
209:            }
210:
211:            public native void _setForeground(int rgb);
212:
213:            public native void _setBackground(int rgb);
214:
215:            public synchronized native void setFont(Font f);
216:
217:            public synchronized native void requestFocus();
218:
219:            public synchronized native void setCursor(Cursor c);
220:
221:            public Image createImage(ImageProducer producer) {
222:                return new PPCImage(producer);
223:            }
224:
225:            public Image createImage(int width, int height) {
226:                return new PPCImage(((Component) target), width, height);
227:            }
228:
229:            public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
230:                return PPCToolkit.prepareScrImage(img, w, h, o);
231:            }
232:
233:            public int checkImage(Image img, int w, int h, ImageObserver o) {
234:                return PPCToolkit.checkScrImage(img, w, h, o);
235:            }
236:
237:            // UpdateClient implementation
238:
239:            public void updateClient(Object arg) {
240:                // bug 4073091.
241:                // Integrated fix as suggested by Oracle.
242:                if (((Component) target).isDisplayable()) {
243:                    Rectangle updateRect = null;
244:                    synchronized (this ) {
245:                        if (repaintPending) {
246:                            updateRect = repaintRect;
247:                            repaintPending = false;
248:                        }
249:                    }
250:                    if (updateRect != null) {
251:                        postEvent(new PaintEvent((Component) target,
252:                                PaintEvent.UPDATE, updateRect));
253:                    }
254:                }
255:            }
256:
257:            // Object overrides
258:
259:            public String toString() {
260:                return getClass().getName() + "[" + target + "]";
261:            }
262:
263:            // Toolkit & peer internals
264:
265:            private int updateX1, updateY1, updateX2, updateY2;
266:
267:            PPCComponentPeer(Component target) {
268:                this .target = target;
269:                this .repaintRect = new Rectangle();
270:                this .repaintPending = false;
271:                Container parent = PPCToolkit.getNativeContainer(target);
272:                PPCComponentPeer parentPeer = (PPCComponentPeer) PeerBasedToolkit
273:                        .getComponentPeer(parent);
274:
275:                if (parent != null && parentPeer == null) {
276:                    parent.addNotify();
277:                    parentPeer = (PPCComponentPeer) PeerBasedToolkit
278:                            .getComponentPeer(parent);
279:                }
280:                create(parentPeer);
281:                initialize();
282:                start(); // Initialize enable/disable state, turn on callbacks
283:            }
284:
285:            abstract void create(PPCComponentPeer parent);
286:
287:            synchronized native void start();
288:
289:            void initialize() {
290:                initZOrderPosition();
291:
292:                if (((Component) target).isVisible()) {
293:                    show(); // the wnd starts hidden
294:                }
295:                Color fg = ((Component) target).getForeground();
296:                if (fg != null) {
297:                    setForeground(fg);
298:                }
299:                // Set background color in C++, to avoid inheriting a parent's color.
300:                Font f = ((Component) target).getFont();
301:                if (f != null) {
302:                    setFont(f);
303:                }
304:                if (!((Component) target).isEnabled()) {
305:                    disable();
306:                }
307:
308:                Rectangle r = ((Component) target).getBounds();
309:                setBounds(r.x, r.y, r.width, r.height);
310:
311:                // Set cursor if necessary.
312:                Cursor c = ((Component) target).getCursor();
313:                if (c != Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)) {
314:                    setCursor(c);
315:                }
316:            }
317:
318:            private synchronized void addRepaintArea(int x, int y, int w, int h) {
319:                if (repaintPending == false) {
320:                    repaintPending = true;
321:                    repaintRect = new Rectangle(x, y, w, h);
322:                } else {
323:                    /* expand the repaint area */
324:                    repaintRect = repaintRect.union(new Rectangle(x, y, w, h));
325:                }
326:            }
327:
328:            // Callbacks for window-system events to the frame
329:
330:            // Invoke a update() method call on the target
331:            void handleRepaint(int x, int y, int w, int h) {
332:                // Repaints are posted from updateClient now...
333:            }
334:
335:            // Invoke a paint() method call on the target, after clearing the
336:            // damaged area.
337:            void handleExpose(int x, int y, int w, int h) {
338:                // Bug ID 4081126 - can't do the clearRect() here, since it
339:                // interferes with the java thread working in the same window
340:                // on multi-processor NT machines.
341:
342:                postEvent(new PaintEvent((Component) target, PaintEvent.PAINT,
343:                        new Rectangle(x, y, w, h)));
344:            }
345:
346:            /* Invoke a paint() method call on the target, without clearing the
347:             * damaged area.  This is normally called by a native control after
348:             * it has painted itself. */
349:            void handlePaint(int x, int y, int w, int h) {
350:                postEvent(new PaintEvent((Component) target, PaintEvent.PAINT,
351:                        new Rectangle(x, y, w, h)));
352:            }
353:
354:            /*
355:             * Post an event. Queue it for execution by the callback thread.
356:             */
357:            void postEvent(AWTEvent event) {
358:                PPCToolkit.postEvent(event);
359:            }
360:
361:            protected void finalize() throws Throwable {
362:                // Calling dispose() here is essentially a NOP since the current
363:                // implementation prohibts gc before an explicit call to dispose().
364:                dispose();
365:                super .finalize();
366:            }
367:
368:            // Routines to support deferred window positioning.
369:            public void beginValidate() {
370:
371:                // Fix for oracle repaint bugs #4045627, #4045617 and #4040638
372:                // Removed call to clearRect that was formerly here.
373:
374:                _beginValidate();
375:            }
376:
377:            public native void _beginValidate();
378:
379:            public native void endValidate();
380:
381:            public void initZOrderPosition() {
382:                Container p = ((Component) target).getParent();
383:                PPCComponentPeer peerAbove = null;
384:
385:                if (p != null) {
386:                    Component children[] = p.getComponents();
387:                    for (int i = 0; i < children.length; i++) {
388:                        if (children[i] == target) {
389:                            break;
390:                        } else {
391:                            Object cpeer = PeerBasedToolkit
392:                                    .getComponentPeer(children[i]);
393:                            if (cpeer != null
394:                                    && !(cpeer instanceof  sun.awt.peer.LightweightPeer)) {
395:                                peerAbove = (PPCComponentPeer) cpeer;
396:                            }
397:                        }
398:                    }
399:
400:                }
401:                setZOrderPosition(peerAbove);
402:            }
403:
404:            native void setZOrderPosition(PPCComponentPeer compAbove);
405:
406:            /**
407:             * DEPRECATED
408:             */
409:            public Dimension minimumSize() {
410:                return getMinimumSize();
411:            }
412:
413:            /**
414:             * DEPRECATED
415:             */
416:            public Dimension preferredSize() {
417:                return getPreferredSize();
418:            }
419:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.