1 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 37 public class TabbedPropertyTitle 38 extends Composite { 39 40 private CLabel label; 41 42 private Image image = null; 43 44 private String text = null; 45 46 private static final String BLANK = ""; 48 private static final String TITLE_FONT = "org.eclipse.ui.internal.views.properties.tabbed.view.TabbedPropertyTitle"; 50 private TabbedPropertySheetWidgetFactory factory; 51 52 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 112 } 113 114 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 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 149 public void setTitle(String 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 |