Package de.innovationgate.eclipse.utils.ui

Source Code of de.innovationgate.eclipse.utils.ui.WidgetFactory

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.utils.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Drawable;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class WidgetFactory {
 
  private FormToolkit _toolkit;

  public static final int DEFAULT_COMBO_STYLE = SWT.DROP_DOWN|SWT.READ_ONLY;
  public static final int DEFAULT_TEXT_STYLE = SWT.BORDER;
  public static final int DEFAULT_TEXTBOX_STYLE = SWT.BORDER|SWT.MULTI|SWT.WRAP| SWT.V_SCROLL;
 
  public WidgetFactory(FormToolkit toolkit) {
    _toolkit = toolkit;
  }
 
  public Label createLabel(Composite container, String label, String bindingKey) {
    _toolkit.createLabel(container, label);
        Label swtLabel  = _toolkit.createLabel(container, "");
        swtLabel.setData(bindingKey);
        return swtLabel;
  }
 
  public Combo createCombo(Composite container, String label, String bindingKey) {
    return createCombo(container, label, bindingKey, DEFAULT_COMBO_STYLE);
  }
 
  public Combo createCombo(Composite container, String label, String bindingKey, int style) {
    _toolkit.createLabel(container, label);   
      Combo combo = new Combo(container, style);     
      combo.setData(bindingKey);
      _toolkit.adapt(combo, true, true);
      return combo;
  }
 
  public void addFiller(Composite comp) {
    addFiller(comp, 1);
  }
 
  public void addFiller(Composite comp, int hSpan) {
    Label filler = _toolkit.createLabel(comp, "");
    GridData data = new GridData();
    data.horizontalSpan = hSpan;
    filler.setLayoutData(data);
  }
 
  public Text createText(Composite container, String label, String bindingKey) {
      _toolkit.createLabel(container, label);
      Text text = _toolkit.createText(container, "", DEFAULT_TEXT_STYLE);
      text.setData(bindingKey);
      return text;
  }
 
  public Text createTextArea(Composite container, String label, String bindingKey) {
      Label swtLabel = _toolkit.createLabel(container, label);
      swtLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
      Text text = _toolkit.createText(container, "", DEFAULT_TEXTBOX_STYLE);
      text.setData(bindingKey);
      return text;
  }
 
  public Button createCheckBox(Composite container, String label, String text, String bindingKey) {
    _toolkit.createLabel(container, label);
    Button btn =_toolkit.createButton(container, text, SWT.CHECK);
    btn.setData(bindingKey);
    return btn;
  }

 
  public static int computeFontHeight(Drawable element) {
    GC gc = new GC(element);
      FontMetrics fm = gc.getFontMetrics ();
      gc.dispose();
      return fm.getHeight();
  }

}
TOP

Related Classes of de.innovationgate.eclipse.utils.ui.WidgetFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.