KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > themes > WorkbenchPreview


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.themes;
12
13 import org.eclipse.jface.preference.IPreferenceStore;
14 import org.eclipse.jface.util.IPropertyChangeListener;
15 import org.eclipse.jface.util.PropertyChangeEvent;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.CLabel;
18 import org.eclipse.swt.custom.CTabFolder;
19 import org.eclipse.swt.custom.CTabItem;
20 import org.eclipse.swt.custom.ViewForm;
21 import org.eclipse.swt.graphics.Color;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.ToolBar;
26 import org.eclipse.swt.widgets.ToolItem;
27 import org.eclipse.ui.ISharedImages;
28 import org.eclipse.ui.IWorkbenchPreferenceConstants;
29 import org.eclipse.ui.internal.IPreferenceConstants;
30 import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
31 import org.eclipse.ui.internal.IWorkbenchThemeConstants;
32 import org.eclipse.ui.internal.WorkbenchImages;
33 import org.eclipse.ui.internal.WorkbenchPlugin;
34 import org.eclipse.ui.internal.util.PrefUtil;
35 import org.eclipse.ui.themes.ITheme;
36 import org.eclipse.ui.themes.IThemePreview;
37
38 /**
39  * @since 3.0
40  */

41 public class WorkbenchPreview implements IThemePreview {
42
43     private static IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault()
44             .getPreferenceStore();
45
46     // don't reset this dynamically, so just keep the information static.
47
// see bug:
48
// 75422 [Presentations] Switching presentation to R21 switches immediately, but only partially
49
private static int tabPos = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION);
50   
51     private IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
52
53     private boolean disposed = false;
54
55     private CTabFolder folder;
56
57     private ITheme theme;
58
59     private ToolBar toolBar;
60
61     private CLabel viewMessage;
62
63     private ViewForm viewForm;
64
65     private IPropertyChangeListener fontAndColorListener = new IPropertyChangeListener() {
66         public void propertyChange(PropertyChangeEvent event) {
67             if (!disposed) {
68                 setColorsAndFonts();
69                 //viewMessage.setSize(viewMessage.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
70
viewForm.layout(true);
71             }
72         }
73     };
74
75     /* (non-Javadoc)
76      * @see org.eclipse.ui.IPresentationPreview#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.themes.ITheme)
77      */

78     public void createControl(Composite parent, ITheme currentTheme) {
79         this.theme = currentTheme;
80         folder = new CTabFolder(parent, SWT.BORDER);
81         folder.setUnselectedCloseVisible(false);
82         folder.setEnabled(false);
83         folder.setMaximizeVisible(true);
84         folder.setMinimizeVisible(true);
85
86         viewForm = new ViewForm(folder, SWT.NONE);
87         viewForm.marginHeight = 0;
88         viewForm.marginWidth = 0;
89         viewForm.verticalSpacing = 0;
90         viewForm.setBorderVisible(false);
91         toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.WRAP);
92         ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
93
94         Image hoverImage = WorkbenchImages
95                 .getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
96         toolItem.setImage(hoverImage);
97
98         viewForm.setTopRight(toolBar);
99
100         viewMessage = new CLabel(viewForm, SWT.NONE);
101         viewMessage.setText("Etu?"); //$NON-NLS-1$
102
viewForm.setTopLeft(viewMessage);
103
104         CTabItem item = new CTabItem(folder, SWT.CLOSE);
105         item.setText("Lorem"); //$NON-NLS-1$
106
Label text = new Label(viewForm, SWT.NONE);
107         viewForm.setContent(text);
108         text.setText("Lorem ipsum dolor sit amet"); //$NON-NLS-1$
109
text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
110         item = new CTabItem(folder, SWT.CLOSE);
111         item.setText("Ipsum"); //$NON-NLS-1$
112
item.setControl(viewForm);
113         item.setImage(WorkbenchImages.getImage(ISharedImages.IMG_TOOL_COPY));
114
115         folder.setSelection(item);
116
117         item = new CTabItem(folder, SWT.CLOSE);
118         item.setText("Dolor"); //$NON-NLS-1$
119
item = new CTabItem(folder, SWT.CLOSE);
120         item.setText("Sit"); //$NON-NLS-1$
121

122         currentTheme.addPropertyChangeListener(fontAndColorListener);
123         setColorsAndFonts();
124         setTabPosition();
125         setTabStyle();
126     }
127
128     /**
129      * Set the tab style from preferences.
130      */

131     protected void setTabStyle() {
132         boolean traditionalTab = apiStore
133                 .getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS);
134         folder.setSimple(traditionalTab);
135     }
136
137     /**
138      * Set the tab location from preferences.
139      */

140     protected void setTabPosition() {
141         tabPos = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION);
142         folder.setTabPosition(tabPos);
143     }
144
145     /**
146      * Set the folder colors and fonts
147      */

148     private void setColorsAndFonts() {
149         folder.setSelectionForeground(theme.getColorRegistry().get(
150                 IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR));
151         folder.setForeground(theme.getColorRegistry().get(
152                 IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR));
153
154         Color[] colors = new Color[2];
155         colors[0] = theme.getColorRegistry().get(
156                 IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
157         colors[1] = theme.getColorRegistry().get(
158                 IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
159         colors[0] = theme.getColorRegistry().get(
160                 IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
161         colors[1] = theme.getColorRegistry().get(
162                 IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
163         folder.setSelectionBackground(colors, new int[] { theme
164                 .getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT) }, theme
165                 .getBoolean(IWorkbenchThemeConstants.ACTIVE_TAB_VERTICAL));
166
167         folder.setFont(theme.getFontRegistry().get(
168                 IWorkbenchThemeConstants.TAB_TEXT_FONT));
169         viewMessage.setFont(theme.getFontRegistry().get(
170                 IWorkbenchThemeConstants.VIEW_MESSAGE_TEXT_FONT));
171     }
172
173     /* (non-Javadoc)
174      * @see org.eclipse.ui.IPresentationPreview#dispose()
175      */

176     public void dispose() {
177         disposed = true;
178         theme.removePropertyChangeListener(fontAndColorListener);
179     }
180 }
181
Popular Tags