001: /*******************************************************************************
002: * Copyright (c) 2001, 2007 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.views.properties.tabbed.view;
011:
012: import org.eclipse.jface.resource.JFaceResources;
013: import org.eclipse.swt.SWT;
014: import org.eclipse.swt.custom.CLabel;
015: import org.eclipse.swt.events.PaintEvent;
016: import org.eclipse.swt.events.PaintListener;
017: import org.eclipse.swt.graphics.Color;
018: import org.eclipse.swt.graphics.Font;
019: import org.eclipse.swt.graphics.FontData;
020: import org.eclipse.swt.graphics.GC;
021: import org.eclipse.swt.graphics.Image;
022: import org.eclipse.swt.graphics.Rectangle;
023: import org.eclipse.swt.layout.FormAttachment;
024: import org.eclipse.swt.layout.FormData;
025: import org.eclipse.swt.layout.FormLayout;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.ui.forms.IFormColors;
028: import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
029:
030: /**
031: * The title in the tabbed property sheet page.
032: *
033: * @author Anthony Hunter
034: */
035: public class TabbedPropertyTitle extends Composite {
036:
037: private CLabel label;
038:
039: private Image image = null;
040:
041: private String text = null;
042:
043: private static final String BLANK = ""; //$NON-NLS-1$
044:
045: private static final String TITLE_FONT = "org.eclipse.ui.internal.views.properties.tabbed.view.TabbedPropertyTitle"; //$NON-NLS-1$
046:
047: private TabbedPropertySheetWidgetFactory factory;
048:
049: /**
050: * Constructor for TabbedPropertyTitle.
051: *
052: * @param parent
053: * the parent composite.
054: * @param factory
055: * the widget factory for the tabbed property sheet
056: */
057: public TabbedPropertyTitle(Composite parent,
058: TabbedPropertySheetWidgetFactory factory) {
059: super (parent, SWT.NO_FOCUS);
060: this .factory = factory;
061:
062: this .addPaintListener(new PaintListener() {
063:
064: public void paintControl(PaintEvent e) {
065: if (image == null
066: && (text == null || text.equals(BLANK))) {
067: label.setVisible(false);
068: } else {
069: label.setVisible(true);
070: drawTitleBackground(e);
071: }
072: }
073: });
074:
075: factory.getColors().initializeSectionToolBarColors();
076: setBackground(factory.getColors().getBackground());
077: setForeground(factory.getColors().getForeground());
078:
079: FormLayout layout = new FormLayout();
080: layout.marginWidth = 1;
081: layout.marginHeight = 2;
082: setLayout(layout);
083:
084: Font font;
085: if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) {
086: FontData[] fontData = JFaceResources.getHeaderFont()
087: .getFontData();
088: fontData[0].setHeight(10);
089: JFaceResources.getFontRegistry().put(TITLE_FONT, fontData);
090: }
091: font = JFaceResources.getFont(TITLE_FONT);
092:
093: label = factory.createCLabel(this , BLANK);
094: label.setBackground(new Color[] {
095: factory.getColors()
096: .getColor(IFormColors.H_GRADIENT_END),
097: factory.getColors().getColor(
098: IFormColors.H_GRADIENT_START) },
099: new int[] { 100 }, true);
100: label.setFont(font);
101: label.setForeground(factory.getColors().getColor(
102: IFormColors.TITLE));
103: FormData data = new FormData();
104: data.left = new FormAttachment(0, 0);
105: data.top = new FormAttachment(0, 0);
106: data.right = new FormAttachment(100, 0);
107: data.bottom = new FormAttachment(100, 0);
108: label.setLayoutData(data);
109:
110: /*
111: * setImage(PlatformUI.getWorkbench().getSharedImages().getImage(
112: * ISharedImages.IMG_OBJ_ELEMENT));
113: */
114: }
115:
116: /**
117: * @param e
118: */
119: protected void drawTitleBackground(PaintEvent e) {
120: Rectangle bounds = getClientArea();
121: label.setBackground(new Color[] {
122: factory.getColors()
123: .getColor(IFormColors.H_GRADIENT_END),
124: factory.getColors().getColor(
125: IFormColors.H_GRADIENT_START) },
126: new int[] { 100 }, true);
127: Color bg = factory.getColors().getColor(
128: IFormColors.H_GRADIENT_END);
129: Color gbg = factory.getColors().getColor(
130: IFormColors.H_GRADIENT_START);
131: GC gc = e.gc;
132: gc.setForeground(bg);
133: gc.setBackground(gbg);
134: gc.fillGradientRectangle(bounds.x, bounds.y, bounds.width,
135: bounds.height, true);
136: // background bottom separator
137: gc.setForeground(factory.getColors().getColor(
138: IFormColors.H_BOTTOM_KEYLINE1));
139: gc.drawLine(bounds.x, bounds.height - 2, bounds.x
140: + bounds.width - 1, bounds.height - 2);
141: gc.setForeground(factory.getColors().getColor(
142: IFormColors.H_BOTTOM_KEYLINE2));
143: gc.drawLine(bounds.x, bounds.height - 1, bounds.x
144: + bounds.width - 1, bounds.height - 1);
145: }
146:
147: /**
148: * Set the text label.
149: *
150: * @param text
151: * the text label.
152: * @param image
153: * the image for the label.
154: */
155: public void setTitle(String text, Image image) {
156: this.text = text;
157: this.image = image;
158: if (text != null) {
159: label.setText(text);
160: } else {
161: label.setText(BLANK);
162: }
163: label.setImage(image);
164: redraw();
165: }
166: }
|