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


001:        package net.refractions.udig.project.ui.preferences;
002:
003:        import net.refractions.udig.ui.PlatformGIS;
004:        import net.refractions.udig.ui.graphics.Glyph;
005:
006:        import org.eclipse.jface.preference.FieldEditor;
007:        import org.eclipse.jface.viewers.ColumnWeightData;
008:        import org.eclipse.jface.viewers.ISelection;
009:        import org.eclipse.jface.viewers.IStructuredContentProvider;
010:        import org.eclipse.jface.viewers.LabelProvider;
011:        import org.eclipse.jface.viewers.StructuredSelection;
012:        import org.eclipse.jface.viewers.TableLayout;
013:        import org.eclipse.jface.viewers.TableViewer;
014:        import org.eclipse.jface.viewers.Viewer;
015:        import org.eclipse.jface.viewers.ViewerSorter;
016:        import org.eclipse.swt.SWT;
017:        import org.eclipse.swt.graphics.Image;
018:        import org.eclipse.swt.layout.GridData;
019:        import org.eclipse.swt.widgets.Composite;
020:        import org.eclipse.swt.widgets.Control;
021:        import org.eclipse.swt.widgets.Table;
022:        import org.eclipse.swt.widgets.TableColumn;
023:        import org.geotools.brewer.color.BrewerPalette;
024:        import org.geotools.brewer.color.ColorBrewer;
025:
026:        public class PaletteSelectionFieldEditor extends FieldEditor {
027:
028:            TableViewer palettes;
029:
030:            public PaletteSelectionFieldEditor(String name, String string,
031:                    Composite parent) {
032:                super (name, string, parent);
033:            }
034:
035:            @Override
036:            protected void adjustForNumColumns(int numColumns) {
037:                Control control = getLabelControl();
038:                ((GridData) control.getLayoutData()).horizontalSpan = numColumns;
039:                ((GridData) palettes.getControl().getLayoutData()).horizontalSpan = numColumns;
040:            }
041:
042:            @Override
043:            protected void doFillIntoGrid(Composite parent, int numColumns) {
044:                Control control = getLabelControl(parent);
045:                GridData gd = new GridData();
046:                gd.horizontalSpan = numColumns;
047:                control.setLayoutData(gd);
048:
049:                palettes = getTableControl(parent);
050:                gd = new GridData(GridData.FILL_HORIZONTAL);
051:                gd.verticalAlignment = GridData.FILL;
052:                gd.horizontalSpan = numColumns;
053:                gd.grabExcessHorizontalSpace = true;
054:                gd.heightHint = 95;
055:                palettes.getControl().setLayoutData(gd);
056:
057:                //        buttonBox = getButtonBoxControl(parent);
058:                //        gd = new GridData();
059:                //        gd.verticalAlignment = GridData.BEGINNING;
060:                //        buttonBox.setLayoutData(gd);
061:            }
062:
063:            private TableViewer getTableControl(Composite parent) {
064:                TableViewer paletteTable = new TableViewer(new Table(parent,
065:                        SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL
066:                                | SWT.FULL_SELECTION));
067:                TableLayout tableLayout = new TableLayout();
068:                tableLayout.addColumnData(new ColumnWeightData(1, 20, false));
069:                TableColumn firstColumn = new TableColumn(paletteTable
070:                        .getTable(), SWT.LEFT);
071:                firstColumn.setAlignment(SWT.LEFT);
072:                paletteTable.getTable().setLayout(tableLayout);
073:                //        gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
074:                //        gridData.horizontalSpan = 2;
075:                //        gridData.heightHint = 150;
076:                //        gridData.widthHint = 175;
077:
078:                paletteTable.setLabelProvider(new LabelProvider() {
079:                    public Image getImage(Object element) {
080:                        if (element instanceof  BrewerPalette) {
081:                            BrewerPalette palette = (BrewerPalette) element;
082:                            return Glyph.palette(
083:                                    palette.getColors(palette.getMaxColors()))
084:                                    .createImage();
085:                        }
086:                        return null;
087:                    }
088:
089:                    public String getText(Object element) {
090:                        if (element instanceof  BrewerPalette) {
091:                            BrewerPalette palette = (BrewerPalette) element;
092:                            String text = null;
093:                            text = palette.getName()
094:                                    + ": " + palette.getDescription(); //$NON-NLS-1$
095:                            if (text == null)
096:                                text = palette.getName();
097:                            return text;
098:                        }
099:                        return null;
100:                    }
101:                });
102:
103:                paletteTable
104:                        .setContentProvider(new IStructuredContentProvider() {
105:
106:                            public Object[] getElements(Object inputElement) {
107:                                if (inputElement instanceof  ColorBrewer) {
108:                                    ColorBrewer brewer = (ColorBrewer) inputElement;
109:                                    return brewer.getPalettes();
110:                                } else {
111:                                    return new Object[0];
112:                                }
113:                            }
114:
115:                            public void dispose() {
116:                            }
117:
118:                            public void inputChanged(Viewer viewer,
119:                                    Object oldInput, Object newInput) {
120:                            }
121:                        });
122:
123:                paletteTable.setSorter(new ViewerSorter() {
124:
125:                    @Override
126:                    public int compare(Viewer viewer, Object e1, Object e2) {
127:                        if (e1 instanceof  BrewerPalette
128:                                && e2 instanceof  BrewerPalette) {
129:                            BrewerPalette p1 = (BrewerPalette) e1;
130:                            BrewerPalette p2 = (BrewerPalette) e2;
131:                            //alphabetical by name
132:                            return p1.getName().compareTo(p2.getName());
133:                        } else
134:                            return super .compare(viewer, e1, e2);
135:                    }
136:
137:                });
138:
139:                paletteTable.setInput(PlatformGIS.getColorBrewer());
140:                return paletteTable;
141:            }
142:
143:            @Override
144:            protected void doLoad() {
145:                if (palettes != null) {
146:                    select(getPreferenceStore().getString(getPreferenceName()));
147:                }
148:            }
149:
150:            @Override
151:            protected void doLoadDefault() {
152:                if (palettes != null) {
153:                    select(getPreferenceStore().getDefaultString(
154:                            getPreferenceName()));
155:                }
156:            }
157:
158:            private void select(String paletteName) {
159:                ColorBrewer brewer = PlatformGIS.getColorBrewer();
160:                if (paletteName == null || !brewer.hasPalette(paletteName))
161:                    return;
162:                BrewerPalette palette = brewer.getPalette(paletteName);
163:                palettes.setSelection(new StructuredSelection(palette));
164:            }
165:
166:            @Override
167:            protected void doStore() {
168:                ISelection select = palettes.getSelection();
169:                if (select == null) {
170:                    getPreferenceStore().setToDefault(getPreferenceName());
171:                    return;
172:                }
173:                BrewerPalette palette = (BrewerPalette) ((StructuredSelection) select)
174:                        .getFirstElement();
175:                getPreferenceStore().setValue(getPreferenceName(),
176:                        palette.getName());
177:            }
178:
179:            @Override
180:            public int getNumberOfControls() {
181:                return 2;
182:            }
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.