1 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 41 public class WorkbenchPreview implements IThemePreview { 42 43 private static IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault() 44 .getPreferenceStore(); 45 46 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 viewForm.layout(true); 71 } 72 } 73 }; 74 75 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?"); viewForm.setTopLeft(viewMessage); 103 104 CTabItem item = new CTabItem(folder, SWT.CLOSE); 105 item.setText("Lorem"); Label text = new Label(viewForm, SWT.NONE); 107 viewForm.setContent(text); 108 text.setText("Lorem ipsum dolor sit amet"); text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); 110 item = new CTabItem(folder, SWT.CLOSE); 111 item.setText("Ipsum"); 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"); item = new CTabItem(folder, SWT.CLOSE); 120 item.setText("Sit"); 122 currentTheme.addPropertyChangeListener(fontAndColorListener); 123 setColorsAndFonts(); 124 setTabPosition(); 125 setTabStyle(); 126 } 127 128 131 protected void setTabStyle() { 132 boolean traditionalTab = apiStore 133 .getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS); 134 folder.setSimple(traditionalTab); 135 } 136 137 140 protected void setTabPosition() { 141 tabPos = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION); 142 folder.setTabPosition(tabPos); 143 } 144 145 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 176 public void dispose() { 177 disposed = true; 178 theme.removePropertyChangeListener(fontAndColorListener); 179 } 180 } 181 | Popular Tags |