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


001:        /*******************************************************************************
002:         * Copyright (c) 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.ui.internal;
011:
012:        import org.eclipse.swt.SWT;
013:        import org.eclipse.swt.events.PaintEvent;
014:        import org.eclipse.swt.events.PaintListener;
015:        import org.eclipse.swt.graphics.Color;
016:        import org.eclipse.swt.graphics.GC;
017:        import org.eclipse.swt.graphics.Point;
018:        import org.eclipse.swt.graphics.RGB;
019:        import org.eclipse.swt.graphics.Rectangle;
020:        import org.eclipse.swt.widgets.Canvas;
021:        import org.eclipse.swt.widgets.Composite;
022:        import org.eclipse.swt.widgets.Control;
023:        import org.eclipse.swt.widgets.CoolBar;
024:        import org.eclipse.swt.widgets.Layout;
025:        import org.eclipse.swt.widgets.ToolBar;
026:        import org.eclipse.ui.themes.ColorUtil;
027:
028:        /**
029:         * Draws a styled frame around its contained controls.
030:         * This class is intended to be used to wrap various
031:         * trim elements that appear in the workbench.
032:         * 
033:         *  Currently this class expects a <b>single</b> child
034:         *  control.
035:         *  
036:         * @since 3.3
037:         *
038:         */
039:        public class TrimFrame {
040:            private static int blend = 40;
041:
042:            Canvas canvas = null;
043:
044:            public TrimFrame(Composite parent) {
045:                createControl(parent);
046:            }
047:
048:            private void createControl(Composite parent) {
049:                dispose();
050:                canvas = new Canvas(parent, SWT.NONE);
051:                canvas.setBackground(parent.getDisplay().getSystemColor(
052:                        SWT.COLOR_WIDGET_BACKGROUND));
053:
054:                // paint the border
055:                canvas.addPaintListener(new PaintListener() {
056:                    private void drawLine(GC gc, int x1, int y1, int x2,
057:                            int y2, boolean flipXY) {
058:                        if (flipXY) {
059:                            int tmp = x1;
060:                            x1 = y1;
061:                            y1 = tmp;
062:                            tmp = x2;
063:                            x2 = y2;
064:                            y2 = tmp;
065:                        }
066:
067:                        gc.drawLine(x1, y1, x2, y2);
068:                    }
069:
070:                    public void paintControl(PaintEvent e) {
071:                        Canvas canvas = (Canvas) e.widget;
072:                        Control child = canvas.getChildren()[0];
073:
074:                        // Are we horizontally or vertically aligned
075:                        boolean flipXY = false;
076:                        if (child instanceof  ToolBar
077:                                && (((ToolBar) child).getStyle() & SWT.VERTICAL) != 0)
078:                            flipXY = true;
079:                        else if (child instanceof  CoolBar
080:                                && (((CoolBar) child).getStyle() & SWT.VERTICAL) != 0)
081:                            flipXY = true;
082:
083:                        Rectangle bb = canvas.getBounds();
084:                        int maxX = bb.width - 1;
085:                        int maxY = bb.height - 1;
086:
087:                        if (flipXY) {
088:                            int tmp = maxX;
089:                            maxX = maxY;
090:                            maxY = tmp;
091:                        }
092:
093:                        Color white = e.gc.getDevice().getSystemColor(
094:                                SWT.COLOR_WHITE);
095:                        Color shadow = e.gc.getDevice().getSystemColor(
096:                                SWT.COLOR_WIDGET_NORMAL_SHADOW);
097:                        RGB outerRGB = ColorUtil.blend(white.getRGB(), shadow
098:                                .getRGB(), blend);
099:                        Color outerColor = new Color(e.gc.getDevice(), outerRGB);
100:
101:                        // Draw the 'outer' bits
102:                        e.gc.setForeground(outerColor);
103:
104:                        // Top Line and curve
105:                        drawLine(e.gc, 1, 0, maxX - 5, 0, flipXY);
106:                        drawLine(e.gc, maxX - 4, 1, maxX - 3, 1, flipXY);
107:                        drawLine(e.gc, maxX - 2, 2, maxX - 2, 2, flipXY);
108:                        drawLine(e.gc, maxX - 1, 3, maxX - 1, 4, flipXY);
109:
110:                        // Bottom line and curve
111:                        drawLine(e.gc, 1, maxY, maxX - 5, maxY, flipXY);
112:                        drawLine(e.gc, maxX - 4, maxY - 1, maxX - 3, maxY - 1,
113:                                flipXY);
114:                        drawLine(e.gc, maxX - 2, maxY - 2, maxX - 2, maxY - 2,
115:                                flipXY);
116:                        drawLine(e.gc, maxX - 1, maxY - 3, maxX - 1, maxY - 4,
117:                                flipXY);
118:
119:                        // Left & Right edges 
120:                        drawLine(e.gc, 0, 1, 0, maxY - 1, flipXY);
121:                        drawLine(e.gc, maxX, 5, maxX, maxY - 5, flipXY);
122:
123:                        // Dispose the color since we created it...
124:                        outerColor.dispose();
125:
126:                        // Draw the 'inner' curve
127:                        e.gc.setForeground(white);
128:
129:                        drawLine(e.gc, 1, 1, maxX - 5, 1, flipXY);
130:                        drawLine(e.gc, maxX - 4, 2, maxX - 3, 2, flipXY);
131:                        drawLine(e.gc, maxX - 3, 3, maxX - 2, 3, flipXY);
132:                        drawLine(e.gc, maxX - 2, 4, maxX - 2, 4, flipXY);
133:
134:                        drawLine(e.gc, 1, maxY - 1, maxX - 5, maxY - 1, flipXY);
135:                        drawLine(e.gc, maxX - 4, maxY - 2, maxX - 3, maxY - 2,
136:                                flipXY);
137:                        drawLine(e.gc, maxX - 3, maxY - 3, maxX - 2, maxY - 3,
138:                                flipXY);
139:                        drawLine(e.gc, maxX - 2, maxY - 4, maxX - 2, maxY - 4,
140:                                flipXY);
141:
142:                        // Left and Right sides
143:                        drawLine(e.gc, 1, 1, 1, maxY - 1, flipXY);
144:                        drawLine(e.gc, maxX - 1, 5, maxX - 1, maxY - 5, flipXY);
145:                    }
146:                });
147:
148:                // provide a layout that provides enough extra space to
149:                // draw the border and to place the child conrol in the
150:                // correct location
151:                canvas.setLayout(new Layout() {
152:
153:                    protected Point computeSize(Composite composite, int wHint,
154:                            int hHint, boolean changed) {
155:                        Control[] children = composite.getChildren();
156:
157:                        if (children.length == 0)
158:                            return new Point(0, 0);
159:
160:                        Point innerSize = children[0].computeSize(hHint, wHint,
161:                                changed);
162:                        innerSize.x += 4;
163:                        innerSize.y += 4;
164:
165:                        Control child = children[0];
166:                        if (child instanceof  CoolBar
167:                                && (((CoolBar) child).getStyle() & SWT.VERTICAL) != 0)
168:                            innerSize.y += 3;
169:                        else
170:                            innerSize.x += 3;
171:
172:                        return innerSize;
173:                    }
174:
175:                    protected void layout(Composite composite,
176:                            boolean flushCache) {
177:                        Control[] children = composite.getChildren();
178:                        if (children.length == 0)
179:                            return;
180:
181:                        children[0].setLocation(2, 2);
182:                    }
183:                });
184:            }
185:
186:            /**
187:             * Dispose the frame
188:             */
189:            private void dispose() {
190:                if (canvas != null && !canvas.isDisposed())
191:                    canvas.dispose();
192:            }
193:
194:            /**
195:             * @return The border canvas
196:             */
197:            public Composite getComposite() {
198:                return canvas;
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.