Source Code Cross Referenced for FileIcon.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) 


001:        package snow.utils.gui;
002:
003:        //import javax.swing.border.EmptyBorder;
004:        import javax.swing.*;
005:        import java.awt.*;
006:
007:        /** Either file or directory shape, with specified color and optional letter
008:         */
009:        public class FileIcon implements  Icon {
010:            public enum IconColor {
011:                Red, Green, RedGreen, White, System
012:            }
013:
014:            private IconColor type;
015:            private int size;
016:
017:            // the file or directory outer shape
018:            Polygon poly;
019:
020:            private String letter = null;
021:            private Font letterFont;
022:
023:            public FileIcon(boolean directory, int size) {
024:                this (directory, IconColor.White, size);
025:            }
026:
027:            public FileIcon(boolean directory, IconColor type, int size) {
028:                this .type = type;
029:                this .size = size;
030:
031:                if (directory) {
032:                    initShapeDirectory();
033:                } else {
034:                    initShapeFile();
035:                }
036:                letterFont = new Font("Dialog", Font.PLAIN, size * 5 / 8);
037:            }
038:
039:            public void setType(IconColor type) {
040:                this .type = type;
041:            }
042:
043:            public void setLetter(String letter) {
044:                this .letter = letter;
045:            }
046:
047:            boolean delete;
048:
049:            public void setRemovedFromProject(boolean delete) {
050:                this .delete = delete;
051:            }
052:
053:            private void initShapeFile() {
054:                poly = new Polygon();
055:                poly.addPoint(size / 8, 0);
056:                poly.addPoint(size * 5 / 8, 0);
057:                poly.addPoint(size * 7 / 8, 2 * size / 8);
058:                poly.addPoint(size * 7 / 8, size);
059:                poly.addPoint(size / 8, size);
060:            }
061:
062:            private void initShapeDirectory() {
063:                poly = new Polygon();
064:                poly.addPoint(0, size / 6);
065:                poly.addPoint((int) (size * 0.5), size / 6);
066:                poly.addPoint((int) (size * 0.65), size / 11);
067:                poly.addPoint((int) (size * 0.85), size / 11);
068:                poly.addPoint(size, size / 6);
069:                poly.addPoint(size, size * 7 / 8);
070:                poly.addPoint(0, size * 7 / 8);
071:            }
072:
073:            public int getIconHeight() {
074:                return size;
075:            }
076:
077:            public int getIconWidth() {
078:                return size;
079:            }
080:
081:            public void paintIcon(Component c, Graphics g, int x, int y) {
082:                Graphics2D g2 = (Graphics2D) g;
083:
084:                g.translate(x, y);
085:
086:                Color color1 = Color.white;
087:                Color color2 = Color.black;
088:
089:                if (type == IconColor.RedGreen) {
090:                    color1 = new Color(220, 0, 0);
091:                    color2 = new Color(0, 220, 0);
092:                } else if (type == IconColor.Red) {
093:                    color1 = new Color(120, 80, 80);
094:                    color2 = new Color(220, 0, 0);
095:                } else if (type == IconColor.Green) {
096:                    color1 = new Color(80, 120, 80);
097:                    color2 = new Color(0, 220, 0);
098:                } else if (type == IconColor.White) {
099:                    color1 = Color.white;
100:                    color2 = Color.white;
101:                } else if (type == IconColor.System) {
102:                    //blue      color1 = new Color(0,80,80);
103:                    //      color2 = new Color(0,220,220);
104:                    color1 = new Color(180, 180, 10);
105:                    color2 = new Color(220, 220, 10);
106:
107:                }
108:
109:                g2.setPaint(new GradientPaint(0, 0, color1, size, size, color2,
110:                        false));
111:                g.fillPolygon(poly);
112:
113:                // for mixed folders
114:                if (type == IconColor.RedGreen) {
115:                }
116:
117:                if (letter != null) {
118:                    Font oldFont = g2.getFont();
119:
120:                    g2.setColor(Color.black);
121:                    g2.setFont(letterFont);
122:                    g2.drawString(letter, size / 4 + 1, size * 6 / 8); // May2007: shift 1
123:
124:                    g2.setFont(oldFont);
125:                }
126:
127:                if (delete) {
128:                    g.setColor(Color.red);
129:
130:                    g.drawLine(0, 0, size, size);
131:                    g.drawLine(1, 0, size, size - 1);
132:                    g.drawLine(0, size, size, 0);
133:                    g.drawLine(0, size - 1, size - 1, 0);
134:
135:                }
136:
137:                // border
138:                g.setColor(Color.black);
139:                g.drawPolygon(poly);
140:
141:                g.translate(-x, -y);
142:            }
143:
144:            /*test
145:             public static void main(String[] a)
146:             {
147:             JFrame frame = new JFrame();
148:             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
149:
150:             frame.setLocationRelativeTo(null);
151:             FileIcon fic = new FileIcon(true, 16);
152:             fic.setLetter("A");
153:             fic.setType(IconColor.System);
154:             JLabel lab = new JLabel(fic);
155:             frame.add(lab);
156:             lab.setBorder(new EmptyBorder(5,5,5,5));
157:             frame.pack();
158:             frame.setVisible(true);
159:             }*/
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.