Source Code Cross Referenced for TreeRenderer.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » ihm » models » 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 » Test Coverage » salome tmf » org.objectweb.salome_tmf.ihm.models 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SalomeTMF is a Test Management Framework
003:         * Copyright (C) 2005 France Telecom R&D
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *
019:         * @author Mikael MARCHE, Fayçal SOUGRATI, Vincent PAUTRET
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.ihm.models;
025:
026:        import java.awt.Color;
027:        import java.awt.Component;
028:        import java.awt.Graphics;
029:
030:        import javax.swing.Icon;
031:        import javax.swing.ImageIcon;
032:        import javax.swing.JLabel;
033:        import javax.swing.JTree;
034:        import javax.swing.UIManager;
035:        import javax.swing.tree.DefaultMutableTreeNode;
036:        import javax.swing.tree.TreeCellRenderer;
037:
038:        import org.objectweb.salome_tmf.data.Campaign;
039:        import org.objectweb.salome_tmf.data.Family;
040:        import org.objectweb.salome_tmf.data.ManualTest;
041:        import org.objectweb.salome_tmf.data.Test;
042:        import org.objectweb.salome_tmf.data.TestList;
043:        import org.objectweb.salome_tmf.ihm.IHMConstants;
044:        import org.objectweb.salome_tmf.ihm.tools.Tools;
045:
046:        /**
047:         * Classe qui d?finit le support pour la visualisation de l'arbre.
048:         * @author teaml039
049:         * @version 0.1
050:         */
051:        public class TreeRenderer extends JLabel implements  TreeCellRenderer,
052:                IHMConstants {
053:
054:            /**
055:             * S?parateur de fichier
056:             */
057:            String fileSeparator = "/";
058:
059:            /**
060:             * L'ancien arbre
061:             */
062:            //private JTree tree;
063:            /**
064:             * Vrai si une valeur est cours de s?lection
065:             */
066:            protected boolean selected;
067:
068:            /**
069:             * Vrai s'il a le focus
070:             */
071:            protected boolean hasFocus;
072:
073:            /**
074:             * Vrai pour dessiner le bord des icones
075:             */
076:            private boolean drawsFocusBorderAroundIcon;
077:            // Icons
078:            /**
079:             * Icone pour les noeuds ferm?s (pas les feuilles)
080:             */
081:            transient protected Icon closedIcon;
082:            /**
083:             * Icone pour les feuilles
084:             */
085:            transient protected Icon leafIcon;
086:
087:            /**
088:             * Icone pour les noeuds ouverts
089:             */
090:            transient protected Icon openIcon;
091:
092:            // Colors
093:            /**
094:             *  Couleur utilis? pour le foreground pour les noeuds s?lectionn?s
095:             */
096:            protected Color textSelectionColor;
097:            /**
098:             *  Couleur utilis? pour le foreground pour les noeuds non s?lectionn?s
099:             */
100:            protected Color textNonSelectionColor;
101:
102:            /**
103:             *  Couleur utilis? pour le background pour les noeuds s?lectionn?s
104:             */
105:            protected Color backgroundSelectionColor;
106:            /**
107:             *  Couleur utilis? pour le background pour les noeuds non s?lectionn?s
108:             */
109:            protected Color backgroundNonSelectionColor;
110:
111:            /**
112:             *  Couleur pour indiquer que le noeud a le focus
113:             */
114:            protected Color borderSelectionColor;
115:
116:            /******************************************************************************/
117:            /** 							CONSTRUCTEUR								***/
118:            /******************************************************************************/
119:
120:            /**
121:             * Constructeur du TreeRenderer
122:             */
123:            public TreeRenderer() {
124:                setHorizontalAlignment(JLabel.LEFT);
125:                setLeafIcon(UIManager.getIcon("Tree.leafIcon"));
126:                setClosedIcon(UIManager.getIcon("Tree.closedIcon"));
127:                setOpenIcon(UIManager.getIcon("Tree.openIcon"));
128:
129:                setTextSelectionColor(UIManager
130:                        .getColor("Tree.selectionForeground"));
131:                setTextNonSelectionColor(UIManager
132:                        .getColor("Tree.textForeground"));
133:                setBackgroundSelectionColor(UIManager
134:                        .getColor("Tree.selectionBackground"));
135:                setBackgroundNonSelectionColor(UIManager
136:                        .getColor("Tree.textBackground"));
137:                setBorderSelectionColor(UIManager
138:                        .getColor("Tree.selectionBorderColor"));
139:                Object value = UIManager.get("Tree.drawsFocusBorderAroundIcon");
140:                drawsFocusBorderAroundIcon = (value != null && ((Boolean) value)
141:                        .booleanValue());
142:            } // Fin du constructeur TreeRenderer
143:
144:            /******************************************************************************/
145:            /** 							ACCESSEURS ET MUTATEURS						***/
146:            /******************************************************************************/
147:
148:            /**
149:             * Mutateur de l'icone de noeud ouvert
150:             * @param newIcon la nouvelle icone
151:             */
152:            public void setOpenIcon(Icon newIcon) {
153:                openIcon = newIcon;
154:            } // Fin de la m?thode setOpenIcon/1
155:
156:            /**
157:             * Accesseur de l'icone de noeud ouvert
158:             * @return une icone
159:             */
160:            public Icon getOpenIcon() {
161:                return openIcon;
162:            } // Fin de la m?thode getOpenIcon/0
163:
164:            /**
165:             * Mutateur de l'icone de noeud ferm?
166:             * @param newIcon la nouvelle icone
167:             */
168:            public void setClosedIcon(Icon newIcon) {
169:                closedIcon = newIcon;
170:            } // Fin de la m?thode setClosedIcon/1
171:
172:            /**
173:             * Accesseur de l'icone de noeud ferm?
174:             * @return une icone
175:             */
176:            public Icon getClosedIcon() {
177:                return closedIcon;
178:            } // Fin de la m?thode getClosedIcon/0
179:
180:            /**
181:             * Mutateur de l'icone de noeud feuille
182:             * @param newIcon la nouvelle icone
183:             */
184:            public void setLeafIcon(Icon newIcon) {
185:                leafIcon = newIcon;
186:            } // Fin de la m?thode setLeafIcon/1
187:
188:            /**
189:             * Accesseur de l'icone de noeud feuille
190:             * @return une icone
191:             */
192:            public Icon getLeafIcon() {
193:                return leafIcon;
194:            } // Fin de la m?thode getLeafIcon/0
195:
196:            /**
197:             * Mutateur de foreground quand le noeud est s?lectionn?
198:             * @param newIcon la nouvelle couleur
199:             */
200:            public void setTextSelectionColor(Color newColor) {
201:                textSelectionColor = newColor;
202:            } // Fin de la m?thode setTextSelectionColor/1
203:
204:            /**
205:             * Accesseur de foreground quand le noeud est s?lectionn?
206:             * @return une couleur
207:             */
208:            public Color getTextSelectionColor() {
209:                return textSelectionColor;
210:            } // Fin de la m?thode getTextSelectionColor/0
211:
212:            /**
213:             * Mutateur de foreground quand le noeud n'est pas s?lectionn?
214:             * @param newIcon la nouvelle couleur
215:             */
216:            public void setTextNonSelectionColor(Color newColor) {
217:                textNonSelectionColor = newColor;
218:            } // Fin de la m?thode setTextNonSelectionColor/1
219:
220:            /**
221:             * Accesseur de foreground quand le noeud n'est pas s?lectionn?
222:             * @return une couleur
223:             */
224:            public Color getTextNonSelectionColor() {
225:                return textNonSelectionColor;
226:            } // Fin de la m?thode getTextNonSelectionColor/0
227:
228:            /**
229:             * Mutateur de background quand le noeud est s?lectionn?
230:             * @param newIcon la nouvelle couleur
231:             */
232:            public void setBackgroundSelectionColor(Color newColor) {
233:                backgroundSelectionColor = newColor;
234:            } // Fin de la m?thode setBackgroundSelectionColor/1
235:
236:            /**
237:             * Accesseur de background quand le noeud est s?lectionn?
238:             * @return une couleur
239:             */
240:            public Color getBackgroundSelectionColor() {
241:                return backgroundSelectionColor;
242:            } // Fin de la m?thode getBackgroundSelectionColor/0
243:
244:            /**
245:             * Mutateur de background quand le noeud n'est pas s?lectionn?
246:             * @param newIcon la nouvelle couleur
247:             */
248:            public void setBackgroundNonSelectionColor(Color newColor) {
249:                backgroundNonSelectionColor = newColor;
250:            } // Fin de la m?thode setBackgroundNonSelectionColor/1
251:
252:            /**
253:             * Accesseur de background quand le noeud n'est pas s?lectionn?
254:             * @return une couleur
255:             */
256:            public Color getBackgroundNonSelectionColor() {
257:                return backgroundNonSelectionColor;
258:            } // Fin de la m?thode getBackgroundNonSelectionColor/0
259:
260:            /**
261:             * Mutateur pour la couleur du border
262:             * @param newIcon la nouvelle couleur
263:             */
264:            public void setBorderSelectionColor(Color newColor) {
265:                borderSelectionColor = newColor;
266:            } // Fin de la m?thode setBorderSelectionColor/1
267:
268:            /**
269:             * Accesseur de la couleur du border
270:             * @return une couleur
271:             */
272:            public Color getBorderSelectionColor() {
273:                return borderSelectionColor;
274:            } // Fin de la m?thode getBorderSelectionColor/0
275:
276:            /**
277:             * Configuration du Renderer sur lequel est bas? l'arbre.
278:             * Configures the renderer based on the passed in components.
279:             * The value is set from messaging the tree with
280:             * <code>convertValueToText</code>, which ultimately invokes
281:             * <code>toString</code> on <code>value</code>.
282:             * The foreground color is set based on the selection and the icon
283:             * is set based on on leaf and expanded.
284:             */
285:            public Component getTreeCellRendererComponent(JTree tree,
286:                    Object value, boolean sel, boolean expanded, boolean leaf,
287:                    int row, boolean hasFocus) {
288:                String stringValue = tree.convertValueToText(value, sel,
289:                        expanded, leaf, row, hasFocus);
290:
291:                //this.tree = tree;
292:                this .hasFocus = hasFocus;
293:                setText(stringValue);
294:                if (sel)
295:                    setForeground(getTextSelectionColor());
296:                else
297:                    setForeground(getTextNonSelectionColor());
298:                // There needs to be a way to specify disabled icons.
299:                if (!tree.isEnabled()) {
300:                    setEnabled(false);
301:                } else {
302:                    setEnabled(true);
303:                }
304:                DefaultMutableTreeNode dmtcr = (DefaultMutableTreeNode) value;
305:                ImageIcon icon = new ImageIcon();
306:                if (dmtcr.getUserObject() instanceof  Family && expanded) {
307:                    icon = Tools.createAppletImageIcon(PATH_TO_GREEN_ICON, "");
308:                } else if (dmtcr.getUserObject() instanceof  Family) {
309:                    icon = Tools.createAppletImageIcon(PATH_TO_RED_ICON, "");
310:                } else if (dmtcr.getUserObject() instanceof  TestList
311:                        && expanded) {
312:                    icon = Tools.createAppletImageIcon(PATH_TO_GRAY_ICON, "");
313:                } else if (dmtcr.getUserObject() instanceof  TestList) {
314:                    icon = Tools.createAppletImageIcon(PATH_TO_PINK_ICON, "");
315:                } else if (dmtcr.getUserObject() instanceof  Test) {
316:                    if (((Test) ((DefaultMutableTreeNode) value)
317:                            .getUserObject()) instanceof  ManualTest) {
318:                        icon = Tools.createAppletImageIcon(PATH_TO_YELLOW_ICON,
319:                                "");
320:                    } else {
321:                        icon = Tools.createAppletImageIcon(PATH_TO_BLUE_ICON,
322:                                "");
323:                    }
324:
325:                } else if (dmtcr.getUserObject() instanceof  Campaign
326:                        && expanded) {
327:                    icon = Tools.createAppletImageIcon(PATH_TO_BROWN_ICON, "");
328:                } else if (dmtcr.getUserObject() instanceof  Campaign) {
329:                    icon = Tools.createAppletImageIcon(PATH_TO_PURPLE_ICON, "");
330:                } else if (expanded) {
331:                    icon = Tools.createAppletImageIcon(PATH_TO_GREEN_ICON, "");
332:                } else {
333:                    icon = Tools.createAppletImageIcon(PATH_TO_RED_ICON, "");
334:                }
335:
336:                setIcon(icon);
337:                setComponentOrientation(tree.getComponentOrientation());
338:
339:                selected = sel;
340:
341:                return this ;
342:            } // Fin de la m?thode getTreeCellRendererComponent/7
343:
344:            /**
345:             * Red?finition de la m?thode paint.
346:             * @param g un objet Graphics
347:             */
348:            public void paint(Graphics g) {
349:                Color bColor;
350:
351:                if (selected) {
352:                    bColor = getBackgroundSelectionColor();
353:                } else {
354:                    bColor = getBackgroundNonSelectionColor();
355:                    if (bColor == null)
356:                        bColor = getBackground();
357:                }
358:                int imageOffset = -1;
359:                if (bColor != null) {
360:                    //Icon currentI = getIcon();
361:
362:                    imageOffset = getLabelStart();
363:                    g.setColor(bColor);
364:                    if (getComponentOrientation().isLeftToRight()) {
365:                        g.fillRect(imageOffset, 0,
366:                                getWidth() - 1 - imageOffset, getHeight());
367:                    } else {
368:                        g.fillRect(0, 0, getWidth() - 1 - imageOffset,
369:                                getHeight());
370:                    }
371:                }
372:
373:                if (hasFocus) {
374:                    if (drawsFocusBorderAroundIcon) {
375:                        imageOffset = 0;
376:                    } else if (imageOffset == -1) {
377:                        imageOffset = getLabelStart();
378:                    }
379:                    Color bsColor = getBorderSelectionColor();
380:
381:                    if (bsColor != null) {
382:                        g.setColor(bsColor);
383:                        if (getComponentOrientation().isLeftToRight()) {
384:                            g.drawRect(imageOffset, 0, getWidth() - 1
385:                                    - imageOffset, getHeight() - 1);
386:                        } else {
387:                            g.drawRect(0, 0, getWidth() - 1 - imageOffset,
388:                                    getHeight() - 1);
389:                        }
390:                    }
391:                }
392:                super .paint(g);
393:            } // Fin de la m?thode paint/1
394:
395:            /**
396:             * M?thode qui calcule le d?but du label (por prendre en compte l'icone)
397:             * @return l'indice de d?but du label
398:             */
399:            private int getLabelStart() {
400:                Icon currentI = getIcon();
401:                if (currentI != null && getText() != null) {
402:                    return currentI.getIconWidth()
403:                            + Math.max(0, getIconTextGap() - 1);
404:                }
405:                return 0;
406:            } // Fin de la m?thode getLabelStart/0
407:
408:        } // Fin de la classe TreeRenderer
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.