Source Code Cross Referenced for SimpleBasisAMSBorder.java in  » 6.0-JDK-Modules » j2me » com » sun » jumpimpl » presentation » simplebasis » 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 » com.sun.jumpimpl.presentation.simplebasis 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Portions Copyright  2000-2006 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation. 
008:         * 
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt). 
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA 
019:         * 
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions.
023:         */
024:
025:        /**
026:         * Copyright(c) 1997 DTAI, Incorporated (http://www.dtai.com)
027:         *
028:         *                        All rights reserved
029:         *
030:         * Permission to use, copy, modify and distribute this material for
031:         * any purpose and without fee is hereby granted, provided that the
032:         * above copyright notice and this permission notice appear in all
033:         * copies, and that the name of DTAI, Incorporated not be used in
034:         * advertising or publicity pertaining to this material without the
035:         * specific, prior written permission of an authorized representative of
036:         * DTAI, Incorporated.
037:         *
038:         * DTAI, INCORPORATED MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES,
039:         * EXPRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
040:         * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
041:         * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST
042:         * INFRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
043:         * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL DTAI, INCORPORATED OR
044:         * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
045:         * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELATING
046:         * TO THE SOFTWARE.
047:         */package com.sun.jumpimpl.presentation.simplebasis;
048:
049:        import java.awt.Color;
050:        import java.awt.Graphics;
051:        import java.awt.Insets;
052:
053:        public class SimpleBasisAMSBorder implements  Cloneable {
054:
055:            public static final int NONE = 0;
056:            public static final int LINE = 1;
057:            public static final int THREED_IN = 2;
058:            public static final int THREED_OUT = 3;
059:            public static final int ETCHED_IN = 4;
060:            public static final int EMBOSSED_OUT = 5;
061:            public static final int ROUND_RECT = 6;
062:
063:            private int type = NONE;
064:            private Color JUMPGuiAMSBorder = null;
065:            private int topMargin = 0;
066:            private int leftMargin = 0;
067:            private int bottomMargin = 0;
068:            private int rightMargin = 0;
069:            private int minMargin = 0;
070:            private int maxMargin = 0;
071:            private int JUMPGuiAMSBorderThickness = 0;
072:
073:            private static final double BRIGHTER_FACTOR = 0.8;
074:            private static final double DARKER_FACTOR = 0.65;
075:
076:            /**
077:             * Returns a brighter version of this color.
078:             * Replaces the "awt.Color" function brighter to use, in my opinion,
079:             * a better factor (awt used FACTOR = 0.7)
080:             *
081:             * @param color     the color to which to apply the factor
082:             * @return          the new, brighter color
083:             */
084:            public static Color brighter(Color color) {
085:                Color newcolor = new Color(
086:                        Math.min(
087:                                (int) (color.getRed() * (1 / BRIGHTER_FACTOR)),
088:                                255),
089:                        Math
090:                                .min(
091:                                        (int) (color.getGreen() * (1 / BRIGHTER_FACTOR)),
092:                                        255),
093:                        Math
094:                                .min(
095:                                        (int) (color.getBlue() * (1 / BRIGHTER_FACTOR)),
096:                                        255));
097:                if (newcolor.equals(color)) {
098:                    return Color.white;
099:                }
100:                return newcolor;
101:            }
102:
103:            /**
104:             * Returns a darker version of this color.
105:             * Replaces the "awt.Color" function brighter to use, in my opinion,
106:             * a better factor (awt used FACTOR = 0.7)
107:             *
108:             * @param color     the color to which to apply the factor
109:             * @return          the new, darker color
110:             */
111:            public static Color darker(Color color) {
112:                Color newcolor = new Color(Math.max(
113:                        (int) (color.getRed() * DARKER_FACTOR), 0), Math.max(
114:                        (int) (color.getGreen() * DARKER_FACTOR), 0), Math.max(
115:                        (int) (color.getBlue() * DARKER_FACTOR), 0));
116:                if (newcolor.equals(color)) {
117:                    return Color.black;
118:                }
119:                return newcolor;
120:            }
121:
122:            /**
123:             * Returns a clone of this JUMPGuiAMSBorder
124:             *
125:             * @return      the new, identical JUMPGuiAMSBorder
126:             */
127:            /*
128:             public Object clone() {
129:             SimpleBasisAMSBorder newJUMPGuiAMSBorder = new SimpleBasisAMSBorder();
130:             newJUMPGuiAMSBorder.type = type;
131:             newJUMPGuiAMSBorder.SimpleBasisAMSBorder = SimpleBasisAMSBorder;
132:             newJUMPGuiAMSBorder.topMargin = topMargin;
133:             newJUMPGuiAMSBorder.leftMargin = leftMargin;
134:             newJUMPGuiAMSBorder.bottomMargin = bottomMargin;
135:             newJUMPGuiAMSBorder.rightMargin = rightMargin;
136:             newJUMPGuiAMSBorder.minMargin = minMargin;
137:             newJUMPGuiAMSBorder.maxMargin = maxMargin;
138:             newJUMPGuiAMSBorder.JUMPGuiAMSBorderThickness = JUMPGuiAMSBorderThickness;
139:             return newJUMPGuiAMSBorder;
140:             }
141:             */
142:
143:            /**
144:             * sets all margins and thicknesses to zero
145:             */
146:            /*
147:             public void setNoInsets() {
148:             topMargin = 0;
149:             leftMargin = 0;
150:             bottomMargin = 0;
151:             rightMargin = 0;
152:             minMargin = 0;
153:             maxMargin = 0;
154:             JUMPGuiAMSBorderThickness = 0;
155:             }
156:             */
157:
158:            /**
159:             * Returns the JUMPGuiAMSBorder type (e.g., JUMPGuiAMSBorder.LINE)
160:             *
161:             * @return      the JUMPGuiAMSBorder type id
162:             */
163:            /*
164:             public int getType() {
165:             return type;
166:             }
167:             */
168:
169:            /**
170:             * Sets the SimpleBasisAMSBorder type (e.g., to SimpleBasisAMSBorder.LINE)
171:             * 
172:             * @param type     the SimpleBasisAMSBorder type
173:             */
174:            public synchronized void setType(int type) {
175:                this .type = type;
176:            }
177:
178:            /**
179:             * Returns the current JUMPGuiAMSBorder color.  If null (the default), a JUMPGuiAMSBorder color is
180:             * dynamically derived from the current background (passed to the "paint" function).
181:             *
182:             * @return     the current Color value for the JUMPGuiAMSBorder
183:             */
184:            /*
185:             public Color getJUMPGuiAMSBorder() {
186:             return SimpleBasisAMSBorder;
187:             }
188:             */
189:
190:            /**
191:             * Sets the current JUMPGuiAMSBorder color.  If null (the default), a JUMPGuiAMSBorder color is
192:             * dynamically derived from the current background (passed to the "paint" function).
193:             *
194:             * @param JUMPGuiAMSBorder     the new JUMPGuiAMSBorder color
195:             */
196:            /*
197:             public synchronized void setJUMPGuiAMSBorder(Color SimpleBasisAMSBorder) {
198:             this.SimpleBasisAMSBorder = SimpleBasisAMSBorder;
199:             }
200:             */
201:
202:            /**
203:             * Returns the top margin.
204:             *
205:             * @return          the top margin
206:             */
207:            /*
208:             public int getTopMargin() {
209:             return topMargin;
210:             }
211:             */
212:
213:            /**
214:             * Returns the left margin.
215:             *
216:             * @return          the left margin
217:             */
218:            /*
219:             public int getLeftMargin() {
220:             return leftMargin;
221:             }
222:             */
223:
224:            /**
225:             * Returns the bottom margin.
226:             *
227:             * @return          the bottom margin
228:             */
229:            /*
230:             public int getBottomMargin() {
231:             return bottomMargin;
232:             }
233:             */
234:
235:            /**
236:             * Returns the right margin.
237:             *
238:             * @return          the right margin
239:             */
240:            public int getRightMargin() {
241:                return rightMargin;
242:            }
243:
244:            /**
245:             * Used internally to calculate the minimum/maximum margin values.
246:             */
247:            private void resetMinMaxMargin() {
248:                maxMargin = topMargin;
249:                maxMargin = Math.max(maxMargin, leftMargin);
250:                maxMargin = Math.max(maxMargin, bottomMargin);
251:                maxMargin = Math.max(maxMargin, rightMargin);
252:                minMargin = topMargin;
253:                minMargin = Math.min(minMargin, leftMargin);
254:                minMargin = Math.min(minMargin, bottomMargin);
255:                minMargin = Math.min(minMargin, rightMargin);
256:            }
257:
258:            /**
259:             * Sets all margins (top, left, bottom, and right) to the same, given value.
260:             *
261:             * @param margin         the margin
262:             */
263:            public synchronized void setMargins(int margin) {
264:                topMargin = margin;
265:                leftMargin = margin;
266:                bottomMargin = margin;
267:                rightMargin = margin;
268:                resetMinMaxMargin();
269:            }
270:
271:            /**
272:             * Sets all margins (top, left, bottom, and right) to the given values.
273:             *
274:             * @param top           the top margin
275:             * @param left          the left margin
276:             * @param bottom        the bottom margin
277:             * @param right         the right margin
278:             */
279:            public synchronized void setMargins(int top, int left, int bottom,
280:                    int right) {
281:                topMargin = top;
282:                leftMargin = left;
283:                bottomMargin = bottom;
284:                rightMargin = right;
285:                resetMinMaxMargin();
286:            }
287:
288:            /**
289:             * Sets the top margin
290:             *
291:             * @param top           the top margin
292:             */
293:            /*
294:            public synchronized void setTopMargin(int margin) {
295:                topMargin = margin;
296:                resetMinMaxMargin();
297:            }
298:             */
299:
300:            /**
301:             * Sets the left margin
302:             *
303:             * @param left          the left margin
304:             */
305:            /*
306:             public synchronized void setLeftMargin(int margin) {
307:             leftMargin = margin;
308:             resetMinMaxMargin();
309:             }
310:             */
311:
312:            /**
313:             * Sets the bottom margin
314:             *
315:             * @param bottom        the bottom margin
316:             */
317:            /*
318:             public synchronized void setBottomMargin(int margin) {
319:             bottomMargin = margin;
320:             resetMinMaxMargin();
321:             }
322:             */
323:
324:            /**
325:             * Sets the right margin
326:             *
327:             * @param right         the right margin
328:             */
329:            /*
330:             public synchronized void setRightMargin(int margin) {
331:             rightMargin = margin;
332:             resetMinMaxMargin();
333:             }
334:             */
335:
336:            /**
337:             * Returns the current setting for the JUMPGuiAMSBorder thickness
338:             *
339:             * @return    the JUMPGuiAMSBorder thickness
340:             */
341:            /*
342:             public int getJUMPGuiAMSBorderThickness() {
343:             return JUMPGuiAMSBorderThickness;
344:             }
345:             */
346:
347:            /**
348:             * Sets the SimpleBasisAMSBorder thickness
349:             * 
350:             * @param JUMPGuiAMSBorderThickness         the SimpleBasisAMSBorder thickness
351:             */
352:            public synchronized void setJUMPGuiAMSBorderThickness(
353:                    int JUMPGuiAMSBorderThickness) {
354:                this .JUMPGuiAMSBorderThickness = JUMPGuiAMSBorderThickness;
355:            }
356:
357:            /**
358:             * returns the left, right, top, and bottom insets of the background of the
359:             * current style, taking into account thickness and margins.
360:             *
361:             * @return  an Insets object containing the inset values
362:             */
363:            public Insets getInsets() {
364:                int top = JUMPGuiAMSBorderThickness + topMargin;
365:                int left = JUMPGuiAMSBorderThickness + leftMargin;
366:                int bottom = JUMPGuiAMSBorderThickness + bottomMargin;
367:                int right = JUMPGuiAMSBorderThickness + rightMargin;
368:                return new Insets(top, left, bottom, right);
369:            }
370:
371:            /**
372:             * returns the left, right, top, and bottom insets of the background of the
373:             * current style, taking into account thickness and margins.
374:             * 
375:             * @param g           the Graphics in which to paint
376:             * @param background  the current background color (or null), used if available to
377:             *                      calculate the SimpleBasisAMSBorder color if that is null.
378:             * @param x           the x location of the upper-left point of the SimpleBasisAMSBorder
379:             * @param y           the y location of the upper-left point of the SimpleBasisAMSBorder
380:             * @param width       the width of the rectangle in which to draw the SimpleBasisAMSBorder
381:             * @param height      the height of the rectangle in which to draw the SimpleBasisAMSBorder
382:             */
383:            public void paint(Graphics g, Color background, int x, int y,
384:                    int width, int height) {
385:                if (JUMPGuiAMSBorder == null) {
386:                    if ((type == LINE) || (type == ROUND_RECT)) {
387:                        if (background == Color.black) {
388:                            JUMPGuiAMSBorder = Color.white;
389:                        } else {
390:                            JUMPGuiAMSBorder = Color.black;
391:                        }
392:                    } else {
393:                        if (background == null) {
394:                            JUMPGuiAMSBorder = Color.lightGray;
395:                        } else {
396:                            JUMPGuiAMSBorder = background;
397:                        }
398:                    }
399:                }
400:
401:                if (JUMPGuiAMSBorder != null) {
402:                    g.setColor(JUMPGuiAMSBorder);
403:
404:                    Color brighter = null;
405:                    Color darker = null;
406:
407:                    switch (type) {
408:
409:                    case THREED_IN:
410:                    case THREED_OUT:
411:                    case ETCHED_IN:
412:                    case EMBOSSED_OUT: {
413:                        brighter = brighter(JUMPGuiAMSBorder);
414:                        darker = darker(JUMPGuiAMSBorder);
415:                        break;
416:                    }
417:                    }
418:
419:                    for (int idx = 0; idx < JUMPGuiAMSBorderThickness; idx++) {
420:                        if (type == LINE) {
421:                            g.drawRect(x + idx, y + idx,
422:                                    ((width - 1) - (idx * 2)),
423:                                    ((height - 1) - (idx * 2)));
424:                        } else if (type == ROUND_RECT) {
425:
426:                            int arcSize = (minMargin * 8 - (idx * 2));
427:                            int rrx = x + idx;
428:                            int rry = y + idx;
429:                            int rrw = (width - 1) - (idx * 2);
430:                            int rrh = (height - 1) - (idx * 2);
431:
432:                            g.drawRoundRect(x + idx, y + idx, rrw, rrh,
433:                                    arcSize, arcSize);
434:                            if ((idx + 1) < JUMPGuiAMSBorderThickness) {
435:                                g.drawRoundRect(rrx, rry, rrw, rrh - 1,
436:                                        arcSize - 1, arcSize);
437:                                g.drawRoundRect(rrx + 1, rry, rrw, rrh - 1,
438:                                        arcSize - 1, arcSize);
439:                                g.drawRoundRect(rrx, rry, rrw - 1, rrh,
440:                                        arcSize, arcSize - 1);
441:                                g.drawRoundRect(rrx, rry + 1, rrw - 1, rrh,
442:                                        arcSize, arcSize - 1);
443:                            }
444:                        } else {
445:                            Color top = brighter;
446:                            Color bottom = darker;
447:
448:                            if ((type == THREED_IN) || (type == ETCHED_IN)) {
449:                                top = darker;
450:                                bottom = brighter;
451:                            }
452:
453:                            if ((type == ETCHED_IN) || (type == EMBOSSED_OUT)) {
454:                                if (idx >= (JUMPGuiAMSBorderThickness / 2)) {
455:                                    Color temp = top;
456:                                    top = bottom;
457:                                    bottom = temp;
458:                                }
459:
460:                            }
461:
462:                            if ((idx == (JUMPGuiAMSBorderThickness - 1))
463:                                    && (type == THREED_IN)) {
464:                                g.setColor(darker(top));
465:                            } else {
466:                                g.setColor(top);
467:                            }
468:
469:                            g.drawLine(x + idx, y + idx, x + idx, y
470:                                    + ((height - 1) - (idx)));
471:                            g.drawLine(x + idx, y + idx, x
472:                                    + ((width - 1) - (idx)), y + idx);
473:
474:                            if (((idx == (JUMPGuiAMSBorderThickness - 1)) && (type == THREED_IN))
475:                                    || ((idx == 0) && (type == THREED_OUT))) {
476:                                g.setColor(darker(bottom));
477:                            } else {
478:                                g.setColor(bottom);
479:                            }
480:
481:                            g.drawLine(x + idx, y + ((height - 1) - (idx)), x
482:                                    + ((width - 1) - (idx)), y
483:                                    + ((height - 1) - (idx)));
484:                            g.drawLine(x + ((width - 1) - (idx)), y + idx, x
485:                                    + ((width - 1) - (idx)), y
486:                                    + ((height - 1) - (idx)));
487:                        }
488:                    }
489:                }
490:            }
491:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.