Source Code Cross Referenced for Icons.java in  » IDE » tIDE » snow » utils » gui » 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 » IDE » tIDE » snow.utils.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package snow.utils.gui;
0002:
0003:        import java.awt.*;
0004:        import java.awt.image.*;
0005:        import java.awt.geom.*;
0006:        import javax.swing.*;
0007:
0008:        /** Contain some icons.
0009:         *
0010:         *  CONCEPT:
0011:         *   PlusIcon: to add
0012:         *   RightArrow: jumps  (gray for deps)
0013:         *   LeftArrow:  undo, revert, ...
0014:         *   DownArrow:  download
0015:         *   UpArrow:    upload
0016:         *   CrossIcon: to delete, ...
0017:         *   WizIcon : for operations that transforms any source content
0018:         */
0019:        public abstract class Icons implements  Icon {
0020:            // all approx of the same size... and active...
0021:            public final static Icon sharedLeftArrow = new HArrow(14, 14, true,
0022:                    false, true);
0023:            public final static Icon sharedRightArrow = new HArrow(14, 14, true);
0024:            public final static Icon sharedDownArrow = new VArrow(14, 14,
0025:                    false, true, true);
0026:            public final static Icon sharedUpArrow = new VArrow(14, 14, true);
0027:
0028:            public final static Icon sharedCross = new CrossIcon(10, 10, true);
0029:            public final static Icon sharedWiz = new WizIcon(13, true);
0030:            public final static Icon sharedOpenLock = new LockIcon(16, 16,
0031:                    true, true);
0032:            public final static Icon sharedClosedLock = new LockIcon(16, 16,
0033:                    false, true);
0034:            public final static Icon sharedTimer = new Icons.TimerIcon(16, 16,
0035:                    true);
0036:            public final static Icon sharedEye = new Icons.EyeIcon(16, 16, true);
0037:            public final static Icon sharedPlus = new PlusIcon(10, 10, true);
0038:            public final static Icon sharedSearch = new SearchIcon(15, true);
0039:            public final static Icon sharedOk = new Icons.OkIcon(12, 12, true);
0040:            public final static Icon sharedWarn = new WarnIcon(16, 16, true);
0041:            public final static Icon sharedStop = new StopIcon(11, 11, true);
0042:            public final static Icon sharedStart = new StartIcon(14, 14, true);
0043:            public final static Icon sharedSmallStart = new StartIcon(10, 10,
0044:                    true);
0045:            public final static Icon sharedDebugStart = new StartIcon(14, 14,
0046:                    true, true, Color.green);
0047:
0048:            public final static Icon sharedUpWedge = new UpWedge(11, 11, true);
0049:            public final static Icon sharedDownWedge = new DownWedge(11, 11,
0050:                    true);
0051:
0052:            public final static Icon sharedStat = new StatIcon(16, 16);
0053:
0054:            protected int w, h;
0055:
0056:            public Icons(int w, int h) {
0057:                this .w = w;
0058:                this .h = h;
0059:            }
0060:
0061:            public int getIconWidth() {
0062:                return w;
0063:            }
0064:
0065:            public int getIconHeight() {
0066:                return h;
0067:            }
0068:
0069:            @Override
0070:            public void paintIcon(Component c, Graphics g, int x, int y) {
0071:                Graphics2D g2 = (Graphics2D) g;
0072:                g2.setRenderingHint(RenderingHints.KEY_RENDERING,
0073:                        RenderingHints.VALUE_RENDER_QUALITY);
0074:                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
0075:                        RenderingHints.VALUE_ANTIALIAS_ON);
0076:
0077:                //g2.setColor(c.getBackground());
0078:                // transparent => no fill
0079:                //g2.fill(new Rectangle2D.Double(x,y,w,h));
0080:
0081:                // backup
0082:                Font oldFont = g2.getFont();
0083:                Stroke oldStroke = g2.getStroke();
0084:                Color oldColor = g2.getColor();
0085:
0086:                if (c != null) {
0087:                    g2.setColor(c.getForeground());
0088:                }
0089:                g2.translate(x, y);
0090:                _paintIcon(c, g2);
0091:                g2.translate(-x, -y);
0092:
0093:                // restore
0094:                g2.setFont(oldFont);
0095:                g2.setStroke(oldStroke);
0096:                g2.setColor(oldColor);
0097:            }
0098:
0099:            public abstract void _paintIcon(Component c, Graphics2D g);
0100:
0101:            /** useful to set a frame icon (that requires to be an image)
0102:             */
0103:            public static Image createImage(Icon icon) {
0104:                BufferedImage bim = new BufferedImage(icon.getIconWidth(), icon
0105:                        .getIconHeight(), BufferedImage.TYPE_INT_ARGB);
0106:                Graphics2D g = bim.createGraphics();
0107:                icon.paintIcon(null, g, 0, 0);
0108:                g.dispose();
0109:                return bim;
0110:            }
0111:
0112:            // The implementations
0113:            //
0114:
0115:            public static class StartIcon extends Icons {
0116:                boolean enabled;
0117:                boolean debug = false;
0118:                Color color = Color.green;
0119:
0120:                public StartIcon(int w, int h, boolean enabled) {
0121:                    this (w, h, enabled, false, Color.green);
0122:                }
0123:
0124:                public StartIcon(int w, int h, boolean enabled, boolean debug,
0125:                        Color c) {
0126:                    super (w, h);
0127:                    this .enabled = enabled;
0128:                    this .color = c;
0129:                    this .debug = debug;
0130:                }
0131:
0132:                @Override
0133:                public void _paintIcon(Component c, Graphics2D g2) {
0134:                    GeneralPath gp = new GeneralPath();
0135:                    gp.moveTo(w / 4f, h / 8f);
0136:                    gp.lineTo(0.8f * w, .5f * h);
0137:                    gp.lineTo(w / 4f, h - h / 8f);
0138:                    gp.closePath();
0139:
0140:                    if (enabled) {
0141:                        g2.setColor(color);
0142:                        g2.fill(gp);
0143:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0144:                        g2.setColor(Color.black);
0145:                        g2.draw(gp);
0146:                    } else {
0147:                        g2.setColor(Color.gray);
0148:                        g2.fill(gp);
0149:                    }
0150:
0151:                    if (debug) {
0152:                        g2.setColor(Color.red);
0153:                        g2.fillOval(w - 6, h - 6, 5, 5);
0154:                    }
0155:                }
0156:            }
0157:
0158:            public static class WizIcon extends Icons {
0159:                boolean enabled;
0160:                final Color col = new Color(120, 120, 120, 130);
0161:
0162:                public WizIcon(int w, boolean enabled) {
0163:                    super (w, w);
0164:                    this .enabled = enabled;
0165:                }
0166:
0167:                @Override
0168:                public void _paintIcon(Component c, Graphics2D g2) {
0169:                    GeneralPath gp = new GeneralPath();
0170:                    gp.moveTo(0.1 * w, 0.1 * h);
0171:                    gp.lineTo(0.6 * w, 0.33 * h);
0172:                    gp.lineTo(0.4 * w, 0.66 * h);
0173:                    gp.lineTo(0.9 * w, 0.9 * h);
0174:                    gp.lineTo(0.9 * w, 0.9 * h);
0175:
0176:                    gp.lineTo(0.8 * w, 0.7 * h);
0177:                    gp.lineTo(0.7 * w, 0.9 * h);
0178:                    gp.lineTo(0.9 * w, 0.9 * h);
0179:
0180:                    if (enabled) {
0181:                        g2.setStroke(new BasicStroke(h / 15.0f));
0182:                        g2.draw(gp);
0183:                    } else {
0184:                        g2.setColor(Color.gray);
0185:                        g2.draw(gp);
0186:                    }
0187:                }
0188:            }
0189:
0190:            public static Icon createHelpIcon(int size, boolean enabled) {
0191:                LetterIcon li = new LetterIcon("?", false, size, size, true,
0192:                        enabled ? new Color(10, 10, 120) : Color.lightGray);
0193:                return li;
0194:            }
0195:
0196:            public static class LetterIcon extends Icons {
0197:                boolean enabled;
0198:                String letter;
0199:                boolean border;
0200:                final Color letterColor;
0201:
0202:                public LetterIcon(String letter, boolean border, int w, int h,
0203:                        boolean enabled) {
0204:                    this (letter, border, w, h, enabled, Color.black);
0205:                }
0206:
0207:                public LetterIcon(String letter, boolean border, int w, int h,
0208:                        boolean enabled, Color letterColor) {
0209:                    super (w, h);
0210:                    this .enabled = enabled;
0211:                    this .letter = letter;
0212:                    this .border = border;
0213:                    this .letterColor = letterColor;
0214:                }
0215:
0216:                @Override
0217:                public void _paintIcon(Component c, Graphics2D g2) {
0218:                    g2.setColor(letterColor);
0219:                    g2.setFont(new Font("Lucida Sans Typewriter", Font.BOLD
0220:                            | Font.BOLD, h * 6 / 7));
0221:                    g2.drawString(letter, w / 3, h - w / 5);
0222:
0223:                    if (border) {
0224:                        g2.setColor(Color.black);
0225:                        Shape rect = new Rectangle2D.Double(1, 1, w - 2, h - 2);
0226:                        g2.draw(rect);
0227:                    }
0228:                }
0229:            }
0230:
0231:            public static class StopIcon extends Icons {
0232:                boolean enabled;
0233:                Color color = Color.red;
0234:
0235:                public StopIcon(int w, int h, boolean enabled) {
0236:                    super (w, h);
0237:                    this .enabled = enabled;
0238:                }
0239:
0240:                @Override
0241:                public void _paintIcon(Component c, Graphics2D g2) {
0242:
0243:                    Shape rect = new Rectangle2D.Double(w / 8, w / 8,
0244:                            w - w / 4, h - w / 4);
0245:                    if (enabled) {
0246:                        g2.setColor(color);
0247:                        g2.fill(rect);
0248:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0249:                        g2.setColor(Color.black);
0250:                        g2.draw(rect);
0251:                    } else {
0252:                        g2.setColor(Color.gray);
0253:                        g2.fill(rect);
0254:                    }
0255:                }
0256:            }
0257:
0258:            public static class DiskIcon extends Icons {
0259:                boolean enabled;
0260:                final Color col;
0261:
0262:                public DiskIcon(int w, int h, Color c, boolean enabled) {
0263:                    super (w, h);
0264:                    this .enabled = enabled;
0265:                    this .col = c;
0266:                }
0267:
0268:                @Override
0269:                public void _paintIcon(Component c, Graphics2D g2) {
0270:
0271:                    Shape disk = new Arc2D.Double(w / 8, w / 8, w - w / 4, h
0272:                            - w / 4, 0, 360, Arc2D.CHORD);
0273:                    if (enabled) {
0274:                        g2.setColor(col);
0275:                        g2.fill(disk);
0276:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0277:                        g2.setColor(Color.black);
0278:                        g2.draw(disk);
0279:                    } else {
0280:                        g2.setColor(Color.gray);
0281:                        g2.fill(disk);
0282:                    }
0283:                }
0284:            }
0285:
0286:            public static class PauseIcon extends Icons {
0287:                boolean enabled;
0288:                Color color = Color.blue;
0289:
0290:                public PauseIcon(int w, int h, boolean enabled) {
0291:                    super (w, h);
0292:                    this .enabled = enabled;
0293:                }
0294:
0295:                @Override
0296:                public void _paintIcon(Component c, Graphics2D g2) {
0297:
0298:                    Shape rect1 = new Rectangle2D.Double(w / 8, w / 8, w / 2
0299:                            - w / 4, h - w / 4);
0300:                    Shape rect2 = new Rectangle2D.Double(w / 2 + w / 8, w / 8,
0301:                            w / 2 - w / 4, h - w / 4);
0302:                    if (enabled) {
0303:                        g2.setColor(color);
0304:                        g2.fill(rect1);
0305:                        g2.fill(rect2);
0306:                        //g2.setStroke(new BasicStroke((float) h/15.0f));
0307:                        //g2.setColor(Color.black);
0308:                        //g2.draw(rect);
0309:                    } else {
0310:                        g2.setColor(Color.gray);
0311:                        g2.fill(rect1);
0312:                        g2.fill(rect2);
0313:                    }
0314:                }
0315:            }
0316:
0317:            /** A red cross icon*/
0318:            public static class CrossIcon extends Icons {
0319:                boolean enabled;
0320:                Color color = Color.red;
0321:
0322:                public CrossIcon(int w, int h, boolean enabled) {
0323:                    super (w, h);
0324:                    this .enabled = enabled;
0325:                }
0326:
0327:                @Override
0328:                public void _paintIcon(Component c, Graphics2D g2) {
0329:
0330:                    Shape line1 = new Line2D.Double(w / 8, w / 8, w - w / 4, h
0331:                            - w / 4);
0332:                    Shape line2 = new Line2D.Double(w / 8, h - w / 4,
0333:                            w - w / 4, w / 8);
0334:                    if (enabled) {
0335:                        g2.setColor(color);
0336:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0337:                        g2.draw(line1);
0338:                        g2.draw(line2);
0339:                    } else {
0340:                        g2.setColor(Color.gray);
0341:                        g2.draw(line1);
0342:                        g2.draw(line2);
0343:                    }
0344:                }
0345:            }
0346:
0347:            /** A green ok icon */
0348:            public static class OkIcon extends Icons {
0349:                boolean enabled;
0350:                Color color = new Color(2, 120, 2);
0351:
0352:                //final public static OkIcon shared10 = new Icons.OkIcon(12,12,true);
0353:
0354:                public OkIcon(int w, int h, boolean enabled) {
0355:                    super (w, h);
0356:                    this .enabled = enabled;
0357:                }
0358:
0359:                @Override
0360:                public void _paintIcon(Component c, Graphics2D g2) {
0361:
0362:                    Shape line1 = new Line2D.Double(w / 3, h / 2, w / 2, h - w
0363:                            / 4);
0364:                    Shape line2 = new Line2D.Double(w / 2, h - w / 4,
0365:                            w - w / 4, w / 8);
0366:                    if (enabled) {
0367:                        g2.setColor(color);
0368:                        g2.setStroke(new BasicStroke((float) h / 7.0f));
0369:                        g2.draw(line1);
0370:                        g2.draw(line2);
0371:                    } else {
0372:                        g2.setColor(Color.gray);
0373:                        g2.draw(line1);
0374:                        g2.draw(line2);
0375:                    }
0376:                }
0377:            }
0378:
0379:            /** A blue "+" icon */
0380:            public static class PlusIcon extends Icons {
0381:                boolean enabled;
0382:                Color color = Color.blue;
0383:
0384:                //public static final PlusIcon shared10 = new PlusIcon(10,10,true);
0385:                public PlusIcon(int w, int h, boolean enabled) {
0386:                    super (w, h);
0387:                    this .enabled = enabled;
0388:                }
0389:
0390:                @Override
0391:                public void _paintIcon(Component c, Graphics2D g2) {
0392:
0393:                    Shape line1 = new Line2D.Double(w / 8, h / 2, w - w / 8,
0394:                            h / 2);
0395:                    Shape line2 = new Line2D.Double(w / 2, h - w / 8, w / 2,
0396:                            w / 8);
0397:                    if (enabled) {
0398:                        g2.setColor(color);
0399:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0400:                        g2.draw(line1);
0401:                        g2.draw(line2);
0402:                    } else {
0403:                        g2.setColor(Color.gray);
0404:                        g2.draw(line1);
0405:                        g2.draw(line2);
0406:                    }
0407:                }
0408:            }
0409:
0410:            /** a blue "->" icon used for jump */
0411:            public static class HArrow extends Icons {
0412:                boolean enabled;
0413:                Color color = Color.blue;
0414:                final boolean showLeft;
0415:                final boolean showRight;
0416:
0417:                public HArrow(int w, int h, boolean enabled) {
0418:                    this (w, h, false, true, enabled);
0419:                }
0420:
0421:                public HArrow(int w, int h, boolean showLeft,
0422:                        boolean showRight, boolean enabled) {
0423:                    super (w, h);
0424:                    this .showLeft = showLeft;
0425:                    this .showRight = showRight;
0426:                    this .enabled = enabled;
0427:                }
0428:
0429:                @Override
0430:                public void _paintIcon(Component c, Graphics2D g2) {
0431:                    if (enabled) {
0432:                        g2.setColor(color);
0433:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0434:                    } else {
0435:                        g2.setColor(Color.gray);
0436:                    }
0437:
0438:                    g2.draw(new Line2D.Double(w / 8, h / 2, w - w / 8, h / 2));
0439:                    if (showRight) {
0440:                        g2.draw(new Line2D.Double(w - w / 8, h / 2, 3 * w / 4
0441:                                - w / 8, h / 2 - h / 5));
0442:                        g2.draw(new Line2D.Double(w - w / 8, h / 2, 3 * w / 4
0443:                                - w / 8, h / 2 + h / 5));
0444:                    }
0445:
0446:                    if (showLeft) {
0447:                        g2.draw(new Line2D.Double(w / 8, h / 2, w / 4 + w / 8,
0448:                                h / 2 - h / 5));
0449:                        g2.draw(new Line2D.Double(w / 8, h / 2, w / 4 + w / 8,
0450:                                h / 2 + h / 5));
0451:
0452:                    }
0453:                }
0454:            }
0455:
0456:            /*
0457:             public static class LeftArrow extends Icons
0458:             {
0459:             boolean enabled;
0460:             Color color = Color.blue;
0461:             public final static Icon shared14 = new LeftArrow(14,14,true);
0462:
0463:             public LeftArrow(int w, int h, boolean enabled)
0464:             {
0465:             super(w,h);
0466:             this.enabled = enabled;
0467:             }
0468:             @Override
0469:             public void _paintIcon(Component c, Graphics2D g2)
0470:             {
0471:
0472:             Shape line1 = new Line2D.Double(w/8,h/2,w-w/8,h/2);
0473:             Shape line2 = new Line2D.Double(w/8,h/2,w/4+w/8,h/2-h/5);
0474:             Shape line3 = new Line2D.Double(w/8,h/2,w/4+w/8,h/2+h/5);
0475:             if(enabled)
0476:             {
0477:             g2.setColor(color);
0478:             g2.setStroke(new BasicStroke((float) h/15.0f));
0479:             g2.draw(line1);
0480:             g2.draw(line2);
0481:             g2.draw(line3);
0482:             }
0483:             else
0484:             {
0485:             g2.setColor(Color.gray);
0486:             g2.draw(line1);
0487:             g2.draw(line2);
0488:             g2.draw(line3);
0489:             }
0490:             }
0491:             }*/
0492:
0493:            /** a blue "->" icon used for uploads/downloads */
0494:            public static class VArrow extends Icons {
0495:                boolean enabled;
0496:                Color color = Color.blue;
0497:                final boolean showUp;
0498:                final boolean showDown;
0499:
0500:                // up
0501:                public VArrow(int w, int h, boolean enabled) {
0502:                    this (w, h, true, false, enabled);
0503:                }
0504:
0505:                public VArrow(int w, int h, boolean showUp, boolean showDown,
0506:                        boolean enabled) {
0507:                    super (w, h);
0508:                    this .enabled = enabled;
0509:                    this .showUp = showUp;
0510:                    this .showDown = showDown;
0511:                }
0512:
0513:                @Override
0514:                public void _paintIcon(Component c, Graphics2D g2) {
0515:
0516:                    if (enabled) {
0517:                        g2.setColor(color);
0518:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0519:                    } else {
0520:                        g2.setColor(Color.gray);
0521:                    }
0522:
0523:                    g2.draw(new Line2D.Double(w / 2, h / 8, w / 2, h - h / 8));
0524:                    if (showUp) {
0525:                        g2.draw(new Line2D.Double(w / 2, h / 8, w / 2 - w / 5,
0526:                                h / 4 + h / 8));
0527:                        g2.draw(new Line2D.Double(w / 2, h / 8, w / 2 + w / 5,
0528:                                h / 4 + h / 8));
0529:                    }
0530:
0531:                    if (showDown) {
0532:                        g2.draw(new Line2D.Double(w / 2, h - h / 8, w / 2 - w
0533:                                / 5, 3 * h / 4 - h / 8));
0534:                        g2.draw(new Line2D.Double(w / 2, h - h / 8, w / 2 + w
0535:                                / 5, 3 * h / 4 - h / 8));
0536:                    }
0537:                }
0538:            }
0539:
0540:            public static class UpWedge extends Icons {
0541:                boolean enabled;
0542:                Color color = Color.blue;
0543:
0544:                public UpWedge(int w, int h, boolean enabled) {
0545:                    super (w, h);
0546:                    this .enabled = enabled;
0547:                }
0548:
0549:                @Override
0550:                public void _paintIcon(Component c, Graphics2D g2) {
0551:                    Shape line1 = new Line2D.Double(w / 4, h - w / 4, w / 2,
0552:                            w / 8);
0553:                    Shape line2 = new Line2D.Double(w / 2, w / 8, w - w / 4, h
0554:                            - w / 4);
0555:
0556:                    if (enabled) {
0557:                        g2.setColor(color);
0558:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0559:                        g2.draw(line1);
0560:                        g2.draw(line2);
0561:                    } else {
0562:                        g2.setColor(Color.gray);
0563:                        g2.draw(line1);
0564:                        g2.draw(line2);
0565:                    }
0566:                }
0567:            }
0568:
0569:            public static class DownWedge extends Icons {
0570:                boolean enabled;
0571:                Color color = Color.blue;
0572:
0573:                public DownWedge(int w, int h, boolean enabled) {
0574:                    super (w, h);
0575:                    this .enabled = enabled;
0576:                }
0577:
0578:                @Override
0579:                public void _paintIcon(Component c, Graphics2D g2) {
0580:                    Shape line1 = new Line2D.Double(w / 4, w / 8, w / 2, h - w
0581:                            / 4);
0582:                    Shape line2 = new Line2D.Double(w / 2, h - w / 4,
0583:                            w - w / 4, w / 8);
0584:
0585:                    if (enabled) {
0586:                        g2.setColor(color);
0587:                        g2.setStroke(new BasicStroke((float) h / 15.0f));
0588:                        g2.draw(line1);
0589:                        g2.draw(line2);
0590:                    } else {
0591:                        g2.setColor(Color.gray);
0592:                        g2.draw(line1);
0593:                        g2.draw(line2);
0594:                    }
0595:                }
0596:            }
0597:
0598:            public static class SearchIcon extends Icons {
0599:                boolean enabled;
0600:                final Color col = new Color(20, 20, 120, 30);
0601:
0602:                // final public static SearchIcon shared18 = new SearchIcon(15, true);
0603:
0604:                public SearchIcon(int w, boolean enabled) {
0605:                    super (w, w);
0606:                    this .enabled = enabled;
0607:                }
0608:
0609:                @Override
0610:                public void _paintIcon(Component c, Graphics2D g2) {
0611:
0612:                    Shape disk = new Arc2D.Double(w / 2 - h / 15, 0, w / 2,
0613:                            w / 2, 0, 360, Arc2D.CHORD);
0614:                    Shape line1 = new Line2D.Double(0.15 * w, 0.75 * h,
0615:                            0.47 * w, 0.46 * w);
0616:                    if (enabled) {
0617:                        g2.setColor(col);
0618:                        g2.fill(disk);
0619:                        g2.setStroke(new BasicStroke(h / 15.0f));
0620:                        g2.setColor(Color.black);
0621:                        g2.draw(disk);
0622:                        g2.setStroke(new BasicStroke(h / 7.0f));
0623:                        g2.draw(line1);
0624:                    } else {
0625:                        g2.setColor(Color.gray);
0626:                        g2.fill(disk);
0627:                        g2.draw(line1);
0628:                    }
0629:                }
0630:            }
0631:
0632:            /** Shrinking/Growing colorized lozange */
0633:            public static class LozIcon extends Icons {
0634:                boolean enabled, grow;
0635:                final public static LozIcon shared16Grow = new LozIcon(16, 16,
0636:                        true, true);
0637:                final public static LozIcon shared16Shrink = new LozIcon(16,
0638:                        16, false, true);
0639:
0640:                public LozIcon(int w, int h, boolean grow, boolean enabled) {
0641:                    super (w, h);
0642:                    this .enabled = enabled;
0643:                    this .grow = grow;
0644:                }
0645:
0646:                @Override
0647:                public void _paintIcon(Component c, Graphics2D g2) {
0648:
0649:                    GeneralPath gp = new GeneralPath();
0650:                    if (grow) {
0651:                        gp.moveTo(w / 8, h / 2 - h / 8);
0652:                        gp.lineTo(w / 8, h / 2 + h / 8);
0653:                        gp.lineTo(w - w / 8, h - h / 8);
0654:                        gp.lineTo(w - w / 8, h / 8);
0655:                    } else {
0656:                        gp.moveTo(w / 8, h - h / 8);
0657:                        gp.lineTo(w / 8, h / 8);
0658:                        gp.lineTo(w - w / 8, h / 2 - h / 8);
0659:                        gp.lineTo(w - w / 8, h / 2 + h / 8);
0660:                    }
0661:
0662:                    gp.closePath();
0663:
0664:                    if (enabled) {
0665:                        if (grow) {
0666:                            g2.setPaint(new GradientPaint(0f, 0f, Color.green,
0667:                                    w, 0, Color.red));
0668:                        } else {
0669:                            g2.setPaint(new GradientPaint(0f, 0f, Color.red, w,
0670:                                    0, Color.green));
0671:                        }
0672:                        g2.fill(gp);
0673:
0674:                        g2.setColor(Color.black);
0675:                        g2.setStroke(new BasicStroke(h / 15.0f));
0676:                        g2.draw(gp);
0677:
0678:                    } else {
0679:                        //g2.setColor(Color.gray);
0680:                        g2.draw(gp);
0681:                    }
0682:                }
0683:            }
0684:
0685:            public static Icon mergeIcons(final int w, final int h,
0686:                    final Icon i1, final int x1, final int y1, final Icon i2,
0687:                    final int x2, final int y2) {
0688:                return new Icons(w, h) {
0689:                    public void _paintIcon(Component c, Graphics2D g2) {
0690:                        i1.paintIcon(c, g2, x1, y1);
0691:                        i2.paintIcon(c, g2, x2, y2);
0692:                    }
0693:                };
0694:            }
0695:
0696:            public static Shape closedDisk(double x, double y, double r) {
0697:                return new Arc2D.Double(x - r, y - r, 2 * r, 2 * r, 0, 360,
0698:                        Arc2D.OPEN);
0699:            }
0700:
0701:            /** a key */
0702:            public static class KeyIcon extends Icons {
0703:                boolean enabled;
0704:                final public static KeyIcon shared16 = new KeyIcon(16, 16, true);
0705:
0706:                public KeyIcon(int w, int h, boolean enabled) {
0707:                    super (w, h);
0708:                    this .enabled = enabled;
0709:                }
0710:
0711:                @Override
0712:                public void _paintIcon(Component c, Graphics2D g2) {
0713:                    final GeneralPath gp = new GeneralPath(
0714:                            GeneralPath.WIND_EVEN_ODD);
0715:                    //mitter joint stroke !      g2.setRenderingHint(RenderingHints.mitter)
0716:                    //gp.moveTo(w/3+w/16, h-h/3);
0717:                    gp.moveTo(w / 3, h - h / 3 + h / 16);
0718:                    gp.lineTo(w - w / 8, h / 8);
0719:
0720:                    gp.lineTo(w - w / 8 - w / 22, h / 8 - h / 22);
0721:                    //gp.lineTo(w-w/3, h/3-h/22);
0722:                    gp.lineTo(w - w / 3 - w / 11, h / 3 - h / 5.5);
0723:
0724:                    gp.lineTo(w - w / 3 - w / 8.0, h / 2 - h / 6);
0725:
0726:                    gp.lineTo(w - w / 3 - w / 4.5, h / 2 - h / 8.0);
0727:
0728:                    gp.lineTo(w / 3 - w / 22.0, h - h / 3);
0729:                    gp.closePath();
0730:
0731:                    final GeneralPath gp2 = new GeneralPath(
0732:                            GeneralPath.WIND_EVEN_ODD);
0733:                    gp2.append(closedDisk(w / 16 + w / 6, h - h / 6 - h / 16,
0734:                            w / 6), false);
0735:                    gp2.append(closedDisk(w / 16 + w / 6, h - h / 6 - h / 16,
0736:                            w / 18), false);
0737:                    gp2.closePath();
0738:
0739:                    if (enabled) {
0740:                        g2.setPaint(new GradientPaint(0f, h, Color.orange, w,
0741:                                0, Color.yellow));
0742:                        g2.fill(gp);
0743:                        g2.setColor(Color.black);
0744:                        g2.setStroke(new BasicStroke(h / 15.0f));
0745:                        g2.draw(gp);
0746:
0747:                        g2.setPaint(new GradientPaint(0f, h, Color.orange, w,
0748:                                0, Color.yellow));
0749:                        g2.fill(gp2);
0750:                        g2.setColor(Color.black);
0751:                        g2.setStroke(new BasicStroke(h / 15.0f));
0752:                        g2.draw(gp2);
0753:
0754:                    } else {
0755:                        //g2.setColor(Color.gray);
0756:                        g2.draw(gp);
0757:                        g2.draw(gp2);
0758:
0759:                    }
0760:                }
0761:            }
0762:
0763:            /** A warning key */
0764:            public static class WarnIcon extends Icons {
0765:                boolean enabled;
0766:
0767:                public WarnIcon(int w, int h, boolean enabled) {
0768:                    super (w, h);
0769:                    this .enabled = enabled;
0770:                }
0771:
0772:                @Override
0773:                public void _paintIcon(Component c, Graphics2D g2) {
0774:                    final GeneralPath gp = new GeneralPath();
0775:                    gp.moveTo(w / 10, h - h / 8);
0776:                    gp.lineTo(w / 2, h / 9);
0777:                    gp.lineTo(w - w / 10, h - h / 8);
0778:                    gp.closePath();
0779:
0780:                    if (enabled) {
0781:                        g2.setPaint(new GradientPaint(0f, 0f, Color.red, w, 0,
0782:                                Color.orange));
0783:
0784:                        g2.fill(gp);
0785:
0786:                        g2.setColor(Color.black);
0787:                        g2.setStroke(new BasicStroke(h / 15.0f));
0788:                        g2.draw(gp);
0789:
0790:                        g2.setFont(new Font("Lucida Sans Typewriter", Font.BOLD
0791:                                | Font.BOLD, h * 5 / 7));
0792:                        g2.drawString("!", w / 3, h - w / 5);
0793:                    } else {
0794:                        //g2.setColor(Color.gray);
0795:                        g2.draw(gp);
0796:                    }
0797:                }
0798:            }
0799:
0800:            /** An open/closed lock */
0801:            public static class LockIcon extends Icons {
0802:                boolean enabled, open;
0803:                final public static LockIcon sharedOpen16 = new LockIcon(16,
0804:                        16, true, true);
0805:                final public static LockIcon sharedClosed16 = new LockIcon(16,
0806:                        16, false, true);
0807:
0808:                public LockIcon(int w, int h, boolean open, boolean enabled) {
0809:                    super (w, h);
0810:                    this .enabled = enabled;
0811:                    this .open = open;
0812:                }
0813:
0814:                @Override
0815:                public void _paintIcon(Component c, Graphics2D g2) {
0816:                    final GeneralPath gp = new GeneralPath();
0817:                    gp.moveTo(w / 4, h / 3);
0818:                    gp.lineTo(w - w / 4, h / 3);
0819:                    gp.lineTo(w - w / 4, h - h / 8);
0820:                    gp.lineTo(w / 4, h - h / 8);
0821:                    gp.closePath();
0822:
0823:                    gp.append(new Arc2D.Double(w / 2 - w / 16, h / 2 + h / 16,
0824:                            w / 8, h / 8, 0, 360, Arc2D.OPEN), false);
0825:
0826:                    final GeneralPath gp2 = new GeneralPath();
0827:
0828:                    gp2.moveTo(w / 3, h / 3);
0829:                    gp2.curveTo(w / 3, h / 11, w / 3, h / 11, w / 2, h / 11);
0830:                    if (!open)
0831:                        gp2.curveTo(2 * w / 3, h / 11, 2 * w / 3, h / 11,
0832:                                2 * w / 3, h / 3);
0833:
0834:                    if (enabled) {
0835:                        if (open) {
0836:                            g2.setPaint(new GradientPaint(0f, 0f,
0837:                                    Color.lightGray, w, 0, Color.darkGray));
0838:                        } else {
0839:                            g2.setPaint(new GradientPaint(0f, 0f, Color.red, w,
0840:                                    0, Color.orange));
0841:                        }
0842:
0843:                        g2.fill(gp);
0844:
0845:                        g2.setColor(Color.black);
0846:                        g2.setStroke(new BasicStroke(h / 15.0f));
0847:                        g2.draw(gp);
0848:                        g2.draw(gp2);
0849:                    } else {
0850:                        g2.setStroke(new BasicStroke(h / 15.0f));
0851:                        g2.setColor(Color.gray);
0852:                        g2.draw(gp);
0853:                        g2.draw(gp2);
0854:                    }
0855:                }
0856:            }
0857:
0858:            public static class TimerIcon extends Icons {
0859:                boolean enabled;
0860:
0861:                //final Color col;
0862:                public TimerIcon(int w, int h, boolean enabled) {
0863:                    super (w, h);
0864:                    this .enabled = enabled;
0865:                }
0866:
0867:                @Override
0868:                public void _paintIcon(Component c, Graphics2D g2) {
0869:
0870:                    Shape disk = new Arc2D.Double(w / 8, w / 8, w - w / 4, h
0871:                            - w / 4, 90, 360, Arc2D.PIE);
0872:                    Shape disk2 = new Arc2D.Double(w / 8, w / 8, w - w / 4, h
0873:                            - w / 4, 90, 60, Arc2D.PIE);
0874:                    if (enabled) {
0875:                        g2.setColor(Color.white);
0876:                        g2.fill(disk);
0877:                        g2.setColor(Color.red);
0878:                        g2.fill(disk2);
0879:
0880:                        g2.setStroke(new BasicStroke(h / 15.0f));
0881:                        g2.setColor(Color.black);
0882:                        g2.draw(disk);
0883:                    } else {
0884:                        g2.setColor(Color.white);
0885:                        g2.fill(disk);
0886:                        g2.setColor(Color.lightGray);
0887:                        g2.fill(disk2);
0888:
0889:                        g2.setStroke(new BasicStroke(h / 15.0f));
0890:                        g2.setColor(Color.black);
0891:                        g2.draw(disk);
0892:                    }
0893:                }
0894:            }
0895:
0896:            public static class EyeIcon extends Icons {
0897:                boolean enabled;
0898:
0899:                public EyeIcon(int w, int h, boolean enabled) {
0900:                    super (w, h);
0901:                    this .enabled = enabled;
0902:                }
0903:
0904:                @Override
0905:                public void _paintIcon(Component c, Graphics2D g2) {
0906:
0907:                    Shape disk = new Arc2D.Double(0, w / 4, w, w / 2, 0, 180,
0908:                            Arc2D.OPEN);
0909:                    Shape disk2 = new Arc2D.Double(0, w / 4, w, w / 2, 180,
0910:                            360, Arc2D.OPEN);
0911:                    Shape disk3 = new Arc2D.Double(w / 2 - w / 4,
0912:                            w / 2 - w / 8, w / 4, w / 4, 0, 360, Arc2D.PIE); // the eye
0913:
0914:                    g2.setColor(new Color(160, 180, 250));
0915:                    g2.fill(disk);
0916:                    g2.fill(disk2);
0917:                    g2.setColor(Color.black);
0918:                    g2.fill(disk3);
0919:
0920:                    g2.setStroke(new BasicStroke(h / 15.0f));
0921:                    g2.setColor(Color.black);
0922:                    g2.draw(disk);
0923:                    g2.draw(disk2);
0924:
0925:                }
0926:            }
0927:
0928:            public static class StatIcon extends Icons {
0929:                public StatIcon(int w, int h) {
0930:                    super (w, h);
0931:                }
0932:
0933:                public void _paintIcon(Component c, Graphics2D g2) {
0934:                    g2.setColor(Color.black);
0935:                    int dx = w / 7;
0936:                    g2.drawRect(dx, h - 2 * dx, dx, 2 * dx);
0937:                    g2.drawRect(2 * dx, h - 4 * dx, dx, 4 * dx);
0938:                    g2.drawRect(3 * dx, h - 6 * dx, dx, 6 * dx);
0939:                    g2.drawRect(4 * dx, h - 5 * dx, dx, 5 * dx);
0940:                    g2.drawRect(5 * dx, h - 2 * dx, dx, 2 * dx);
0941:
0942:                }
0943:            }
0944:
0945:            public static class TableIcon extends Icons {
0946:                final int nx, ny;
0947:                boolean header = true;
0948:
0949:                public TableIcon(int w, int h, int nx, int ny, boolean header) {
0950:                    super (w, h);
0951:                    this .nx = nx;
0952:                    this .ny = ny;
0953:                    this .header = header;
0954:                }
0955:
0956:                @Override
0957:                public void _paintIcon(Component c, Graphics2D g2) {
0958:                    if (header) {
0959:                        g2.setColor(Color.lightGray);
0960:                        g2.fillRect(w / nx, h / ny, w - 2 * w / nx, h
0961:                                / (ny + 1));
0962:                        g2.setColor(Color.black);
0963:                    }
0964:                    for (int i = 0; i < ny; i++) {
0965:                        int hh = h / ny + i * h / (ny + 1);
0966:                        g2.drawLine(w / nx, hh, w - w / nx, hh);
0967:                    }
0968:                    for (int i = 0; i < nx; i++) {
0969:                        int ww = w / nx + i * w / (nx + 1);
0970:                        g2.drawLine(ww, h / ny, ww, h - h / ny);
0971:                    }
0972:
0973:                }
0974:            }
0975:
0976:            public static class FileIcon extends Icons {
0977:                boolean enabled;
0978:                String letter;
0979:                boolean directory;
0980:                boolean isText;
0981:                Font letterFont;
0982:
0983:                public FileIcon(int w, boolean directory) {
0984:                    this (w, w, directory, true, null);
0985:                }
0986:
0987:                public static FileIcon textFile(int w) {
0988:                    FileIcon fi = new FileIcon(w, false);
0989:                    fi.isText = true;
0990:                    return fi;
0991:                }
0992:
0993:                public FileIcon(int w, int h, boolean directory,
0994:                        boolean enabled, String letter) {
0995:                    super (w, h);
0996:                    this .directory = directory;
0997:                    this .enabled = enabled;
0998:                    this .letter = letter;
0999:                    if (letter != null) {
1000:                        letterFont = new Font("Lucida Sans Typewriter",
1001:                                Font.PLAIN, w * 5 / 8);
1002:                    }
1003:                }
1004:
1005:                @Override
1006:                public void _paintIcon(Component c, Graphics2D g2) {
1007:
1008:                    Polygon poly = new Polygon();
1009:                    if (directory) {
1010:                        poly.addPoint((int) (w * 0.10), (int) (h * 0.16)); // upper left
1011:                        poly.addPoint((int) (w * 0.45), (int) (h * 0.16));
1012:                        poly.addPoint((int) (w * 0.50), (int) (h * 0.04));
1013:                        poly.addPoint((int) (w * 0.88), (int) (h * 0.04));
1014:                        poly.addPoint(w - 1, (int) (h * 0.18));
1015:                        poly.addPoint(w - 1, (int) (h * 0.85));
1016:                        poly.addPoint((int) (w * 0.1), (int) (h * 0.85));
1017:                    } else {
1018:                        poly.addPoint((int) (w * 0.15), (int) (h * 0.1)); // upper left
1019:                        poly.addPoint((int) (w * 0.55), (int) (h * 0.1));
1020:                        poly.addPoint((int) (w * 0.8), (int) (h * 0.34));
1021:                        poly.addPoint((int) (w * 0.8), h);
1022:                        poly.addPoint((int) (w * 0.15), h);
1023:                    }
1024:
1025:                    g2.setColor(Color.white);
1026:                    g2.fill(poly);
1027:                    g2.setColor(Color.black);
1028:
1029:                    if (letter != null) {
1030:                        Font oldFont = g2.getFont();
1031:
1032:                        g2.setFont(letterFont);
1033:                        if (this .directory) {
1034:                            g2.drawString(letter, w / 3 + 1, h * 6 / 8 + 1);
1035:                        } else {
1036:                            g2.drawString(letter, w / 4, h * 7 / 8);
1037:                        }
1038:
1039:                        g2.setFont(oldFont);
1040:                    }
1041:
1042:                    g2.drawPolygon(poly);
1043:
1044:                    if (isText) {
1045:                        for (int i = 0; i < 3; i++) {
1046:                            int hh = h / 3 + h / 8 + i * h / 5;
1047:                            g2.drawLine(w / 2 - w / 5, hh, w / 2 + w / 7, hh);
1048:                        }
1049:                    }
1050:                }
1051:            }
1052:
1053:            /*TEST*/
1054:            public static void main(String[] a) {
1055:                EventQueue.invokeLater(new Runnable() {
1056:                    public void run() {
1057:
1058:                        //LetterIcon li = ;
1059:                        EyeIcon li = new EyeIcon(64, 64, true);
1060:
1061:                        final JFrame fr = new JFrame("Test Icon");
1062:                        fr.setIconImage(Icons.createImage(li));
1063:                        fr.setContentPane(new JLabel(li));
1064:
1065:                        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1066:
1067:                        fr.pack();
1068:                        fr.setLocationRelativeTo(null);
1069:                        fr.setVisible(true);
1070:
1071:                        final JPopupMenu pop = new JPopupMenu();
1072:                        pop.add(new JMenuItem("Search", sharedSearch));
1073:                        pop.add(new JMenuItem("Up", sharedUpWedge));
1074:                        pop.add(new JMenuItem("Down", sharedDownWedge));
1075:                        pop.add(new JMenuItem("Compile", new LetterIcon("C",
1076:                                true, 17, 17, true)));
1077:                        pop.add(new JMenuItem("Jump", sharedRightArrow));
1078:                        pop.add(new JMenuItem("Back", sharedLeftArrow));
1079:                        pop.add(new JMenuItem("Down", sharedDownArrow));
1080:                        pop.add(new JMenuItem("Up", sharedUpArrow));
1081:
1082:                        pop
1083:                                .add(new JMenuItem("Eye", new EyeIcon(16, 16,
1084:                                        true)));
1085:
1086:                        pop.add(new JMenuItem("Disk", new DiskIcon(10, 10,
1087:                                Color.red, true)));
1088:                        pop.addSeparator();
1089:                        pop.add(new JMenuItem("Start", new StartIcon(12, 12,
1090:                                true)));
1091:                        pop.add(new JMenuItem("Pause", new PauseIcon(12, 12,
1092:                                true)));
1093:                        pop.add(new JMenuItem("Stop",
1094:                                new StopIcon(12, 12, true)));
1095:                        pop.addSeparator();
1096:                        pop.add(new JMenuItem("Wiz", new WizIcon(12, true)));
1097:                        pop.addSeparator();
1098:                        pop.add(new JMenuItem("A12", new LetterIcon("A", true,
1099:                                12, 12, true)));
1100:                        pop.add(new JMenuItem("A18", new LetterIcon("A", true,
1101:                                18, 18, true)));
1102:                        pop.add(new JMenuItem("All", new LetterIcon("*", false,
1103:                                18, 18, true)));
1104:                        pop.add(new JMenuItem("Omega", new LetterIcon("\u03a9",
1105:                                false, 17, 17, true)));
1106:                        pop.add(new JMenuItem("Breakpoint", new DiskIcon(7, 7,
1107:                                Color.red, true)));
1108:
1109:                        pop.addSeparator();
1110:                        pop.add(new JMenuItem(createHelpIcon(14, false)));
1111:
1112:                        pop.add(new JMenuItem("Ok", new OkIcon(12, 12, true)));
1113:                        pop.add(new JMenuItem("Warn",
1114:                                new WarnIcon(12, 12, true)));
1115:                        pop.add(new JMenuItem("Lock", new LockIcon(16, 16,
1116:                                true, true)));
1117:                        pop.add(new JMenuItem("Lock", new LockIcon(16, 16,
1118:                                false, true)));
1119:                        pop.add(new JMenuItem("Plus", Icons.sharedPlus));
1120:                        pop.add(new JMenuItem("Stat", new StatIcon(16, 16)));
1121:
1122:                        Icon i1 = mergeIcons(16, 16, new DiskIcon(10, 10,
1123:                                Color.red, true), 0, 0, Icons.sharedPlus, 0, 0);
1124:                        pop.add(new JMenuItem("merged", i1));
1125:
1126:                        pop.add(new JMenuItem("File", new FileIcon(16, 16,
1127:                                false, true, "J")));
1128:                        pop.add(new JMenuItem("Folder", new FileIcon(16, 16,
1129:                                true, true, "J")));
1130:                        pop.add(new JMenuItem("TFile", FileIcon.textFile(16)));
1131:                        pop.add(new JMenuItem("Table", new FileIcon.TableIcon(
1132:                                16, 16, 4, 4, true)));
1133:
1134:                        pop.add(new JMenuItem("Close", new CrossIcon(12, 12,
1135:                                true)));
1136:                        pop.add(new JMenuItem("Relat", new HArrow(14, 14, true,
1137:                                true, false)));
1138:                        EventQueue.invokeLater(new Runnable() {
1139:                            public void run() {
1140:                                pop.show(fr, 0, 0);
1141:                            }
1142:                        });
1143:                    }
1144:                });
1145:            }
1146:
1147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.