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


001:        /*******************************************************************************
002:         * Copyright (c) 2004 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials 
004:         * are made available under the terms of the Common Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/cpl-v10.html
007:         * 
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.examples.presentation.baretittle;
011:
012:        import org.eclipse.jface.resource.JFaceResources;
013:        import org.eclipse.swt.SWT;
014:        import org.eclipse.swt.events.*;
015:        import org.eclipse.swt.graphics.*;
016:        import org.eclipse.swt.widgets.*;
017:        import org.eclipse.ui.presentations.*;
018:
019:        public class BareTitleStackPresentation extends StackPresentation {
020:
021:            private static final String PART_DATA = "part";
022:
023:            private static final int TITLE_HEIGHT = 22;
024:
025:            private boolean activeFocus = false;
026:
027:            /**
028:             * Main widget for the presentation
029:             */
030:            private Composite presentationControl;
031:            private Composite titleArea;
032:            private Composite contentArea;
033:
034:            /**
035:             * Currently selected part
036:             */
037:            private IPresentablePart current;
038:
039:            /**
040:             * close button
041:             */
042:            private ToolItem close;
043:
044:            /**
045:             * View menu button
046:             */
047:            private ToolItem viewMenu;
048:
049:            /**
050:             * Minimize button
051:             */
052:            private ToolItem minView;
053:
054:            private MouseListener mouseListener = new MouseAdapter() {
055:                // If we single-click on an empty space on the toolbar, move focus to the
056:                // active control
057:                public void mouseDown(MouseEvent e) {
058:                    if (current != null) {
059:                        current.setFocus();
060:                    }
061:                }
062:            };
063:
064:            /** 
065:             * Drag listener for regions outside the toolbar
066:             */
067:            Listener dragListener = new Listener() {
068:                public void handleEvent(Event event) {
069:                    Point loc = new Point(event.x, event.y);
070:                    Control ctrl = (Control) event.widget;
071:
072:                    getSite().dragStart(ctrl.toDisplay(loc), false);
073:                }
074:            };
075:
076:            public BareTitleStackPresentation(Composite parent,
077:                    IStackPresentationSite stackSite) {
078:                super (stackSite);
079:
080:                // Create a top-level control for the presentation.
081:                presentationControl = new Composite(parent, SWT.NONE);
082:                titleArea = new Composite(presentationControl, SWT.NONE);
083:                contentArea = new Composite(presentationControl, SWT.NONE);
084:                titleArea.addMouseListener(mouseListener);
085:                PresentationUtil.addDragListener(titleArea, dragListener);
086:
087:                // Add a dispose listener. This will call the presentationDisposed()
088:                // method when the widget is destroyed.
089:                presentationControl.addDisposeListener(new DisposeListener() {
090:                    public void widgetDisposed(DisposeEvent e) {
091:                        presentationDisposed();
092:                    }
093:                });
094:
095:                presentationControl.addPaintListener(new PaintListener() {
096:                    public void paintControl(PaintEvent e) {
097:                        Rectangle clientArea = presentationControl
098:                                .getClientArea();
099:                        e.gc.setLineWidth(1);
100:                        e.gc.setForeground(e.display
101:                                .getSystemColor(SWT.COLOR_DARK_GRAY));
102:                        e.gc.drawRectangle(clientArea.x, clientArea.y,
103:                                clientArea.width - 1, clientArea.height - 1);
104:                        Rectangle contentAreaBounds = contentArea.getBounds();
105:                        int ypos = contentAreaBounds.y - 1;
106:                        e.gc.drawLine(clientArea.x, ypos, clientArea.x
107:                                + clientArea.width - 1, ypos);
108:                    }
109:                });
110:
111:                titleArea.addPaintListener(new PaintListener() {
112:                    public void paintControl(PaintEvent e) {
113:                        Rectangle titleRect = titleArea.getClientArea();
114:                        GC gc = e.gc;
115:                        e.gc.setBackground(e.display
116:                                .getSystemColor(SWT.COLOR_GRAY));
117:                        if (activeFocus)
118:                            e.gc.setForeground(e.display
119:                                    .getSystemColor(SWT.COLOR_BLUE));
120:                        else
121:                            e.gc.setForeground(e.display
122:                                    .getSystemColor(SWT.COLOR_WHITE));
123:                        e.gc.fillGradientRectangle(titleRect.x, titleRect.y,
124:                                titleRect.x + titleRect.width, titleRect.y
125:                                        + titleRect.height, true);
126:
127:                        if (current != null) {
128:                            int textWidth = titleRect.width - 1;
129:                            if (textWidth > 0) {
130:                                Font gcFont = gc.getFont();
131:                                gc.setFont(presentationControl.getFont());
132:                                String text = current.getTitle();
133:
134:                                Point extent = gc.textExtent(text,
135:                                        SWT.DRAW_TRANSPARENT
136:                                                | SWT.DRAW_MNEMONIC);
137:                                int textY = titleRect.y
138:                                        + (titleRect.height - extent.y) / 2;
139:
140:                                if (activeFocus)
141:                                    gc.setForeground(e.display
142:                                            .getSystemColor(SWT.COLOR_WHITE));
143:                                else
144:                                    gc.setForeground(e.display
145:                                            .getSystemColor(SWT.COLOR_BLACK));
146:                                gc.setFont(JFaceResources.getBannerFont());
147:                                gc.drawText(text, titleRect.x + 3, textY,
148:                                        SWT.DRAW_TRANSPARENT
149:                                                | SWT.DRAW_MNEMONIC);
150:                            }
151:                        }
152:                    }
153:                });
154:                layout();
155:            }
156:
157:            protected void presentationDisposed() {
158:                // Remove any listeners that were attached to any
159:                // global Eclipse resources. This is necessary in order to prevent
160:                // memory leaks.
161:            }
162:
163:            protected int getBorderWidth() {
164:                return 1;
165:            }
166:
167:            public void layout() {
168:                // Determine the inner bounds of the presentation
169:                Rectangle presentationClientArea = presentationControl
170:                        .getClientArea();
171:                presentationClientArea.x += getBorderWidth();
172:                presentationClientArea.width -= getBorderWidth() * 2;
173:                presentationClientArea.y += getBorderWidth();
174:                presentationClientArea.height -= getBorderWidth() * 2;
175:                titleArea.setBounds(presentationClientArea.x,
176:                        presentationClientArea.y, presentationClientArea.width,
177:                        presentationClientArea.y + TITLE_HEIGHT);
178:                int yy = TITLE_HEIGHT + 2;
179:                contentArea.setBounds(presentationClientArea.x,
180:                        presentationClientArea.y + yy,
181:                        presentationClientArea.width,
182:                        presentationClientArea.height - yy);
183:
184:                titleArea.setBackground(titleArea.getDisplay().getSystemColor(
185:                        SWT.COLOR_DARK_GREEN));
186:                contentArea.setBackground(titleArea.getDisplay()
187:                        .getSystemColor(SWT.COLOR_DARK_RED));
188:
189:                // Position the view's widgets
190:                if (current != null) {
191:                    Rectangle clientRectangle = contentArea.getBounds();
192:                    Point clientAreaStart = presentationControl.getParent()
193:                            .toControl(
194:                                    presentationControl.toDisplay(
195:                                            clientRectangle.x,
196:                                            clientRectangle.y));
197:                    // current isn't parented by this widget hierarchy, the coordinates must be
198:                    // relative to the workbench window. The workbench window parents every
199:                    // part.
200:                    current.setBounds(new Rectangle(clientAreaStart.x,
201:                            clientAreaStart.y, clientRectangle.width,
202:                            clientRectangle.height));
203:                }
204:
205:            }
206:
207:            public void setBounds(Rectangle bounds) {
208:                presentationControl.setBounds(bounds);
209:                layout();
210:            }
211:
212:            public void dispose() {
213:            }
214:
215:            public void setActive(int newState) {
216:                activeFocus = (newState == AS_ACTIVE_FOCUS);
217:                titleArea.redraw();
218:            }
219:
220:            public void setVisible(boolean isVisible) {
221:            }
222:
223:            public void setState(int state) {
224:            }
225:
226:            public Control getControl() {
227:                return presentationControl;
228:            }
229:
230:            public void addPart(IPresentablePart newPart, Object cookie) {
231:                newPart.setBounds(contentArea.getBounds());
232:                this .current = newPart;
233:                layout();
234:            }
235:
236:            public void removePart(IPresentablePart oldPart) {
237:            }
238:
239:            public void selectPart(IPresentablePart toSelect) {
240:            }
241:
242:            public StackDropResult dragOver(Control currentControl,
243:                    Point location) {
244:                return null;
245:            }
246:
247:            public void showSystemMenu() {
248:            }
249:
250:            public void showPaneMenu() {
251:            }
252:
253:            public Control[] getTabList(IPresentablePart part) {
254:                if (current != null) {
255:                    return new Control[] { current.getControl() };
256:                } else {
257:                    return new Control[0];
258:                }
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.