Source Code Cross Referenced for StolenColorEditor.java in  » GIS » udig-1.1 » net » refractions » udig » style » sld » 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.style.sld.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.style.sld.internal;
010:
011:        import org.eclipse.jface.resource.JFaceResources;
012:        import org.eclipse.swt.SWT;
013:        import org.eclipse.swt.events.DisposeEvent;
014:        import org.eclipse.swt.events.DisposeListener;
015:        import org.eclipse.swt.events.SelectionAdapter;
016:        import org.eclipse.swt.events.SelectionEvent;
017:        import org.eclipse.swt.events.SelectionListener;
018:        import org.eclipse.swt.graphics.Color;
019:        import org.eclipse.swt.graphics.Font;
020:        import org.eclipse.swt.graphics.GC;
021:        import org.eclipse.swt.graphics.Image;
022:        import org.eclipse.swt.graphics.Point;
023:        import org.eclipse.swt.graphics.RGB;
024:        import org.eclipse.swt.widgets.Button;
025:        import org.eclipse.swt.widgets.ColorDialog;
026:        import org.eclipse.swt.widgets.Composite;
027:        import org.eclipse.swt.widgets.Control;
028:        import org.eclipse.swt.widgets.Display;
029:
030:        /**
031:         * A "button" of a certain color determined by the color picker.
032:         */
033:        public class StolenColorEditor {
034:
035:            private Point fExtent;
036:            private Image fImage;
037:            private RGB fColorValue;
038:            private Color fColor;
039:            private Button fButton;
040:            private SelectionListener listener;
041:
042:            public StolenColorEditor(Composite parent) {
043:                this (parent, null);
044:            }
045:
046:            public StolenColorEditor(Composite parent,
047:                    SelectionListener parentListener) {
048:                this .listener = parentListener;
049:                fButton = new Button(parent, SWT.PUSH);
050:                fExtent = computeImageSize(parent);
051:                fImage = new Image(parent.getDisplay(), fExtent.x, fExtent.y);
052:
053:                GC gc = new GC(fImage);
054:                gc.setBackground(fButton.getBackground());
055:                gc.fillRectangle(0, 0, fExtent.x, fExtent.y);
056:                gc.dispose();
057:
058:                fButton.setImage(fImage);
059:                fButton.addSelectionListener(new SelectionAdapter() {
060:                    public void widgetSelected(SelectionEvent event) {
061:                        ColorDialog colorDialog = new ColorDialog(fButton
062:                                .getShell());
063:                        colorDialog.setRGB(fColorValue);
064:                        RGB newColor = colorDialog.open();
065:                        if (newColor != null) {
066:                            fColorValue = newColor;
067:                            updateColorImage();
068:                        }
069:                        notifyParent(event);
070:                    }
071:                });
072:
073:                fButton.addDisposeListener(new DisposeListener() {
074:                    public void widgetDisposed(DisposeEvent event) {
075:                        if (fImage != null) {
076:                            fImage.dispose();
077:                            fImage = null;
078:                        }
079:                        if (fColor != null) {
080:                            fColor.dispose();
081:                            fColor = null;
082:                        }
083:                    }
084:                });
085:            }
086:
087:            public void setListener(SelectionListener newListener) {
088:                listener = newListener;
089:            }
090:
091:            private void notifyParent(SelectionEvent event) {
092:                if (listener != null)
093:                    listener.widgetSelected(event);
094:            }
095:
096:            public java.awt.Color getColor() {
097:                RGB rgb = getColorValue();
098:                return new java.awt.Color(rgb.red, rgb.green, rgb.blue);
099:            }
100:
101:            public void setColor(java.awt.Color color) {
102:                if (color == null) {
103:                    setColorValue(null);
104:                } else {
105:                    RGB rgb = new RGB(color.getRed(), color.getGreen(), color
106:                            .getBlue());
107:                    setColorValue(rgb);
108:                }
109:            }
110:
111:            public void setEnabled(boolean isEnabled) {
112:                getButton().setEnabled(isEnabled);
113:            }
114:
115:            public RGB getColorValue() {
116:                return fColorValue;
117:            }
118:
119:            public void setColorValue(RGB rgb) {
120:                if (rgb == null) {
121:                    rgb = new RGB(0, 0, 0);
122:                }
123:                fColorValue = rgb;
124:                updateColorImage();
125:            }
126:
127:            public Button getButton() {
128:                return fButton;
129:            }
130:
131:            protected void updateColorImage() {
132:
133:                Display display = fButton.getDisplay();
134:
135:                GC gc = new GC(fImage);
136:                gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
137:                gc.drawRectangle(0, 2, fExtent.x - 1, fExtent.y - 4);
138:
139:                if (fColor != null)
140:                    fColor.dispose();
141:
142:                fColor = new Color(display, fColorValue);
143:                gc.setBackground(fColor);
144:                gc.fillRectangle(1, 3, fExtent.x - 2, fExtent.y - 5);
145:                gc.dispose();
146:
147:                fButton.setImage(fImage);
148:            }
149:
150:            protected Point computeImageSize(Control window) {
151:                GC gc = new GC(window);
152:                Font f = JFaceResources.getFontRegistry().get(
153:                        JFaceResources.DEFAULT_FONT);
154:                gc.setFont(f);
155:                int height = gc.getFontMetrics().getHeight();
156:                gc.dispose();
157:                Point p = new Point(height * 3 - 6, height);
158:                return p;
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.