Source Code Cross Referenced for SourcesTreeIcon.java in  » IDE » tIDE » tide » sources » 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 » tide.sources 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tide.sources;
002:
003:        import javax.swing.border.EmptyBorder;
004:        import snow.utils.gui.GUIUtils;
005:        import snow.lookandfeel.ThemesManager;
006:        import java.awt.geom.GeneralPath;
007:
008:        import javax.swing.*;
009:        import java.awt.*;
010:
011:        /** Either file or directory shape, with specified color and optional letter, and compiled, edited status, ...
012:         */
013:        public class SourcesTreeIcon implements  Icon {
014:
015:            public enum IconColor {
016:                Red, Green, RedGreen, White
017:            } // white for empty dirs
018:
019:            public enum Ignored {
020:                Yes, No, Partially
021:            } // Partially for directories
022:
023:            private IconColor type;
024:            private int size;
025:            private Ignored ignoredType = Ignored.No;
026:
027:            // the file or directory outer shape
028:            private Polygon poly;
029:
030:            private String letter = null;
031:            private Font letterFont;
032:
033:            public boolean compiled = false;
034:            public final boolean isDirectory;
035:
036:            public boolean hasMessages = false;
037:            public boolean hasMainMethod = false;
038:            public boolean isMainProjectClass = false;
039:
040:            public boolean isVisible = true;
041:
042:            public boolean doNotDrawCompiledBar = false; // not draw ! [Dec2006]
043:
044:            public SourcesTreeIcon(boolean directory, int size) {
045:                this (directory, IconColor.White, size);
046:            }
047:
048:            public SourcesTreeIcon(boolean directory, IconColor type, int size) {
049:                this .type = type;
050:                this .size = size;
051:                this .isDirectory = directory;
052:
053:                if (directory) {
054:                    initShapeDirectory();
055:                    letterFont = new Font("Lucida Sans Typewriter", Font.PLAIN,
056:                            size * 5 / 8);
057:                } else {
058:                    initShapeFile();
059:                    letterFont = new Font("Lucida Sans Typewriter", Font.PLAIN,
060:                            size * 5 / 8);
061:                }
062:
063:            }
064:
065:            public void setType(IconColor type) {
066:                this .type = type;
067:            }
068:
069:            public void setLetter(String letter) {
070:                this .letter = letter;
071:            }
072:
073:            /** will draw a red cross above the icon
074:             */
075:            public void setIgnored(Ignored type) {
076:                this .ignoredType = type;
077:            }
078:
079:            private void initLockShape() {
080:            }
081:
082:            private void initShapeFile() {
083:                poly = new Polygon();
084:
085:                poly.addPoint((int) (size * 0.15), (int) (size * 0.1)); // upper left
086:                poly.addPoint((int) (size * 0.55), (int) (size * 0.1));
087:                poly.addPoint((int) (size * 0.8), (int) (size * 0.34));
088:                poly.addPoint((int) (size * 0.8), size);
089:                poly.addPoint((int) (size * 0.15), size);
090:            }
091:
092:            private void initShapeDirectory() {
093:                poly = new Polygon();
094:                poly.addPoint((int) (size * 0.10), (int) (size * 0.16)); // upper left
095:                poly.addPoint((int) (size * 0.45), (int) (size * 0.16));
096:                poly.addPoint((int) (size * 0.50), (int) (size * 0.04));
097:                poly.addPoint((int) (size * 0.88), (int) (size * 0.04));
098:                poly.addPoint(size - 1, (int) (size * 0.18));
099:                poly.addPoint(size - 1, (int) (size * 0.85));
100:                poly.addPoint((int) (size * 0.1), (int) (size * 0.85));
101:            }
102:
103:            public int getIconHeight() {
104:                return size;
105:            }
106:
107:            public int getIconWidth() {
108:                return size;
109:            }
110:
111:            public Color green1 = new Color(60, 180, 60); // contrast
112:            public Color green2 = new Color(120, 220, 120); // light
113:
114:            public Color red1 = new Color(180, 60, 60); // contrast
115:            public Color red2 = new Color(230, 160, 160); // light
116:
117:            /** TODO !! */
118:            public void setColorsFromChoosenUI() {
119:                green1 = ThemesManager.getInstance().getGreen();
120:                // ... TODO ...
121:
122:            }
123:
124:            public void paintIcon(Component c, Graphics g, int x, int y) {
125:                if (!isVisible)
126:                    return;
127:
128:                Graphics2D g2 = (Graphics2D) g;
129:                Color oldColor = g.getColor();
130:
131:                g.translate(x, y);
132:
133:                Color color1 = Color.white;
134:                Color color2 = Color.black;
135:
136:                if (type == IconColor.RedGreen) {
137:                    color1 = green2;
138:                    color2 = red2;
139:                } else if (type == IconColor.Red) {
140:                    color1 = red1;
141:                    color2 = red2;
142:                } else if (type == IconColor.Green) {
143:                    color1 = green1;
144:                    color2 = green2;
145:                } else if (type == IconColor.White) {
146:                    color1 = Color.white;
147:                    color2 = Color.white;
148:                }
149:
150:                g2.setPaint(new GradientPaint(0, 0, color1, size, size, color2,
151:                        false));
152:                g.fillPolygon(poly);
153:
154:                if (letter != null) {
155:                    Font oldFont = g2.getFont();
156:
157:                    g2.setColor(Color.black);
158:                    g2.setFont(letterFont);
159:                    if (this .isDirectory) {
160:                        g2.drawString(letter, size / 3 + 1, size * 6 / 8 + 1);
161:                    } else {
162:                        g2.drawString(letter, size / 4, size * 7 / 8);
163:                    }
164:
165:                    g2.setFont(oldFont);
166:                }
167:
168:                if (ignoredType == Ignored.Partially
169:                        || ignoredType == Ignored.Yes) {
170:                    g.setColor(Color.red);
171:                    g.drawLine(0, 0, size, size);
172:                    g.drawLine(1, 0, size, size - 1);
173:
174:                    if (ignoredType == Ignored.Yes) {
175:                        g.drawLine(0, size, size, 0);
176:                        g.drawLine(0, size - 1, size - 1, 0);
177:                    }
178:                }
179:
180:                // border
181:                g.setColor(Color.black);
182:                g.drawPolygon(poly);
183:
184:                if (!doNotDrawCompiledBar) {
185:                    if (compiled) {
186:                        // [Dec2006]: do nothing if compiled
187:                        g.setColor(Color.green);
188:                    } else {
189:                        g.setColor(Color.red);
190:                        g.drawLine(0, size - 2, 0, 2);
191:                        g.drawLine(1, size - 2, 1, 2);
192:
193:                    }
194:
195:                }
196:
197:                if (this .hasMessages) {
198:                    g.setColor(Color.cyan);
199:                    g.fillArc(size - 2, size - 6, 4, 4, 0, 360);
200:                    //g.drawLine(size, size-2, size, 2);
201:                    //g.drawLine(size-1, size-2, size-1, 2);
202:                }
203:
204:                if (hasMainMethod) {
205:
206:                    if (isMainProjectClass) {
207:                        g.setColor(new Color(0, 0, 220)); // blue
208:                    } else {
209:                        g.setColor(new Color(0, 220, 0)); // green
210:                    }
211:                    //g.drawRect(0,0,size,size);
212:                    GeneralPath gp = new GeneralPath();
213:                    gp.moveTo(size, 0);
214:                    gp.lineTo(size * 7 / 10, 0);
215:                    gp.lineTo(size, size * 2 / 10);
216:                    gp.closePath();
217:                    g.fillPolygon(new int[] { size, size * 7 / 10, size },
218:                            new int[] { 0, 0, size * 3 / 10 }, 3);
219:
220:                }
221:
222:                // restore old graphics settings
223:                g.translate(-x, -y);
224:                g.setColor(oldColor);
225:            }
226:
227:            public static SourcesTreeIcon createSimpleLetterIcon(String le) {
228:                SourcesTreeIcon jarIcon = new SourcesTreeIcon(false,
229:                        SourcesTreeIcon.IconColor.White, 17);
230:                jarIcon.setLetter(le);
231:                jarIcon.doNotDrawCompiledBar = true;
232:                return jarIcon;
233:            }
234:
235:            /*test*/
236:            public static void main(String[] a) {
237:                JPanel pan = new JPanel();
238:                pan.setLayout(new BoxLayout(pan, BoxLayout.X_AXIS));
239:                for (int i = 10; i < 30; i++) {
240:                    SourcesTreeIcon sti = new SourcesTreeIcon(false, i);
241:                    sti.setLetter("J");
242:                    sti.hasMessages = true;
243:                    sti.hasMainMethod = true;
244:                    sti.setType(IconColor.Green);
245:                    JLabel lab = new JLabel(sti);
246:                    pan.add(lab);
247:                    pan.add(Box.createHorizontalStrut(5));
248:                    lab.setBorder(new EmptyBorder(4, 4, 4, 4));
249:                }
250:
251:                pan.setBorder(new EmptyBorder(4, 4, 4, 4));
252:                GUIUtils.displayInFrame("test", pan, true);
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.