Source Code Cross Referenced for TableUtils.java in  » GIS » udig-1.1 » net » refractions » udig » ui » graphics » 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 » GIS » udig 1.1 » net.refractions.udig.ui.graphics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* uDig - User Friendly Desktop Internet GIS client
002:         * http://udig.refractions.net
003:         * (C) 2004, Refractions Research Inc.
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;
008:         * version 2.1 of the License.
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:        package net.refractions.udig.ui.graphics;
016:
017:        import org.eclipse.swt.widgets.Table;
018:        import org.eclipse.swt.widgets.TableColumn;
019:        import org.eclipse.swt.widgets.Tree;
020:        import org.eclipse.swt.widgets.TreeColumn;
021:
022:        /**
023:         * Utility class for dealing with the resizing of table columns.
024:         * <p>
025:         * 
026:         * </p>
027:         * 
028:         * @author chorner
029:         * @since 1.0.1
030:         */
031:        public class TableUtils {
032:            // Considerations for future modifications:
033:            // -- keep the table somewhat stable
034:            // -- keep content visible
035:            // -- don't annoy the user with chaotic resizing (which overrides what the
036:            // user does)
037:
038:            /**
039:             * The columns are left as is unless they exceed the bounds set by the
040:             * TableSettings.
041:             */
042:            public static final int MODE_LAZY = 1;
043:
044:            /**
045:             * Columns are automatically sized, and adjusted to fit into the
046:             * TableSettings bounds.
047:             */
048:            public static final int MODE_AUTO = 2;
049:
050:            /**
051:             * We start off with MODE_AUTO, but switch to MODE_LAZY when the user
052:             * modifies a column size (listener required).
053:             */
054:            public static final int MODE_JUMP = 3;
055:
056:            /**
057:             * Given a table, this method resizes the columns as specified. Although
058:             * automatic column sizing works well under Linux , it
059:             * does not work well under Windows and Mac OSX and hence this method is needed (in
060:             * particular, an empty column on the right appears under Win).
061:             * 
062:             * @param table
063:             * @param settings
064:             *            the configured settings for the table (column min, max, etc)
065:             * @param mode one of {@link #MODE_AUTO}, {@link #MODE_LAZY} , {@link #MODE_JUMP} 
066:             */
067:            public static void resizeColumns(Table table,
068:                    TableSettings settings, int mode) {
069:                int mode2 = mode;
070:                // turn off redraw (reduces flicker)
071:                table.setRedraw(false);
072:
073:                int tableWidth = table.getSize().x;
074:                int columnCount = table.getColumnCount();
075:                int columnSum = 0;
076:
077:                // load/save the current calling mode
078:                if (!(mode2 > 0)) {
079:                    mode2 = MODE_JUMP; // mode wasn't defined; set a default
080:                }
081:
082:                // oldMode is only set:
083:                // a) when this method is called for the first time
084:                // b) when the listener detects a user column-resize <-- NOT IMPLEMENTED
085:
086:                // MODES:
087:                // MODE_JUMP --> MODE_AUTO
088:                // until the user manually-resizes, then:
089:                // MODE_JUMP --> MODE_LAZY
090:
091:                int oldMode = settings.getCurrentMode();
092:                if (oldMode == 0) {
093:                    settings.setCurrentMode(mode2); // store the mode
094:                }
095:                if (mode2 == MODE_JUMP) { // hey! we'll actually use the oldMode
096:                    if (oldMode != mode2) {
097:                        mode2 = oldMode; // oldMode should be MODE_LAZY
098:                    } else {
099:                        mode2 = MODE_AUTO;
100:                    }
101:                }
102:
103:                // iterate through each column in the array, and set the size as
104:                // appropriate
105:                for (int i = 0; i < columnCount - 1; i++) {
106:                    int minWidth = (int) settings.getColumnMin(i);
107:                    int maxWidth = (int) (settings.getColumnMax(i) * tableWidth);
108:                    TableColumn column = table.getColumn(i);
109:                    if (mode2 == MODE_AUTO)
110:                        column.pack(); // automatically resize the column
111:                    int width = column.getWidth();
112:                    // check the values
113:                    if (width < minWidth) {
114:                        // ensure the table isn't incredibly small
115:                        if (!(columnCount * minWidth > tableWidth)) {
116:                            // column is too small, and the table is a reasonable size,
117:                            // so resize it
118:                            column.setWidth(minWidth);
119:                        }
120:                    } else if (width > maxWidth) {
121:                        // too big
122:                        column.setWidth(maxWidth);
123:                    }
124:                    columnSum += width;
125:                }
126:
127:                // treat the last column a little bit differently (just fill in the
128:                // remaining space)
129:                TableColumn column = table.getColumn(columnCount - 1);
130:                column.setWidth(tableWidth - columnSum
131:                        - (2 * table.getBorderWidth()));
132:
133:                // TODO: verify that 2*borderWidth is the correct adjustment for MacOS
134:                // and Linux (Looks good on Win)
135:
136:                // turn redraw back on
137:                table.setRedraw(true);
138:            }
139:
140:            public static void resizeColumns(Tree treeTable,
141:                    TableSettings settings, int mode) {
142:                int mode2 = mode;
143:                // turn off redraw (reduces flicker)
144:                treeTable.setRedraw(false);
145:
146:                int tableWidth = treeTable.getSize().x;
147:                int columnCount = treeTable.getColumnCount();
148:                int columnSum = 0;
149:
150:                // load/save the current calling mode
151:                if (!(mode2 > 0)) {
152:                    mode2 = MODE_JUMP; // mode wasn't defined; set a default
153:                }
154:
155:                // oldMode is only set:
156:                // a) when this method is called for the first time
157:                // b) when the listener detects a user column-resize <-- NOT IMPLEMENTED
158:
159:                // MODES:
160:                // MODE_JUMP --> MODE_AUTO
161:                // until the user manually-resizes, then:
162:                // MODE_JUMP --> MODE_LAZY
163:
164:                int oldMode = settings.getCurrentMode();
165:                if (oldMode == 0) {
166:                    settings.setCurrentMode(mode2); // store the mode
167:                }
168:                if (mode2 == MODE_JUMP) { // hey! we'll actually use the oldMode
169:                    if (oldMode != mode2) {
170:                        mode2 = oldMode; // oldMode should be MODE_LAZY
171:                    } else {
172:                        mode2 = MODE_AUTO;
173:                    }
174:                }
175:
176:                // iterate through each column in the array, and set the size as
177:                // appropriate
178:                for (int i = 0; i < columnCount - 1; i++) {
179:                    int minWidth = (int) settings.getColumnMin(i);
180:                    int maxWidth = (int) (settings.getColumnMax(i) * tableWidth);
181:                    TreeColumn column = treeTable.getColumn(i);
182:                    if (mode2 == MODE_AUTO)
183:                        column.pack(); // automatically resize the column
184:                    // check the values
185:                    if (column.getWidth() < minWidth) {
186:                        // ensure the table isn't incredibly small
187:                        if (!(columnCount * minWidth > tableWidth)) {
188:                            // column is too small, and the table is a reasonable size,
189:                            // so resize it
190:                            column.setWidth(minWidth);
191:                        }
192:                    } else if (column.getWidth() > maxWidth) {
193:                        // too big
194:                        column.setWidth(maxWidth);
195:                    }
196:                    columnSum += column.getWidth();
197:                }
198:
199:                // treat the last column a little bit differently (just fill in the
200:                // remaining space)
201:                TreeColumn column = treeTable.getColumn(columnCount - 1);
202:                column.setWidth(tableWidth - columnSum
203:                        - (2 * treeTable.getBorderWidth()) - 1);
204:
205:                // TODO: verify that 2*borderWidth is the correct adjustment for MacOS
206:                // and Linux (Looks good on Win)
207:
208:                // turn redraw back on
209:                treeTable.setRedraw(true);
210:            }
211:
212:            // FIXME: Implement the listener, if we need it
213:            // public static void createListener(Table table) {
214:            // table.addControlListener(new ColumnResizeListener());
215:            // }
216:
217:            // public class ColumnResizeListener implements ControlListener {
218:            // public void controlMoved(ControlEvent e) {
219:            // }
220:            //
221:            // public void controlResized(ControlEvent e) {
222:            // System.out.println("Resized!:"+e.getSource().toString());
223:            // }
224:            // }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.