Source Code Cross Referenced for OwnerDrawLabelProvider.java in  » IDE-Eclipse » jface » org » eclipse » jface » viewers » 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 » jface » org.eclipse.jface.viewers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006, 2007 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.jface.viewers;
011:
012:        import org.eclipse.swt.SWT;
013:        import org.eclipse.swt.graphics.Color;
014:        import org.eclipse.swt.graphics.Rectangle;
015:        import org.eclipse.swt.widgets.Event;
016:        import org.eclipse.swt.widgets.Listener;
017:
018:        /**
019:         * OwnerDrawLabelProvider is an abstract implementation of a label provider that
020:         * handles custom draw.
021:         * 
022:         * <p>
023:         * <b>This class is intended to be subclassed by implementors.</b>
024:         * </p>
025:         * 
026:         * @since 3.3
027:         * 
028:         */
029:        public abstract class OwnerDrawLabelProvider extends CellLabelProvider {
030:
031:            /**
032:             * Set up the owner draw callbacks for the viewer.
033:             * 
034:             * @param viewer
035:             *            the viewer the owner draw is set up
036:             */
037:            public static void setUpOwnerDraw(final ColumnViewer viewer) {
038:                viewer.getControl().addListener(SWT.MeasureItem,
039:                        new Listener() {
040:                            /*
041:                             * (non-Javadoc)
042:                             * 
043:                             * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
044:                             */
045:                            public void handleEvent(Event event) {
046:                                CellLabelProvider provider = viewer
047:                                        .getViewerColumn(event.index)
048:                                        .getLabelProvider();
049:                                Object element = event.item.getData();
050:
051:                                if (provider instanceof  OwnerDrawLabelProvider)
052:                                    ((OwnerDrawLabelProvider) provider)
053:                                            .measure(event, element);
054:                            }
055:                        });
056:
057:                viewer.getControl().addListener(SWT.PaintItem, new Listener() {
058:                    /*
059:                     * (non-Javadoc)
060:                     * 
061:                     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
062:                     */
063:                    public void handleEvent(Event event) {
064:                        CellLabelProvider provider = viewer.getViewerColumn(
065:                                event.index).getLabelProvider();
066:                        Object element = event.item.getData();
067:
068:                        if (provider instanceof  OwnerDrawLabelProvider)
069:                            ((OwnerDrawLabelProvider) provider).paint(event,
070:                                    element);
071:                    }
072:                });
073:
074:                viewer.getControl().addListener(SWT.EraseItem, new Listener() {
075:                    /*
076:                     * (non-Javadoc)
077:                     * 
078:                     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
079:                     */
080:                    public void handleEvent(Event event) {
081:
082:                        CellLabelProvider provider = getLabelProvider(viewer,
083:                                event);
084:                        Object element = getElement(event);
085:
086:                        if (provider instanceof  OwnerDrawLabelProvider)
087:                            ((OwnerDrawLabelProvider) provider).erase(event,
088:                                    element);
089:
090:                    }
091:
092:                    /**
093:                     * Return the item for the event
094:                     * 
095:                     * @param event
096:                     * @return Object
097:                     */
098:                    private Object getElement(Event event) {
099:                        return event.item.getData();
100:                    }
101:
102:                    /**
103:                     * Return the label provider for the column.
104:                     * 
105:                     * @param viewer
106:                     * @param event
107:                     * @return CellLabelProvider
108:                     */
109:                    private CellLabelProvider getLabelProvider(
110:                            final ColumnViewer viewer, Event event) {
111:                        return viewer.getViewerColumn(event.index)
112:                                .getLabelProvider();
113:                    }
114:                });
115:            }
116:
117:            /**
118:             * Handle the erase event. The default implementation colors the background
119:             * of selected areas with {@link SWT#COLOR_LIST_SELECTION} and foregrounds
120:             * with {@link SWT#COLOR_LIST_SELECTION_TEXT}
121:             * 
122:             * @param event
123:             *            the erase event
124:             * @param element
125:             *            the model object
126:             * @see SWT#EraseItem
127:             * @see SWT#COLOR_LIST_SELECTION
128:             * @see SWT#COLOR_LIST_SELECTION_TEXT
129:             */
130:            protected void erase(Event event, Object element) {
131:
132:                Rectangle bounds = event.getBounds();
133:                if ((event.detail & SWT.SELECTED) != 0) {
134:
135:                    Color oldForeground = event.gc.getForeground();
136:                    Color oldBackground = event.gc.getBackground();
137:
138:                    event.gc.setBackground(event.item.getDisplay()
139:                            .getSystemColor(SWT.COLOR_LIST_SELECTION));
140:                    event.gc.setForeground(event.item.getDisplay()
141:                            .getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
142:                    event.gc.fillRectangle(bounds);
143:                    /* restore the old GC colors */
144:                    event.gc.setForeground(oldForeground);
145:                    event.gc.setBackground(oldBackground);
146:                    /* ensure that default selection is not drawn */
147:                    event.detail &= ~SWT.SELECTED;
148:
149:                }
150:
151:            }
152:
153:            /**
154:             * Handle the paint event.
155:             * 
156:             * @param event
157:             *            the paint event
158:             * @param element
159:             *            the model element
160:             * @see SWT#PaintItem
161:             */
162:            protected abstract void paint(Event event, Object element);
163:
164:            /**
165:             * Handle the measure event.
166:             * 
167:             * @param event
168:             *            the measure event
169:             * @param element
170:             *            the model element
171:             * @see SWT#MeasureItem
172:             */
173:            protected abstract void measure(Event event, Object element);
174:
175:            /**
176:             * Create a new instance of the receiver based on a column viewer.
177:             * 
178:             */
179:            public OwnerDrawLabelProvider() {
180:
181:            }
182:
183:            /*
184:             * (non-Javadoc)
185:             * 
186:             * @see org.eclipse.jface.viewers.ViewerLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
187:             */
188:            public void update(ViewerCell cell) {
189:                // Force a redraw
190:                Rectangle cellBounds = cell.getBounds();
191:                cell.getControl().redraw(cellBounds.x, cellBounds.y,
192:                        cellBounds.width, cellBounds.height, true);
193:
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.