Source Code Cross Referenced for PercentLayout.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » tools » tracesviewer » 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 » 6.0 JDK Modules » Java Advanced Imaging » tools.tracesviewer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tools.tracesviewer;
002:
003:        import java.awt.*;
004:        import java.util.*;
005:
006:        /**
007:         * Lays out components within a Container such that each component takes a fixed percentage of the size.
008:         * 
009:         * Each Component added to the Container must have a Constraint object that specifies what proportion 
010:         * of the container it will fill. The Component will be stretched to fill exactly that percentage.
011:         * 
012:         * @see Constraint
013:         */
014:        public class PercentLayout implements  LayoutManager2 {
015:            public void addLayoutComponent(Component component,
016:                    Object constraint) {
017:                if (constraint instanceof  PercentLayoutConstraint) {
018:                    hash.put(component, constraint);
019:                } else {
020:                    throw new IllegalArgumentException("Invalid constraint");
021:
022:                }
023:            }
024:
025:            public void addLayoutComponent(String constraint, Component comp) {
026:                throw new IllegalArgumentException("Invalid constraint");
027:            }
028:
029:            public void removeLayoutComponent(Component component) {
030:                hash.remove(component);
031:            }
032:
033:            public Dimension preferredLayoutSize(Container p1) {
034:                int prefx = 0;
035:                int prefy = 0;
036:
037:                Enumeration keys = hash.keys();
038:                while (keys.hasMoreElements()) {
039:                    Component comp = (Component) keys.nextElement();
040:                    PercentLayoutConstraint constraint = (PercentLayoutConstraint) hash
041:                            .get(comp);
042:                    Dimension pref = comp.getPreferredSize();
043:                    prefx += pref.width * 100 / constraint.width;
044:                    prefy += pref.height * 100 / constraint.height;
045:                }
046:                int n = hash.size();
047:                return new Dimension(prefx / n, prefy / n);
048:            }
049:
050:            public Dimension minimumLayoutSize(Container p1) {
051:                int minx = 0;
052:                int miny = 0;
053:
054:                Enumeration keys = hash.keys();
055:                while (keys.hasMoreElements()) {
056:                    Component comp = (Component) keys.nextElement();
057:                    PercentLayoutConstraint constraint = (PercentLayoutConstraint) hash
058:                            .get(comp);
059:                    Dimension min = comp.getMinimumSize();
060:                    int mx = (int) (min.width * 100 / constraint.width);
061:                    int my = (int) (min.height * 100 / constraint.height);
062:                    if (mx > minx)
063:                        minx = mx;
064:                    if (my > miny)
065:                        miny = my;
066:                }
067:                return new Dimension(minx, miny);
068:            }
069:
070:            public Dimension maximumLayoutSize(Container p1) {
071:                int maxx = Integer.MAX_VALUE;
072:                int maxy = Integer.MAX_VALUE;
073:
074:                Enumeration keys = hash.keys();
075:                while (keys.hasMoreElements()) {
076:                    Component comp = (Component) keys.nextElement();
077:                    PercentLayoutConstraint constraint = (PercentLayoutConstraint) hash
078:                            .get(comp);
079:                    Dimension max = comp.getMaximumSize();
080:                    int mx = max.width == Integer.MAX_VALUE ? max.width
081:                            : (int) (max.width * 100 / constraint.width);
082:                    int my = max.height == Integer.MAX_VALUE ? max.height
083:                            : (int) (max.height * 100 / constraint.height);
084:                    if (mx < maxx)
085:                        maxx = mx;
086:                    if (my < maxy)
087:                        maxy = my;
088:                }
089:                return new Dimension(maxx, maxy);
090:            }
091:
092:            public void layoutContainer(Container p1) {
093:                Dimension size = p1.getSize();
094:                Enumeration keys = hash.keys();
095:                while (keys.hasMoreElements()) {
096:                    Component comp = (Component) keys.nextElement();
097:                    PercentLayoutConstraint constraint = (PercentLayoutConstraint) hash
098:                            .get(comp);
099:                    int x = (int) (size.width * constraint.x / 100);
100:                    int y = (int) (size.height * constraint.y / 100);
101:                    int width = (int) (size.width * constraint.width / 100);
102:                    int height = (int) (size.height * constraint.height / 100);
103:                    comp.setBounds(x, y, width, height);
104:                }
105:            }
106:
107:            public void invalidateLayout(Container p1) {
108:            }
109:
110:            public float getLayoutAlignmentY(Container p1) {
111:                return 0.5f;
112:            }
113:
114:            public float getLayoutAlignmentX(Container p1) {
115:                return 0.5f;
116:            }
117:
118:            private Hashtable hash = new Hashtable();
119:
120:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.