001: /*
002: * Copyright 2006 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.dev.shell;
017:
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.events.DisposeEvent;
020: import org.eclipse.swt.events.DisposeListener;
021: import org.eclipse.swt.graphics.Color;
022: import org.eclipse.swt.layout.FillLayout;
023: import org.eclipse.swt.layout.GridData;
024: import org.eclipse.swt.layout.GridLayout;
025: import org.eclipse.swt.layout.RowLayout;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Label;
028: import org.eclipse.swt.widgets.ToolBar;
029: import org.eclipse.swt.widgets.ToolItem;
030:
031: /**
032: * Base class for <code>Composites</code> that contain <code>ToolItem</code>
033: * entities.
034: */
035: public class HeaderBarBase extends Composite implements DisposeListener {
036:
037: private final Color bgColor;
038: private final ToolBar toolBar;
039:
040: public HeaderBarBase(Composite parent) {
041: super (parent, SWT.NONE);
042:
043: Composite outer = new Composite(this , SWT.NONE);
044: FillLayout fillLayout = new FillLayout();
045: fillLayout.marginHeight = 1;
046: fillLayout.marginWidth = 1;
047: setLayout(fillLayout);
048:
049: bgColor = new Color(null, 239, 237, 216);
050: addDisposeListener(this );
051:
052: GridLayout gridLayout = new GridLayout(2, false);
053: gridLayout.marginLeft = 8;
054: gridLayout.marginRight = 2;
055: gridLayout.marginTop = 0;
056: gridLayout.marginBottom = 0;
057: gridLayout.marginWidth = 0;
058: gridLayout.marginHeight = 0;
059: outer.setLayout(gridLayout);
060: outer.setBackground(bgColor);
061:
062: toolBar = new ToolBar(outer, SWT.FLAT);
063: toolBar.setBackground(new Color(null, 255, 0, 0));
064: GridData data = new GridData();
065: data.grabExcessHorizontalSpace = true;
066: data.verticalAlignment = SWT.CENTER;
067: data.horizontalAlignment = SWT.FILL;
068: toolBar.setLayoutData(data);
069: toolBar.setBackground(bgColor);
070:
071: RowLayout rowLayout = new RowLayout();
072: rowLayout.fill = true;
073: rowLayout.pack = false;
074: rowLayout.wrap = false;
075: toolBar.setLayout(rowLayout);
076:
077: Label logoLabel = new Label(outer, SWT.BORDER | SWT.SHADOW_IN);
078: logoLabel.setImage(LowLevel.loadImage("logo.gif"));
079: logoLabel.setLayoutData(new GridData(
080: GridData.HORIZONTAL_ALIGN_END));
081: }
082:
083: public ToolBar getToolBar() {
084: return toolBar;
085: }
086:
087: public ToolItem newItem(String imageName, String label,
088: String tooltip) {
089: ToolItem item = new ToolItem(toolBar, SWT.PUSH);
090: item.setImage(LowLevel.loadImage(imageName));
091: item.setText(label);
092: item.setSelection(false);
093: item.setToolTipText(tooltip);
094: item.setWidth(60);
095: return item;
096: }
097:
098: public void newSeparator() {
099: new ToolItem(toolBar, SWT.SEPARATOR);
100: }
101:
102: public void widgetDisposed(DisposeEvent e) {
103: bgColor.dispose();
104: }
105: }
|