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


001:        /*
002:         * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003:         * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004:         * under the terms of the GNU Lesser General Public License as published by the Free Software
005:         * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006:         * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008:         */
009:        package net.refractions.udig.project.ui.internal;
010:
011:        import java.util.ArrayList;
012:        import java.util.Arrays;
013:        import java.util.Iterator;
014:        import java.util.List;
015:
016:        import net.refractions.udig.project.ILayer;
017:        import net.refractions.udig.project.internal.Layer;
018:        import net.refractions.udig.project.internal.Map;
019:        import net.refractions.udig.ui.PlatformGIS;
020:        import net.refractions.udig.ui.palette.ColourScheme;
021:
022:        import org.eclipse.swt.SWT;
023:        import org.eclipse.swt.custom.ScrolledComposite;
024:        import org.eclipse.swt.events.SelectionEvent;
025:        import org.eclipse.swt.events.SelectionListener;
026:        import org.eclipse.swt.graphics.Point;
027:        import org.eclipse.swt.layout.GridData;
028:        import org.eclipse.swt.layout.GridLayout;
029:        import org.eclipse.swt.widgets.Combo;
030:        import org.eclipse.swt.widgets.Composite;
031:        import org.eclipse.swt.widgets.Control;
032:        import org.eclipse.swt.widgets.Label;
033:        import org.eclipse.swt.widgets.ScrollBar;
034:        import org.geotools.brewer.color.BrewerPalette;
035:
036:        /**
037:         * <p>
038:         * <b>Purpose:</b>
039:         * </p>
040:         * <p>
041:         * Panel for Property page for <em><b>Map</b></em> objects with widgets that allow users to
042:         * change default colours for the map.
043:         * </p>
044:         * 
045:         * @author ptozer
046:         * @author chorner
047:         */
048:        public class PaletteDefaultChooserPanel {
049:            Composite composite;
050:            ScrolledComposite scrolledComposite;
051:            BrewerPalette mapPalette = null;
052:            ColourScheme mapScheme = null;
053:            Combo paletteSelectionCombo = null;
054:            Combo quantityCombo = null;
055:            ArrayList<PaletteCombo> allLayerControls = new ArrayList<PaletteCombo>();
056:            Map map = null;
057:
058:            int index = 0;
059:            int numberOfLayers = 0;
060:
061:            /**
062:             * Constructor
063:             */
064:            public PaletteDefaultChooserPanel() {
065:                /*
066:                 * colourLetterCombo lists to choose colours per Each layer- show colour and allow colour
067:                 * choice in drop-down Background colour neutrals plus blue Polygon borders neutrals Polygon
068:                 * Fill palette Line palette plus black and white Point palette plus black and white Text
069:                 * palette plus black and white
070:                 */
071:            }
072:
073:            /**
074:             * <p>
075:             * Creates a Control with:<br>
076:             * A colourLetterCombo box to allow the user to change the default colour scheme used to colour
077:             * all subsequent layers after closing this panel.<br>
078:             * <br>
079:             * A list of all current Map Layers and the colour assigned to the layer. The colour is combined
080:             * with a drop-down of all available colours to choose from. Currently, choosing from this list
081:             * does nothing expect change the colour beside it. No changes are affected to the layer.
082:             * </p>
083:             * 
084:             * @param parent
085:             * @param element
086:             * @return
087:             */
088:            public Control createPaletteDefaultChooserPanel(Composite parent,
089:                    Map this Map) {
090:                /*
091:                 * uses ColorBrewer.com as a guide- all palettes and colour schemes taken from this. The
092:                 * concept of lettered colours also comes from ColorBrewer.
093:                 */
094:
095:                this .map = this Map;
096:                numberOfLayers = this .map.getContextModel().getLayers().size();
097:                mapPalette = map.getColorPalette();
098:                mapScheme = map.getColourScheme();
099:                //workaround for non-saving (need to correct number of colours)
100:                if (mapScheme.getSizePalette() < numberOfLayers) {
101:                    mapScheme.setSizePalette(numberOfLayers);
102:                }
103:                if (mapScheme.getSizeScheme() < numberOfLayers) {
104:                    mapScheme.setSizeScheme(numberOfLayers);
105:                }
106:                scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL
107:                        | SWT.H_SCROLL);
108:                composite = new Composite(scrolledComposite, SWT.NONE);
109:
110:                scrolledComposite.setContent(composite);
111:
112:                GridLayout gridLayout = new GridLayout();
113:                gridLayout.numColumns = 4;
114:                composite.setLayout(gridLayout);
115:
116:                // title at top of panel
117:                Label titleLabel = new Label(composite, SWT.NONE);
118:                titleLabel.setText(Messages.PaletteDefaultChooserPanel_title);
119:
120:                GridData data = new GridData();
121:                data.horizontalSpan = 4;
122:                titleLabel.setLayoutData(data);
123:
124:                // palette label
125:                Label paletteLabel = new Label(composite, SWT.NONE);
126:                paletteLabel
127:                        .setText(Messages.PaletteDefaultChooserPanel_palette);
128:
129:                data = new GridData();
130:                data.horizontalSpan = 1;
131:                paletteLabel.setLayoutData(data);
132:
133:                // palette colourLetterCombo box
134:                paletteSelectionCombo = new Combo(composite, SWT.DROP_DOWN
135:                        | SWT.READ_ONLY);
136:
137:                String[] names = PlatformGIS.getColorBrewer().getPaletteNames();
138:
139:                paletteSelectionCombo.setItems(names);
140:
141:                // find out index number for selection
142:                index = 0;
143:                for (int i = 0; i < names.length; i++) {
144:                    if ((names[i]).equalsIgnoreCase(mapPalette.getName())) {
145:                        index = i;
146:                        break;
147:                    }
148:                }
149:
150:                paletteSelectionCombo
151:                        .addSelectionListener(new SelectionListener() {
152:                            public void widgetSelected(SelectionEvent e) {
153:                                /*
154:                                 * When a new palette is selected: get the palette String and then we want to
155:                                 * repaint all paletteCombos to have new colours
156:                                 */
157:                                index = paletteSelectionCombo
158:                                        .getSelectionIndex();
159:                                String name = paletteSelectionCombo
160:                                        .getItem(index);
161:                                BrewerPalette palette = PlatformGIS
162:                                        .getColorBrewer().getPalette(name);
163:                                ColourScheme scheme = map.getColourScheme();
164:                                scheme.setColourPalette(palette);
165:                                map.setColorPalette(palette);
166:                                map.setColourScheme(scheme);
167:                                updateLayerDisplay();
168:                            }
169:
170:                            public void widgetDefaultSelected(SelectionEvent e) {
171:                            }
172:                        });
173:
174:                // TODO set selection to default or current colour palette
175:                paletteSelectionCombo.select(index);// default
176:
177:                data = new GridData();
178:                data.horizontalSpan = 3;
179:                data.widthHint = 50;
180:
181:                paletteSelectionCombo.setLayoutData(data);
182:
183:                // palette label
184:                Label quantityLabel = new Label(composite, SWT.NONE);
185:                quantityLabel
186:                        .setText(Messages.PaletteDefaultChooserPanel_colours);
187:
188:                data = new GridData();
189:                data.horizontalSpan = 1;
190:                quantityLabel.setLayoutData(data);
191:
192:                quantityCombo = new Combo(composite, SWT.DROP_DOWN
193:                        | SWT.READ_ONLY);
194:                int minColours = mapScheme.getMinColours();
195:                int maxColours = mapPalette.getMaxColors();
196:                for (int i = minColours; i <= maxColours; i++) {
197:                    quantityCombo.add(Integer.toString(i));
198:                }
199:                quantityCombo.select(quantityCombo.indexOf(Integer
200:                        .toString(mapScheme.getSizePalette())));
201:
202:                quantityCombo.addSelectionListener(new SelectionListener() {
203:                    public void widgetSelected(SelectionEvent e) {
204:                        //when the number of colours is modified, regenerate the list of layers w/ colours
205:                        mapScheme.setSizePalette(Integer.parseInt(quantityCombo
206:                                .getText()));
207:                        updateLayerDisplay();
208:                    }
209:
210:                    public void widgetDefaultSelected(SelectionEvent e) {
211:                    }
212:                });
213:
214:                data = new GridData();
215:                data.horizontalSpan = 3;
216:                data.widthHint = 50;
217:
218:                quantityCombo.setLayoutData(data);
219:
220:                /*
221:                 * //TODO what we want eventually here is to allow the user to change to map background,
222:                 * polygon outline colours. Each layer has its own colourscheme These should be defaulted to
223:                 * greysclae (plus cyan for background)
224:                 */
225:
226:                Label checkBoxLabel = new Label(composite, SWT.NONE);
227:                checkBoxLabel
228:                        .setText(Messages.PaletteDefaultChooserPanel_check);
229:                data = new GridData();
230:                data.horizontalSpan = 4;
231:                checkBoxLabel.setLayoutData(data);
232:
233:                createLayerDisplay();
234:                Point pt = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
235:                composite.setSize(pt);
236:
237:                return scrolledComposite;
238:
239:            }
240:
241:            void createLayerDisplay() {
242:                // clear all existing colour controls
243:                if (allLayerControls != null && allLayerControls.size() > 0) {
244:                    Iterator iter = allLayerControls.iterator();
245:                    while (iter.hasNext()) {
246:                        ((PaletteCombo) iter.next()).dispose();
247:                    }
248:                    allLayerControls = new ArrayList<PaletteCombo>();
249:                }
250:
251:                // get the layers from the map
252:                List<ILayer> layers = map.getMapLayers();
253:                Iterator<ILayer> layerIterator = layers.iterator();
254:                while (layerIterator.hasNext()) {
255:                    // for each layer display its current colour
256:                    Layer layer = (Layer) layerIterator.next();
257:                    // System.out.println(layer.getName());
258:
259:                    PaletteCombo layerColourCombo = new PaletteCombo(composite);
260:                    // ad the colour indicator for the layer to the dialog panel
261:                    Control layerCombo = layerColourCombo
262:                            .getPaletteCombo(layer);
263:
264:                    GridData data = new GridData();
265:                    data.horizontalSpan = 3;
266:                    layerCombo.setLayoutData(data);
267:
268:                    allLayerControls.add(layerColourCombo);
269:                }
270:                Point pt = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
271:                composite.setSize(pt);
272:                composite.layout(true);
273:                scrolledComposite.layout(true);
274:            }
275:
276:            void updateLayerDisplay() {
277:                Iterator<PaletteCombo> layerIterator = allLayerControls
278:                        .iterator();
279:                while (layerIterator.hasNext()) {
280:                    PaletteCombo this Layer = layerIterator.next();
281:                    this Layer.updateContents(mapScheme);
282:                }
283:            }
284:
285:            /**
286:             * TODO: rewrite to dispose off all class vars.
287:             */
288:            public void dispose() {
289:                Control[] controls = composite.getChildren();
290:                for (int i = 0; i < controls.length; i++) {
291:
292:                    controls[i].dispose();
293:                }
294:                composite.dispose();
295:                scrolledComposite.dispose();
296:            }
297:
298:            /**
299:             * @return Returns the allLayerControls.
300:             */
301:            public ArrayList<PaletteCombo> getAllLayerControls() {
302:                return allLayerControls;
303:            }
304:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.