001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 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.themes;
011:
012: import org.eclipse.jface.preference.IPreferenceStore;
013: import org.eclipse.jface.util.IPropertyChangeListener;
014: import org.eclipse.jface.util.PropertyChangeEvent;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.custom.CLabel;
017: import org.eclipse.swt.custom.CTabFolder;
018: import org.eclipse.swt.custom.CTabItem;
019: import org.eclipse.swt.custom.ViewForm;
020: import org.eclipse.swt.graphics.Color;
021: import org.eclipse.swt.graphics.Image;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.swt.widgets.Label;
024: import org.eclipse.swt.widgets.ToolBar;
025: import org.eclipse.swt.widgets.ToolItem;
026: import org.eclipse.ui.ISharedImages;
027: import org.eclipse.ui.IWorkbenchPreferenceConstants;
028: import org.eclipse.ui.internal.IPreferenceConstants;
029: import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
030: import org.eclipse.ui.internal.IWorkbenchThemeConstants;
031: import org.eclipse.ui.internal.WorkbenchImages;
032: import org.eclipse.ui.internal.WorkbenchPlugin;
033: import org.eclipse.ui.internal.util.PrefUtil;
034: import org.eclipse.ui.themes.ITheme;
035: import org.eclipse.ui.themes.IThemePreview;
036:
037: /**
038: * @since 3.0
039: */
040: public class WorkbenchPreview implements IThemePreview {
041:
042: private static IPreferenceStore preferenceStore = WorkbenchPlugin
043: .getDefault().getPreferenceStore();
044:
045: // don't reset this dynamically, so just keep the information static.
046: // see bug:
047: // 75422 [Presentations] Switching presentation to R21 switches immediately, but only partially
048: private static int tabPos = preferenceStore
049: .getInt(IPreferenceConstants.VIEW_TAB_POSITION);
050:
051: private IPreferenceStore apiStore = PrefUtil
052: .getAPIPreferenceStore();
053:
054: private boolean disposed = false;
055:
056: private CTabFolder folder;
057:
058: private ITheme theme;
059:
060: private ToolBar toolBar;
061:
062: private CLabel viewMessage;
063:
064: private ViewForm viewForm;
065:
066: private IPropertyChangeListener fontAndColorListener = new IPropertyChangeListener() {
067: public void propertyChange(PropertyChangeEvent event) {
068: if (!disposed) {
069: setColorsAndFonts();
070: //viewMessage.setSize(viewMessage.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
071: viewForm.layout(true);
072: }
073: }
074: };
075:
076: /* (non-Javadoc)
077: * @see org.eclipse.ui.IPresentationPreview#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.themes.ITheme)
078: */
079: public void createControl(Composite parent, ITheme currentTheme) {
080: this .theme = currentTheme;
081: folder = new CTabFolder(parent, SWT.BORDER);
082: folder.setUnselectedCloseVisible(false);
083: folder.setEnabled(false);
084: folder.setMaximizeVisible(true);
085: folder.setMinimizeVisible(true);
086:
087: viewForm = new ViewForm(folder, SWT.NONE);
088: viewForm.marginHeight = 0;
089: viewForm.marginWidth = 0;
090: viewForm.verticalSpacing = 0;
091: viewForm.setBorderVisible(false);
092: toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.WRAP);
093: ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
094:
095: Image hoverImage = WorkbenchImages
096: .getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
097: toolItem.setImage(hoverImage);
098:
099: viewForm.setTopRight(toolBar);
100:
101: viewMessage = new CLabel(viewForm, SWT.NONE);
102: viewMessage.setText("Etu?"); //$NON-NLS-1$
103: viewForm.setTopLeft(viewMessage);
104:
105: CTabItem item = new CTabItem(folder, SWT.CLOSE);
106: item.setText("Lorem"); //$NON-NLS-1$
107: Label text = new Label(viewForm, SWT.NONE);
108: viewForm.setContent(text);
109: text.setText("Lorem ipsum dolor sit amet"); //$NON-NLS-1$
110: text.setBackground(parent.getDisplay().getSystemColor(
111: SWT.COLOR_WHITE));
112: item = new CTabItem(folder, SWT.CLOSE);
113: item.setText("Ipsum"); //$NON-NLS-1$
114: item.setControl(viewForm);
115: item.setImage(WorkbenchImages
116: .getImage(ISharedImages.IMG_TOOL_COPY));
117:
118: folder.setSelection(item);
119:
120: item = new CTabItem(folder, SWT.CLOSE);
121: item.setText("Dolor"); //$NON-NLS-1$
122: item = new CTabItem(folder, SWT.CLOSE);
123: item.setText("Sit"); //$NON-NLS-1$
124:
125: currentTheme.addPropertyChangeListener(fontAndColorListener);
126: setColorsAndFonts();
127: setTabPosition();
128: setTabStyle();
129: }
130:
131: /**
132: * Set the tab style from preferences.
133: */
134: protected void setTabStyle() {
135: boolean traditionalTab = apiStore
136: .getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS);
137: folder.setSimple(traditionalTab);
138: }
139:
140: /**
141: * Set the tab location from preferences.
142: */
143: protected void setTabPosition() {
144: tabPos = preferenceStore
145: .getInt(IPreferenceConstants.VIEW_TAB_POSITION);
146: folder.setTabPosition(tabPos);
147: }
148:
149: /**
150: * Set the folder colors and fonts
151: */
152: private void setColorsAndFonts() {
153: folder.setSelectionForeground(theme.getColorRegistry().get(
154: IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR));
155: folder.setForeground(theme.getColorRegistry().get(
156: IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR));
157:
158: Color[] colors = new Color[2];
159: colors[0] = theme.getColorRegistry().get(
160: IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
161: colors[1] = theme.getColorRegistry().get(
162: IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
163: colors[0] = theme.getColorRegistry().get(
164: IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
165: colors[1] = theme.getColorRegistry().get(
166: IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
167: folder
168: .setSelectionBackground(
169: colors,
170: new int[] { theme
171: .getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT) },
172: theme
173: .getBoolean(IWorkbenchThemeConstants.ACTIVE_TAB_VERTICAL));
174:
175: folder.setFont(theme.getFontRegistry().get(
176: IWorkbenchThemeConstants.TAB_TEXT_FONT));
177: viewMessage.setFont(theme.getFontRegistry().get(
178: IWorkbenchThemeConstants.VIEW_MESSAGE_TEXT_FONT));
179: }
180:
181: /* (non-Javadoc)
182: * @see org.eclipse.ui.IPresentationPreview#dispose()
183: */
184: public void dispose() {
185: disposed = true;
186: theme.removePropertyChangeListener(fontAndColorListener);
187: }
188: }
|