Source Code Cross Referenced for ItemSorter.java in  » Database-Client » prefuse » prefuse » visual » sort » 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 » Database Client » prefuse » prefuse.visual.sort 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        package prefuse.visual.sort;
02:
03:        import java.util.Comparator;
04:
05:        import prefuse.Visualization;
06:        import prefuse.visual.AggregateItem;
07:        import prefuse.visual.DecoratorItem;
08:        import prefuse.visual.EdgeItem;
09:        import prefuse.visual.VisualItem;
10:
11:        /**
12:         * ItemSorter instances provide an integer score for each VisualItem;
13:         * these scores are then used to sort the items in ascending order of score.
14:         * ItemSorters are used to determine the rendering order of items in a
15:         * Display.
16:         * 
17:         * @author <a href="http://jheer.org">jeffrey heer</a>
18:         */
19:        public class ItemSorter implements  Comparator {
20:
21:            protected static final int AGGREGATE = 0;
22:            protected static final int EDGE = 1;
23:            protected static final int ITEM = 2;
24:            protected static final int DECORATOR = 3;
25:
26:            /**
27:             * <p>Return an ordering score for an item. The default scoring imparts
28:             * the following order:
29:             * hover items > highlighted items > items in the
30:             * {@link prefuse.Visualization#FOCUS_ITEMS} set >
31:             * {@link prefuse.Visualization#SEARCH_ITEMS} set >
32:             * DecoratorItem instances > normal VisualItem instances. A zero
33:             * score is returned for normal items, with scores starting at
34:             * 1&lt;&lt;27 for other items, leaving the number range beneath that
35:             * value open for additional nuanced scoring.</p> 
36:             * 
37:             * <p>Subclasses can override this method to provide custom sorting
38:             * criteria.</p>
39:             * @param item the VisualItem to provide an ordering score
40:             * @return the ordering score
41:             */
42:            public int score(VisualItem item) {
43:                int type = ITEM;
44:                if (item instanceof  EdgeItem) {
45:                    type = EDGE;
46:                } else if (item instanceof  AggregateItem) {
47:                    type = AGGREGATE;
48:                } else if (item instanceof  DecoratorItem) {
49:                    type = DECORATOR;
50:                }
51:
52:                int score = (1 << (26 + type));
53:                if (item.isHover()) {
54:                    score += (1 << 25);
55:                }
56:                if (item.isHighlighted()) {
57:                    score += (1 << 24);
58:                }
59:                if (item.isInGroup(Visualization.FOCUS_ITEMS)) {
60:                    score += (1 << 23);
61:                }
62:                if (item.isInGroup(Visualization.SEARCH_ITEMS)) {
63:                    score += (1 << 22);
64:                }
65:
66:                return score;
67:            }
68:
69:            /**
70:             * Compare two items based on their ordering scores. Calls the
71:             * {@link #score(VisualItem)} on each item and compares the result.
72:             * @param v1 the first VisualItem to compare
73:             * @param v2 the second VisualItem to compare
74:             * @return -1 if score(v1) &lt; score(v2), 1 if score(v1) &gt; score(v2)
75:             * and 0 if score(v1) == score(v2).
76:             */
77:            public int compare(VisualItem v1, VisualItem v2) {
78:                int score1 = score(v1);
79:                int score2 = score(v2);
80:                return (score1 < score2 ? -1 : (score1 == score2 ? 0 : 1));
81:            }
82:
83:            /**
84:             * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
85:             * @see #compare(VisualItem, VisualItem)
86:             */
87:            public int compare(Object o1, Object o2) {
88:                if (!(o1 instanceof  VisualItem && o2 instanceof  VisualItem)) {
89:                    throw new IllegalArgumentException();
90:                }
91:                return compare((VisualItem) o1, (VisualItem) o2);
92:            }
93:
94:        } // end of class ItemSorter
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.