Package es.iiia.sgi.controls

Source Code of es.iiia.sgi.controls.ZoomCombo

package es.iiia.sgi.controls;

import org.eclipse.jface.action.ControlContribution;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.PlatformUI;

import es.iiia.shapeeditor.ShapeEditor;

public class ZoomCombo extends ControlContribution {

  Combo combo;
  int selectedIndex;

  public ZoomCombo(String str) {
    super(str);
  }

  @Override
  protected Control createControl(Composite parent) {

    combo = new Combo(parent, SWT.NONE | SWT.DROP_DOWN | SWT.READ_ONLY);

    combo.add("15%");
    combo.add("25%");
    combo.add("50%");
    combo.add("75%");
    combo.add("100%");
    combo.add("150%");
    combo.add("200%");
    combo.add("300%");
    combo.add("500%");
    combo.setTextLimit(10);
    combo.select(4);
    //combo.setBackground(ColorConstants.Bold);
    combo.setToolTipText("Zoom Level");

    combo.addModifyListener(new ModifyListener() {
      public void modifyText(final ModifyEvent e) {
        ShapeEditor editor = ((ShapeEditor) PlatformUI
            .getWorkbench().getActiveWorkbenchWindow()
              .getActivePage().getActiveEditor());

        String txval = combo.getItem(combo.getSelectionIndex());
        txval = txval.replace('%', ' ').trim();
        int val = Integer.parseInt(txval);
       
        editor.setZoom((float) val / 100f);
        selectedIndex = combo.getSelectionIndex();
      }
    });

    return combo;
  }
}
TOP

Related Classes of es.iiia.sgi.controls.ZoomCombo

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.