[draw2d] ZoomIn and ZoomOut 放大缩小

代码:

package com.iteye.xmind.draw2d.version2;

import org.eclipse.draw2d.Button;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.ScalableFreeformLayeredPane;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


public class ZoomInZoomOut
{
	private static ScalableFreeformLayeredPane chart;
	
	public static void main(String args[])
	{
		Shell shell = new Shell();
		shell.setSize(300,200);
		shell.open();
		shell.setText("F5 ZoomIn, F6 ZoomOut!");
		
		shell.addKeyListener(new KeyListener() {
			public void keyPressed(KeyEvent e) {
			}
			public void keyReleased(KeyEvent e) {
				if(e.keyCode == SWT.F5) {
					double scale = chart.getScale();
					chart.setScale(scale+0.2);
				}
				if(e.keyCode == SWT.F6) {
					double scale = chart.getScale();
					double newScale = scale-0.2;
					if (newScale > 0.5)
						chart.setScale(newScale);
					else
						chart.setScale(scale);
				}
			}
		});
		
		
		chart = new ScalableFreeformLayeredPane();

		Button b = new Button("F5 ZoomIn, F6 ZoomOut!");
		b.setBounds(new Rectangle(40,20,160,20));
		chart.add(b);

		LightweightSystem lws = new LightweightSystem(shell);
		lws.setContents(chart);
		chart.setSize(shell.getSize().x,shell.getSize().y);
		
		Display display = Display.getDefault();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
}

 

 

F5放大,F6缩小。

你可能感兴趣的:(draw2d)