KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > views > properties > tabbed > view > TabbedPropertyTitle


1 /*******************************************************************************
2  * Copyright (c) 2001, 2007 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.views.properties.tabbed.view;
12
13 import org.eclipse.jface.resource.JFaceResources;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.custom.CLabel;
16 import org.eclipse.swt.events.PaintEvent;
17 import org.eclipse.swt.events.PaintListener;
18 import org.eclipse.swt.graphics.Color;
19 import org.eclipse.swt.graphics.Font;
20 import org.eclipse.swt.graphics.FontData;
21 import org.eclipse.swt.graphics.GC;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.graphics.Rectangle;
24 import org.eclipse.swt.layout.FormAttachment;
25 import org.eclipse.swt.layout.FormData;
26 import org.eclipse.swt.layout.FormLayout;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.ui.forms.IFormColors;
29 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
30
31
32 /**
33  * The title in the tabbed property sheet page.
34  *
35  * @author Anthony Hunter
36  */

37 public class TabbedPropertyTitle
38     extends Composite {
39
40     private CLabel label;
41
42     private Image image = null;
43
44     private String JavaDoc text = null;
45     
46     private static final String JavaDoc BLANK = ""; //$NON-NLS-1$
47

48     private static final String JavaDoc TITLE_FONT = "org.eclipse.ui.internal.views.properties.tabbed.view.TabbedPropertyTitle"; //$NON-NLS-1$
49

50     private TabbedPropertySheetWidgetFactory factory;
51
52     /**
53      * Constructor for TabbedPropertyTitle.
54      *
55      * @param parent
56      * the parent composite.
57      * @param factory
58      * the widget factory for the tabbed property sheet
59      */

60     public TabbedPropertyTitle(Composite parent,
61             TabbedPropertySheetWidgetFactory factory) {
62         super(parent, SWT.NO_FOCUS);
63         this.factory = factory;
64
65         this.addPaintListener(new PaintListener() {
66
67             public void paintControl(PaintEvent e) {
68                 if (image == null && (text == null || text.equals(BLANK))) {
69                     label.setVisible(false);
70                 } else {
71                     label.setVisible(true);
72                     drawTitleBackground(e);
73                 }
74             }
75         });
76
77         factory.getColors().initializeSectionToolBarColors();
78         setBackground(factory.getColors().getBackground());
79         setForeground(factory.getColors().getForeground());
80
81         FormLayout layout = new FormLayout();
82         layout.marginWidth = 1;
83         layout.marginHeight = 2;
84         setLayout(layout);
85
86         Font font;
87         if (! JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) {
88             FontData[] fontData = JFaceResources.getHeaderFont().getFontData();
89             fontData[0].setHeight(10);
90             JFaceResources.getFontRegistry().put(TITLE_FONT, fontData);
91         }
92         font = JFaceResources.getFont(TITLE_FONT);
93         
94         label = factory.createCLabel(this, BLANK);
95         label.setBackground(new Color[] {
96                 factory.getColors().getColor(IFormColors.H_GRADIENT_END),
97                 factory.getColors().getColor(IFormColors.H_GRADIENT_START) },
98                 new int[] { 100 }, true);
99         label.setFont(font);
100         label.setForeground(factory.getColors().getColor(IFormColors.TITLE));
101         FormData data = new FormData();
102         data.left = new FormAttachment(0, 0);
103         data.top = new FormAttachment(0, 0);
104         data.right = new FormAttachment(100, 0);
105         data.bottom = new FormAttachment(100, 0);
106         label.setLayoutData(data);
107
108         /*
109          * setImage(PlatformUI.getWorkbench().getSharedImages().getImage(
110          * ISharedImages.IMG_OBJ_ELEMENT));
111          */

112     }
113
114     /**
115      * @param e
116      */

117     protected void drawTitleBackground(PaintEvent e) {
118         Rectangle bounds = getClientArea();
119         label.setBackground(new Color[] {
120                 factory.getColors().getColor(IFormColors.H_GRADIENT_END),
121                 factory.getColors().getColor(IFormColors.H_GRADIENT_START) },
122                 new int[] { 100 }, true);
123         Color bg = factory.getColors().getColor(IFormColors.H_GRADIENT_END);
124         Color gbg = factory.getColors().getColor(IFormColors.H_GRADIENT_START);
125         GC gc = e.gc;
126         gc.setForeground(bg);
127         gc.setBackground(gbg);
128         gc.fillGradientRectangle(bounds.x, bounds.y, bounds.width,
129                 bounds.height, true);
130         // background bottom separator
131
gc.setForeground(factory.getColors().getColor(
132                 IFormColors.H_BOTTOM_KEYLINE1));
133         gc.drawLine(bounds.x, bounds.height - 2, bounds.x + bounds.width - 1,
134                 bounds.height - 2);
135         gc.setForeground(factory.getColors().getColor(
136                 IFormColors.H_BOTTOM_KEYLINE2));
137         gc.drawLine(bounds.x, bounds.height - 1, bounds.x + bounds.width - 1,
138                 bounds.height - 1);
139     }
140
141     /**
142      * Set the text label.
143      *
144      * @param text
145      * the text label.
146      * @param image
147      * the image for the label.
148      */

149     public void setTitle(String JavaDoc text, Image image) {
150         this.text = text;
151         this.image = image;
152         if (text != null) {
153             label.setText(text);
154         } else {
155             label.setText(BLANK);
156         }
157         label.setImage(image);
158         redraw();
159     }
160 }
161
Popular Tags