Source Code Cross Referenced for GridInfo.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » layout » 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 Eclipse » ui workbench » org.eclipse.ui.internal.layout 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.layout;
011:
012:        import org.eclipse.swt.widgets.Control;
013:
014:        /**
015:         * Computes and the positions of controls in a CellLayout, based on their span.
016:         */
017:        class GridInfo {
018:            private int cols = 0;
019:
020:            private int rows = 0;
021:
022:            private int[] gridInfo;
023:
024:            int[] controlRow;
025:
026:            int[] controlCol;
027:
028:            private CellData[] cellData;
029:
030:            Control[] controls;
031:
032:            /**
033:             * Initialize the grid
034:             * 
035:             * @param newControls
036:             * @param cols
037:             */
038:            public void initGrid(Control[] newControls, CellLayout layout) {
039:                cols = layout.getColumns();
040:                controls = newControls;
041:
042:                int area = 0;
043:                int totalWidth = 0;
044:
045:                controlRow = new int[controls.length];
046:                controlCol = new int[controls.length];
047:
048:                // Get the CellData objects for each control, and compute
049:                // the total number of cells spanned by controls in this layout.
050:                cellData = new CellData[controls.length];
051:                for (int idx = 0; idx < controls.length; idx++) {
052:                    if (controls[idx] == null) {
053:                        continue;
054:                    }
055:
056:                    CellData next = CellLayoutUtil.getData(controls[idx]);
057:                    cellData[idx] = next;
058:                    area += next.horizontalSpan * next.verticalSpan;
059:                    totalWidth += next.horizontalSpan;
060:                }
061:
062:                // Compute the number of columns
063:                if (cols == 0) {
064:                    cols = totalWidth;
065:                }
066:
067:                // Compute the number of rows
068:                rows = area / cols;
069:                if (area % cols > 0) {
070:                    // Ensure we count any partial rows
071:                    rows++;
072:                }
073:
074:                area = rows * cols;
075:
076:                // Allocate the gridInfo array
077:                gridInfo = new int[area];
078:                for (int idx = 0; idx < area; idx++) {
079:                    gridInfo[idx] = -1;
080:                }
081:
082:                int infoIdx = 0;
083:                // Compute the positions of each control
084:                for (int idx = 0; idx < controls.length; idx++) {
085:                    CellData data = cellData[idx];
086:
087:                    // Find an empty position to insert the control
088:                    while (gridInfo[infoIdx] >= 0) {
089:                        infoIdx++;
090:                    }
091:
092:                    controlRow[idx] = infoIdx / cols;
093:                    controlCol[idx] = infoIdx % cols;
094:
095:                    // Insert the new control here
096:                    for (int rowIdx = 0; rowIdx < data.verticalSpan; rowIdx++) {
097:                        for (int colIdx = 0; colIdx < data.horizontalSpan; colIdx++) {
098:                            gridInfo[infoIdx + rowIdx * cols + colIdx] = idx;
099:                        }
100:                    }
101:
102:                    infoIdx += data.horizontalSpan;
103:                }
104:            }
105:
106:            public int getRows() {
107:                return rows;
108:            }
109:
110:            public int getStartPos(int control, boolean row) {
111:                if (row) {
112:                    return controlRow[control];
113:                } else {
114:                    return controlCol[control];
115:                }
116:            }
117:
118:            /**
119:             * Returns the number of rows or columns
120:             * 
121:             * @param isRow if true, returns the number of rows. If false, returns the number of columns
122:             * @return
123:             */
124:            public int getNumRows(boolean isRow) {
125:                if (isRow) {
126:                    return rows;
127:                } else {
128:                    return cols;
129:                }
130:            }
131:
132:            public void getRow(int[] result, int rowId, boolean horizontal) {
133:                if (horizontal) {
134:                    int prev = -1;
135:                    for (int colIdx = 0; colIdx < cols; colIdx++) {
136:                        int next = gridInfo[cols * rowId + colIdx];
137:
138:                        if (prev == next) {
139:                            result[colIdx] = -1;
140:                        } else {
141:                            result[colIdx] = next;
142:                        }
143:
144:                        prev = next;
145:                    }
146:                } else {
147:                    int prev = -1;
148:                    for (int rowIdx = 0; rowIdx < rows; rowIdx++) {
149:                        int next = gridInfo[cols * rowIdx + rowId];
150:
151:                        if (prev == next) {
152:                            result[rowIdx] = -1;
153:                        } else {
154:                            result[rowIdx] = next;
155:                        }
156:
157:                        prev = next;
158:                    }
159:                }
160:            }
161:
162:            public CellData getCellData(int controlId) {
163:                return cellData[controlId];
164:            }
165:
166:            public int getCols() {
167:                return cols;
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.