Source Code Cross Referenced for RatioLayout.java in  » Testing » jacareto » jacareto » toolkit » awt » 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 » Testing » jacareto » jacareto.toolkit.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        //
025:        // package
026:        //
027:        package jacareto.toolkit.awt;
028:
029:        import java.awt.Component;
030:        import java.awt.Container;
031:        import java.awt.Dimension;
032:        import java.awt.Insets;
033:        import java.awt.LayoutManager;
034:
035:        //JAVA
036:        import java.io.Serializable;
037:
038:        import java.util.StringTokenizer;
039:        import java.util.Vector;
040:
041:        /**
042:         * Layout Manager, der es ermöglicht, die Position und den Platz den eine Komponente beansprucht
043:         * relativ zum vorhandenen Platz anzugeben. Die Angaben werden in Prozent gemacht,
044:         * Positionsangaben erfolgen relativ zur linken oberen Ecke. <br>
045:         * <pre>
046:         * z.B.
047:         *      setLayout(new RatioLayout());
048:         *      add("0,0;.45,.5", new Button("OK")); //0% nach rechts verschoben, 0% nach unten verschoben; 45% des verfügbaren Platzes in vertikaler Richtung, 50% des verfügbaren Platzes, in horizontaler Richtung
049:         *      add(".75,.75", new Button("QUIT")); //75% nach rechts verschoben, 75% nach unten verschoben; benutze die bevorzugte Größe der Komponente
050:         * </pre>
051:         */
052:        public class RatioLayout implements  LayoutManager, Serializable {
053:            //ATTRIBUTE
054:
055:            /** Speichert die gesetzten Werte für jedes Objekt. */
056:            Vector ratios = new Vector(10);
057:
058:            /** Speichert die vom Layout Manager verwalteten Objekte. */
059:            Vector components = new Vector(10);
060:
061:            //METHODEN
062:
063:            /**
064:             * Fügt eine Komponenete zum Layout hinzu.
065:             * <pre>
066:             * Vorbedingung : comp != null && r != null
067:             * Nachbedingung: components.indexOf(comp) != -1
068:             * </pre>
069:             *
070:             * @param r Verhalten der Komponente(siehe Klassenkopf)
071:             * @param comp Komponente, die eingefügt werden soll
072:             */
073:            public void addLayoutComponent(String r, Component comp) {
074:                ratios.addElement(r);
075:                components.addElement(comp);
076:            }
077:
078:            /**
079:             * Entfernt eine Komponente aus dem Layout
080:             * <pre>
081:             * Vorbedingung : comp != null
082:             * Nachbedingung: components.indexOf(comp) == -1
083:             * </pre>
084:             *
085:             * @param comp Zu entfernende Komponente
086:             */
087:            public void removeLayoutComponent(Component comp) {
088:                int i = components.indexOf(comp);
089:
090:                if (i != -1) {
091:                    ratios.removeElementAt(i);
092:                    components.removeElementAt(i);
093:                }
094:            }
095:
096:            /**
097:             * Aendert das Layout einer Komponente
098:             * <pre>
099:             * Vorbedingung : comp != null
100:             * Nachbedingung: components.indexOf(comp) == -1
101:             * </pre>
102:             *
103:             * @param comp Zu aendernde Komponente
104:             * @param newLayout DOCUMENT ME!
105:             */
106:            public void changeLayoutComponent(Component comp, String newLayout) {
107:                int i = components.indexOf(comp);
108:
109:                if (i != -1) {
110:                    ratios.removeElementAt(i);
111:                    ratios.insertElementAt(newLayout, i);
112:                }
113:            }
114:
115:            /**
116:             * Bevorzugte Größe des Containers.
117:             * <pre>
118:             * Vorbedingung : target != null
119:             * Nachbedingung: true
120:             * </pre>
121:             *
122:             * @param target Der betroffene Kontainer
123:             *
124:             * @return DOCUMENT ME!
125:             */
126:            public Dimension preferredLayoutSize(Container target) {
127:                return target.getSize();
128:            }
129:
130:            /**
131:             * Minimale Größe des Kontainers.
132:             * <pre>
133:             * Vorbedingung : target != null
134:             * Nachbedingung: true
135:             * </pre>
136:             *
137:             * @param target Der betroffene Kontainer
138:             *
139:             * @return DOCUMENT ME!
140:             */
141:            public Dimension minimumLayoutSize(Container target) {
142:                return target.getSize();
143:            }
144:
145:            /**
146:             * Platziert die Komponenten in dem Container entsprechend der gemachten Angaben.
147:             * <pre>
148:             * Vorbedingung : target != null
149:             * Nachbedingung: true
150:             * </pre>
151:             *
152:             * @param target Der betroffene Kontainer
153:             */
154:            public void layoutContainer(Container target) {
155:                Insets insets = target.getInsets();
156:                int ncomponents = components.size();
157:
158:                Dimension d = target.getSize();
159:                d.width -= (insets.left + insets.right);
160:                d.height -= (insets.top + insets.bottom);
161:
162:                for (int i = 0; i < ncomponents; i++) {
163:                    Component comp = target.getComponent(i);
164:
165:                    if (ratios.size() > i) {
166:                        StringTokenizer st = new StringTokenizer(
167:                                (String) ratios.elementAt(i), ", \t;");
168:                        float rx = Float.valueOf(st.nextToken()).floatValue();
169:                        float ry = Float.valueOf(st.nextToken()).floatValue();
170:                        float rw = 0;
171:                        float rh = 0;
172:                        int w;
173:                        int h;
174:
175:                        if (st.hasMoreElements()) { // get width, height if they exist
176:                            rw = Float.valueOf(st.nextToken()).floatValue();
177:                            rh = Float.valueOf(st.nextToken()).floatValue();
178:                            w = (int) (d.width * rw);
179:                            h = (int) (d.height * rh);
180:                        } else {
181:                            Dimension compDim = comp.getPreferredSize();
182:                            w = compDim.width;
183:                            h = compDim.height;
184:                        }
185:
186:                        int x = (int) (d.width * rx);
187:                        int y = (int) (d.height * ry);
188:                        comp.setBounds(x + insets.left, y + insets.top, w, h);
189:                    }
190:                }
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.