1 16 package com.google.gwt.dev.shell; 17 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.events.DisposeEvent; 20 import org.eclipse.swt.events.DisposeListener; 21 import org.eclipse.swt.graphics.Color; 22 import org.eclipse.swt.layout.FillLayout; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.layout.RowLayout; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Label; 28 import org.eclipse.swt.widgets.ToolBar; 29 import org.eclipse.swt.widgets.ToolItem; 30 31 35 public class HeaderBarBase extends Composite implements DisposeListener { 36 37 private final Color bgColor; 38 private final ToolBar toolBar; 39 40 public HeaderBarBase(Composite parent) { 41 super(parent, SWT.NONE); 42 43 Composite outer = new Composite(this, SWT.NONE); 44 FillLayout fillLayout = new FillLayout(); 45 fillLayout.marginHeight = 1; 46 fillLayout.marginWidth = 1; 47 setLayout(fillLayout); 48 49 bgColor = new Color(null, 239, 237, 216); 50 addDisposeListener(this); 51 52 GridLayout gridLayout = new GridLayout(2, false); 53 gridLayout.marginLeft = 8; 54 gridLayout.marginRight = 2; 55 gridLayout.marginTop = 0; 56 gridLayout.marginBottom = 0; 57 gridLayout.marginWidth = 0; 58 gridLayout.marginHeight = 0; 59 outer.setLayout(gridLayout); 60 outer.setBackground(bgColor); 61 62 toolBar = new ToolBar(outer, SWT.FLAT); 63 toolBar.setBackground(new Color(null, 255, 0, 0)); 64 GridData data = new GridData(); 65 data.grabExcessHorizontalSpace = true; 66 data.verticalAlignment = SWT.CENTER; 67 data.horizontalAlignment = SWT.FILL; 68 toolBar.setLayoutData(data); 69 toolBar.setBackground(bgColor); 70 71 RowLayout rowLayout = new RowLayout(); 72 rowLayout.fill = true; 73 rowLayout.pack = false; 74 rowLayout.wrap = false; 75 toolBar.setLayout(rowLayout); 76 77 Label logoLabel = new Label(outer, SWT.BORDER | SWT.SHADOW_IN); 78 logoLabel.setImage(LowLevel.loadImage("logo.gif")); 79 logoLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); 80 } 81 82 public ToolBar getToolBar() { 83 return toolBar; 84 } 85 86 public ToolItem newItem(String imageName, String label, String tooltip) { 87 ToolItem item = new ToolItem(toolBar, SWT.PUSH); 88 item.setImage(LowLevel.loadImage(imageName)); 89 item.setText(label); 90 item.setSelection(false); 91 item.setToolTipText(tooltip); 92 item.setWidth(60); 93 return item; 94 } 95 96 public void newSeparator() { 97 new ToolItem(toolBar, SWT.SEPARATOR); 98 } 99 100 public void widgetDisposed(DisposeEvent e) { 101 bgColor.dispose(); 102 } 103 } 104 | Popular Tags |