01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.contributions;
11:
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.layout.FillLayout;
14: import org.eclipse.swt.widgets.Composite;
15: import org.eclipse.swt.widgets.Control;
16: import org.eclipse.swt.widgets.Label;
17: import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
18:
19: /**
20: * Moved from org.eclipse.ui.examples.readmetool
21: *
22: * @since 3.3
23: */
24: public class ExampleControlContribution extends
25: WorkbenchWindowControlContribution {
26: /*
27: * (non-Javadoc)
28: *
29: * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
30: */
31: protected Control createControl(Composite parent) {
32: // Create a composite to place the label in
33: Composite comp = new Composite(parent, SWT.NONE);
34:
35: // Give some room around the control
36: FillLayout layout = new FillLayout();
37: layout.marginHeight = 2;
38: layout.marginWidth = 2;
39: comp.setLayout(layout);
40:
41: // Create a label for the trim.
42: Label ccCtrl = new Label(comp, SWT.BORDER | SWT.CENTER);
43: ccCtrl.setBackground(parent.getDisplay().getSystemColor(
44: SWT.COLOR_DARK_BLUE));
45: ccCtrl.setForeground(parent.getDisplay().getSystemColor(
46: SWT.COLOR_WHITE));
47: ccCtrl
48: .setText(" Ctrl Contrib (" + getSideName(getCurSide()) + ")"); //$NON-NLS-1$ //$NON-NLS-2$
49: ccCtrl.setToolTipText("Ctrl Contrib Tooltip"); //$NON-NLS-1$
50:
51: return comp;
52: }
53:
54: private String getSideName(int side) {
55: if (side == SWT.TOP)
56: return "Top"; //$NON-NLS-1$
57: if (side == SWT.BOTTOM)
58: return "Bottom"; //$NON-NLS-1$
59: if (side == SWT.LEFT)
60: return "Left"; //$NON-NLS-1$
61: if (side == SWT.RIGHT)
62: return "Right"; //$NON-NLS-1$
63:
64: return "Unknown Side"; //$NON-NLS-1$
65: }
66: }
|